Sha256: ba78e699d5a10b63a7072cac437f733d6a6096dd0997b965a751d6044e8bceaa
Contents?: true
Size: 931 Bytes
Versions: 2
Compression:
Stored size: 931 Bytes
Contents
# -*- coding: utf-8 -*- require 'json' require 'net/http' require 'previews/version' require 'previews/array' require 'previews/hirb_vertical_table' module Previews class PackageReviews def initialize(locale, release, package) @url = "http://reviews.ubuntu.com/reviews/api/1.0/reviews/filter/#{locale}/ubuntu/#{release}/any/#{package}/" @reviews = [] end # Return Array of Hases def reviews download_reviews @reviews.flatten! @reviews end private # Get all reviews # Return Array of Hashes def download_reviews page = 1 loop do @reviews << download_page(page) break if @reviews.last.empty? page += 1 end end # Get the one page of reviews. # Return Array of Hashes def download_page(page_number) print '.' JSON.parse(Net::HTTP.get(URI(@url + "page/#{page_number}/"))) end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
previews-0.0.3 | lib/previews.rb |
previews-0.0.2 | lib/previews.rb |