README.md in inbox-0.18.2 vs README.md in inbox-1.0.0
- old
+ new
@@ -53,11 +53,11 @@
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 Nylas 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 Nylas, visit the [Developer Documentation](https://www.nylas.com/docs/knowledgebase#authentication).
+The Nylas 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 Nylas, visit the [Developer Documentation](https://nylas.com/docs/platform#authentication).
**Step 1: Redirect the user to Nylas:**
```ruby
require 'nylas'
@@ -111,53 +111,50 @@
### Fetching Namespaces
```ruby
nylas = Nylas::API.new(config.nylas_app_id, config.nylas_app_secret, nylas_token)
-# Get the first namespace
-namespace = nylas.namespaces.first
-
# Print out the email address and provider (Gmail, Exchange)
-puts namespace.email_address
-puts namespace.provider
+puts nylas.account.email_address
+puts nylas.account.provider
```
### Fetching Threads
```ruby
# Fetch the first thread
-thread = namespace.threads.first
+thread = nylas.threads.first
# Fetch a specific thread
-thread = namespace.threads.find('ac123acd123ef123')
+thread = nylas.threads.find('ac123acd123ef123')
# List all threads tagged `inbox`
# (paginating 50 at a time until no more are returned.)
-namespace.threads.where(:tag => 'inbox').each do |thread|
+nylas.threads.where(:tag => 'inbox').each do |thread|
puts thread.subject
end
# List the 5 most recent unread threads
-namespace.threads.where(:tag => 'unread').range(0,4).each do |thread|
+nylas.threads.where(:tag => 'unread').range(0,4).each do |thread|
puts thread.subject
end
# List all threads with 'ben@nylas.com'
-namespace.threads.where(:any_email => 'ben@nylas.com').each do |thread|
+nylas.threads.where(:any_email => 'ben@nylas.com').each do |thread|
puts thread.subject
end
# Get number of all threads
-count = namespace.threads.count
+count = nylas.threads.count
# Get number of threads with 'ben@inboxapp.com'
-count = namespace.threads.where(:any_email => 'ben@inboxapp.com').count
+count = nylas.threads.where(:any_email => 'ben@inboxapp.com').count
# Collect all threads with 'ben@nylas.com' into an array.
# Note: for large numbers of threads, this is not advised.
-threads = namespace.threads.where(:any_email => 'ben@nylas.com').all
+threads = nylas.threads.where(:any_email => 'ben@nylas.com').all
```
### Working with Threads
@@ -179,17 +176,17 @@
thread.update_tags!(tagsToAdd, tagsToRemove)
# Add a new label to a message
important = nil
-ns.labels.each do |label|
+nylas.labels.each do |label|
if label.display_name == 'Important'
important = label
end
end
-thread = ns.threads.where(:from => "helena@nylas.com").first
+thread = nylas.threads.where(:from => "helena@nylas.com").first
thread.labels.push(important)
thread.save!
# List messages
thread.messages.each do |message|
@@ -200,59 +197,59 @@
### Working with Files
```ruby
# List files
-namespace.files.each do |file|
+nylas.files.each do |file|
puts file.filename
end
# Create a new file
-file = namespace.files.build(:file => File.new("./public/favicon.ico", 'rb'))
+file = nylas.files.build(:file => File.new("./public/favicon.ico", 'rb'))
file.save!
```
-### Working with Labels/Folder
+### Working with Labels/Folders
The new folders and labels API replaces the now deprecated Tags API. It allows you to apply Gmail labels to whole threads or individual messages and, for providers other than Gmail, to move threads and messages between folders.
```ruby
# List labels
-namespace.labels.each do |label|
+nylas.labels.each do |label|
puts label.display_name, label.id
end
# Create a label
-label = ns.folders.build(:display_name => 'Test label', :name => 'test name')
+label = nylas.folders.build(:display_name => 'Test label', :name => 'test name')
label.save!
# Create a folder
#
# Note that Folders and Labels are absolutely identical from the standpoint of the SDK.
# The only difference is that a message can have many labels but only a single folder.
-fld = ns.folders.build(:display_name => 'Test folder', :name => 'test name')
+fld = nylas.folders.build(:display_name => 'Test folder', :name => 'test name')
fld.save!
# Rename a folder
#
# Note that you can not rename folders like INBOX, Trash, etc.
-fld = ns.folders.first
+fld = nylas.folders.first
fld.display_name = 'Renamed folder'
fld.save!
```
### 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@nylas.com`).all
+messages = nylas.messages.where(:to => 'ben@nylas.com`).all
```
-The `where` method accepts a hash of filters, as documented in the [Filters Documentation](https://www.nylas.com/docs/api#filters).
+The `where` method accepts a hash of filters, as documented in the [Filters Documentation](https://nylas.com/docs/platform#filters).
### Getting the raw contents of a message
It's possible to access the unprocessed contents of a message using the raw method:
@@ -263,11 +260,11 @@
### Creating and Sending Drafts
```ruby
# Create a new draft
-draft = namespace.drafts.build(
+draft = nylas.drafts.build(
:to => [{:name => 'Ben Gotow', :email => 'ben@nylas.com'}],
:subject => "Sent by Ruby",
:body => "Hi there!<strong>This is HTML</strong>"
)
@@ -286,12 +283,12 @@
### Creating an event
````ruby
# Every event is attached to a calendar -- get the id of the first calendar
-calendar_id = inbox.namespaces.first.calendars.first.id
-new_event = inbox.namespaces.first.events.build(:calendar_id => calendar_id, :title => 'Coffee?')
+calendar_id = nylas.calendars.first.id
+new_event = nylas.events.build(:calendar_id => calendar_id, :title => 'Coffee?')
# Modify attributes as necessary
new_event.location = "L'excelsior"
# Dates are expressed by the Inbox API as UTC timestamps
@@ -308,21 +305,20 @@
emailed_invite.rsvp!(status='yes', comment='I will come')
```
## Using the Delta sync API
-The delta sync API allows fetching all the changes that occured since a specified time. [Read this](https://nylas.com/docs/api#sync-protocol) for more details about the API.
+The delta sync API allows fetching all the changes that occured after a specific time. [Read this](https://nylas.com/docs/platform/#deltas) for more details about the API.
````ruby
-# Get all the messages starting from timestamp
-#
-# we first need to get a cursor object a cursor is simply the id of
-# an individual change.
-cursor = nylas.namespaces.first.get_cursor(1407543195)
+# Get an API cursor. Cursors are API objects identifying an individual change.
+# The latest cursor is the id of the latest change which was applied
+# to an API object (e.g: a message got read, an event got created, etc.)
+cursor = nylas.latest_cursor
last_cursor = nil
-nylas.namespaces.first.deltas(cursor) do |event, object|
+nylas.deltas(cursor) do |event, object|
if event == "create" or event == "modify"
if object.is_a?(Nylas::Contact)
puts "#{object.name} - #{object.email}"
elsif object.is_a?(Nylas::Event)
puts "Event!"
@@ -344,18 +340,14 @@
### Using the Delta sync streaming API
The streaming API will receive deltas in real time, without needing to repeatedly poll. It uses EventMachine for async IO.
````ruby
-# Get all the messages starting from timestamp
-#
-# we first need to get a cursor object a cursor is simply the id of
-# an individual change.
-cursor = inbox.namespaces.first.get_cursor(1407543195)
+cursor = nylas.latest_cursor
last_cursor = nil
-inbox.namespaces.first.delta_stream(cursor) do |event, object|
+nylas.delta_stream(cursor) do |event, object|
if event == "create" or event == "modify"
if object.is_a?(Inbox::Contact)
puts "#{object.name} - #{object.email}"
elsif object.is_a?(Inbox::Event)
puts "Event!"
@@ -374,15 +366,15 @@
```
### Exclude changes from a specific type --- get only messages
````ruby
-nylas.namespaces.first.deltas(cursor, exclude=[Nylas::Contact,
- Nylas::Event,
- Nylas::File,
- Nylas::Tag,
- Nylas::Thread]) do |event, object|
+nylas.deltas(cursor, exclude=[Nylas::Contact,
+ Nylas::Event,
+ Nylas::File,
+ Nylas::Tag,
+ Nylas::Thread]) do |event, object|
if event == 'create' or event == 'modify'
puts object.subject
end
end
```
@@ -408,15 +400,23 @@
## Open-Source Sync Engine
-The [Nylas Sync Engine](http://github.com/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, App Secret, and API Token, and pass the fully-qualified address to your copy of the sync engine:
+The [Nylas Sync Engine](http://github.com/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:
```ruby
-require 'inbox'
-inbox = Nylas::API.new(nil, nil, nil, 'http://localhost:5555/')
+require 'nylas'
+nylas = Nylas::API.new(nil, nil, nil, '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 contents of the first message for the first account
+nylas = Nylas::API.new(nil, nil, account_id, 'http://localhost:5555/')
+puts nylas.messages.first.contents
```
## Contributing
@@ -441,12 +441,12 @@
rake inbox_release
rake nylas_release
If it's your first time updating the ruby gems, you may be prompted for the username/password for rubygems.org. Members of the Nylas team can find that by doing `fetch-password rubygems`.
-## OAuth self-test
+## API self-tests
-Because it's very important that we don't break OAuth, we require releasers to run the OAuth self-test before releasing a version of the gem. The self-test is a small sinatra program which will ask you to click on a couple URLs. You need to make sure that following the URLs returns a working token.
+Because it's critical that we don't break the SDK for our customers, we require releasers to run some tests before releasing a new version of the gem. The test programs are located in the test/ directory. To set up them up, you'll need to copy `tests/credentials.rb.templates` as `test/credentials.rb` and edit the `APP_ID` and `APP_SECRET` with a working Nylas API app id and secret. You also need to set up a `/callback` URL in the Nylas admin panel.
-To set up the program, you need to copy `tests/credentials.rb.templates` as `test/credentials.rb` and edit the `APP_ID` and `APP_SECRET` with a working Nylas API app id and secret. You also need to set up a `/callback` URL in the Nylas admin panel.
-
-You can then run the program using `cd tests && ruby -I../lib auth.rb`
+You can run the programs like this:
+`cd tests && ruby -I../lib auth.rb`
+`cd tests && ruby -I../lib system.rb`