Class: GoogleClient::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/google_client/configuration.rb

Overview

Configuration class

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



42
43
44
45
46
47
# File 'lib/google_client/configuration.rb', line 42

def initialize
  @redirect_uris = []
  @javascript_origins = []
  @auth_uri = 'https://accounts.google.com/o/oauth2/auth'
  @token_uri = 'https://accounts.google.com/o/oauth2/token'
end

Instance Attribute Details

#app_nameObject

Returns the value of attribute app_name.



33
34
35
# File 'lib/google_client/configuration.rb', line 33

def app_name
  @app_name
end

#app_versionObject

Returns the value of attribute app_version.



33
34
35
# File 'lib/google_client/configuration.rb', line 33

def app_version
  @app_version
end

#auth_uriObject

Returns the value of attribute auth_uri.



33
34
35
# File 'lib/google_client/configuration.rb', line 33

def auth_uri
  @auth_uri
end

#client_idObject

Returns the value of attribute client_id.



33
34
35
# File 'lib/google_client/configuration.rb', line 33

def client_id
  @client_id
end

#client_secretObject

Returns the value of attribute client_secret.



33
34
35
# File 'lib/google_client/configuration.rb', line 33

def client_secret
  @client_secret
end

#javascript_originsObject

Returns the value of attribute javascript_origins.



33
34
35
# File 'lib/google_client/configuration.rb', line 33

def javascript_origins
  @javascript_origins
end

#redirect_urisObject

Returns the value of attribute redirect_uris.



33
34
35
# File 'lib/google_client/configuration.rb', line 33

def redirect_uris
  @redirect_uris
end

#token_uriObject

Returns the value of attribute token_uri.



33
34
35
# File 'lib/google_client/configuration.rb', line 33

def token_uri
  @token_uri
end

Instance Method Details

#authorizationObject



66
67
68
69
70
71
72
73
74
# File 'lib/google_client/configuration.rb', line 66

def authorization
  errors = []

  errors << 'app_name not set' unless @app_name.present?
  errors << 'app_version not set' unless @app_version.present?

  fail "Couldn't create the authorizationt:\n" << errors.to_sentence unless errors.blank?
  Google::APIClient::ClientSecrets.new(to_hash).to_authorization
end

#clientObject



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/google_client/configuration.rb', line 49

def client
  return @client if @client
  errors = []

  # symbols = %i(app_name app_version)
  # symbols.each do |sym|
  #   errors << errors_for(sym)
  # end
  errors << 'app_name not set' unless @app_name.present?
  errors << 'app_version not set' unless @app_version.present?

  fail "Couldn't create the client:\n" << errors.to_sentence unless errors.blank?

  @client = Google::APIClient.new(application_name: @app_name,
                                  application_version: @app_version)
end

#to_hashObject



76
77
78
79
80
81
82
83
84
85
# File 'lib/google_client/configuration.rb', line 76

def to_hash
  { web: {
    client_id: @client_id,
    client_secret: @client_secret,
    redirect_uris: @redirect_uris,
    javascript_origins: @javascript_origins,
    auth_uri: @auth_uri,
    token_uri: @token_uri,
  } }.with_indifferent_access
end