Updated to handle content types correctly.

git-svn-id: https://google-api-ruby-client.googlecode.com/svn/trunk@54 c1d61fac-ed7f-fcc1-18f7-ff78120a04ef
This commit is contained in:
Bob Aman 2010-10-12 02:09:14 +00:00
parent 733655684a
commit c183d6ddfd
1 changed files with 23 additions and 1 deletions

View File

@ -38,6 +38,21 @@ OptionParser.new do |opts|
"--service-version <id>", String, "Select service version") do |id| "--service-version <id>", String, "Select service version") do |id|
options[:service_version] = id options[:service_version] = id
end end
opts.on(
"--content-type <format>", 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| opts.on("--fuzz [rpcname]", String, "Fuzz an API or endpoint") do |rpcname|
command = 'fuzz' command = 'fuzz'
options[:fuzz] = rpcname options[:fuzz] = rpcname
@ -193,8 +208,15 @@ def execute(options={})
request_body = '' request_body = ''
input_streams, _, _ = IO.select([STDIN], [], [], 0) input_streams, _, _ = IO.select([STDIN], [], [], 0)
request_body = STDIN.read || '' if input_streams 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( response = client.execute(
method, parameters, request_body, [], {:signed => signed} method, parameters, request_body, headers, {:signed => signed}
) )
status, headers, body = response status, headers, body = response
puts body puts body