Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Predictable parameter ordering

  • Loading branch information...
commit 98bac1b2fcd4f0e7bc0cff76b2178d09dbb66cdb 1 parent c9cbe31
@sam-wan sam-wan authored
Showing with 7 additions and 4 deletions.
  1. +6 −3 lib/itunes_link_maker.rb
  2. +1 −1  spec/itunes_link_maker_spec.rb
View
9 lib/itunes_link_maker.rb
@@ -17,6 +17,8 @@ class ItunesLinkMaker
TYPE_INDICES = { 0 => :name, 1 => :album, 2 => :artist }
+ OPTION_ORDER = [ 'WOURLEncoding', 'lang', 'output', 'partnerId', 'LS_PARAM', 'country', 'term', 'media' ]
+
@default_options = {
'media' => 'music',
'country' => 'US',
@@ -37,7 +39,7 @@ def self.search(query, options={})
def self.quick_search(query, options={})
search(query, options).first
end
-
+
private
def self.parse_html(html)
doc = Hpricot(html)
@@ -54,10 +56,11 @@ def self.parse_html(html)
end
def self.get_html(query, options={})
- open("#{SEARCH_URL}?term=#{CGI.escape(query)}&#{serialize(options)}").read
+ options['term'] = CGI.escape(query)
+ open("#{SEARCH_URL}?#{serialize(options)}").read
end
def self.serialize(options={})
- options.map { |k, v| "#{k}=#{v}" }.join('&')
+ options.sort_by { |k, v| OPTION_ORDER.index(k) }.map { |k, v| "#{k}=#{v}" }.join('&')
end
end
View
2  spec/itunes_link_maker_spec.rb
@@ -20,7 +20,7 @@ def search
it "should send a GET request to the iTunes search URL" do
ItunesLinkMaker.should_receive(:open).with(
- "http://ax.phobos.apple.com.edgesuite.net/WebObjects/MZStoreServices.woa/wa/itmsSearch?term=search+query&media=music&country=US&output=lm&lang=1&WOURLEncoding=ISO8859_1"
+ "http://ax.phobos.apple.com.edgesuite.net/WebObjects/MZStoreServices.woa/wa/itmsSearch?WOURLEncoding=ISO8859_1&lang=1&output=lm&country=US&term=search+query&media=music"
).and_return(@open_result)
search
end
Please sign in to comment.
Something went wrong with that request. Please try again.