README.md in inbox-1.3.0 vs README.md in inbox-2.0.0

- old
+ new

@@ -81,11 +81,13 @@ user_email = 'ben@nylas.com' # This URL must be registered with your application in the developer portal callback_url = url_for(:action => 'login_callback') - redirect_to nylas.url_for_authentication(callback_url, user_email) + # You can also optionally pass state, an optional arbitrary string that + # will be passed back to us at the end of the auth flow. + redirect_to nylas.url_for_authentication(callback_url, user_email, {:state => 'ben auth'}) end ``` **Step 2: Handle the Authentication Response:** @@ -456,27 +458,40 @@ The streaming API will receive deltas in real time, without needing to repeatedly poll. It uses EventMachine for async IO. ```ruby cursor = nylas.latest_cursor -last_cursor = nil -nylas.delta_stream(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!" +EventMachine.run do + nylas.delta_stream(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!" + end + elsif event == "delete" + # In the case of a deletion, the API only returns the ID of the object. + # In this case, the Ruby SDK returns a dummy object with only the id field + # set. + puts "Deleting from collection #{object.class.name}, id: #{object}" end - elsif event == "delete" - # In the case of a deletion, the API only returns the ID of the object. - # In this case, the Ruby SDK returns a dummy object with only the id field - # set. - puts "Deleting from collection #{object.class.name}, id: #{object}" end - last_cursor = object.cursor +end +``` - # This will loop indefintely +To receive streams from multiple accounts, call `delta_stream` for each of them inside an `EventMachine.run` block. + +```ruby +api_handles = [] # a list of Nylas::API objects + +EventMachine.run do + api_handles.each do |a| + cursor = a.latest_cursor() + a.delta_stream(cursor) do |event, object| + puts object + end + end end ``` ### Exclude changes from a specific type --- get only messages @@ -539,12 +554,12 @@ # 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 +# Display the body of the first message for the first account nylas = Nylas::API.new(nil, nil, account_id, 'http://localhost:5555/') -puts nylas.messages.first.contents +puts nylas.messages.first.body ``` ## Contributing