2010-09-18 00:30:02 +00:00
|
|
|
# Copyright 2010 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.
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
2011-08-02 20:20:54 +00:00
|
|
|
require 'json'
|
2010-09-18 00:30:02 +00:00
|
|
|
require 'signet/oauth_1/client'
|
|
|
|
require 'httpadapter/adapters/net_http'
|
|
|
|
|
|
|
|
require 'google/api_client'
|
|
|
|
require 'google/api_client/version'
|
|
|
|
require 'google/api_client/parsers/json_parser'
|
|
|
|
|
2011-05-04 11:44:35 +00:00
|
|
|
describe Google::APIClient do
|
2010-09-28 23:09:07 +00:00
|
|
|
before do
|
|
|
|
@client = Google::APIClient.new
|
|
|
|
end
|
|
|
|
|
2011-05-04 11:44:35 +00:00
|
|
|
it 'should raise a type error for bogus authorization' do
|
2010-09-28 23:09:07 +00:00
|
|
|
(lambda do
|
2011-05-04 11:44:35 +00:00
|
|
|
Google::APIClient.new(:authorization => 42)
|
|
|
|
end).should raise_error(TypeError)
|
2010-09-28 23:09:07 +00:00
|
|
|
end
|
|
|
|
|
2011-05-04 11:44:35 +00:00
|
|
|
it 'should not be able to retrieve the discovery document for a bogus API' do
|
2010-09-28 23:09:07 +00:00
|
|
|
(lambda do
|
2011-05-04 11:44:35 +00:00
|
|
|
@client.discovery_document('bogus')
|
2010-09-28 23:09:07 +00:00
|
|
|
end).should raise_error(Google::APIClient::TransmissionError)
|
2010-09-30 21:33:23 +00:00
|
|
|
(lambda do
|
2011-05-04 11:44:35 +00:00
|
|
|
@client.discovered_api('bogus')
|
|
|
|
end).should raise_error(Google::APIClient::TransmissionError)
|
2010-09-30 21:33:23 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should raise an error for bogus services' do
|
|
|
|
(lambda do
|
2011-05-04 11:44:35 +00:00
|
|
|
@client.discovered_api(42)
|
2010-09-30 21:33:23 +00:00
|
|
|
end).should raise_error(TypeError)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should raise an error for bogus services' do
|
|
|
|
(lambda do
|
2011-05-04 11:44:35 +00:00
|
|
|
@client.preferred_version(42)
|
2010-09-30 21:33:23 +00:00
|
|
|
end).should raise_error(TypeError)
|
2010-09-18 00:30:02 +00:00
|
|
|
end
|
|
|
|
|
2010-09-30 21:33:23 +00:00
|
|
|
it 'should raise an error for bogus methods' do
|
|
|
|
(lambda do
|
|
|
|
@client.generate_request(42)
|
|
|
|
end).should raise_error(TypeError)
|
|
|
|
end
|
2010-10-09 02:41:38 +00:00
|
|
|
|
2011-05-04 11:44:35 +00:00
|
|
|
it 'should not return a preferred version for bogus service names' do
|
|
|
|
@client.preferred_version('bogus').should == nil
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'with the prediction API' do
|
|
|
|
before do
|
|
|
|
@client.authorization = nil
|
2011-07-29 22:07:04 +00:00
|
|
|
# The prediction API no longer exposes a v1, so we have to be
|
|
|
|
# careful about looking up the wrong API version.
|
|
|
|
@prediction = @client.discovered_api('prediction', 'v1.2')
|
2011-05-04 11:44:35 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should correctly determine the discovery URI' do
|
|
|
|
@client.discovery_uri('prediction').should ===
|
2011-05-12 20:14:15 +00:00
|
|
|
'https://www.googleapis.com/discovery/v1/apis/prediction/v1/rest'
|
2011-05-04 11:44:35 +00:00
|
|
|
end
|
|
|
|
|
2011-09-22 10:49:46 +00:00
|
|
|
it 'should correctly determine the discovery URI if :user_ip is set' do
|
|
|
|
@client.user_ip = '127.0.0.1'
|
|
|
|
request = @client.generate_request(
|
|
|
|
:http_method => 'GET',
|
|
|
|
:uri => @client.discovery_uri('prediction', 'v1.2'),
|
|
|
|
:authenticated => false
|
|
|
|
)
|
|
|
|
http_method, uri, headers, body = request
|
|
|
|
uri.should === (
|
|
|
|
'https://www.googleapis.com/discovery/v1/apis/prediction/v1.2/rest' +
|
|
|
|
'?userIp=127.0.0.1'
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should correctly determine the discovery URI if :key is set' do
|
|
|
|
@client.key = 'qwerty'
|
|
|
|
request = @client.generate_request(
|
|
|
|
:http_method => 'GET',
|
|
|
|
:uri => @client.discovery_uri('prediction', 'v1.2'),
|
|
|
|
:authenticated => false
|
|
|
|
)
|
|
|
|
http_method, uri, headers, body = request
|
|
|
|
uri.should === (
|
|
|
|
'https://www.googleapis.com/discovery/v1/apis/prediction/v1.2/rest' +
|
|
|
|
'?key=qwerty'
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should correctly determine the discovery URI if both are set' do
|
|
|
|
@client.key = 'qwerty'
|
|
|
|
@client.user_ip = '127.0.0.1'
|
|
|
|
request = @client.generate_request(
|
|
|
|
:http_method => 'GET',
|
|
|
|
:uri => @client.discovery_uri('prediction', 'v1.2'),
|
|
|
|
:authenticated => false
|
|
|
|
)
|
|
|
|
http_method, uri, headers, body = request
|
|
|
|
uri.should === (
|
|
|
|
'https://www.googleapis.com/discovery/v1/apis/prediction/v1.2/rest' +
|
|
|
|
'?key=qwerty&userIp=127.0.0.1'
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
2011-05-04 11:44:35 +00:00
|
|
|
it 'should correctly generate API objects' do
|
2011-07-29 22:07:04 +00:00
|
|
|
@client.discovered_api('prediction', 'v1.2').name.should == 'prediction'
|
|
|
|
@client.discovered_api('prediction', 'v1.2').version.should == 'v1.2'
|
|
|
|
@client.discovered_api(:prediction, 'v1.2').name.should == 'prediction'
|
|
|
|
@client.discovered_api(:prediction, 'v1.2').version.should == 'v1.2'
|
2011-05-04 11:44:35 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should discover methods' do
|
|
|
|
@client.discovered_method(
|
2011-07-29 22:07:04 +00:00
|
|
|
'prediction.training.insert', 'prediction', 'v1.2'
|
2011-05-04 11:44:35 +00:00
|
|
|
).name.should == 'insert'
|
|
|
|
@client.discovered_method(
|
2011-07-29 22:07:04 +00:00
|
|
|
:'prediction.training.insert', :prediction, 'v1.2'
|
2011-05-04 11:44:35 +00:00
|
|
|
).name.should == 'insert'
|
|
|
|
@client.discovered_method(
|
2011-07-29 22:07:04 +00:00
|
|
|
'prediction.training.delete', 'prediction', 'v1.2'
|
2011-05-04 11:44:35 +00:00
|
|
|
).name.should == 'delete'
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should not find methods that are not in the discovery document' do
|
|
|
|
@client.discovered_method(
|
2011-07-29 22:07:04 +00:00
|
|
|
'prediction.bogus', 'prediction', 'v1.2'
|
2011-05-04 11:44:35 +00:00
|
|
|
).should == nil
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should raise an error for bogus methods' do
|
|
|
|
(lambda do
|
2011-07-29 22:07:04 +00:00
|
|
|
@client.discovered_method(42, 'prediction', 'v1.2')
|
2011-05-04 11:44:35 +00:00
|
|
|
end).should raise_error(TypeError)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should raise an error for bogus methods' do
|
|
|
|
(lambda do
|
2011-07-29 22:07:04 +00:00
|
|
|
@client.generate_request(@client.discovered_api('prediction', 'v1.2'))
|
2011-05-04 11:44:35 +00:00
|
|
|
end).should raise_error(TypeError)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should correctly determine the preferred version' do
|
|
|
|
@client.preferred_version('prediction').version.should_not == 'v1'
|
|
|
|
@client.preferred_version(:prediction).version.should_not == 'v1'
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should generate valid requests' do
|
|
|
|
request = @client.generate_request(
|
2011-07-29 22:07:04 +00:00
|
|
|
:api_method => @prediction.training.insert,
|
|
|
|
:parameters => {'data' => '12345', }
|
2011-05-04 11:44:35 +00:00
|
|
|
)
|
|
|
|
method, uri, headers, body = request
|
|
|
|
method.should == 'POST'
|
|
|
|
uri.should ==
|
2011-07-29 22:07:04 +00:00
|
|
|
'https://www.googleapis.com/prediction/v1.2/training?data=12345'
|
2011-05-04 11:44:35 +00:00
|
|
|
(headers.inject({}) { |h,(k,v)| h[k]=v; h }).should == {}
|
|
|
|
body.should respond_to(:each)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should generate requests against the correct URIs' do
|
|
|
|
request = @client.generate_request(
|
2011-07-29 22:07:04 +00:00
|
|
|
:api_method => @prediction.training.insert,
|
|
|
|
:parameters => {'data' => '12345'}
|
2011-05-04 11:44:35 +00:00
|
|
|
)
|
|
|
|
method, uri, headers, body = request
|
|
|
|
uri.should ==
|
2011-07-29 22:07:04 +00:00
|
|
|
'https://www.googleapis.com/prediction/v1.2/training?data=12345'
|
2011-05-04 11:44:35 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should generate requests against the correct URIs' do
|
|
|
|
request = @client.generate_request(
|
2011-07-29 22:07:04 +00:00
|
|
|
:api_method => @prediction.training.insert,
|
|
|
|
:parameters => {'data' => '12345'}
|
2011-05-04 11:44:35 +00:00
|
|
|
)
|
|
|
|
method, uri, headers, body = request
|
|
|
|
uri.should ==
|
2011-07-29 22:07:04 +00:00
|
|
|
'https://www.googleapis.com/prediction/v1.2/training?data=12345'
|
2011-05-04 11:44:35 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should allow modification to the base URIs for testing purposes' do
|
2011-07-29 22:07:04 +00:00
|
|
|
prediction = @client.discovered_api('prediction', 'v1.2')
|
2011-05-12 20:14:15 +00:00
|
|
|
prediction.method_base =
|
2011-07-29 22:07:04 +00:00
|
|
|
'https://testing-domain.googleapis.com/prediction/v1.2/'
|
2011-05-04 11:44:35 +00:00
|
|
|
request = @client.generate_request(
|
2011-07-29 22:07:04 +00:00
|
|
|
:api_method => prediction.training.insert,
|
|
|
|
:parameters => {'data' => '123'}
|
2011-05-04 11:44:35 +00:00
|
|
|
)
|
|
|
|
method, uri, headers, body = request
|
2011-07-29 22:07:04 +00:00
|
|
|
uri.should == (
|
|
|
|
'https://testing-domain.googleapis.com/' +
|
|
|
|
'prediction/v1.2/training?data=123'
|
|
|
|
)
|
2011-05-04 11:44:35 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should generate OAuth 1 requests' do
|
|
|
|
@client.authorization = :oauth_1
|
|
|
|
@client.authorization.token_credential_key = '12345'
|
|
|
|
@client.authorization.token_credential_secret = '12345'
|
|
|
|
request = @client.generate_request(
|
2011-07-29 22:07:04 +00:00
|
|
|
:api_method => @prediction.training.insert,
|
|
|
|
:parameters => {'data' => '12345'}
|
2011-05-04 11:44:35 +00:00
|
|
|
)
|
|
|
|
method, uri, headers, body = request
|
|
|
|
headers = headers.inject({}) { |h,(k,v)| h[k]=v; h }
|
|
|
|
headers.keys.should include('Authorization')
|
|
|
|
headers['Authorization'].should =~ /^OAuth/
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should generate OAuth 2 requests' do
|
|
|
|
@client.authorization = :oauth_2
|
|
|
|
@client.authorization.access_token = '12345'
|
|
|
|
request = @client.generate_request(
|
2011-07-29 22:07:04 +00:00
|
|
|
:api_method => @prediction.training.insert,
|
|
|
|
:parameters => {'data' => '12345'}
|
2011-05-04 11:44:35 +00:00
|
|
|
)
|
|
|
|
method, uri, headers, body = request
|
|
|
|
headers = headers.inject({}) { |h,(k,v)| h[k]=v; h }
|
|
|
|
headers.keys.should include('Authorization')
|
|
|
|
headers['Authorization'].should =~ /^OAuth/
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should not be able to execute improperly authorized requests' do
|
|
|
|
@client.authorization = :oauth_1
|
|
|
|
@client.authorization.token_credential_key = '12345'
|
|
|
|
@client.authorization.token_credential_secret = '12345'
|
2011-07-29 22:07:04 +00:00
|
|
|
result = @client.execute(
|
|
|
|
@prediction.training.insert,
|
2011-05-04 11:44:35 +00:00
|
|
|
{'data' => '12345'}
|
|
|
|
)
|
2011-07-29 22:07:04 +00:00
|
|
|
status, headers, body = result.response
|
2011-05-04 11:44:35 +00:00
|
|
|
status.should == 401
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should not be able to execute improperly authorized requests' do
|
|
|
|
@client.authorization = :oauth_2
|
|
|
|
@client.authorization.access_token = '12345'
|
2011-07-29 22:07:04 +00:00
|
|
|
result = @client.execute(
|
|
|
|
@prediction.training.insert,
|
2011-05-04 11:44:35 +00:00
|
|
|
{'data' => '12345'}
|
|
|
|
)
|
2011-07-29 22:07:04 +00:00
|
|
|
status, headers, body = result.response
|
2011-05-04 11:44:35 +00:00
|
|
|
status.should == 401
|
|
|
|
end
|
2011-07-29 22:07:04 +00:00
|
|
|
|
|
|
|
it 'should not be able to execute improperly authorized requests' do
|
|
|
|
(lambda do
|
|
|
|
@client.authorization = :oauth_1
|
|
|
|
@client.authorization.token_credential_key = '12345'
|
|
|
|
@client.authorization.token_credential_secret = '12345'
|
|
|
|
result = @client.execute!(
|
|
|
|
@prediction.training.insert,
|
|
|
|
{'data' => '12345'}
|
|
|
|
)
|
|
|
|
end).should raise_error(Google::APIClient::ClientError)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should not be able to execute improperly authorized requests' do
|
|
|
|
(lambda do
|
|
|
|
@client.authorization = :oauth_2
|
|
|
|
@client.authorization.access_token = '12345'
|
|
|
|
result = @client.execute!(
|
|
|
|
@prediction.training.insert,
|
|
|
|
{'data' => '12345'}
|
|
|
|
)
|
|
|
|
end).should raise_error(Google::APIClient::ClientError)
|
|
|
|
end
|
2011-08-02 20:20:54 +00:00
|
|
|
|
|
|
|
it 'should correctly handle unnamed parameters' do
|
|
|
|
@client.authorization = :oauth_2
|
|
|
|
@client.authorization.access_token = '12345'
|
|
|
|
result = @client.execute(
|
|
|
|
@prediction.training.insert,
|
|
|
|
{},
|
|
|
|
JSON.generate({"id" => "bucket/object"}),
|
|
|
|
{'Content-Type' => 'application/json'}
|
|
|
|
)
|
|
|
|
method, uri, headers, body = result.request
|
|
|
|
Hash[headers]['Content-Type'].should == 'application/json'
|
|
|
|
end
|
2011-05-04 11:44:35 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
describe 'with the buzz API' do
|
|
|
|
before do
|
|
|
|
@client.authorization = nil
|
|
|
|
@buzz = @client.discovered_api('buzz')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should correctly determine the discovery URI' do
|
|
|
|
@client.discovery_uri('buzz').should ===
|
2011-05-12 20:14:15 +00:00
|
|
|
'https://www.googleapis.com/discovery/v1/apis/buzz/v1/rest'
|
2011-05-04 11:44:35 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should find APIs that are in the discovery document' do
|
|
|
|
@client.discovered_api('buzz').name.should == 'buzz'
|
|
|
|
@client.discovered_api('buzz').version.should == 'v1'
|
|
|
|
@client.discovered_api(:buzz).name.should == 'buzz'
|
|
|
|
@client.discovered_api(:buzz).version.should == 'v1'
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should find methods that are in the discovery document' do
|
|
|
|
# TODO(bobaman) Fix this when the RPC names are correct
|
|
|
|
@client.discovered_method(
|
|
|
|
'chili.activities.list', 'buzz'
|
|
|
|
).name.should == 'list'
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should not find methods that are not in the discovery document' do
|
|
|
|
@client.discovered_method('buzz.bogus', 'buzz').should == nil
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should fail for string RPC names that do not match API name' do
|
|
|
|
(lambda do
|
|
|
|
@client.generate_request(
|
2011-07-29 22:07:04 +00:00
|
|
|
:api_method => 'chili.activities.list',
|
|
|
|
:parameters => {'alt' => 'json'},
|
|
|
|
:authenticated => false
|
2011-05-04 11:44:35 +00:00
|
|
|
)
|
|
|
|
end).should raise_error(Google::APIClient::TransmissionError)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should generate requests against the correct URIs' do
|
|
|
|
request = @client.generate_request(
|
2011-07-29 22:07:04 +00:00
|
|
|
:api_method => @buzz.activities.list,
|
|
|
|
:parameters => {'userId' => 'hikingfan', 'scope' => '@public'},
|
|
|
|
:authenticated => false
|
2010-09-30 21:33:23 +00:00
|
|
|
)
|
2011-05-04 11:44:35 +00:00
|
|
|
method, uri, headers, body = request
|
|
|
|
uri.should ==
|
|
|
|
'https://www.googleapis.com/buzz/v1/activities/hikingfan/@public'
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should correctly validate parameters' do
|
|
|
|
(lambda do
|
|
|
|
@client.generate_request(
|
2011-07-29 22:07:04 +00:00
|
|
|
:api_method => @buzz.activities.list,
|
|
|
|
:parameters => {'alt' => 'json'},
|
|
|
|
:authenticated => false
|
2011-05-04 11:44:35 +00:00
|
|
|
)
|
|
|
|
end).should raise_error(ArgumentError)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should correctly validate parameters' do
|
|
|
|
(lambda do
|
|
|
|
@client.generate_request(
|
2011-07-29 22:07:04 +00:00
|
|
|
:api_method => @buzz.activities.list,
|
|
|
|
:parameters => {'userId' => 'hikingfan', 'scope' => '@bogus'},
|
|
|
|
:authenticated => false
|
2011-05-04 11:44:35 +00:00
|
|
|
)
|
|
|
|
end).should raise_error(ArgumentError)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should be able to execute requests without authorization' do
|
2011-07-29 22:07:04 +00:00
|
|
|
result = @client.execute(
|
2011-05-04 11:44:35 +00:00
|
|
|
@buzz.activities.list,
|
|
|
|
{'alt' => 'json', 'userId' => 'hikingfan', 'scope' => '@public'},
|
2010-09-30 21:33:23 +00:00
|
|
|
'',
|
|
|
|
[],
|
2011-07-29 22:07:04 +00:00
|
|
|
:authenticated => false
|
2010-09-30 21:33:23 +00:00
|
|
|
)
|
2011-07-29 22:07:04 +00:00
|
|
|
status, headers, body = result.response
|
2011-05-04 11:44:35 +00:00
|
|
|
status.should == 200
|
|
|
|
end
|
2011-07-29 22:07:04 +00:00
|
|
|
|
2011-10-05 11:13:39 +00:00
|
|
|
it 'should correctly handle nested schema objects' do
|
|
|
|
result = @client.execute(
|
|
|
|
@buzz.activities.list,
|
|
|
|
{'alt' => 'json', 'userId' => 'hikingfan', 'scope' => '@public'},
|
|
|
|
'',
|
|
|
|
[],
|
|
|
|
:authenticated => false
|
|
|
|
)
|
|
|
|
feed = result.data
|
|
|
|
puts feed.inspect
|
|
|
|
end
|
|
|
|
|
2011-07-29 22:07:04 +00:00
|
|
|
it 'should not be able to execute requests without authorization' do
|
|
|
|
result = @client.execute(
|
|
|
|
@buzz.activities.list,
|
|
|
|
'alt' => 'json', 'userId' => '@me', 'scope' => '@self'
|
|
|
|
)
|
|
|
|
status, headers, body = result.response
|
|
|
|
status.should == 401
|
|
|
|
end
|
2011-05-04 11:44:35 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
describe 'with the latitude API' do
|
|
|
|
before do
|
|
|
|
@client.authorization = nil
|
|
|
|
@latitude = @client.discovered_api('latitude')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should correctly determine the discovery URI' do
|
|
|
|
@client.discovery_uri('latitude').should ===
|
2011-05-12 20:14:15 +00:00
|
|
|
'https://www.googleapis.com/discovery/v1/apis/latitude/v1/rest'
|
2011-05-04 11:44:35 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should find APIs that are in the discovery document' do
|
|
|
|
@client.discovered_api('latitude').name.should == 'latitude'
|
|
|
|
@client.discovered_api('latitude').version.should == 'v1'
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should find methods that are in the discovery document' do
|
|
|
|
@client.discovered_method(
|
|
|
|
'latitude.currentLocation.get', 'latitude'
|
|
|
|
).name.should == 'get'
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should not find methods that are not in the discovery document' do
|
|
|
|
@client.discovered_method('latitude.bogus', 'latitude').should == nil
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should generate requests against the correct URIs' do
|
|
|
|
request = @client.generate_request(
|
2011-07-29 22:07:04 +00:00
|
|
|
:api_method => 'latitude.currentLocation.get',
|
|
|
|
:authenticated => false
|
2011-05-04 11:44:35 +00:00
|
|
|
)
|
|
|
|
method, uri, headers, body = request
|
|
|
|
uri.should ==
|
|
|
|
'https://www.googleapis.com/latitude/v1/currentLocation'
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should generate requests against the correct URIs' do
|
|
|
|
request = @client.generate_request(
|
2011-07-29 22:07:04 +00:00
|
|
|
:api_method => @latitude.current_location.get,
|
|
|
|
:authenticated => false
|
2011-05-04 11:44:35 +00:00
|
|
|
)
|
|
|
|
method, uri, headers, body = request
|
|
|
|
uri.should ==
|
|
|
|
'https://www.googleapis.com/latitude/v1/currentLocation'
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should not be able to execute requests without authorization' do
|
2011-07-29 22:07:04 +00:00
|
|
|
result = @client.execute(
|
|
|
|
:api_method => 'latitude.currentLocation.get',
|
|
|
|
:authenticated => false
|
2011-05-04 11:44:35 +00:00
|
|
|
)
|
2011-07-29 22:07:04 +00:00
|
|
|
status, headers, body = result.response
|
2011-05-04 11:44:35 +00:00
|
|
|
status.should == 401
|
|
|
|
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 ===
|
2011-05-12 20:14:15 +00:00
|
|
|
'https://www.googleapis.com/discovery/v1/apis/moderator/v1/rest'
|
2011-05-04 11:44:35 +00:00
|
|
|
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 not find methods that are not in the discovery document' do
|
|
|
|
@client.discovered_method('moderator.bogus', 'moderator').should == nil
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should generate requests against the correct URIs' do
|
|
|
|
request = @client.generate_request(
|
2011-07-29 22:07:04 +00:00
|
|
|
:api_method => 'moderator.profiles.get',
|
|
|
|
:authenticated => false
|
2011-05-04 11:44:35 +00:00
|
|
|
)
|
|
|
|
method, uri, headers, body = request
|
|
|
|
uri.should ==
|
|
|
|
'https://www.googleapis.com/moderator/v1/profiles/@me'
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should generate requests against the correct URIs' do
|
|
|
|
request = @client.generate_request(
|
2011-07-29 22:07:04 +00:00
|
|
|
:api_method => @moderator.profiles.get,
|
|
|
|
:authenticated => false
|
2011-05-04 11:44:35 +00:00
|
|
|
)
|
|
|
|
method, uri, headers, body = request
|
|
|
|
uri.should ==
|
|
|
|
'https://www.googleapis.com/moderator/v1/profiles/@me'
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should not be able to execute requests without authorization' do
|
2011-07-29 22:07:04 +00:00
|
|
|
result = @client.execute(
|
2011-05-04 11:44:35 +00:00
|
|
|
'moderator.profiles.get',
|
|
|
|
{},
|
|
|
|
'',
|
|
|
|
[],
|
2011-07-29 22:07:04 +00:00
|
|
|
{:authenticated => false}
|
2011-05-04 11:44:35 +00:00
|
|
|
)
|
2011-07-29 22:07:04 +00:00
|
|
|
status, headers, body = result.response
|
2011-05-04 11:44:35 +00:00
|
|
|
status.should == 401
|
|
|
|
end
|
2010-09-30 21:57:13 +00:00
|
|
|
end
|
|
|
|
end
|