README.md in inbox-0.13.0 vs README.md in inbox-0.14.0

- old
+ new

@@ -1,6 +1,6 @@ -# Inbox Ruby bindings +# Nilas REST API Ruby bindings ## Installation Add this line to your application's Gemfile: @@ -22,11 +22,11 @@ - rest-client, json ## Example Rails App -A small example Rails app is included in the `example` directory. You can run the sample app to see how an authentication flow might be implemented. +A small example Rails app is included in the `example` directory. You can run the sample app to see how an authentication flow might be implemented. `cd example` `RESTCLIENT_LOG=stdout rails s` @@ -34,85 +34,85 @@ ## Usage ### App ID and Secret -Before you can interact with the Inbox API, you need to register for the Inbox Developer Program at [http://www.inboxapp.com/](http://www.inboxapp.com/). After you've created a developer account, you can create a new application to generate an App ID / Secret pair. +Before you can interact with the Inbox API, you need to register for the Nilas Developer Program at [https://www.nilas.com/](https://www.nilas.com/). After you've created a developer account, you can create a new application to generate an App ID / Secret pair. Generally, you should store your App ID and Secret into environment variables to avoid adding them to source control. That said, in the example project and code snippets below, the values were added to `config/environments/development.rb` for convenience. ### Authentication -The Inbox API uses server-side (three-legged) OAuth, and the Ruby gem provides convenience methods that simplify the OAuth process. For more information about authenticating with Inbox, visit the [Developer Documentation](https://www.inboxapp.com/docs/gettingstarted-hosted#authenticating). +The Nilas REST API uses server-side (three-legged) OAuth, and the Ruby gem provides convenience methods that simplify the OAuth process. For more information about authenticating with Nilas, visit the [Developer Documentation](https://www.nilas.com/docs/gettingstarted-hosted#authenticating). -**Step 1: Redirect the user to Inbox:** +**Step 1: Redirect the user to Nilas:** ```ruby require 'inbox' def login inbox = Inbox::API.new(config.inbox_app_id, config.inbox_app_secret, nil) # The email address of the user you want to authenticate - user_email = 'ben@inboxapp.com' + user_email = 'ben@nilas.com' # This URL must be registered with your application in the developer portal callback_url = url_for(:action => 'login_callback') - + redirect_to inbox.url_for_authentication(callback_url, user_email) end ``` **Step 2: Handle the Authentication Response:** ```ruby -def login_callback +def login_callback inbox = Inbox::API.new(config.inbox_app_id, config.inbox_app_secret, nil) inbox_token = inbox.token_for_code(params[:code]) # Save the inbox_token to the current session, save it to the user model, etc. end ``` ### Managing Billing -If you're using the open-source version of the Inbox API or have fewer than 10 accounts associated with your developer app, you don't need to worry about billing. However, if you've requested production access to the Inbox API, you are billed monthly based on the number of email accounts you've connected to Inbox. You can choose to start accounts in "trial" state and sync slowly at a rate of one message per minute so users can try out your app. If you use trial mode, you need to upgrade accounts (and start paying for them) within 30 days or they will automatically expire. You may wish to upgrade accounts earlier to dramatically speed up the mail sync progress depending on your app's needs. +If you're using the open-source version of the Nilas Sync Engine or have fewer than 10 accounts associated with your developer app, you don't need to worry about billing. However, if you've requested production access to the Sync Engine, you are billed monthly based on the number of email accounts you've connected to Inbox. You can choose to start accounts in "trial" state and sync slowly at a rate of one message per minute so users can try out your app. If you use trial mode, you need to upgrade accounts (and start paying for them) within 30 days or they will automatically expire. You may wish to upgrade accounts earlier to dramatically speed up the mail sync progress depending on your app's needs. **Starting an Account in Trial Mode** -When you're redirecting the user to Inbox to authenticate with their email provider, +When you're redirecting the user to Nilas to authenticate with their email provider, pass the additional `trial: true` option to start their account in trial mode. ```ruby redirect_to inbox.url_for_authentication(callback_url, user_email, {trial: true}) ``` **Upgrading an Account** ```ruby - # Initialize an Inbox object with your app ID and secret, and the API token - # for the user account you'd like to upgrade. - inbox = Inbox::API.new(config.inbox_app_id, config.inbox_app_secret, inbox_token) - inbox.upgrade_account! + inbox = Inbox::API.new(config.inbox_app_id, config.inbox_app_secret, nil) + account = inbox.accounts.find(account_id) + account.upgrade! ``` **Cancelling an Account** ```ruby - inbox = Inbox::API.new(config.inbox_app_id, config.inbox_app_secret, inbox_token) - inbox.downgrade_account! + inbox = Inbox::API.new(config.inbox_app_id, config.inbox_app_secret, nil) + account = inbox.accounts.find(account_id) + account.downgrade! # Your Inbox API token will be revoked, you will not be charged ``` ### Account Status ````ruby # Query the status of every account linked to the app inbox = Inbox::API.new(config.inbox_app_id, config.inbox_app_secret, inbox_token) accounts = inbox.accounts - accounts.map { |a| [a.account_id, a.sync_state] } # Available fields are: account_id, sync_state, trial and trial_expires. See lib/account.rb for more details. + accounts.each { |a| [a.account_id, a.sync_state] } # Available fields are: account_id, sync_state, trial, trial_expires, billing_state and namespace_id. See lib/account.rb for more details. ``` ### Fetching Namespaces ```ruby @@ -138,25 +138,31 @@ # List all threads tagged `inbox` # (paginating 50 at a time until no more are returned.) namespace.threads.where(:tag => 'inbox').each do |thread| puts thread.subject -end +end # List the 5 most recent unread threads namespace.threads.where(:tag => 'unread').range(0,4).each do |thread| puts thread.subject -end +end -# List all threads with 'ben@inboxapp.com' -namespace.threads.where(:any_email => 'ben@inboxapp.com').each do |thread| +# List all threads with 'ben@nilas.com' +namespace.threads.where(:any_email => 'ben@nilas.com').each do |thread| puts thread.subject -end +end -# Collect all threads with 'ben@inboxapp.com' into an array. +# Get number of all threads +count = namespace.threads.count + +# Get number of threads with 'ben@inboxapp.com' +count = namespace.threads.where(:any_email => 'ben@inboxapp.com').count + +# Collect all threads with 'ben@nilas.com' into an array. # Note: for large numbers of threads, this is not advised. -threads = namespace.threads.where(:any_email => 'ben@inboxapp.com').all +threads = namespace.threads.where(:any_email => 'ben@nilas.com').all ``` ### Working with Threads @@ -200,14 +206,14 @@ ### Working with Messages, Contacts, etc. Each of the primary collections (contacts, messages, etc.) behave the same way as `threads`. For example, finding messages with a filter is similar to finding threads: ```ruby -messages = namespace.messages.where(:to => 'ben@inboxapp.com`).all +messages = namespace.messages.where(:to => 'ben@nilas.com`).all ``` -The `where` method accepts a hash of filters, as documented in the [Inbox Filters Documentation](https://www.inboxapp.com/docs/api#filters). +The `where` method accepts a hash of filters, as documented in the [Inbox Filters Documentation](https://www.nilas.com/docs/api#filters). ### Getting the raw contents of a message It's possible to access the unprocessed contents of a message using the raw method: @@ -219,26 +225,25 @@ ### Creating and Sending Drafts ```ruby # Create a new draft draft = namespace.drafts.build( - :to => [{:name => 'Ben Gotow', :email => 'ben@inboxapp.com'}], + :to => [{:name => 'Ben Gotow', :email => 'ben@nilas.com'}], :subject => "Sent by Ruby", :body => "Hi there!<strong>This is HTML</strong>" ) # Modify attributes as necessary -draft.cc = [{:name => 'Michael', :email => 'mg@inboxapp.com'}] +draft.cc = [{:name => 'Michael', :email => 'mg@nilas.com'}] # Add the file we uploaded as an attachment draft.attach(file) # Save the draft draft.save! -# Send the draft. This method returns immediately and queues the message -# with Inbox for delivery through the user's SMTP gateway. +# Send the draft. draft.send! ``` ### Creating an event @@ -255,38 +260,57 @@ # Persist the event --- it's automatically synced back to the Google or Exchange calendar new_event.save! ``` +### Handling Errors +The Nilas 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 | APIError | There was an internal error with the Nilas 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. +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 [Inbox Sync Engine](http://github.com/inboxapp/inbox) 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 Inbox object, provide nil for the App ID, App Secret, and API Token, and pass the fully-qualified address to your copy of the sync engine: +The [Nilas Sync Engine](http://github.com/inboxapp/inbox) 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 Inbox object, provide `nil` for the App ID, App Secret, and API Token, and pass the fully-qualified address to your copy of the sync engine: ```ruby require 'inbox' inbox = Inbox::API.new(nil, nil, nil, 'http://localhost:5555/') ``` ## Contributing -We'd love your help making the Inbox ruby gem better. Join the Google Group for project updates and feature discussion. We also hang out in `##inbox` on [irc.freenode.net](http://irc.freenode.net), or you can email [help@inboxapp.com](mailto:help@inboxapp.com). +We'd love your help making the Nilas ruby gem better. Join the Google Group for project updates and feature discussion. We also hang out in `#nilas` on [irc.freenode.net](http://irc.freenode.net), or you can email [support@nilas.com](mailto:support@nilas.com). -Please sign the Contributor License Agreement before submitting pull requests. (It's similar to other projects, like NodeJS or Meteor.) +Please sign the [Contributor License Agreement](https://www.nilas.com/cla.html) before submitting pull requests. (It's similar to other projects, like NodeJS or Meteor.) Tests can be run with: rspec spec -## Deployment +## Deployment -The Inbox ruby gem uses [Jeweler](https://github.com/technicalpickles/jeweler) for release management. Jeweler should be installed automatically when you call `bundle`, and extends `rake` to include a few more commands. When you're ready to release a new version, do something like this: +The Nilas ruby gem uses [Jeweler](https://github.com/technicalpickles/jeweler) for release management. Jeweler should be installed automatically when you call `bundle`, and extends `rake` to include a few more commands. When you're ready to release a new version, edit `lib/version.rb` and then build: - rake version:bump:minor (or :major or :patch) rake build Test your new version (found in `pkg/`) locally, and then release with: rake release -If it's your first time updating the ruby gem, you may be prompted for the username/password for rubygems.org. Members of the Inbox team can find that by doing `fetch-password rubygems`. +If it's your first time updating the ruby gem, you may be prompted for the username/password for rubygems.org. Members of the Nilas team can find that by doing `fetch-password rubygems`.