Class: Google::APIClient::ClientSecrets

Inherits:
Object
  • Object
show all
Defined in:
lib/google/api_client/client_secrets.rb

Overview

Manages the persistence of client configuration data and secrets.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ ClientSecrets

Returns a new instance of ClientSecrets.



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/google/api_client/client_secrets.rb', line 47

def initialize(options={})
  # Client auth configuration
  @flow = options[:flow] || options.keys.first.to_s || 'web'
  fdata = options[@flow]
  @client_id = fdata[:client_id] || fdata["client_id"]
  @client_secret = fdata[:client_secret] || fdata["client_secret"]
  @redirect_uris = fdata[:redirect_uris] || fdata["redirect_uris"]
  @redirect_uris ||= [fdata[:redirect_uri]]
  @javascript_origins = (
    fdata[:javascript_origins] ||
    fdata["javascript_origins"]
  )
  @javascript_origins ||= [fdata[:javascript_origin]]
  @authorization_uri = fdata[:auth_uri] || fdata["auth_uri"]
  @authorization_uri ||= fdata[:authorization_uri]
  @token_credential_uri = fdata[:token_uri] || fdata["token_uri"]
  @token_credential_uri ||= fdata[:token_credential_uri]

  # Associated token info
  @access_token = fdata[:access_token] || fdata["access_token"]
  @refresh_token = fdata[:refresh_token] || fdata["refresh_token"]
  @id_token = fdata[:id_token] || fdata["id_token"]
  @expires_in = fdata[:expires_in] || fdata["expires_in"]
  @expires_at = fdata[:expires_at] || fdata["expires_at"]
  @issued_at = fdata[:issued_at] || fdata["issued_at"]
end

Instance Attribute Details

#access_tokenObject (readonly)

Returns the value of attribute access_token.



74
75
76
# File 'lib/google/api_client/client_secrets.rb', line 74

def access_token
  @access_token
end

#authorization_uriObject (readonly)

Returns the value of attribute authorization_uri.



74
75
76
# File 'lib/google/api_client/client_secrets.rb', line 74

def authorization_uri
  @authorization_uri
end

#client_idObject (readonly)

Returns the value of attribute client_id.



74
75
76
# File 'lib/google/api_client/client_secrets.rb', line 74

def client_id
  @client_id
end

#client_secretObject (readonly)

Returns the value of attribute client_secret.



74
75
76
# File 'lib/google/api_client/client_secrets.rb', line 74

def client_secret
  @client_secret
end

#expires_atObject (readonly)

Returns the value of attribute expires_at.



74
75
76
# File 'lib/google/api_client/client_secrets.rb', line 74

def expires_at
  @expires_at
end

#expires_inObject (readonly)

Returns the value of attribute expires_in.



74
75
76
# File 'lib/google/api_client/client_secrets.rb', line 74

def expires_in
  @expires_in
end

#flowObject (readonly)

Returns the value of attribute flow.



74
75
76
# File 'lib/google/api_client/client_secrets.rb', line 74

def flow
  @flow
end

#id_tokenObject (readonly)

Returns the value of attribute id_token.



74
75
76
# File 'lib/google/api_client/client_secrets.rb', line 74

def id_token
  @id_token
end

#issued_atObject (readonly)

Returns the value of attribute issued_at.



74
75
76
# File 'lib/google/api_client/client_secrets.rb', line 74

def issued_at
  @issued_at
end

#javascript_originsObject (readonly)

Returns the value of attribute javascript_origins.



74
75
76
# File 'lib/google/api_client/client_secrets.rb', line 74

def javascript_origins
  @javascript_origins
end

#redirect_urisObject (readonly)

Returns the value of attribute redirect_uris.



74
75
76
# File 'lib/google/api_client/client_secrets.rb', line 74

def redirect_uris
  @redirect_uris
end

#refresh_tokenObject (readonly)

Returns the value of attribute refresh_token.



74
75
76
# File 'lib/google/api_client/client_secrets.rb', line 74

def refresh_token
  @refresh_token
end

#token_credential_uriObject (readonly)

Returns the value of attribute token_credential_uri.



74
75
76
# File 'lib/google/api_client/client_secrets.rb', line 74

def token_credential_uri
  @token_credential_uri
end

Class Method Details

.load(filename = nil) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/google/api_client/client_secrets.rb', line 25

def self.load(filename=nil)
  if filename && File.directory?(filename)
    search_path = File.expand_path(filename)
    filename = nil
  end
  while filename == nil
    search_path ||= File.expand_path('.')
    puts search_path
    if File.exist?(File.join(search_path, 'client_secrets.json'))
      filename = File.join(search_path, 'client_secrets.json')
    elsif search_path == '/' || search_path =~ /[a-zA-Z]:[\/\\]/
      raise ArgumentError,
        'No client_secrets.json filename supplied ' +
        'and/or could not be found in search path.'
    else
      search_path = File.expand_path(File.join(search_path, '..'))
    end
  end
  data = File.open(filename, 'r') { |file| MultiJson.load(file.read) }
  return self.new(data)
end

Instance Method Details

#to_jsonObject



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/google/api_client/client_secrets.rb', line 80

def to_json
  return MultiJson.dump({
    self.flow => ({
      'client_id' => self.client_id,
      'client_secret' => self.client_secret,
      'redirect_uris' => self.redirect_uris,
      'javascript_origins' => self.javascript_origins,
      'auth_uri' => self.authorization_uri,
      'token_uri' => self.token_credential_uri,
      'access_token' => self.access_token,
      'refresh_token' => self.refresh_token,
      'id_token' => self.id_token,
      'expires_in' => self.expires_in,
      'expires_at' => self.expires_at,
      'issued_at' => self.issued_at
    }).inject({}) do |accu, (k, v)|
      # Prunes empty values from JSON output.
      unless v == nil || (v.respond_to?(:empty?) && v.empty?)
        accu[k] = v
      end
      accu
    end
  })
end