From b0846efa4ae2813488680cd793516ec3ed8f4ec7 Mon Sep 17 00:00:00 2001 From: Bob Aman Date: Fri, 22 Oct 2010 19:15:05 +0000 Subject: [PATCH] Added support for xoauth_requestor_id. git-svn-id: https://google-api-ruby-client.googlecode.com/svn/trunk@100 c1d61fac-ed7f-fcc1-18f7-ff78120a04ef --- bin/google-api | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/bin/google-api b/bin/google-api index 2ad40f7ff..a017685ee 100755 --- a/bin/google-api +++ b/bin/google-api @@ -137,6 +137,11 @@ HTML "Sets the HTTP method to use for the request") do |m| options[:http_method] = m end + opts.on( + "--requestor-id ", String, + "Sets the email address of the requestor") do |e| + options[:requestor_id] = e + end opts.on("-v", "--verbose", "Run verbosely") do |v| options[:verbose] = v @@ -277,6 +282,7 @@ HTML require 'yaml' config_file = File.expand_path('~/.google-api.yaml') signed = File.exist?(config_file) + authorization_type = :oauth_1 # Setup HTTP request data request_body = '' @@ -307,6 +313,9 @@ HTML config["token_credential_key"] client.authorization.token_credential_secret = config["token_credential_secret"] + if client.authorization.token_credential == nil + authorization_type = :two_legged_oauth_1 + end end if options[:uri] @@ -316,10 +325,15 @@ HTML STDERR.puts('URI may not be relative.') exit(1) end + if options[:requestor_id] + uri.query_values = uri.query_values.merge( + 'xoauth_requestor_id' => options[:requestor_id] + ) + end method = options[:http_method] method ||= request_body == '' ? 'GET' : 'POST' method.upcase! - client = Google::APIClient.new(:authorization => :two_legged_oauth_1) + client = Google::APIClient.new(:authorization => authorization_type) configure_authorization.call(client) if signed request = [method, uri.to_str, headers, [request_body]] request = client.sign_request(request) @@ -337,7 +351,7 @@ HTML options[:service_name] || self.rpcname[/^([^\.]+)\./, 1] client = Google::APIClient.new( :service => service_name, - :authorization => :oauth_1 + :authorization => authorization_type ) configure_authorization.call(client) if signed service_version = @@ -357,6 +371,9 @@ HTML accu[name] = value accu end + if options[:requestor_id] + parameters['xoauth_requestor_id'] = options[:requestor_id] + end begin response = client.execute( method, parameters, request_body, headers, {:signed => signed}