Skip to content

Commit

Permalink
Changed the way query string information gets encoded in hopes that i…
Browse files Browse the repository at this point in the history
…t fixes some problems for some people.
  • Loading branch information
jnunemaker committed Apr 13, 2009
1 parent 4da3c34 commit ff6dca2
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
1 change: 1 addition & 0 deletions History.txt
@@ -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
6 changes: 5 additions & 1 deletion examples/track.rb
@@ -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
8 changes: 6 additions & 2 deletions lib/scrobbler/rest.rb
Expand Up @@ -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
Expand All @@ -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.