Skip to content

Commit

Permalink
parse JSON
Browse files Browse the repository at this point in the history
  • Loading branch information
dstnbrkr authored and spohlenz committed May 6, 2010
1 parent 799b278 commit 036244f
Showing 1 changed file with 4 additions and 13 deletions.
17 changes: 4 additions & 13 deletions lib/itunes_link_maker.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require 'rubygems'
require 'open-uri'
require 'cgi'
require 'hpricot'
require 'json'

require File.join(File.dirname(__FILE__), 'result')

Expand Down Expand Up @@ -41,18 +41,9 @@ def self.quick_search(query, options={})
end

private
def self.parse_html(html)
doc = Hpricot(html)

result = []
(doc/'a.searchResults').each_with_index do |element, i|
name = element.inner_text.strip
type = TYPE_INDICES[i]
url = element['href']

result << Result.new(name, type, url)
end
result
def self.parse_html(json)
parser = JSON.parse(json)
parser.collect { |e| Result.new(e["itemName"], e["mediaType"], e["itemLinkUrl"]) }
end

def self.get_html(query, options={})
Expand Down

0 comments on commit 036244f

Please sign in to comment.