Class: GcDatastore::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/gc_datastore/client.rb

Constant Summary collapse

SCOPE =
['https://www.googleapis.com/auth/datastore',
'https://www.googleapis.com/auth/userinfo.email']

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Client

Returns a new instance of Client.



6
7
8
9
10
# File 'lib/gc_datastore/client.rb', line 6

def initialize(options)
  @client = Google::APIClient.new(
    :application_name => options[:app_name],
    :application_version => options[:version])
end

Instance Method Details

#authorize(options) ⇒ Object



12
13
14
15
16
17
18
19
20
21
# File 'lib/gc_datastore/client.rb', line 12

def authorize(options)
  private_key = Google::APIClient::KeyUtils.load_from_pkcs12(options[:key_path], 'noasecret')
  @client.authorization = Signet::OAuth2::Client.new(
    :token_credential_uri => 'https://accounts.google.com/o/oauth2/token',
    :audience => 'https://accounts.google.com/o/oauth2/token',
    :scope => SCOPE,
    :issuer => options[:account],
    :signing_key => private_key)
  @client.authorization.fetch_access_token!
end