describe Google::APIClient do
include ConnectionHelpers
- CLIENT = Google::APIClient.new unless defined?(CLIENT)
+ CLIENT = Google::APIClient.new(:application_name => 'API Client Tests') unless defined?(CLIENT)
after do
# Reset client to not-quite-pristine state
it 'should raise a type error for bogus authorization' do
(lambda do
- Google::APIClient.new(:authorization => 42)
+ Google::APIClient.new(:application_name => 'API Client Tests', :authorization => 42)
end).should raise_error(TypeError)
end
conn.verify
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
pending("This is caused by Faraday's encoding of query parameters.")
conn = stub_connection do |stub|
it 'should allow modification to the base URIs for testing purposes' do
# Using a new client instance here to avoid caching rebased discovery doc
prediction_rebase =
- Google::APIClient.new.discovered_api('prediction', 'v1.2')
+ Google::APIClient.new(:application_name => 'API Client Tests').discovered_api('prediction', 'v1.2')
prediction_rebase.method_base =
'https://testing-domain.example.com/prediction/v1.2/'
it 'should generate requests against the correct URIs' do
conn = stub_connection do |stub|
- stub.get('/plus/v1/people/107807692475771887386/activities/public' +
- '?collection=public&userId=107807692475771887386') do |env|
+ stub.get('/plus/v1/people/107807692475771887386/activities/public') do |env|
end
end
end
end
-=begin
describe 'with the latitude API' do
before do
CLIENT.authorization = nil
it 'should generate requests against the correct URIs' do
request = CLIENT.generate_request(
- :api_method => 'latitude.currentLocation.get',
+ :api_method => @latitude.current_location.get,
:authenticated => false
)
request.to_env(Faraday.default_connection)[:url].to_s.should ===
it 'should not be able to execute requests without authorization' do
result = CLIENT.execute(
- :api_method => 'latitude.currentLocation.get',
+ :api_method => @latitude.current_location.get,
:authenticated => false
)
result.response.status.should == 401
end
end
-=end
-
- describe 'with the moderator API' do
- before do
- CLIENT.authorization = nil
- @moderator = CLIENT.discovered_api('moderator')
- end
-
- it 'should correctly determine the discovery URI' do
- CLIENT.discovery_uri('moderator').should ===
- 'https://www.googleapis.com/discovery/v1/apis/moderator/v1/rest'
- end
-
- it 'should find APIs that are in the discovery document' do
- CLIENT.discovered_api('moderator').name.should == 'moderator'
- CLIENT.discovered_api('moderator').version.should == 'v1'
- end
-
- it 'should find methods that are in the discovery document' do
- CLIENT.discovered_method(
- 'moderator.profiles.get', 'moderator'
- ).name.should == 'get'
- end
-
- it 'should define the origin API in discovered methods' do
- CLIENT.discovered_method(
- 'moderator.profiles.get', 'moderator'
- ).api.name.should == 'moderator'
- end
-
- it 'should not find methods that are not in the discovery document' do
- CLIENT.discovered_method('moderator.bogus', 'moderator').should == nil
- end
-
- it 'should return a batch path' do
- CLIENT.discovered_api('moderator').batch_path.should_not be_nil
- end
-
- it 'should generate requests against the correct URIs' do
- conn = stub_connection do |stub|
- stub.get('/moderator/v1/profiles/@me') do |env|
- end
- end
- request = CLIENT.execute(
- :api_method => @moderator.profiles.get,
- :authenticated => false,
- :connection => conn
- )
- conn.verify
- end
-
- it 'should not be able to execute requests without authorization' do
- result = CLIENT.execute(
- @moderator.profiles.get,
- {},
- '',
- [],
- {:authenticated => false}
- )
- result.response.status.should == 401
- end
- end
describe 'with the adsense API' do
before do