From c183d6ddfd14d0c1a6708127f78558dae9377aa4 Mon Sep 17 00:00:00 2001 From: Bob Aman Date: Tue, 12 Oct 2010 02:09:14 +0000 Subject: [PATCH] Updated to handle content types correctly. git-svn-id: https://google-api-ruby-client.googlecode.com/svn/trunk@54 c1d61fac-ed7f-fcc1-18f7-ff78120a04ef --- bin/google-api | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/bin/google-api b/bin/google-api index 02f2f6f57..1e41f940d 100755 --- a/bin/google-api +++ b/bin/google-api @@ -38,6 +38,21 @@ OptionParser.new do |opts| "--service-version ", String, "Select service version") do |id| options[:service_version] = id end + opts.on( + "--content-type ", String, "Content-Type for request") do |f| + # Resolve content type shortcuts + case f + when 'json' + f = 'application/json' + when 'xml' + f = 'application/xml' + when 'atom' + f = 'application/atom+xml' + when 'rss' + f = 'application/rss+xml' + end + options[:content_type] = f + end opts.on("--fuzz [rpcname]", String, "Fuzz an API or endpoint") do |rpcname| command = 'fuzz' options[:fuzz] = rpcname @@ -193,8 +208,15 @@ def execute(options={}) request_body = '' input_streams, _, _ = IO.select([STDIN], [], [], 0) request_body = STDIN.read || '' if input_streams + headers = [] + if options[:content_type] + headers << ['Content-Type', options[:content_type]] + elsif request_body + # Default to JSON + headers << ['Content-Type', 'application/json'] + end response = client.execute( - method, parameters, request_body, [], {:signed => signed} + method, parameters, request_body, headers, {:signed => signed} ) status, headers, body = response puts body