Class: Soothsayer::API

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/soothsayer.rb

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.api_clientObject

Returns the value of attribute api_client.



40
41
42
# File 'lib/soothsayer.rb', line 40

def api_client
  @api_client
end

Class Method Details

.create_clientObject

Raises:



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/soothsayer.rb', line 52

def create_client
  raise OAuthTokenError, 'Please configure Soothsayer first with Soothsayer.config.' if Soothsayer.credentials.nil?
  client = Google::APIClient.new(:authorization => :oauth_2)
  unless client.authorization.nil?
    client.authorization.scope = nil
    client.authorization.client_id = Soothsayer.credentials.client_id
    client.authorization.client_secret = Soothsayer.credentials.client_secret
    client.authorization.access_token = Soothsayer.credentials.access_token
    client.authorization.refresh_token = Soothsayer.credentials.refresh_token
    client.register_discovery_uri('discovery', 'v1.5', nil)
    self.api_client = client
  else
    raise OAuthTokenError
  end
end

.oauth_tokenObject



42
43
44
45
46
47
48
49
50
# File 'lib/soothsayer.rb', line 42

def oauth_token
  if api_client.nil?
    create_client
    api_client.authorization.fetch_access_token!
  elsif api_client.authorization.expired?
    api_client.authorization.fetch_access_token!
  end
  api_client.authorization.access_token
end