Class: ActiveDatastore::Client

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

Instance Method Summary collapse

Constructor Details

#initialize(email, secret) ⇒ Client

Returns a new instance of Client.



5
6
7
8
9
10
11
12
13
14
# File 'lib/active_datastore/client.rb', line 5

def initialize email, secret
  @client = Google::APIClient.new
  key = Google::APIClient::KeyUtils.load_from_pkcs12(secret, 'notasecret')
   = Google::APIClient::JWTAsserter.new(
    email,
    ['https://www.googleapis.com/auth/datastore', 'https://www.googleapis.com/auth/userinfo.email'],
  	key)
  @client.authorization = .authorize

end

Instance Method Details

#apiObject



20
21
22
# File 'lib/active_datastore/client.rb', line 20

def api
	@api ||= @client.discovered_api('datastore', 'v1beta1').datasets
end

#execute(opts) ⇒ Object



24
25
26
27
28
29
30
# File 'lib/active_datastore/client.rb', line 24

def execute opts
	@client.execute({
		api_method: api.send(opts[:method]),
		body_object: opts[:body],
		parameters: opts[:params]
	})
end

#valid?Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/active_datastore/client.rb', line 16

def valid?
	not @client.authorization.expired?
end