Class: Inbox::API
- Inherits:
-
Object
- Object
- Inbox::API
- Defined in:
- lib/inbox.rb,
lib/nylas.rb
Instance Attribute Summary collapse
-
#access_token ⇒ Object
readonly
Returns the value of attribute access_token.
-
#api_server ⇒ Object
Returns the value of attribute api_server.
-
#app_id ⇒ Object
readonly
Returns the value of attribute app_id.
-
#app_secret ⇒ Object
readonly
Returns the value of attribute app_secret.
Instance Method Summary collapse
-
#accounts ⇒ Object
Billing Methods.
-
#initialize(app_id, app_secret, access_token = nil, api_server = 'https://api.nylas.com', service_domain = 'api.nylas.com') ⇒ API
constructor
A new instance of API.
-
#namespaces ⇒ Object
Convenience Methods.
- #set_access_token(token) ⇒ Object
- #token_for_code(code) ⇒ Object
- #url_for_authentication(redirect_uri, login_hint = '', options = {}) ⇒ Object
- #url_for_management ⇒ Object
- #url_for_path(path) ⇒ Object
Constructor Details
#initialize(app_id, app_secret, access_token = nil, api_server = 'https://api.nylas.com', service_domain = 'api.nylas.com') ⇒ API
Returns a new instance of API.
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/inbox.rb', line 70 def initialize(app_id, app_secret, access_token = nil, api_server = 'https://api.nylas.com', service_domain = 'api.nylas.com') raise "When overriding the Inbox API server address, you must include https://" unless api_server.include?('://') @api_server = api_server @access_token = access_token @app_secret = app_secret @app_id = app_id @service_domain = service_domain @version = Inbox::VERSION if ::RestClient.before_execution_procs.empty? ::RestClient.add_before_execution_proc do |req, params| req.add_field('X-Inbox-API-Wrapper', 'ruby') req['User-Agent'] = "Nylas Ruby SDK #{@version} - #{RUBY_VERSION}" end end end |
Instance Attribute Details
#access_token ⇒ Object (readonly)
Returns the value of attribute access_token.
66 67 68 |
# File 'lib/inbox.rb', line 66 def access_token @access_token end |
#api_server ⇒ Object
Returns the value of attribute api_server.
65 66 67 |
# File 'lib/inbox.rb', line 65 def api_server @api_server end |
#app_id ⇒ Object (readonly)
Returns the value of attribute app_id.
67 68 69 |
# File 'lib/inbox.rb', line 67 def app_id @app_id end |
#app_secret ⇒ Object (readonly)
Returns the value of attribute app_secret.
68 69 70 |
# File 'lib/inbox.rb', line 68 def app_secret @app_secret end |
Instance Method Details
#accounts ⇒ Object
Billing Methods
134 135 136 137 |
# File 'lib/inbox.rb', line 134 def accounts @accounts ||= ManagementModelCollection.new(Account, self, nil) @accounts end |
#namespaces ⇒ Object
Convenience Methods
127 128 129 130 |
# File 'lib/inbox.rb', line 127 def namespaces @namespaces ||= RestfulModelCollection.new(Namespace, self, nil) @namespaces end |
#set_access_token(token) ⇒ Object
107 108 109 |
# File 'lib/inbox.rb', line 107 def set_access_token(token) @access_token = token end |
#token_for_code(code) ⇒ Object
111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/inbox.rb', line 111 def token_for_code(code) data = { 'client_id' => app_id, 'client_secret' => app_secret, 'grant_type' => 'authorization_code', 'code' => code } ::RestClient.post("https://#{@service_domain}/oauth/token", data) do |response, request, result| json = Inbox.interpret_response(result, response, :expected_class => Object) return json['access_token'] end end |
#url_for_authentication(redirect_uri, login_hint = '', options = {}) ⇒ Object
94 95 96 97 98 99 100 |
# File 'lib/inbox.rb', line 94 def url_for_authentication(redirect_uri, login_hint = '', = {}) trialString = 'false' if [:trial] == true trialString = 'true' 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}" end |
#url_for_management ⇒ Object
102 103 104 105 |
# File 'lib/inbox.rb', line 102 def url_for_management protocol, domain = @api_server.split('//') accounts_path = "#{protocol}//#{@app_secret}:@#{domain}/a/#{@app_id}/accounts" end |
#url_for_path(path) ⇒ Object
88 89 90 91 92 |
# File 'lib/inbox.rb', line 88 def url_for_path(path) raise NoAuthToken.new if @access_token == nil and (@app_secret != nil or @app_id != nil) protocol, domain = @api_server.split('//') "#{protocol}//#{@access_token}:@#{domain}#{path}" end |