Module: Peekapp::Reviews
- Defined in:
- lib/peekapp/reviews.rb
Class Method Summary collapse
Class Method Details
.from_app(id, stores, options = {}) ⇒ Object
{{{
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/peekapp/reviews.rb', line 5 def self.from_app id, stores, = {} # {{{ reviews = Array.new begin stores.each do |s| args = { :url => $peekapp_config[:reviews_url], :app_id => id, :store_id => s, :page => ([:page] ? [:page] : 1), :app_version => ([:app_version] ? [:app_version] : "all") } dom = Peekapp::query args begin nb_page = Nokogiri::HTML.parse(dom).css("div.paginated-content").first["total-number-of-pages"].to_i rescue raise ReviewsUnavailableForThisApp end nb_page.times do |z| # dom is already instanciated for z === 0 args[:page] = z+1 dom = Peekapp::query args if z > 0 parse(dom).each do |p| raise LatestReviewReached if [:latest_review_hash] and p.id == [:latest_review_hash] reviews << p end end end rescue LatestReviewReached # Do nothing... just get out. end reviews end |
.parse(data) ⇒ Object
}}}
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/peekapp/reviews.rb', line 38 def self.parse data # {{{ reviews = Array.new dom = Nokogiri::HTML.parse(data) dom.css("div.customer-review").each do |r| # That's some ugly stuff... I know reviews << Review.new({ :title => r.css("span.customerReviewTitle").children.to_s, :comment => r.css("p.content").children.to_s.gsub("\n", "").gsub(" ", ""), :username => r.css("a.reviewer").children.to_s.gsub("\n", "").gsub(" ", ""), :user_id => r.css("a.reviewer").first["href"].split('=').last, :rating => r.css("div.rating").first['aria-label'].split(' ').first.to_i, :date => r.css("span.user-info").children.to_s.split(" -\n").last.gsub("\n", "").gsub(" ", ""), :version => r.css("span.user-info").children.to_s.split(" -\n")[1].split(" - ").first.split(" ").last.to_s, }) end reviews end |