module BusinessInsightApiClient::Api::Applications

Applications API based methods. This module contains methods to query the Applications API.

Public Instance Methods

get_access_token(client_credential_token, installation_id) click to toggle source

Retrieves an access token belonging to the application for a specific installation.

@example

client = BusinessInsightApiClient::Client.new
token = client.get_access_token(client.authorization.get_login_token, 20)

@param client_credential_token [OAuth2::AccessToken] the client credential token as retrieves with a client credential request. @param installation_id [Integer] the installation to find. @return [OAuth2::AccessToken] the access token. @see www.rubydoc.info/gems/oauth2/1.0.0/OAuth2/AccessToken OAuth2::AccessToken information @see BusinessInsightApiClient::Helpers::Authorization @see BusinessInsightApiClient::Client

# File lib/business_insight_api_client/api/applications.rb, line 48
def get_access_token(client_credential_token, installation_id)
  tokens = get_access_tokens(client_credential_token)
  tokens[installation_id]
end
get_access_tokens(client_credential_token) click to toggle source

Retrieves an access token for a specific application.

@example

client = BusinessInsightApiClient::Client.new
tokens = client.get_access_tokens(client.authorization.get_login_token)
tokens.each do |installation_id, token|
  ......
end

@param client_credential_token [OAuth2::AccessToken] the client credential token as retrieved with a client credential request. @return [Hash{Integer => OAuth2::AccessToken}] all access tokens with the installation id as key and token as value. @see www.rubydoc.info/gems/oauth2/1.0.0/OAuth2/AccessToken OAuth2::AccessToken information @see BusinessInsightApiClient::Helpers::Authorization @see BusinessInsightApiClient::Client

# File lib/business_insight_api_client/api/applications.rb, line 20
def get_access_tokens(client_credential_token)
  tokens = ::BusinessInsightApiClient::Mash.from_json client.get('/applications/access_tokens', header: client_credential_token.headers)
  expired_time = Time.now
  Hash[tokens.access_tokens.collect do |token|
         [
             token.resource_owner_id,
             authorization.access_token_from_hash(
                 token: token.token,
                 expires_in: token.expires_in_seconds,
                 expires_at: Time.now.to_i + token.expires_in_seconds,
                 refresh_token: token.refresh_token
             )
         ]
       end]

end