Coder Social home page Coder Social logo

elixir-gmail's Introduction

elixir-gmail

Build Status Coverage Status hex.pm version hex.pm downloads Inline docs

A simple Gmail REST API client for Elixir.

You can find the hex package here, and the docs here.

You can find documentation for Gmail's API at https://developers.google.com/gmail/api/

Usage

First, add the client to your mix.exs dependencies:

def deps do
  [{:gmail, "~> 0.1"}]
end

Then run $ mix do deps.get, compile to download and compile your dependencies.

Finally, add the :gmail application as your list of applications in mix.exs:

def application do
  [applications: [:logger, :gmail]]
end

Before you can work with mail for a user you'll need to start a process for them.

{:ok, pid} = Gmail.User.start_mail("[email protected]", "user-refresh-token")

When a user process starts it will automatically fetch a new access token for that user. Then you can start playing with mail:

# fetch a list of threads
{:ok, threads, next_page_token} = Gmail.User.threads("[email protected]") 

# fetch the next page of threads using a page token
{:ok, _, _} = Gmail.User.threads("[email protected]", %{page_token: next_page_token}) 

# fetch a thread by ID
{:ok, thread} = Gmail.User.thread("[email protected]", "1233454566") 

# fetch a list of labels
{:ok, labels} = Gmail.User.labels("[email protected]") 

Check the docs for a more complete list of functionality.

API Support

  • Threads
    • get
    • list
    • modify
    • delete
    • trash
    • untrash
  • Messages
    • delete
    • get
    • insert
    • list
    • modify
    • send
    • trash
    • untrash
    • import
    • batchDelete
  • Labels
    • create
    • delete
    • list
    • update
    • get
    • update
    • patch
  • Drafts
    • list
    • get
    • delete
    • update
    • create
    • send
    • send (with upload)
  • History
  • Attachments

Auth

As of now the library doesn't do the initial auth generation for you; you'll need to create an app on the Google Developer Console to get a client ID and secret and authorize a user to get an authorization code, which you can trade for an access token.

The library will however, when you supply a refresh token, use that to refresh an expired access token for you. Take a look in the dev.exs.sample config file to see what your config should look like.

TODO

  • Stop mocking HTTP requests and use Bypass instead
  • Add format option when fetching threads
  • .. and messages
  • .. and drafts
  • Batched requests

elixir-gmail's People

Contributors

craigp avatar

Watchers

 avatar

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.