class BusinessInsightApiClient::Client

The client that has to make requests to the Business Insight Api. This class includes all api endpoint methods. See section Instance Method Summary, for available methods.

@example Call an API method

client = BusinessInsightApiClient::Client.new
access_token = client.authorization.access_token_from_hash(token: 'abc', refresh_token: 'efc', expires_in: 30020, expires_at: 23939192)
client.access_token= access_token
animals = client.animals

@see Api::Applications Applications endpoint methods. @see Api::Animals Animals endpoint methods. @see Api::Calendar Calendar endpoint methods. @see Api::Groups Groups endpoint methods. @see Api::Installations Installations endpoint methods.

Attributes

options[R]

Lists all options that are set for the client.

Public Class Methods

new(options = {}) click to toggle source

Initializes a new Client with options. If no options are given the default configuration options are used for the client, like configured in BusinessInsightApiClient.configure. @example

BusinessInsightApiClient::Client.new api_url: 'some url', client_id: 'some id' , client_secret: 'some secret'

@param [Hash] options the options to configure the client. @option options [String] :api_url (BusinessInsightApiClient.api_url) the api url. @option options [String] :authorization_url (BusinessInsightApiClient.authorization_url) the authorization url of the api. @option options [String] :content_type (BusinessInsightApiClient.default_content_type) the content type used for sending and requesting. @option options [String] :client_id (BusinessInsightApiClient.client_id) the client id uses in OAuth authorization. @option options [String] :client_secret (BusinessInsightApiClient.client_secret) the client secret uses in OAuth authorization.

# File lib/business_insight_api_client/client.rb, line 40
def initialize(options = {})
  @options = options
  @options[:api_url] ||= BusinessInsightApiClient.api_url
  @options[:authorization_url] ||= BusinessInsightApiClient.authorization_url
  @options[:content_type] ||= BusinessInsightApiClient.default_content_type
  @options[:client_id] ||= BusinessInsightApiClient.client_id
  @options[:client_secret] ||= BusinessInsightApiClient.client_secret
end

Public Instance Methods

access_token=(token) click to toggle source

Sets the access token to make requests with to the protected endpoints. Make sure the access token is not expired, or has enough time to make requests. Otherwise refresh the token with {OAuth2::AccessToken#refresh!} @param [OAuth2::AccessToken] token sets a auth token to make requests with. @see www.rubydoc.info/gems/oauth2/1.0.0/OAuth2/AccessToken OAuth2::AccessToken information @see www.rubydoc.info/gems/oauth2/1.0.0/OAuth2/AccessToken#refresh%21-instance_method Refreshing an Access Token.

# File lib/business_insight_api_client/client.rb, line 65
def access_token=(token)
  # TODO: fail when not access token class.
  authorization.current_token = token
end
authorization() click to toggle source

Creates new or returns an existing Authorization helper. The helper can be used to retrieve OAuth Tokens from the Authorization server. The helper passes default options as configured with the client.

@return [BusinessInsightApiClient::Helpers::Authorization] authorization helper.

# File lib/business_insight_api_client/client.rb, line 54
def authorization
  @authorization ||= BusinessInsightApiClient::Helpers::Authorization.new(options)
end

Private Instance Methods

client() click to toggle source
# File lib/business_insight_api_client/client.rb, line 72
def client
  @client ||= BusinessInsightApiClient::Helpers::RESTClient.new(authorization, options)
end