Permalink
Browse files

Changed the way query string information gets encoded in hopes that i…

…t fixes some problems for some people.
  • Loading branch information...
1 parent 4da3c34 commit ff6dca2878e4572c3d5ef523fdba96074a6c4585 @jnunemaker committed Apr 13, 2009
Showing with 12 additions and 3 deletions.
  1. +1 −0 History.txt
  2. +5 −1 examples/track.rb
  3. +6 −2 lib/scrobbler/rest.rb
View
@@ -1,3 +1,4 @@
+* v 0.2.3: changed the way things get escaped in hopes that it would fix some problems some were having
* v 0.2.2: a bunch of changes from titanous, mostly refactoring
* v 0.2.0: added support for scrobbling tracks and now playing submission (Titanous)
* v 0.1.0: initial release
View
@@ -1,6 +1,10 @@
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib', 'scrobbler'))
+require 'pp'
track = Scrobbler::Track.new('Carrie Underwood', 'Before He Cheats')
puts 'Fans'
puts "=" * 4
-track.fans.each { |u| puts "(#{u.weight}) #{u.username}" }
+track.fans.each { |u| puts "(#{u.weight}) #{u.username}" }
+
+track = Scrobbler::Track.new('U2 & Green Day', 'The Saints Are Coming')
+pp track.tags
@@ -21,8 +21,7 @@ def request(resource, method = "get", args = nil)
url = URI.join(@base_url, resource)
if args
- # TODO: What about keys without value?
- url.query = args.map { |k,v| "%s=%s" % [URI.encode(k.to_s), URI.encode(v.to_s)] }.join("&")
+ url.query = args.map { |k,v| "%s=%s" % [escape(k.to_s), escape(v.to_s)] }.join("&")
end
case method
@@ -42,6 +41,11 @@ def request(resource, method = "get", args = nil)
res = http.start() { |conn| conn.request(req) }
res.body
end
+
+ private
+ def escape(str)
+ URI.escape(str, Regexp.new("[^#{URI::PATTERN::UNRESERVED}]"))
+ end
end
end
end

0 comments on commit ff6dca2

Please sign in to comment.