Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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

…t fixes some problems for some people.
  • Loading branch information...
commit ff6dca2878e4572c3d5ef523fdba96074a6c4585 1 parent 4da3c34
John Nunemaker authored April 13, 2009
1  History.txt
... ...
@@ -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
1 2
 * v 0.2.2: a bunch of changes from titanous, mostly refactoring
2 3
 * v 0.2.0: added support for scrobbling tracks and now playing submission (Titanous)
3 4
 * v 0.1.0: initial release
6  examples/track.rb
... ...
@@ -1,6 +1,10 @@
1 1
 require File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib', 'scrobbler'))
  2
+require 'pp'
2 3
 
3 4
 track = Scrobbler::Track.new('Carrie Underwood', 'Before He Cheats')
4 5
 puts 'Fans'
5 6
 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
8  lib/scrobbler/rest.rb
@@ -21,8 +21,7 @@ def request(resource, method = "get", args = nil)
21 21
   			url = URI.join(@base_url, resource)
22 22
 
23 23
   			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("&")
26 25
   			end
27 26
 
28 27
   			case method
@@ -42,6 +41,11 @@ def request(resource, method = "get", args = nil)
42 41
   			res = http.start() { |conn| conn.request(req) }
43 42
   			res.body
44 43
   		end
  44
+  		
  45
+  		private
  46
+  		  def escape(str)
  47
+  		    URI.escape(str, Regexp.new("[^#{URI::PATTERN::UNRESERVED}]"))
  48
+  		  end
45 49
   	end
46 50
   end
47 51
 end

0 notes on commit ff6dca2

Please sign in to comment.
Something went wrong with that request. Please try again.