Module: ElvantoAPI
- Defined in:
- lib/elvanto.rb,
lib/elvanto/error.rb,
lib/elvanto/pager.rb,
lib/elvanto/utils.rb,
lib/elvanto/client.rb,
lib/elvanto/version.rb,
lib/elvanto/resources/resource.rb
Defined Under Namespace
Modules: Resource, Utils Classes: BadRequest, Client, Error, InternalError, NotFound, Pager, StandardError, Unauthorized
Constant Summary collapse
- CLASS_MAPPING =
{}
- VERSION =
"1.0.2"
Class Attribute Summary collapse
-
.client ⇒ Object
Returns the value of attribute client.
-
.config ⇒ Object
Returns the value of attribute config.
-
.tokens ⇒ Object
Returns the value of attribute tokens.
Class Method Summary collapse
-
.authorize_url(client_id, redirect_uri, scope = "AdministerAccount", state = nil) ⇒ String
The authorization URL to which users of your application should be redirected.
- .call(endpoint, options = {}) ⇒ Object
-
.configure(options = {}) ⇒ Object
In order to authenticate with access token: options = “access_token”, … In order to authenticate with API key: options = “api_key”, ….
-
.exchange_token(client_id, client_secret, code, redirect_uri) ⇒ Hash
The hash with keys ‘access_token’, ‘expires_in’, and ‘refresh_token’.
- .post(href, options = {}) ⇒ Object
-
.refresh_token(token = nil) ⇒ Hash
The hash with keys ‘access_token’, ‘expires_in’, and ‘refresh_token’.
Class Attribute Details
.client ⇒ Object
Returns the value of attribute client.
28 29 30 |
# File 'lib/elvanto.rb', line 28 def client @client end |
.config ⇒ Object
Returns the value of attribute config.
29 30 31 |
# File 'lib/elvanto.rb', line 29 def config @config end |
.tokens ⇒ Object
Returns the value of attribute tokens.
30 31 32 |
# File 'lib/elvanto.rb', line 30 def tokens @tokens end |
Class Method Details
.authorize_url(client_id, redirect_uri, scope = "AdministerAccount", state = nil) ⇒ String
Returns The authorization URL to which users of your application should be redirected.
49 50 51 52 53 54 55 56 57 58 |
# File 'lib/elvanto.rb', line 49 def (client_id, redirect_uri, scope="AdministerAccount", state=nil) scope = scope.join(",") if scope.class == Array params = {type: "web_server", client_id: client_id, redirect_uri: redirect_uri, scope: scope} params[:state] = state if state uri = Addressable::URI.new({:host => config[:host],:scheme => config[:scheme], :path => "oauth",:query_values => params}) return uri.to_s end |
.call(endpoint, options = {}) ⇒ Object
91 92 93 94 |
# File 'lib/elvanto.rb', line 91 def call(endpoint, ={}) response = post endpoint, return response.body end |
.configure(options = {}) ⇒ Object
In order to authenticate with access token: options = “access_token”, … In order to authenticate with API key: options = “api_key”, …
36 37 38 39 40 |
# File 'lib/elvanto.rb', line 36 def configure(={}) @config = @config.merge() @config[:access_token] ||= tokens[:access_token] @client = ElvantoAPI::Client.new(@config) end |
.exchange_token(client_id, client_secret, code, redirect_uri) ⇒ Hash
Returns The hash with keys ‘access_token’, ‘expires_in’, and ‘refresh_token’.
65 66 67 68 69 70 |
# File 'lib/elvanto.rb', line 65 def exchange_token(client_id, client_secret, code, redirect_uri) params = {grant_type: 'authorization_code', client_id: client_id, client_secret: client_secret, code: code, redirect_uri: redirect_uri} response = Faraday.new(client.url).post "oauth/token", params @tokens = JSON.parse(response.body, :symbolize_keys => true) return @tokens end |
.post(href, options = {}) ⇒ Object
84 85 86 |
# File 'lib/elvanto.rb', line 84 def post(href, ={}) self.client.post href, end |
.refresh_token(token = nil) ⇒ Hash
Returns The hash with keys ‘access_token’, ‘expires_in’, and ‘refresh_token’.
74 75 76 77 78 79 80 81 82 |
# File 'lib/elvanto.rb', line 74 def refresh_token(token=nil) token ||= tokens[:refresh_token] raise "Error refreshing token. There is no refresh token set on this object" unless token params = {grant_type: "refresh_token", refresh_token: token} response = Faraday.new(client.url).post "oauth/token", params @tokens = JSON.parse(response.body,:symbolize_keys => true) return @tokens end |