lib/rockstar/rest.rb in rockstar-0.6.3 vs lib/rockstar/rest.rb in rockstar-0.6.4
- old
+ new
@@ -18,23 +18,23 @@
request(resource, "post", args, sign_request)
end
def request(resource, method = "get", args = {}, sign_request=false)
url = URI.parse(@base_url)
-
+
if (!resource.blank?)
args[:method] = resource
args[:api_key]= Rockstar.lastfm_api_key
end
-
+
if args
sorted_keys = args.keys.sort_by{|k|k.to_s}
query = sorted_keys.collect { |k| "%s=%s" % [escape(k.to_s), escape(args[k].to_s)] }.join("&")
if !args[:sk].nil? ||sign_request # Session Key available => sign the request or sign_request = true?
signed = sorted_keys.collect {|k| "%s%s" % [k.to_s, args[k].to_s]}.join()
-
+
auth = Digest::MD5.hexdigest("#{signed}#{Rockstar.lastfm_api_secret}")
query += "&api_sig=#{auth}"
end
url.query = query
end
@@ -54,10 +54,10 @@
http.use_ssl = (url.port == 443)
res = http.start() { |conn| conn.request(req) }
res.body
end
-
+
private
def escape(str)
URI.escape(str, Regexp.new("[^#{URI::PATTERN::UNRESERVED}]"))
end
end