Permalink
Browse files

parse JSON

  • Loading branch information...
1 parent 799b278 commit 036244f9a7ee6ff17db2b871e9675eb095e89812 @dstnbrkr dstnbrkr committed with May 4, 2010
Showing with 4 additions and 13 deletions.
  1. +4 −13 lib/itunes_link_maker.rb
View
@@ -1,7 +1,7 @@
require 'rubygems'
require 'open-uri'
require 'cgi'
-require 'hpricot'
+require 'json'
require File.join(File.dirname(__FILE__), 'result')
@@ -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={})

0 comments on commit 036244f

Please sign in to comment.