lib/google/cloud/translate/service.rb in google-cloud-translate-1.3.0 vs lib/google/cloud/translate/service.rb in google-cloud-translate-1.3.1
- old
+ new
@@ -108,14 +108,14 @@
##
# The default HTTP headers to be sent on all API calls.
def default_http_headers
@default_http_headers ||= {
- "User-Agent" => "gcloud-ruby/#{Google::Cloud::Translate::VERSION}",
+ "User-Agent" => "gcloud-ruby/#{Google::Cloud::Translate::VERSION}",
"google-cloud-resource-prefix" => "projects/#{@project}",
- "Content-Type" => "application/json",
- "x-goog-api-client" => "gl-ruby/#{RUBY_VERSION} " \
+ "Content-Type" => "application/json",
+ "x-goog-api-client" => "gl-ruby/#{RUBY_VERSION} " \
"gccl/#{Google::Cloud::Translate::VERSION}"
}
end
##
@@ -151,11 +151,11 @@
end
# Set the default values
self.retries = 3
self.http_codes = [500, 503]
- self.reasons = %w[rateLimitExceeded userRateLimitExceeded]
+ self.reasons = ["rateLimitExceeded", "userRateLimitExceeded"]
self.backoff = ->(retries) { sleep retries.to_i }
def initialize options = {} #:nodoc:
@max_retries = (options[:retries] || Backoff.retries).to_i
@http_codes = (options[:http_codes] || Backoff.http_codes).to_a
@@ -187,17 +187,13 @@
def retry_http_code? response #:nodoc:
@http_codes.include? response.status
end
def retry_error_reason? response #:nodoc:
- result = JSON.parse(response.body)
- if result &&
- result["error"] &&
- result["error"]["errors"]
+ result = JSON.parse response.body
+ if result && result["error"] && result["error"]["errors"]
Array(result["error"]["errors"]).each do |error|
- if error["reason"] && @reasons.include?(error["reason"])
- return true
- end
+ return true if error["reason"] && @reasons.include?(error["reason"])
end
end
false
end
end