This commit is contained in:
Steven Bazyl 2013-01-02 11:51:15 -08:00
commit 250e9e7b2d
6 changed files with 71 additions and 35 deletions

View File

@ -23,11 +23,15 @@ The Google API Ruby Client makes it trivial to discover and access supported
APIs. APIs.
TEXT TEXT
PKG_FILES = FileList[ list = FileList[
'lib/**/*', 'spec/**/*', 'vendor/**/*', 'lib/**/*', 'spec/**/*', 'vendor/**/*',
'tasks/**/*', 'website/**/*', 'tasks/**/*', 'website/**/*',
'[A-Z]*', 'Rakefile' '[A-Z]*', 'Rakefile'
].exclude(/database\.yml/).exclude(/[_\.]git$/) ].exclude(/[_\.]git$/)
(open(".gitignore") { |file| file.read }).split("\n").each do |pattern|
list.exclude(pattern)
end
PKG_FILES = list
RCOV_ENABLED = !!(RUBY_PLATFORM != 'java' && RUBY_VERSION =~ /^1\.8/) RCOV_ENABLED = !!(RUBY_PLATFORM != 'java' && RUBY_VERSION =~ /^1\.8/)
if RCOV_ENABLED if RCOV_ENABLED

View File

@ -6,16 +6,16 @@ Gem::Specification.new do |s|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version= s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["Bob Aman", "Steve Bazyl"] s.authors = ["Bob Aman", "Steve Bazyl"]
s.date = "2012-10-25" s.date = "2012-11-19"
s.description = "The Google API Ruby Client makes it trivial to discover and access supported\nAPIs.\n" s.description = "The Google API Ruby Client makes it trivial to discover and access supported\nAPIs.\n"
s.email = "sbazyl@google.com" s.email = "sbazyl@google.com"
s.executables = ["google-api"] s.executables = ["google-api"]
s.extra_rdoc_files = ["README.md"] s.extra_rdoc_files = ["README.md"]
s.files = ["lib/compat", "lib/compat/multi_json.rb", "lib/google", "lib/google/api_client", "lib/google/api_client/auth", "lib/google/api_client/auth/jwt_asserter.rb", "lib/google/api_client/auth/pkcs12.rb", "lib/google/api_client/batch.rb", "lib/google/api_client/client_secrets.rb", "lib/google/api_client/discovery", "lib/google/api_client/discovery/api.rb", "lib/google/api_client/discovery/media.rb", "lib/google/api_client/discovery/method.rb", "lib/google/api_client/discovery/resource.rb", "lib/google/api_client/discovery/schema.rb", "lib/google/api_client/discovery.rb", "lib/google/api_client/environment.rb", "lib/google/api_client/errors.rb", "lib/google/api_client/media.rb", "lib/google/api_client/reference.rb", "lib/google/api_client/request.rb", "lib/google/api_client/result.rb", "lib/google/api_client/service_account.rb", "lib/google/api_client/version.rb", "lib/google/api_client.rb", "lib/google/inflection.rb", "spec/fixtures", "spec/fixtures/files", "spec/fixtures/files/sample.txt", "spec/google", "spec/google/api_client", "spec/google/api_client/batch_spec.rb", "spec/google/api_client/discovery_spec.rb", "spec/google/api_client/media_spec.rb", "spec/google/api_client/result_spec.rb", "spec/google/api_client/service_account_spec.rb", "spec/google/api_client_spec.rb", "spec/spec_helper.rb", "tasks/gem.rake", "tasks/git.rake", "tasks/metrics.rake", "tasks/spec.rake", "tasks/wiki.rake", "tasks/yard.rake", "CHANGELOG.md", "Gemfile", "Gemfile.lock", "LICENSE", "Rakefile", "README.md", "bin/google-api"] s.files = ["lib/compat", "lib/compat/multi_json.rb", "lib/google", "lib/google/api_client", "lib/google/api_client.rb", "lib/google/api_client/auth", "lib/google/api_client/auth/jwt_asserter.rb", "lib/google/api_client/auth/key_utils.rb", "lib/google/api_client/auth/pkcs12.rb", "lib/google/api_client/batch.rb", "lib/google/api_client/client_secrets.rb", "lib/google/api_client/discovery", "lib/google/api_client/discovery.rb", "lib/google/api_client/discovery/api.rb", "lib/google/api_client/discovery/media.rb", "lib/google/api_client/discovery/method.rb", "lib/google/api_client/discovery/resource.rb", "lib/google/api_client/discovery/schema.rb", "lib/google/api_client/environment.rb", "lib/google/api_client/errors.rb", "lib/google/api_client/media.rb", "lib/google/api_client/reference.rb", "lib/google/api_client/request.rb", "lib/google/api_client/result.rb", "lib/google/api_client/service_account.rb", "lib/google/api_client/version.rb", "lib/google/inflection.rb", "spec/fixtures", "spec/fixtures/files", "spec/fixtures/files/privatekey.p12", "spec/fixtures/files/sample.txt", "spec/fixtures/files/secret.pem", "spec/google", "spec/google/api_client", "spec/google/api_client/batch_spec.rb", "spec/google/api_client/discovery_spec.rb", "spec/google/api_client/media_spec.rb", "spec/google/api_client/result_spec.rb", "spec/google/api_client/service_account_spec.rb", "spec/google/api_client_spec.rb", "spec/spec_helper.rb", "tasks/gem.rake", "tasks/git.rake", "tasks/metrics.rake", "tasks/spec.rake", "tasks/wiki.rake", "tasks/yard.rake", "CHANGELOG.md", "Gemfile", "LICENSE", "README.md", "Rakefile", "bin/google-api"]
s.homepage = "http://code.google.com/p/google-api-ruby-client/" s.homepage = "http://code.google.com/p/google-api-ruby-client/"
s.rdoc_options = ["--main", "README.md"] s.rdoc_options = ["--main", "README.md"]
s.require_paths = ["lib"] s.require_paths = ["lib"]
s.rubygems_version = "1.8.10" s.rubygems_version = "1.8.24"
s.summary = "Package Summary" s.summary = "Package Summary"
if s.respond_to? :specification_version then if s.respond_to? :specification_version then

View File

@ -1,6 +1,9 @@
require 'multi_json' require 'multi_json'
if !MultiJson.respond_to?(:load) || MultiJson.method(:load).owner == Kernel if !MultiJson.respond_to?(:load) || [
Kernel,
defined?(ActiveSupport::Dependencies::Loadable) && ActiveSupport::Dependencies::Loadable
].compact.include?(MultiJson.method(:load).owner)
module MultiJson module MultiJson
class <<self class <<self
alias :load :decode alias :load :decode

View File

@ -52,6 +52,10 @@ module Google
# <li><code>:oauth_1</code></li> # <li><code>:oauth_1</code></li>
# <li><code>:oauth_2</code></li> # <li><code>:oauth_2</code></li>
# </ul> # </ul>
# @option options [Boolean] :auto_refresh_token (true)
# The setting that controls whether or not the api client attempts to
# refresh authorization when a 401 is hit in #execute. If the token does
# not support it, this option is ignored.
# @option options [String] :application_name # @option options [String] :application_name
# The name of the application using the client. # The name of the application using the client.
# @option options [String] :application_version # @option options [String] :application_version
@ -95,6 +99,7 @@ module Google
# default authentication mechanisms. # default authentication mechanisms.
self.authorization = self.authorization =
options.key?(:authorization) ? options[:authorization] : :oauth_2 options.key?(:authorization) ? options[:authorization] : :oauth_2
self.auto_refresh_token = options.fetch(:auto_refresh_token){ true }
self.key = options[:key] self.key = options[:key]
self.user_ip = options[:user_ip] self.user_ip = options[:user_ip]
@discovery_uris = {} @discovery_uris = {}
@ -165,6 +170,13 @@ module Google
# @return [String] The API key. # @return [String] The API key.
attr_accessor :key attr_accessor :key
##
# The setting that controls whether or not the api client attempts to
# refresh authorization when a 401 is hit in #execute.
#
# @return [Boolean]
attr_accessor :auto_refresh_token
## ##
# The IP address of the user this request is being performed on behalf of. # The IP address of the user this request is being performed on behalf of.
# #
@ -546,7 +558,7 @@ module Google
request.authorization = options[:authorization] || self.authorization unless options[:authenticated] == false request.authorization = options[:authorization] || self.authorization unless options[:authenticated] == false
result = request.send(connection) result = request.send(connection)
if result.status == 401 && authorization.respond_to?(:refresh_token) if result.status == 401 && authorization.respond_to?(:refresh_token) && auto_refresh_token
begin begin
authorization.fetch_access_token! authorization.fetch_access_token!
result = request.send(connection) result = request.send(connection)

View File

@ -326,7 +326,7 @@ module Google
# JSON # JSON
def serialize_body(body) def serialize_body(body)
return body.to_json if body.respond_to?(:to_json) return body.to_json if body.respond_to?(:to_json)
return MultiJson.dump(options[:body_object].to_hash) if body.respond_to?(:to_hash) return MultiJson.dump(body.to_hash) if body.respond_to?(:to_hash)
raise TypeError, 'Could not convert body object to JSON.' + raise TypeError, 'Could not convert body object to JSON.' +
'Must respond to :to_json or :to_hash.' 'Must respond to :to_json or :to_hash.'
end end

View File

@ -214,6 +214,23 @@ describe Google::APIClient do
conn.verify conn.verify
end end
it 'should generate valid requests when parameter value includes semicolon' do
conn = stub_connection do |stub|
# semicolon (;) in parameter value was being converted to
# bare ampersand (&) in 0.4.7. ensure that it gets converted
# to a CGI-escaped semicolon (%3B) instead.
stub.post('/prediction/v1.2/training?data=12345%3B67890') do |env|
env[:body].should == ''
end
end
request = CLIENT.execute(
:api_method => @prediction.training.insert,
:parameters => {'data' => '12345;67890'},
:connection => conn
)
conn.verify
end
it 'should generate valid requests when repeated parameters are passed' do it 'should generate valid requests when repeated parameters are passed' do
pending("This is caused by Faraday's encoding of query parameters.") pending("This is caused by Faraday's encoding of query parameters.")
conn = stub_connection do |stub| conn = stub_connection do |stub|