Class: Gecko::Client

Inherits:
Object
  • Object
show all
Extended by:
Helpers::RecordHelper
Defined in:
lib/gecko/client.rb

Overview

The Gecko::Client class

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Helpers::RecordHelper

record

Constructor Details

#initialize(client_id, client_secret, options = {}) ⇒ undefined

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Initialize a new Gecko client object with an instantiated OAuth2::Client

Parameters:

  • client_id (String)
  • client_secret (String)
  • extra (#to_hash)

    options hash to pass to the OAuth2::Client



62
63
64
# File 'lib/gecko/client.rb', line 62

def initialize(client_id, client_secret, options = {})
  setup_oauth_client(client_id, client_secret, options)
end

Instance Attribute Details

#access_tokenOAuth2::AccessToken

Access the OAuth AccessToken for this client

Returns:

  • (OAuth2::AccessToken)


51
52
53
# File 'lib/gecko/client.rb', line 51

def access_token
  @access_token
end

#oauth_clientOAuth2::Client (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Return OAuth client

Returns:

  • (OAuth2::Client)


44
45
46
# File 'lib/gecko/client.rb', line 44

def oauth_client
  @oauth_client
end

Class Method Details

.default_headersObject



115
116
117
118
119
120
121
122
# File 'lib/gecko/client.rb', line 115

def self.default_headers
  {
    'User-Agent' => ["Gecko/#{Gecko::VERSION}",
                     "OAuth2/#{OAuth2::Version}",
                     "Faraday/#{Faraday::VERSION}",
                     "Ruby/#{RUBY_VERSION}"].join(' ')
  }
end

Instance Method Details

#adapter_for(klass_name) ⇒ Gecko::Record::BaseAdapter

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Fetch the adapter for a specified Gecko::Record class

Parameters:

  • klass_name (String)

    Gecko::Record subclass name

Returns:



111
112
113
# File 'lib/gecko/client.rb', line 111

def adapter_for(klass_name)
  public_send(klass_name.to_sym)
end

#authorize_from_existing(access_token, refresh_token, expires_at) ⇒ OAuth2::AccessToken

Authorize client from existing access and refresh token

Examples:

client.authorize_from_existing("ABC", "DEF", "1393982563")

Parameters:

  • access_token (String)
  • refresh_token (String)
  • expires_at (String)

Returns:

  • (OAuth2::AccessToken)


78
79
80
81
82
83
# File 'lib/gecko/client.rb', line 78

def authorize_from_existing(access_token, refresh_token, expires_at)
  @access_token = OAuth2::AccessToken.new(oauth_client, access_token, {
    refresh_token: refresh_token,
    expires_at:    expires_at
  })
end

#authorize_from_refresh_token(refresh_token) ⇒ OAuth2::AccessToken

Authorize client by fetching a new access_token via refresh token

Examples:

client.authorize_from_refresh_token("DEF")

Parameters:

  • refresh_token (String)

Returns:

  • (OAuth2::AccessToken)


95
96
97
98
99
100
101
102
# File 'lib/gecko/client.rb', line 95

def authorize_from_refresh_token(refresh_token)
  @access_token = oauth_client.get_token({
    client_id:     oauth_client.id,
    client_secret: oauth_client.secret,
    refresh_token: refresh_token,
    grant_type:    'refresh_token'
  })
end