Git Product home page Git Product logo

exgrid's Introduction

ExGrid

Build Status Hex.pm

Elixir library to interact with Sendgrid's REST API

This is a WIP, YMMV

Installation

Hex does not include git repo's from mix, so you will have to add ibrowse to your deps.

In order to install it via hex, add exgrid and ibrowse package into the deps list of your mix.exs.

  defp deps do
    [
      {:ibrowse, github: "cmullaparthi/ibrowse", tag: "v4.1.0"},
      {:exgrid, "~> 0.2.3"}
    ]
  end

Usage

Send an email

ExGrid.Mail.send requires a credential Map and a message Map

  • note api_user and api_key must contain those keys or you will get a match error
{ :ok, creds } = ExGrid.credentials(%{api_key: key, api_user: user})
{ :ok, message } = ExGrid.Message.new([to: '[email protected]', subject: 'hello world', from: '[email protected]'])

{code, body} = ExGrid.Mail.send(creds, message)
code #=> 200
body #=> #HashDict<[{"message", "success"}]>

body is a json return code is the HTTP response code

Profile

Get your profile

{200, body } = ExGrid.Profile.get(creds)
IO.inspect body #=>
[#HashDict<[{"first_name", "John"}, {"username", "[email protected]"}, {"website_access", "true"}, {"phone", "123456789"}, {"state", "CO"}, {"last_name", "Doe"}, {"address2", ""}, {"city", "Denver"}, {"email", "[email protected]"}, {"website", "http://sendgrid.com"}, {"country", "US"}, {"active", "true"}, {"zip", "80020"}, {"address", "123 main st"}]>]

Set a profile attribute

{200, body} = ExGrid.Profile.set(creds, %{address: "456 Main st"})
IO.inspect body #=> #HashDict<[{"message", "success"}]>

Bounces

Please see docs for all parameters

{200, body} = ExGrid.Bounces.get(creds)
# return the `created` time for each bounce
{200, body} = ExGrid.Bounces.get(creds, %{date: 1})

remove bounces

{200, body} = ExGrid.Bounces.remove(creds, %{type: "soft"}) 
IO.inspect body #=> {"message", "success"}
{200, body} = ExGrid.Bounces.remove(creds, %{email: "[email protected]"}) 
IO.inspect body #=> {"message", "success"}

You can even get bounce counts

{200, body} = ExGrid.Bounces.count(creds)
IO.inspect body #=> {"count", "4"}

Blocks

Please see docs for all parameters

{200, body} = ExGrid.Blocks.get(creds)
# return the `created` time for each block
{200, body} = ExGrid.Blocks.get(creds, %{date: 1})

remove blocks

  • only parameter accepted is email
{200, body} = ExGrid.Blocks.remove(creds, %{email: "[email protected]"}) 
IO.inspect body #=> {"message", "success"}

You can even get block counts

{200, body} = ExGrid.Blocks.count(creds)
IO.inspect body #=> {"count", "4"}

Statistics

Please see docs for all parameters

{200, body} = ExGrid.Statistics.get(creds)
IO.inspect body #=>
HashDict<[
[
   {
      "date": "2014-02-26",
      "delivered": 314,
      "unsubscribes": 1,
      "invalid_email": 5,
      "bounces": 9,
      "repeat_unsubscribes": 2,
      "unique_clicks": 65,
      "blocked": 3,
      "spam_drop": 5,
      "repeat_bounces": 8,
      "repeat_spamreports": 9,
      "requests": 350,
      "spamreports": 1,
      "clicks": 78,
      "opens": 80,
      "unique_opens": 70
]>

Number of days in the past to include statistics (Includes today)

{200, body} = ExGrid.Statistics.get(creds, %{days: 1})

List all categories

{200, body} = ExGrid.Statistics.categories(creds)

You can even get aggregate stats

{200, body} = ExGrid.Statistics.get(creds, %{aggregate: 1})

Tests

You must supply your credentials as environment vars to run tests.

API_KEY="secret" API_USER="[email protected]" mix test test

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.