Class: Inbox::API
- Inherits:
-
Object
- Object
- Inbox::API
- Defined in:
- lib/inbox.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
-
#initialize(app_id, app_secret, access_token = nil, api_server = 'https://api.inboxapp.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 = '') ⇒ Object
- #url_for_path(path) ⇒ Object
Constructor Details
#initialize(app_id, app_secret, access_token = nil, api_server = 'https://api.inboxapp.com') ⇒ API
Returns a new instance of API.
46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/inbox.rb', line 46 def initialize(app_id, app_secret, access_token = nil, api_server = 'https://api.inboxapp.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 ::RestClient.add_before_execution_proc do |req, params| req.add_field('X-Inbox-API-Wrapper', 'ruby') end end |
Instance Attribute Details
#access_token ⇒ Object (readonly)
Returns the value of attribute access_token.
42 43 44 |
# File 'lib/inbox.rb', line 42 def access_token @access_token end |
#api_server ⇒ Object
Returns the value of attribute api_server.
41 42 43 |
# File 'lib/inbox.rb', line 41 def api_server @api_server end |
#app_id ⇒ Object (readonly)
Returns the value of attribute app_id.
43 44 45 |
# File 'lib/inbox.rb', line 43 def app_id @app_id end |
#app_secret ⇒ Object (readonly)
Returns the value of attribute app_secret.
44 45 46 |
# File 'lib/inbox.rb', line 44 def app_secret @app_secret end |
Instance Method Details
#namespaces ⇒ Object
Convenience Methods
88 89 90 91 |
# File 'lib/inbox.rb', line 88 def namespaces @namespaces ||= RestfulModelCollection.new(Namespace, self, nil) @namespaces end |
#set_access_token(token) ⇒ Object
68 69 70 |
# File 'lib/inbox.rb', line 68 def set_access_token(token) @access_token = token end |
#token_for_code(code) ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/inbox.rb', line 72 def token_for_code(code) data = { 'client_id' => app_id, 'client_secret' => app_secret, 'grant_type' => 'authorization_code', 'code' => code } ::RestClient.get("https://www.inboxapp.com/oauth/token", {:params => 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 = '') ⇒ Object
64 65 66 |
# File 'lib/inbox.rb', line 64 def url_for_authentication(redirect_uri, login_hint = '') "https://www.inboxapp.com/oauth/authorize?client_id=#{@app_id}&response_type=code&scope=email&login_hint=#{login_hint}&redirect_uri=#{redirect_uri}" end |
#url_for_path(path) ⇒ Object
58 59 60 61 62 |
# File 'lib/inbox.rb', line 58 def url_for_path(path) raise NoAuthToken.new if @access_token == nil protocol, domain = @api_server.split('//') "#{protocol}//#{@access_token}:@#{domain}#{path}" end |