lib/inbox.rb in nylas-1.3.0 vs lib/inbox.rb in nylas-2.0.0

- old
+ new

@@ -1,10 +1,11 @@ require 'json' require 'rest-client' require 'yajl' require 'em-http' require 'ostruct' +require 'active_support/core_ext/hash' require 'account' require 'api_account' require 'api_thread' require 'calendar' @@ -111,15 +112,24 @@ protocol, domain = @api_server.split('//') "#{protocol}//#{@access_token}:@#{domain}#{path}" end def url_for_authentication(redirect_uri, login_hint = '', options = {}) - trialString = 'false' - if options[:trial] == true - trialString = 'true' + params = { + :client_id => @app_id, + :trial => options.fetch(:trial, false), + :response_type => 'code', + :scope => 'email', + :login_hint => login_hint, + :redirect_uri => redirect_uri, + } + + if options.has_key?(:state) then + params[:state] = options[:state] end - "https://#{@service_domain}/oauth/authorize?client_id=#{@app_id}&trial=#{trialString}&response_type=code&scope=email&login_hint=#{login_hint}&redirect_uri=#{redirect_uri}" + + "https://#{@service_domain}/oauth/authorize?" + params.to_query end def url_for_management protocol, domain = @api_server.split('//') accounts_path = "#{protocol}//#{@app_secret}:@#{domain}/a/#{@app_id}/accounts" @@ -201,27 +211,10 @@ else @accounts ||= RestfulModelCollection.new(APIAccount, self) end end - def get_cursor(timestamp) - # Get the cursor corresponding to a specific timestamp. - warn "Nylas#get_cursor is deprecated. Use Nylas#latest_cursor instead." - - path = self.url_for_path("/delta/generate_cursor") - data = { :start => timestamp } - - cursor = nil - - RestClient.post(path, data.to_json, :content_type => :json) do |response,request,result| - json = Inbox.interpret_response(result, response, {:expected_class => Object}) - cursor = json["cursor"] - end - - cursor - end - def latest_cursor # Get the cursor corresponding to a specific timestamp. path = self.url_for_path("/delta/latest_cursor") cursor = nil @@ -362,18 +355,20 @@ obj.cursor = delta["cursor"] yield delta["event"], obj end end - EventMachine.run do - http = EventMachine::HttpRequest.new(path, :connect_timeout => 0, :inactivity_timeout => timeout).get(:keepalive => true) - http.stream do |chunk| - parser << chunk - end - http.errback do - raise UnexpectedResponse.new http.error - end + http = EventMachine::HttpRequest.new(path, :connect_timeout => 0, :inactivity_timeout => timeout).get(:keepalive => true) + + # set a callback on the HTTP stream that parses incoming chunks as they come in + http.stream do |chunk| + parser << chunk end + + http.errback do + raise UnexpectedResponse.new http.error + end + end end end Nylas = Inbox.clone