1 # Copyright 2010 Google Inc.
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
17 require 'signet/oauth_1/client'
18 require 'httpadapter/adapters/net_http'
20 require 'google/api_client'
21 require 'google/api_client/version'
22 require 'google/api_client/parsers/json_parser'
24 describe Google::APIClient, 'configured for the prediction API' do
26 @client = Google::APIClient.new(:service => 'prediction')
29 it 'should have multiple versions available' do
30 @client.discovered_services.size.should > 1
33 it 'should correctly determine the latest version' do
34 @client.latest_service('prediction').version.should_not == 'v1'
37 it 'should correctly determine the latest version' do
38 # Sanity check the algorithm
39 @client.discovered_services.clear
40 @client.discovered_services <<
41 Google::APIClient::Service.new('magic', 'v1', {})
42 @client.discovered_services <<
43 Google::APIClient::Service.new('magic', 'v1.1', {})
44 @client.discovered_services <<
45 Google::APIClient::Service.new('magic', 'v1.10', {})
46 @client.discovered_services <<
47 Google::APIClient::Service.new('magic', 'v10.1', {})
48 @client.discovered_services <<
49 Google::APIClient::Service.new('magic', 'v2.1', {})
50 @client.discovered_services <<
51 Google::APIClient::Service.new('magic', 'v10.0', {})
52 @client.latest_service('magic').version.should == 'v10.1'
55 it 'should correctly determine the latest version' do
56 # Sanity check the algorithm
57 @client.discovered_services.clear
58 @client.discovered_services <<
59 Google::APIClient::Service.new('one', 'v3', {})
60 @client.discovered_services <<
61 Google::APIClient::Service.new('two', 'v1', {})
62 @client.discovered_services <<
63 Google::APIClient::Service.new('two', 'v2', {})
64 @client.latest_service('two').version.should == 'v2'
67 it 'should return nil for bogus service names' do
68 # Sanity check the algorithm
69 @client.latest_service('bogus').should == nil