Having trouble with official Yahoo BOSS API Ruby Documentation-Collection of common programming errors
I’m following the tutorial over here, right on developer.yahoo.com:
I left their oauth_util.rb
alone but I have changed a couple of things with test.rb
– the line 1 and I added the keys, obviously.
require './oauth_util.rb'
require 'net/http'
def get_response(args,buckets)
url = "http://yboss.yahooapis.com/ysearch/"+buckets+"?"
arg_count = 0
args.each do|key,value|
url = url + key + "=" + value+"&"
++arg_count
end
if(arg_count > 0)
url.slice!(url.length-1)
end
parsed_url = URI.parse( url )
puts "url midway:"
puts url
o = OauthUtil.new
o.consumer_key = "asfasfasdfasdf"
o.consumer_secret = "asfasfasf123123"
Net::HTTP.start( parsed_url.host ) { | http |
req = Net::HTTP::Get.new "#{ parsed_url.path }?#{ o.sign(parsed_url).query_string }"
response = http.request(req)
return response.read_body
}
end
args = Hash.new
args["format"] = "xml"
#args["format"] = "json"
args["q"] = "watch1"
args["count"] = "1"
buckets = "web"
print get_response(args,buckets)
Here is the error I’m getting currently:
{"bossresponse":{"responsecode":"400","reason":"Invalid 'format' parameter'["xml"]'"}}
It’s mis-parsing it somewhere. I’ve commented everything out in args except args["q"]
and args["count"]
, and the resulting error is this:
{"bossresponse":{"responsecode":"400","reason":"Non-integer value in parameter count"}}
Okay. Let’s change it to args["count"] = 1
:
Boom! Ruby error:
test.rb:8:in `+': can't convert Fixnum into String (TypeError)
Change line 8 in test.rb to make value
a string with .to_s and we get:
test.rb:8: syntax error, unexpected tUPLUS, expecting keyword_end
url = url + key + "=" + value.to_s +"&"
What is going on? Why is this on the official Ruby docs on Yahoo?