Class: ContextIO::API
- Inherits:
-
Object
- Object
- ContextIO::API
- Defined in:
- lib/contextio/api.rb,
lib/contextio/api/resource.rb,
lib/contextio/api/url_builder.rb,
lib/contextio/api/association_helpers.rb,
lib/contextio/api/resource_collection.rb
Overview
For internal use only. Users of this gem should not be using this directly. Represents the handle on the Context.IO API. It handles the user's OAuth credentials with Context.IO and signing requests, etc.
Defined Under Namespace
Modules: AssociationHelpers, Resource, ResourceCollection Classes: Error, URLBuilder
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.
-
.url_for(resource) ⇒ String
The URL for the resource in the API.
- .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 = {}) ⇒ API
constructor
A new instance of API.
-
#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.
-
#url_for(resource) ⇒ String
The URL for the resource in the API.
- #user_agent_string ⇒ Object
Constructor Details
#initialize(key, secret, opts = {}) ⇒ API
Returns a new instance of API.
69 70 71 72 73 74 75 |
# File 'lib/contextio/api.rb', line 69 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.
56 57 58 |
# File 'lib/contextio/api.rb', line 56 def base_url @base_url end |
#key ⇒ String (readonly)
Returns The OAuth key for the user's Context.IO account.
64 65 66 |
# File 'lib/contextio/api.rb', line 64 def key @key end |
#opts ⇒ Object (readonly)
Returns the value of attribute opts.
64 |
# File 'lib/contextio/api.rb', line 64 attr_reader :key, :secret, :opts |
#secret ⇒ String (readonly)
Returns The OAuth secret for the user's Context.IO account.
64 |
# File 'lib/contextio/api.rb', line 64 attr_reader :key, :secret, :opts |
#version ⇒ Object
Returns the value of attribute version.
56 57 58 |
# File 'lib/contextio/api.rb', line 56 def version @version end |
Class Method Details
.base_url ⇒ String
Returns The base URL the API is served from.
30 31 32 |
# File 'lib/contextio/api.rb', line 30 def self.base_url BASE_URL end |
.url_for(resource) ⇒ String
Returns The URL for the resource in the API.
37 38 39 |
# File 'lib/contextio/api.rb', line 37 def self.url_for(resource) ContextIO::API::URLBuilder.url_for(resource) end |
.user_agent_string ⇒ Object
48 49 50 |
# File 'lib/contextio/api.rb', line 48 def self.user_agent_string "contextio-ruby-#{ContextIO.version}" end |
.version ⇒ String
Returns The version of the Context.IO API this version of the gem is intended for use with.
22 23 24 |
# File 'lib/contextio/api.rb', line 22 def self.version 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.
83 84 85 |
# File 'lib/contextio/api.rb', line 83 def path(resource_path, params = {}) "/#{version}/#{strip_resource_path(resource_path)}#{API.hash_to_url_params(params)}" end |
#raw_request(method, resource_path, params = {}) ⇒ Object
104 105 106 107 108 109 110 |
# File 'lib/contextio/api.rb', line 104 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.
96 97 98 99 100 101 102 |
# File 'lib/contextio/api.rb', line 96 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 |
#url_for(resource) ⇒ String
Returns The URL for the resource in the API.
44 45 46 |
# File 'lib/contextio/api.rb', line 44 def url_for(resource) ContextIO::API.url_for(resource) end |
#user_agent_string ⇒ Object
52 53 54 |
# File 'lib/contextio/api.rb', line 52 def user_agent_string self.class.user_agent_string end |