Resolving issues introduced by Faraday dependency upgrade.
This commit is contained in:
parent
5e751681dd
commit
3bc7d52764
5
Gemfile
5
Gemfile
|
@ -7,12 +7,12 @@ gem 'addressable', '>= 2.2.3'
|
||||||
gem 'uuidtools', '>= 2.1.0'
|
gem 'uuidtools', '>= 2.1.0'
|
||||||
gem 'autoparse', '>= 0.3.1'
|
gem 'autoparse', '>= 0.3.1'
|
||||||
gem 'faraday', '~> 0.8.1'
|
gem 'faraday', '~> 0.8.1'
|
||||||
gem 'multi_json', '>= 1.3.0'
|
gem 'multi_json', '>= 1.0.0'
|
||||||
gem 'extlib', '>= 0.9.15'
|
gem 'extlib', '>= 0.9.15'
|
||||||
gem 'jruby-openssl', :platforms => :jruby
|
gem 'jruby-openssl', :platforms => :jruby
|
||||||
|
|
||||||
group :development do
|
group :development do
|
||||||
gem 'launchy'
|
gem 'launchy', '>= 2.0.0'
|
||||||
gem 'yard'
|
gem 'yard'
|
||||||
gem 'redcarpet'
|
gem 'redcarpet'
|
||||||
end
|
end
|
||||||
|
@ -23,6 +23,7 @@ end
|
||||||
|
|
||||||
group :test, :development do
|
group :test, :development do
|
||||||
gem 'rake', '>= 0.9.0'
|
gem 'rake', '>= 0.9.0'
|
||||||
|
gem 'rspec', '>= 2.11.0'
|
||||||
gem 'rcov', '>= 0.9.9', :platform => :mri_18
|
gem 'rcov', '>= 0.9.9', :platform => :mri_18
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -655,8 +655,10 @@ module Google
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
request = Faraday::Request.create(method.to_s.downcase.to_sym) do |req|
|
request = options[:connection].build_request(
|
||||||
req.url(Addressable::URI.parse(uri))
|
method.to_s.downcase.to_sym
|
||||||
|
) do |req|
|
||||||
|
req.url(Addressable::URI.parse(uri).normalize.to_s)
|
||||||
req.headers = Faraday::Utils::Headers.new(headers)
|
req.headers = Faraday::Utils::Headers.new(headers)
|
||||||
req.body = body
|
req.body = body
|
||||||
end
|
end
|
||||||
|
@ -709,6 +711,7 @@ module Google
|
||||||
params.size == 1
|
params.size == 1
|
||||||
batch = params.pop
|
batch = params.pop
|
||||||
options = batch.options
|
options = batch.options
|
||||||
|
options[:connection] ||= Faraday.default_connection
|
||||||
http_request = batch.to_http_request
|
http_request = batch.to_http_request
|
||||||
request = nil
|
request = nil
|
||||||
|
|
||||||
|
@ -716,8 +719,10 @@ module Google
|
||||||
method, uri, headers, body = http_request
|
method, uri, headers, body = http_request
|
||||||
method = method.to_s.downcase.to_sym
|
method = method.to_s.downcase.to_sym
|
||||||
|
|
||||||
faraday_request = Faraday::Request.create(method) do |req|
|
faraday_request = options[:connection].build_request(
|
||||||
req.url(uri.to_s)
|
method.to_s.downcase.to_sym
|
||||||
|
) do |req|
|
||||||
|
req.url(Addressable::URI.parse(uri).normalize.to_s)
|
||||||
req.headers = Faraday::Utils::Headers.new(headers)
|
req.headers = Faraday::Utils::Headers.new(headers)
|
||||||
req.body = body
|
req.body = body
|
||||||
end
|
end
|
||||||
|
@ -755,6 +760,7 @@ module Google
|
||||||
options[:body] = params.shift if params.size > 0
|
options[:body] = params.shift if params.size > 0
|
||||||
options[:headers] = params.shift if params.size > 0
|
options[:headers] = params.shift if params.size > 0
|
||||||
options[:client] = self
|
options[:client] = self
|
||||||
|
options[:connection] ||= Faraday.default_connection
|
||||||
reference = Google::APIClient::Reference.new(options)
|
reference = Google::APIClient::Reference.new(options)
|
||||||
request = self.generate_request(reference)
|
request = self.generate_request(reference)
|
||||||
response = self.transmit(
|
response = self.transmit(
|
||||||
|
|
|
@ -218,9 +218,12 @@ module Google
|
||||||
# The parameters to send.
|
# The parameters to send.
|
||||||
# @param [String, StringIO] body The body for the HTTP request.
|
# @param [String, StringIO] body The body for the HTTP request.
|
||||||
# @param [Hash, Array] headers The HTTP headers for the request.
|
# @param [Hash, Array] headers The HTTP headers for the request.
|
||||||
|
# @option options [Faraday::Connection] :connection
|
||||||
|
# The HTTP connection to use.
|
||||||
#
|
#
|
||||||
# @return [Array] The generated HTTP request.
|
# @return [Array] The generated HTTP request.
|
||||||
def generate_request(parameters={}, body='', headers=[])
|
def generate_request(parameters={}, body='', headers=[], options={})
|
||||||
|
options[:connection] ||= Faraday.default_connection
|
||||||
if body.respond_to?(:string)
|
if body.respond_to?(:string)
|
||||||
body = body.string
|
body = body.string
|
||||||
elsif body.respond_to?(:to_str)
|
elsif body.respond_to?(:to_str)
|
||||||
|
@ -234,8 +237,10 @@ module Google
|
||||||
method = self.http_method
|
method = self.http_method
|
||||||
uri = self.generate_uri(parameters)
|
uri = self.generate_uri(parameters)
|
||||||
headers = headers.to_a if headers.kind_of?(Hash)
|
headers = headers.to_a if headers.kind_of?(Hash)
|
||||||
return Faraday::Request.create(method.to_s.downcase.to_sym) do |req|
|
return options[:connection].build_request(
|
||||||
req.url(Addressable::URI.parse(uri))
|
method.to_s.downcase.to_sym
|
||||||
|
) do |req|
|
||||||
|
req.url(Addressable::URI.parse(uri).normalize.to_s)
|
||||||
req.headers = Faraday::Utils::Headers.new(headers)
|
req.headers = Faraday::Utils::Headers.new(headers)
|
||||||
req.body = body
|
req.body = body
|
||||||
end
|
end
|
||||||
|
|
|
@ -26,8 +26,8 @@ require 'google/api_client/discovery'
|
||||||
module Google
|
module Google
|
||||||
class APIClient
|
class APIClient
|
||||||
class Reference
|
class Reference
|
||||||
|
|
||||||
MULTIPART_BOUNDARY = "-----------RubyApiMultipartPost".freeze
|
MULTIPART_BOUNDARY = "-----------RubyApiMultipartPost".freeze
|
||||||
|
|
||||||
def initialize(options={})
|
def initialize(options={})
|
||||||
# We only need this to do lookups on method ID String values
|
# We only need this to do lookups on method ID String values
|
||||||
# It's optional, but method ID lookups will fail if the client is
|
# It's optional, but method ID lookups will fail if the client is
|
||||||
|
@ -241,13 +241,14 @@ module Google
|
||||||
def to_request
|
def to_request
|
||||||
if self.api_method
|
if self.api_method
|
||||||
return self.api_method.generate_request(
|
return self.api_method.generate_request(
|
||||||
self.parameters, self.body, self.headers
|
self.parameters, self.body, self.headers,
|
||||||
|
:connection => self.connection
|
||||||
)
|
)
|
||||||
else
|
else
|
||||||
return Faraday::Request.create(
|
return self.connection.build_request(
|
||||||
self.http_method.to_s.downcase.to_sym
|
self.http_method.to_s.downcase.to_sym
|
||||||
) do |req|
|
) do |req|
|
||||||
req.url(Addressable::URI.parse(self.uri))
|
req.url(Addressable::URI.parse(self.uri).normalize.to_s)
|
||||||
req.headers = Faraday::Utils::Headers.new(self.headers)
|
req.headers = Faraday::Utils::Headers.new(self.headers)
|
||||||
req.body = self.body
|
req.body = self.body
|
||||||
end
|
end
|
||||||
|
|
|
@ -207,14 +207,14 @@ describe Google::APIClient::BatchRequest do
|
||||||
@call1 = {
|
@call1 = {
|
||||||
:api_method => @calendar.events.insert,
|
:api_method => @calendar.events.insert,
|
||||||
:parameters => {'calendarId' => 'myemail@mydomain.tld'},
|
:parameters => {'calendarId' => 'myemail@mydomain.tld'},
|
||||||
:body => JSON.dump(event1),
|
:body => MultiJson.dump(event1),
|
||||||
:headers => {'Content-Type' => 'application/json'}
|
:headers => {'Content-Type' => 'application/json'}
|
||||||
}
|
}
|
||||||
|
|
||||||
@call2 = {
|
@call2 = {
|
||||||
:api_method => @calendar.events.insert,
|
:api_method => @calendar.events.insert,
|
||||||
:parameters => {'calendarId' => 'myemail@mydomain.tld'},
|
:parameters => {'calendarId' => 'myemail@mydomain.tld'},
|
||||||
:body => JSON.dump(event2),
|
:body => MultiJson.dump(event2),
|
||||||
:headers => {'Content-Type' => 'application/json'}
|
:headers => {'Content-Type' => 'application/json'}
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
|
@ -90,7 +90,7 @@ describe Google::APIClient do
|
||||||
:uri => @client.discovery_uri('prediction', 'v1.2'),
|
:uri => @client.discovery_uri('prediction', 'v1.2'),
|
||||||
:authenticated => false
|
:authenticated => false
|
||||||
)
|
)
|
||||||
request.to_env(Faraday.default_connection)[:url].should === (
|
request.to_env(Faraday.default_connection)[:url].to_s.should === (
|
||||||
'https://www.googleapis.com/discovery/v1/apis/prediction/v1.2/rest' +
|
'https://www.googleapis.com/discovery/v1/apis/prediction/v1.2/rest' +
|
||||||
'?userIp=127.0.0.1'
|
'?userIp=127.0.0.1'
|
||||||
)
|
)
|
||||||
|
@ -103,7 +103,7 @@ describe Google::APIClient do
|
||||||
:uri => @client.discovery_uri('prediction', 'v1.2'),
|
:uri => @client.discovery_uri('prediction', 'v1.2'),
|
||||||
:authenticated => false
|
:authenticated => false
|
||||||
)
|
)
|
||||||
request.to_env(Faraday.default_connection)[:url].should === (
|
request.to_env(Faraday.default_connection)[:url].to_s.should === (
|
||||||
'https://www.googleapis.com/discovery/v1/apis/prediction/v1.2/rest' +
|
'https://www.googleapis.com/discovery/v1/apis/prediction/v1.2/rest' +
|
||||||
'?key=qwerty'
|
'?key=qwerty'
|
||||||
)
|
)
|
||||||
|
@ -117,7 +117,9 @@ describe Google::APIClient do
|
||||||
:uri => @client.discovery_uri('prediction', 'v1.2'),
|
:uri => @client.discovery_uri('prediction', 'v1.2'),
|
||||||
:authenticated => false
|
:authenticated => false
|
||||||
)
|
)
|
||||||
request.to_env(Faraday.default_connection)[:url].query_values.should == {
|
Addressable::URI.parse(
|
||||||
|
request.to_env(Faraday.default_connection)[:url]
|
||||||
|
).query_values.should == {
|
||||||
'key' => 'qwerty',
|
'key' => 'qwerty',
|
||||||
'userIp' => '127.0.0.1'
|
'userIp' => '127.0.0.1'
|
||||||
}
|
}
|
||||||
|
@ -178,10 +180,10 @@ describe Google::APIClient do
|
||||||
it 'should generate valid requests' do
|
it 'should generate valid requests' do
|
||||||
request = @client.generate_request(
|
request = @client.generate_request(
|
||||||
:api_method => @prediction.training.insert,
|
:api_method => @prediction.training.insert,
|
||||||
:parameters => {'data' => '12345', }
|
:parameters => {'data' => '12345'}
|
||||||
)
|
)
|
||||||
request.method.should == :post
|
request.method.should == :post
|
||||||
request.to_env(Faraday.default_connection)[:url].should ===
|
request.to_env(Faraday.default_connection)[:url].to_s.should ===
|
||||||
'https://www.googleapis.com/prediction/v1.2/training?data=12345'
|
'https://www.googleapis.com/prediction/v1.2/training?data=12345'
|
||||||
request.headers.should be_empty
|
request.headers.should be_empty
|
||||||
request.body.should == ''
|
request.body.should == ''
|
||||||
|
@ -190,10 +192,10 @@ describe Google::APIClient do
|
||||||
it 'should generate valid requests when repeated parameters are passed' do
|
it 'should generate valid requests when repeated parameters are passed' do
|
||||||
request = @client.generate_request(
|
request = @client.generate_request(
|
||||||
:api_method => @prediction.training.insert,
|
:api_method => @prediction.training.insert,
|
||||||
:parameters => [['data', '1'],['data','2']]
|
:parameters => [['data', '1'], ['data','2']]
|
||||||
)
|
)
|
||||||
request.method.should == :post
|
request.method.should == :post
|
||||||
request.to_env(Faraday.default_connection)[:url].should ===
|
request.to_env(Faraday.default_connection)[:url].to_s.should ===
|
||||||
'https://www.googleapis.com/prediction/v1.2/training?data=1&data=2'
|
'https://www.googleapis.com/prediction/v1.2/training?data=1&data=2'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -202,7 +204,7 @@ describe Google::APIClient do
|
||||||
:api_method => @prediction.training.insert,
|
:api_method => @prediction.training.insert,
|
||||||
:parameters => {'data' => '12345'}
|
:parameters => {'data' => '12345'}
|
||||||
)
|
)
|
||||||
request.to_env(Faraday.default_connection)[:url].should ===
|
request.to_env(Faraday.default_connection)[:url].to_s.should ===
|
||||||
'https://www.googleapis.com/prediction/v1.2/training?data=12345'
|
'https://www.googleapis.com/prediction/v1.2/training?data=12345'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -211,7 +213,7 @@ describe Google::APIClient do
|
||||||
:api_method => @prediction.training.insert,
|
:api_method => @prediction.training.insert,
|
||||||
:parameters => {'data' => '12345'}
|
:parameters => {'data' => '12345'}
|
||||||
)
|
)
|
||||||
request.to_env(Faraday.default_connection)[:url].should ===
|
request.to_env(Faraday.default_connection)[:url].to_s.should ===
|
||||||
'https://www.googleapis.com/prediction/v1.2/training?data=12345'
|
'https://www.googleapis.com/prediction/v1.2/training?data=12345'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -223,7 +225,7 @@ describe Google::APIClient do
|
||||||
:api_method => prediction.training.insert,
|
:api_method => prediction.training.insert,
|
||||||
:parameters => {'data' => '123'}
|
:parameters => {'data' => '123'}
|
||||||
)
|
)
|
||||||
request.to_env(Faraday.default_connection)[:url].should === (
|
request.to_env(Faraday.default_connection)[:url].to_s.should === (
|
||||||
'https://testing-domain.googleapis.com/' +
|
'https://testing-domain.googleapis.com/' +
|
||||||
'prediction/v1.2/training?data=123'
|
'prediction/v1.2/training?data=123'
|
||||||
)
|
)
|
||||||
|
@ -352,7 +354,7 @@ describe Google::APIClient do
|
||||||
},
|
},
|
||||||
:authenticated => false
|
:authenticated => false
|
||||||
)
|
)
|
||||||
request.to_env(Faraday.default_connection)[:url].should === (
|
request.to_env(Faraday.default_connection)[:url].to_s.should === (
|
||||||
'https://www.googleapis.com/plus/v1/' +
|
'https://www.googleapis.com/plus/v1/' +
|
||||||
'people/107807692475771887386/activities/public'
|
'people/107807692475771887386/activities/public'
|
||||||
)
|
)
|
||||||
|
@ -422,7 +424,7 @@ describe Google::APIClient do
|
||||||
:api_method => 'latitude.currentLocation.get',
|
:api_method => 'latitude.currentLocation.get',
|
||||||
:authenticated => false
|
:authenticated => false
|
||||||
)
|
)
|
||||||
request.to_env(Faraday.default_connection)[:url].should ===
|
request.to_env(Faraday.default_connection)[:url].to_s.should ===
|
||||||
'https://www.googleapis.com/latitude/v1/currentLocation'
|
'https://www.googleapis.com/latitude/v1/currentLocation'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -431,7 +433,7 @@ describe Google::APIClient do
|
||||||
:api_method => @latitude.current_location.get,
|
:api_method => @latitude.current_location.get,
|
||||||
:authenticated => false
|
:authenticated => false
|
||||||
)
|
)
|
||||||
request.to_env(Faraday.default_connection)[:url].should ===
|
request.to_env(Faraday.default_connection)[:url].to_s.should ===
|
||||||
'https://www.googleapis.com/latitude/v1/currentLocation'
|
'https://www.googleapis.com/latitude/v1/currentLocation'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -485,7 +487,7 @@ describe Google::APIClient do
|
||||||
:api_method => 'moderator.profiles.get',
|
:api_method => 'moderator.profiles.get',
|
||||||
:authenticated => false
|
:authenticated => false
|
||||||
)
|
)
|
||||||
request.to_env(Faraday.default_connection)[:url].should ===
|
request.to_env(Faraday.default_connection)[:url].to_s.should ===
|
||||||
'https://www.googleapis.com/moderator/v1/profiles/@me'
|
'https://www.googleapis.com/moderator/v1/profiles/@me'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -494,7 +496,7 @@ describe Google::APIClient do
|
||||||
:api_method => @moderator.profiles.get,
|
:api_method => @moderator.profiles.get,
|
||||||
:authenticated => false
|
:authenticated => false
|
||||||
)
|
)
|
||||||
request.to_env(Faraday.default_connection)[:url].should ===
|
request.to_env(Faraday.default_connection)[:url].to_s.should ===
|
||||||
'https://www.googleapis.com/moderator/v1/profiles/@me'
|
'https://www.googleapis.com/moderator/v1/profiles/@me'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -545,7 +547,7 @@ describe Google::APIClient do
|
||||||
:api_method => 'adsense.adclients.list',
|
:api_method => 'adsense.adclients.list',
|
||||||
:authenticated => false
|
:authenticated => false
|
||||||
)
|
)
|
||||||
request.to_env(Faraday.default_connection)[:url].should ===
|
request.to_env(Faraday.default_connection)[:url].to_s.should ===
|
||||||
'https://www.googleapis.com/adsense/v1/adclients'
|
'https://www.googleapis.com/adsense/v1/adclients'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -554,7 +556,7 @@ describe Google::APIClient do
|
||||||
:api_method => @adsense.adclients.list,
|
:api_method => @adsense.adclients.list,
|
||||||
:authenticated => false
|
:authenticated => false
|
||||||
)
|
)
|
||||||
request.to_env(Faraday.default_connection)[:url].should ===
|
request.to_env(Faraday.default_connection)[:url].to_s.should ===
|
||||||
'https://www.googleapis.com/adsense/v1/adclients'
|
'https://www.googleapis.com/adsense/v1/adclients'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -28,7 +28,7 @@ namespace :gem do
|
||||||
s.add_runtime_dependency('addressable', '>= 2.2.3')
|
s.add_runtime_dependency('addressable', '>= 2.2.3')
|
||||||
s.add_runtime_dependency('autoparse', '>= 0.3.1')
|
s.add_runtime_dependency('autoparse', '>= 0.3.1')
|
||||||
s.add_runtime_dependency('faraday', '~> 0.8.1')
|
s.add_runtime_dependency('faraday', '~> 0.8.1')
|
||||||
s.add_runtime_dependency('multi_json', '>= 1.3.0')
|
s.add_runtime_dependency('multi_json', '>= 1.0.0')
|
||||||
s.add_runtime_dependency('extlib', '>= 0.9.15')
|
s.add_runtime_dependency('extlib', '>= 0.9.15')
|
||||||
s.add_runtime_dependency('uuidtools', '>= 2.1.0')
|
s.add_runtime_dependency('uuidtools', '>= 2.1.0')
|
||||||
|
|
||||||
|
@ -39,7 +39,7 @@ namespace :gem do
|
||||||
s.add_development_dependency('sinatra', '>= 1.2.0')
|
s.add_development_dependency('sinatra', '>= 1.2.0')
|
||||||
|
|
||||||
s.add_development_dependency('rake', '>= 0.9.0')
|
s.add_development_dependency('rake', '>= 0.9.0')
|
||||||
s.add_development_dependency('rspec', '~> 2.10.0')
|
s.add_development_dependency('rspec', '>= 2.11.0')
|
||||||
|
|
||||||
s.require_path = 'lib'
|
s.require_path = 'lib'
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue