Class: ContextIO::API::AbstractAPI
- Inherits:
-
Object
- Object
- ContextIO::API::AbstractAPI
- Defined in:
- lib/contextio/api/abstract_api.rb
Direct Known Subclasses
Constant Summary collapse
- BASE_URL =
'https://api.context.io'
Instance Attribute Summary collapse
-
#base_url ⇒ Object
Returns the value of attribute base_url.
-
#key ⇒ String
readonly
The OAuth key for the user’s Context.IO account.
-
#opts ⇒ Object
readonly
Returns the value of attribute opts.
-
#secret ⇒ String
readonly
The OAuth secret for the user’s Context.IO account.
-
#version ⇒ Object
Returns the value of attribute version.
Class Method Summary collapse
-
.base_url ⇒ String
The base URL the API is served from.
- .user_agent_string ⇒ Object
-
.version ⇒ String
The version of the Context.IO API this version of the gem is intended for use with.
Instance Method Summary collapse
-
#initialize(key, secret, opts = {}) ⇒ AbstractAPI
constructor
A new instance of AbstractAPI.
-
#path(resource_path, params = {}) ⇒ Object
Generates the path for a resource_path and params hash for use with the API.
- #raw_request(method, resource_path, params = {}) ⇒ Object
-
#request(method, resource_path, params = {}) ⇒ Object
Makes a request against the Context.IO API.
- #user_agent_string ⇒ Object
Constructor Details
#initialize(key, secret, opts = {}) ⇒ AbstractAPI
Returns a new instance of AbstractAPI.
46 47 48 49 50 51 52 |
# File 'lib/contextio/api/abstract_api.rb', line 46 def initialize(key, secret, opts={}) @key = key @secret = secret @opts = opts || {} @base_url = self.class.base_url @version = self.class.version end |
Instance Attribute Details
#base_url ⇒ Object
Returns the value of attribute base_url.
33 34 35 |
# File 'lib/contextio/api/abstract_api.rb', line 33 def base_url @base_url end |
#key ⇒ String (readonly)
Returns The OAuth key for the user’s Context.IO account.
41 42 43 |
# File 'lib/contextio/api/abstract_api.rb', line 41 def key @key end |
#opts ⇒ Object (readonly)
Returns the value of attribute opts.
41 |
# File 'lib/contextio/api/abstract_api.rb', line 41 attr_reader :key, :secret, :opts |
#secret ⇒ String (readonly)
Returns The OAuth secret for the user’s Context.IO account.
41 |
# File 'lib/contextio/api/abstract_api.rb', line 41 attr_reader :key, :secret, :opts |
#version ⇒ Object
Returns the value of attribute version.
33 34 35 |
# File 'lib/contextio/api/abstract_api.rb', line 33 def version @version end |
Class Method Details
.base_url ⇒ String
Returns The base URL the API is served from.
21 22 23 |
# File 'lib/contextio/api/abstract_api.rb', line 21 def self.base_url BASE_URL end |
.user_agent_string ⇒ Object
25 26 27 |
# File 'lib/contextio/api/abstract_api.rb', line 25 def self.user_agent_string raise NotDefinedError, 'user_agent_string undefined in your API subclassed model.' end |
.version ⇒ String
Returns The version of the Context.IO API this version of the gem is intended for use with.
15 16 17 18 |
# File 'lib/contextio/api/abstract_api.rb', line 15 def self.version raise NotDefinedError, 'VERSION is not defined in your API subclassed model.' if self::VERSION.nil? self::VERSION end |
Instance Method Details
#path(resource_path, params = {}) ⇒ Object
Generates the path for a resource_path and params hash for use with the API.
60 61 62 |
# File 'lib/contextio/api/abstract_api.rb', line 60 def path(resource_path, params = {}) "/#{version}/#{strip_resource_path(resource_path)}#{self.class.hash_to_url_params(params)}" end |
#raw_request(method, resource_path, params = {}) ⇒ Object
81 82 83 84 85 86 87 |
# File 'lib/contextio/api/abstract_api.rb', line 81 def raw_request(method, resource_path, params={}) response = oauth_request(method, resource_path, params) with_error_handling(response) do |response| response.body end end |
#request(method, resource_path, params = {}) ⇒ Object
Makes a request against the Context.IO API.
73 74 75 76 77 78 79 |
# File 'lib/contextio/api/abstract_api.rb', line 73 def request(method, resource_path, params = {}) response = oauth_request(method, resource_path, params, { 'Accept' => 'application/json' }) with_error_handling(response) do |response| parse_json(response.body) end end |
#user_agent_string ⇒ Object
29 30 31 |
# File 'lib/contextio/api/abstract_api.rb', line 29 def user_agent_string self.class.user_agent_string end |