1 # Copyright 2012 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 'google/api_client'
18 require 'google/api_client/version'
20 describe Google::APIClient::Result do
22 @client = Google::APIClient.new
25 describe 'with the plus API' do
27 @client.authorization = nil
28 @plus = @client.discovered_api('plus', 'v1')
29 @reference = Google::APIClient::Reference.new({
30 :api_method => @plus.activities.list,
33 'collection' => 'public',
37 @request = @reference.to_request
40 @response = stub("response")
41 @response.stub(:status).and_return(200)
42 @response.stub(:headers).and_return({
44 'x-google-apiary-auth-scopes' =>
45 'https://www.googleapis.com/auth/plus.me',
46 'content-type' => 'application/json; charset=UTF-8',
47 'date' => 'Mon, 23 Apr 2012 00:00:00 GMT',
48 'cache-control' => 'private, max-age=0, must-revalidate, no-transform',
50 'connection' => 'close'
52 @response.stub(:body).and_return(
55 "kind": "plus#activityFeed",
57 "nextPageToken": "NEXT+PAGE+TOKEN",
58 "selfLink": "https://www.googleapis.com/plus/v1/people/foo/activities/public?",
59 "nextLink": "https://www.googleapis.com/plus/v1/people/foo/activities/public?maxResults=20&pageToken=NEXT%2BPAGE%2BTOKEN",
60 "title": "Plus Public Activity Feed for ",
61 "updated": "2012-04-23T00:00:00.000Z",
62 "id": "tag:google.com,2010:/plus/people/foo/activities/public",
67 @result = Google::APIClient::Result.new(@reference, @request, @response)
70 it 'should return the correct next page token' do
71 @result.next_page_token.should == 'NEXT+PAGE+TOKEN'
74 it 'should escape the next page token when calling next_page' do
75 reference = @result.next_page
76 reference.parameters.should include('pageToken')
77 reference.parameters['pageToken'].should == 'NEXT+PAGE+TOKEN'
78 path = reference.to_request.path.to_s
79 path.should include 'pageToken=NEXT%2BPAGE%2BTOKEN'