Module: BusinessInsightApiClient::Api::Applications

Included in:
Client
Defined in:
lib/business_insight_api_client/api/applications.rb

Overview

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

Instance Method Summary collapse

Instance Method Details

#get_access_token(client_credential_token, installation_id) ⇒ OAuth2::AccessToken

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

Examples:

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

Parameters:

  • client_credential_token (OAuth2::AccessToken)

    the client credential token as retrieves with a client credential request.

  • installation_id (Integer)

    the installation to find.

Returns:

  • (OAuth2::AccessToken)

    the access token.

See Also:



48
49
50
51
# 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) ⇒ Hash{Integer => OAuth2::AccessToken}

Retrieves an access token for a specific application.

Examples:

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

Parameters:

  • client_credential_token (OAuth2::AccessToken)

    the client credential token as retrieved with a client credential request.

Returns:

  • (Hash{Integer => OAuth2::AccessToken})

    all access tokens with the installation id as key and token as value.

See Also:



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# 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