module ElvantoAPI
Constants
- CLASS_MAPPING
- VERSION
Attributes
Public Class Methods
@param [String] enpoint The name of endpoint, for example: “people/getAll” or “groups/GetInfo” @param [Hash] option List of parametrs @result [Hash] Body of the API response
# File lib/elvanto.rb, line 91 def call(endpoint, options={}) response = post endpoint, options return response.body end
@params [Hash] options Connection configuration options In order to authenticate with access token: options = {access_token: “access_token”, …} In order to authenticate with API key: options = {api_key: “api_key”, …}
# File lib/elvanto.rb, line 36 def configure(options={}) @config = @config.merge(options) @config[:access_token] ||= tokens[:access_token] @client = ElvantoAPI::Client.new(@config) end
@params [String] client_id The Client
ID of your registered OAuth application. @param [String] client_secret The Client
Secret of your registered OAuth application. @param [String] code The unique OAuth code to be exchanged for an access token. @param [String] redirect_url The Redirect URI of your registered OAuth application. @return [Hash] The hash with keys 'access_token', 'expires_in', and 'refresh_token'
# 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
# File lib/elvanto.rb, line 84 def post(href, options={}) self.client.post href, options end
@param [String] refresh_token
Was included when the original token was granted to automatically retrieve a new access token. @return [Hash] The hash with keys 'access_token', 'expires_in', and 'refresh_token'
# 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