Skip to content

Commit ff6dca2

Browse files
committed
Changed the way query string information gets encoded in hopes that it fixes some problems for some people.
1 parent 4da3c34 commit ff6dca2

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

History.txt

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
* v 0.2.3: changed the way things get escaped in hopes that it would fix some problems some were having
12
* v 0.2.2: a bunch of changes from titanous, mostly refactoring
23
* v 0.2.0: added support for scrobbling tracks and now playing submission (Titanous)
34
* v 0.1.0: initial release

examples/track.rb

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib', 'scrobbler'))
2+
require 'pp'
23

34
track = Scrobbler::Track.new('Carrie Underwood', 'Before He Cheats')
45
puts 'Fans'
56
puts "=" * 4
6-
track.fans.each { |u| puts "(#{u.weight}) #{u.username}" }
7+
track.fans.each { |u| puts "(#{u.weight}) #{u.username}" }
8+
9+
track = Scrobbler::Track.new('U2 & Green Day', 'The Saints Are Coming')
10+
pp track.tags

lib/scrobbler/rest.rb

+6-2
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@ def request(resource, method = "get", args = nil)
2121
url = URI.join(@base_url, resource)
2222

2323
if args
24-
# TODO: What about keys without value?
25-
url.query = args.map { |k,v| "%s=%s" % [URI.encode(k.to_s), URI.encode(v.to_s)] }.join("&")
24+
url.query = args.map { |k,v| "%s=%s" % [escape(k.to_s), escape(v.to_s)] }.join("&")
2625
end
2726

2827
case method
@@ -42,6 +41,11 @@ def request(resource, method = "get", args = nil)
4241
res = http.start() { |conn| conn.request(req) }
4342
res.body
4443
end
44+
45+
private
46+
def escape(str)
47+
URI.escape(str, Regexp.new("[^#{URI::PATTERN::UNRESERVED}]"))
48+
end
4549
end
4650
end
4751
end

0 commit comments

Comments
 (0)