Class: GooglePlay
- Inherits:
-
Object
- Object
- GooglePlay
- Includes:
- Parser
- Defined in:
- lib/google-play.rb,
lib/google-play/app.rb,
lib/google-play/parser.rb,
lib/google-play/review.rb,
lib/google-play/version.rb
Defined Under Namespace
Modules: Parser Classes: App, Review
Constant Summary collapse
- BASE_URL =
'https://play.google.com'
- SORT_ORDERS =
[:newest, :rating, :helpfulness]
- VERSION =
'0.0.2'
Instance Method Summary collapse
- #app(id) ⇒ Object
-
#initialize ⇒ GooglePlay
constructor
A new instance of GooglePlay.
- #reviews(id, opts = {}) ⇒ Object
Methods included from Parser
Constructor Details
#initialize ⇒ GooglePlay
Returns a new instance of GooglePlay.
13 14 15 |
# File 'lib/google-play.rb', line 13 def initialize @client = HTTPClient.new end |
Instance Method Details
#app(id) ⇒ Object
17 18 19 20 21 |
# File 'lib/google-play.rb', line 17 def app(id) res = @client.get("#{GooglePlay::BASE_URL}/store/apps/details", {:id => id}) raise GooglePlay::App::NotFoundError.new("'#{id}' is not found") if res.status_code == 404 parse_app(res.content) end |
#reviews(id, opts = {}) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/google-play.rb', line 23 def reviews(id, opts = {}) page = opts[:page] || :all sort_order = opts[:sort_order] || :newest if page.is_a?(Integer) return fetch_reviews(id, page, sort_order) else all_reviews = [] i = 0 loop do reviews = fetch_reviews(id, i, sort_order) return all_reviews if (all_reviews.size > 0) and (all_reviews.last.id == reviews.last.id) if block_given? reviews.each do |r| return all_reviews unless yield(r) all_reviews << r end else all_reviews += reviews end i += 1 end return all_reviews end end |