@@ -41,7 +41,7 @@ module Google
41
41
# This class manages APIs communication.
42
42
class APIClient
43
43
include Google ::APIClient ::Logging
44
-
44
+
45
45
##
46
46
# Creates a new Google API client.
47
47
#
@@ -58,7 +58,7 @@ class APIClient
58
58
# </ul>
59
59
# @option options [Boolean] :auto_refresh_token (true)
60
60
# The setting that controls whether or not the api client attempts to
61
- # refresh authorization when a 401 is hit in #execute. If the token does
61
+ # refresh authorization when a 401 is hit in #execute. If the token does
62
62
# not support it, this option is ignored.
63
63
# @option options [String] :application_name
64
64
# The name of the application using the client.
@@ -86,7 +86,7 @@ class APIClient
86
86
# Pass through of options to set on the Faraday connection
87
87
def initialize ( options = { } )
88
88
logger . debug { "#{ self . class } - Initializing client with options #{ options } " }
89
-
89
+
90
90
# Normalize key to String to allow indifferent access.
91
91
options = options . inject ( { } ) do |accu , ( key , value ) |
92
92
accu [ key . to_sym ] = value
@@ -182,7 +182,7 @@ def authorization=(new_authorization)
182
182
)
183
183
when :google_app_default
184
184
require 'googleauth'
185
- new_authorization = Google ::Auth . get_application_default ( nil )
185
+ new_authorization = Google ::Auth . get_application_default
186
186
187
187
when :oauth_2
188
188
require 'signet/oauth_2/client'
@@ -214,7 +214,7 @@ def authorization=(new_authorization)
214
214
215
215
##
216
216
# The setting that controls whether or not the api client attempts to
217
- # refresh authorization when a 401 is hit in #execute.
217
+ # refresh authorization when a 401 is hit in #execute.
218
218
#
219
219
# @return [Boolean]
220
220
attr_accessor :auto_refresh_token
@@ -261,7 +261,7 @@ def authorization=(new_authorization)
261
261
262
262
##
263
263
# Number of times to retry on recoverable errors
264
- #
264
+ #
265
265
# @return [FixNum]
266
266
# Number of retries
267
267
attr_accessor :retries
@@ -471,7 +471,7 @@ def preferred_version(api)
471
471
# Verifies an ID token against a server certificate. Used to ensure that
472
472
# an ID token supplied by an untrusted client-side mechanism is valid.
473
473
# Raises an error if the token is invalid or missing.
474
- #
474
+ #
475
475
# @deprecated Use the google-id-token gem for verifying JWTs
476
476
def verify_id_token!
477
477
require 'jwt'
@@ -580,7 +580,7 @@ def generate_request(options={})
580
580
# - (TrueClass, FalseClass) :authenticated (default: true) -
581
581
# `true` if the request must be signed or somehow
582
582
# authenticated, `false` otherwise.
583
- # - (TrueClass, FalseClass) :gzip (default: true) -
583
+ # - (TrueClass, FalseClass) :gzip (default: true) -
584
584
# `true` if gzip enabled, `false` otherwise.
585
585
# - (FixNum) :retries -
586
586
# # of times to retry on recoverable errors
@@ -620,7 +620,7 @@ def execute!(*params)
620
620
options . update ( params . shift ) if params . size > 0
621
621
request = self . generate_request ( options )
622
622
end
623
-
623
+
624
624
request . headers [ 'User-Agent' ] ||= '' + self . user_agent unless self . user_agent . nil?
625
625
request . headers [ 'Accept-Encoding' ] ||= 'gzip' unless options [ :gzip ] == false
626
626
request . headers [ 'Content-Type' ] ||= ''
@@ -629,11 +629,11 @@ def execute!(*params)
629
629
630
630
connection = options [ :connection ] || self . connection
631
631
request . authorization = options [ :authorization ] || self . authorization unless options [ :authenticated ] == false
632
-
632
+
633
633
tries = 1 + ( options [ :retries ] || self . retries )
634
634
attempt = 0
635
635
636
- Retriable . retriable :tries => tries ,
636
+ Retriable . retriable :tries => tries ,
637
637
:on => [ TransmissionError ] ,
638
638
:on_retry => client_error_handler ,
639
639
:interval => lambda { |attempts | ( 2 ** attempts ) + rand } do
@@ -642,7 +642,7 @@ def execute!(*params)
642
642
# This 2nd level retriable only catches auth errors, and supports 1 retry, which allows
643
643
# auth to be re-attempted without having to retry all sorts of other failures like
644
644
# NotFound, etc
645
- Retriable . retriable :tries => ( ( expired_auth_retry || tries > 1 ) && attempt == 1 ) ? 2 : 1 ,
645
+ Retriable . retriable :tries => ( ( expired_auth_retry || tries > 1 ) && attempt == 1 ) ? 2 : 1 ,
646
646
:on => [ AuthorizationError ] ,
647
647
:on_retry => authorization_error_handler ( request . authorization ) do
648
648
result = request . send ( connection , true )
@@ -709,7 +709,7 @@ def resolve_uri(template, mapping={})
709
709
end
710
710
return Addressable ::Template . new ( @base_uri + template ) . expand ( mapping )
711
711
end
712
-
712
+
713
713
714
714
##
715
715
# Returns on proc for special processing of retries for authorization errors
@@ -719,7 +719,7 @@ def resolve_uri(template, mapping={})
719
719
# OAuth 2 credentials
720
720
# @return [Proc]
721
721
def authorization_error_handler ( authorization )
722
- can_refresh = authorization . respond_to? ( :refresh_token ) && auto_refresh_token
722
+ can_refresh = authorization . respond_to? ( :refresh_token ) && auto_refresh_token
723
723
Proc . new do |exception , tries |
724
724
next unless exception . kind_of? ( AuthorizationError )
725
725
if can_refresh
0 commit comments