Reorganized some of the code and removed unnecessary stuff.

git-svn-id: https://google-api-ruby-client.googlecode.com/svn/trunk@35 c1d61fac-ed7f-fcc1-18f7-ff78120a04ef
This commit is contained in:
Bob Aman committed 2010-09-18 00:30:02 +00:00
1 parent 3a9d58108a
commit f96412cf23
11 files changed
+130 -222

No files matched your search

@@ -1,46 +0,0 @@
# 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'
require 'oauth'
require 'google/api_client/discovery/discovery'
describe Google::APIClient::Discovery, 'configured for use with a service' do
before do
@discovery = Google::APIClient::Discovery.new(:service => :magic)
end
it 'should have the correct discovery document URI' do
@discovery.discovery_uri.should ==
'http://www.googleapis.com/discovery/0.1/describe' +
'?api=magic&apiVersion=1.0'
end
end
describe Google::APIClient::Discovery,
'configured for use with a specific service version' do
before do
@discovery = Google::APIClient::Discovery.new(
:service => :magic,
:service_version => 42.0
)
end
it 'should have the correct discovery document URI' do
@discovery.discovery_uri.should ==
'http://www.googleapis.com/discovery/0.1/describe' +
'?api=magic&apiVersion=42.0'
end
end
+71
View File
@@ -0,0 +1,71 @@
# 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'
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'
describe Google::APIClient, 'configured for the prediction API' do
before do
@client = Google::APIClient.new(:service => 'prediction')
end
it 'should have multiple versions available' do
@client.discovered_services.size.should > 1
end
it 'should correctly determine the latest version' do
@client.latest_service('prediction').version.should_not == 'v1'
end
it 'should correctly determine the latest version' do
# Sanity check the algorithm
@client.discovered_services.clear
@client.discovered_services <<
Google::APIClient::Service.new('magic', 'v1', {})
@client.discovered_services <<
Google::APIClient::Service.new('magic', 'v1.1', {})
@client.discovered_services <<
Google::APIClient::Service.new('magic', 'v1.10', {})
@client.discovered_services <<
Google::APIClient::Service.new('magic', 'v10.1', {})
@client.discovered_services <<
Google::APIClient::Service.new('magic', 'v2.1', {})
@client.discovered_services <<
Google::APIClient::Service.new('magic', 'v10.0', {})
@client.latest_service('magic').version.should == 'v10.1'
end
it 'should correctly determine the latest version' do
# Sanity check the algorithm
@client.discovered_services.clear
@client.discovered_services <<
Google::APIClient::Service.new('one', 'v3', {})
@client.discovered_services <<
Google::APIClient::Service.new('two', 'v1', {})
@client.discovered_services <<
Google::APIClient::Service.new('two', 'v2', {})
@client.latest_service('two').version.should == 'v2'
end
it 'should return nil for bogus service names' do
# Sanity check the algorithm
@client.latest_service('bogus').should == nil
end
end
@@ -15,25 +15,28 @@
require 'spec_helper'
require 'json'
require 'google/api_client/parser/json_parser'
require 'google/api_client/parsers/json_parser'
describe Google::APIClient::JSONParser, 'generates json from hash' do
before do
@parser = Google::APIClient::JSONParser.new
@parser = Google::APIClient::JSONParser
end
it 'should translate simple hash to JSON string' do
@parser.generate('test' => 23).should == "{\"test\":23}"
@parser.serialize('test' => 23).should == '{"test":23}'
end
it 'should translate simple nested into to nested JSON string' do
@parser.generate({'test' => 23, 'test2' => {'foo' => 'baz', 12 => 3.14 }}).should ==
"{\"test2\":{\"12\":3.14,\"foo\":\"baz\"},\"test\":23}"
@parser.serialize({
'test' => 23, 'test2' => {'foo' => 'baz', 12 => 3.14 }
}).should ==
'{"test2":{"12":3.14,"foo":"baz"},"test":23}'
end
end
describe Google::APIClient::JSONParser, 'parses json string into hash' do
before do
@parser = Google::APIClient::JSONParser.new
@parser = Google::APIClient::JSONParser
end
it 'should parse simple json string into hash' do
@@ -41,8 +44,8 @@ describe Google::APIClient::JSONParser, 'parses json string into hash' do
end
it 'should parse nested json object into hash' do
@parser.parse('{"test":23, "test2":{"bar":"baz", "foo":3.14}}').should ==
{'test' => 23, 'test2' => {'bar' => 'baz', 'foo' => 3.14}}
@parser.parse('{"test":23, "test2":{"bar":"baz", "foo":3.14}}').should == {
'test' => 23, 'test2' => {'bar' => 'baz', 'foo' => 3.14}
}
end
end
+2 -2
View File
@@ -19,7 +19,7 @@ require 'httpadapter/adapters/net_http'
require 'google/api_client'
require 'google/api_client/version'
require 'google/api_client/parser/json_parser'
require 'google/api_client/parsers/json_parser'
describe Google::APIClient, 'with default configuration' do
before do
@@ -31,7 +31,7 @@ describe Google::APIClient, 'with default configuration' do
end
it 'should use the default JSON parser' do
@client.parser.should be_instance_of(Google::APIClient::JSONParser)
@client.parser.should be(Google::APIClient::JSONParser)
end
it 'should use the default OAuth1 client configuration' do