Code Monkey home page Code Monkey logo

nylas-ruby's Introduction

Nylas REST API Ruby bindings Travis build status

Maintainability Test Coverage

This README is for the Nylas Ruby SDK version 4. For those who are still using Nylas Ruby SDK Version 3, the documentation and source code is located in the 3.X-master branch. For those upgrading from 3.X to 4.0, review the upgrade guide

Installation

Add this line to your application's Gemfile:

gem 'nylas'

And then execute:

bundle

You don't need to use this repo unless you're planning to modify the gem. If you just want to use the Nylas SDK with Ruby bindings, you should run:

gem install nylas

MacOS 10.11 (El Capitan) note

Apple stopped bundling openssl with MacOS 10.11. However, one of the dependencies of this gem (EventMachine) requires it. If you're on El Capitan and are unable to install the gem, try running the following commands in a terminal:

sudo brew install openssl
sudo brew link openssl --force
gem install nylas

Requirements

  • Ruby 2.3 or above.
  • rest-client, json, yajl-ruby, em-http-request

Supported Rails Versions

We support Rails 4.2 and above. A more detailed compatibility list can be found in our list of Gemfiles

Examples

Examples are located in the examples directory. Examples in plain ruby are in examples/plain-ruby/. They are grouped by the API endpoints they interact with.

Scopes

The Nylas API allows you to set various scopes during the authentication process in order to use the Selective Sync feature. Currently, these scopes are email, calendar, and contacts. You can pass an array of scopes to Nylas::API#authenticate, like this:

api = Nylas::API.new()
api.authenticate(
    name: 'fake',
    email_address: '[email protected]',
    provider: :gmail,
    settings: {},
    scopes: ["email"]
)

If you do not pass any scopes, then the SDK will default to using all of them.

Handling Errors

The Nylas API uses conventional HTTP response codes to indicate success or failure of an API request. The ruby gem raises these as native exceptions.

Code Error Type Description
400 InvalidRequest Your request has invalid parameters.
403 AccessDenied You don't have authorization to access the requested resource or perform the requested action. You may need to re-authenticate the user.
404 ResourceNotFound The requested resource doesn't exist.
500 InternalError There was an internal error with the Nylas server.
502 BadGateway Nylas received an invalid response from the upstream server.

A few additional exceptions are raised by the draft.send! method if your draft couldn't be sent.

Code Error Type Description
402 MessageRejected The message was syntactically valid, but rejected for delivery by the mail server.
422 MailProviderError There was an error with the mail provider when trying to send the message
429 SendingQuotaExceeded The user has exceeded their daily sending quota.
503 ServiceUnavailable There was a temporary error establishing a connection to the user's mail server.

Open-Source Sync Engine

The Nylas Sync Engine is open source, and you can also use the Ruby gem with the open source API. Since the open source API provides no authentication or security, connecting to it is simple. When you instantiate the Nylas object, provide nil for the App ID and App Secret, and set the API Token to the id of the account you're going to access. Finally, don't forget to pass the fully-qualified address to your copy of the sync engine:

require 'nylas'
nylas = Nylas::API.new(api_server: 'http://localhost:5555/')

# Get the id of the first account -- this is the access token we're
# going to use.
account_id = nylas.accounts.first.id

# Display the body of the first message for the first account
nylas = Nylas::API.new(access_token: account_id, api_server: 'http://localhost:5555/')
puts nylas.messages.first.body

Development

Requirements

Install RubyGems if you don't have it

gem install bundler
gem update --system

Setup

bundle install

You can run tests locally using rspec

rspec spec

Contributing

Our guidelines for contributing are in CONTRIBUTING.md.

nylas-ruby's People

Contributors

khamidou avatar zspencer avatar bengotow avatar spang avatar singingwolfboy avatar pfista avatar stevenharman avatar mguymon avatar kartiktalwar avatar grinich avatar brettgerry avatar emfree avatar amanda103 avatar hayleycanderson avatar marshall-lee avatar ajhodges avatar sionide21 avatar kamilbielawski avatar dem avatar flyingclimber avatar 34ndju avatar 0xflotus avatar adarsh avatar jastkand avatar brianjolney avatar cberkom avatar dkirilenko avatar jockee avatar hartator avatar

Watchers

James Cloos 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.