2015-04-17 00:28:38 +00:00
|
|
|
# Copyright 2015 Google Inc.
|
|
|
|
#
|
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
# you may not use this file except in compliance with the License.
|
|
|
|
# You may obtain a copy of the License at
|
|
|
|
#
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
#
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
# See the License for the specific language governing permissions and
|
|
|
|
# limitations under the License.
|
|
|
|
|
|
|
|
module Google
|
|
|
|
module Apis
|
|
|
|
# General options for API requests
|
|
|
|
ClientOptions = Struct.new(
|
|
|
|
:application_name,
|
|
|
|
:application_version,
|
2015-12-18 22:37:21 +00:00
|
|
|
:proxy_url,
|
|
|
|
:use_net_http)
|
2015-04-17 00:28:38 +00:00
|
|
|
|
|
|
|
RequestOptions = Struct.new(
|
|
|
|
:authorization,
|
|
|
|
:retries,
|
|
|
|
:header,
|
2015-10-02 20:42:47 +00:00
|
|
|
:timeout_sec,
|
|
|
|
:open_timeout_sec)
|
2015-04-17 00:28:38 +00:00
|
|
|
|
|
|
|
# General client options
|
|
|
|
class ClientOptions
|
|
|
|
# @!attribute [rw] application_name
|
|
|
|
# @return [String] Name of the application, for identification in the User-Agent header
|
|
|
|
# @!attribute [rw] application_version
|
|
|
|
# @return [String] Version of the application, for identification in the User-Agent header
|
|
|
|
# @!attribute [rw] proxy_url
|
|
|
|
# @return [String] URL of a proxy server
|
|
|
|
|
|
|
|
# Get the default options
|
|
|
|
# @return [Google::Apis::ClientOptions]
|
|
|
|
def self.default
|
|
|
|
@options ||= ClientOptions.new
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# Request options
|
|
|
|
class RequestOptions
|
2015-08-18 11:13:21 +00:00
|
|
|
# @!attribute [rw] authorization
|
2015-04-17 00:28:38 +00:00
|
|
|
# @return [Signet::OAuth2::Client, #apply(Hash)] OAuth2 credentials
|
|
|
|
# @!attribute [rw] retries
|
|
|
|
# @return [Fixnum] Number of times to retry requests on server error
|
|
|
|
# @!attribute [rw] timeout_sec
|
|
|
|
# @return [Fixnum] How long, in seconds, before requests time out
|
2015-10-02 20:42:47 +00:00
|
|
|
# @!attribute [rw] open_timeout_sec
|
|
|
|
# @return [Fixnum] How long, in seconds, before failed connections time out
|
2015-04-17 00:28:38 +00:00
|
|
|
# @!attribute [rw] header
|
|
|
|
# @return [Hash<String,String] Additional HTTP headers to include in requests
|
|
|
|
|
|
|
|
# Get the default options
|
|
|
|
# @return [Google::Apis::RequestOptions]
|
|
|
|
def self.default
|
|
|
|
@options ||= RequestOptions.new
|
|
|
|
end
|
|
|
|
|
|
|
|
def merge(options)
|
|
|
|
return self if options.nil?
|
|
|
|
|
|
|
|
new_options = dup
|
2015-08-18 11:13:21 +00:00
|
|
|
members.each do |opt|
|
2015-04-17 00:28:38 +00:00
|
|
|
opt = opt.to_sym
|
|
|
|
new_options[opt] = options[opt] unless options[opt].nil?
|
|
|
|
end
|
|
|
|
new_options
|
|
|
|
end
|
|
|
|
end
|
2015-12-18 22:37:21 +00:00
|
|
|
|
|
|
|
ClientOptions.default.use_net_http = false
|
2015-04-17 00:28:38 +00:00
|
|
|
ClientOptions.default.application_name = 'unknown'
|
|
|
|
ClientOptions.default.application_version = '0.0.0'
|
|
|
|
|
|
|
|
RequestOptions.default.retries = 0
|
2015-10-02 20:42:47 +00:00
|
|
|
RequestOptions.default.open_timeout_sec = 20
|
2015-04-17 00:28:38 +00:00
|
|
|
end
|
|
|
|
end
|