store-ratings 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/lib/store-rating.rb +61 -0
  3. metadata +59 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 897229ba3700835216e3448e642a7b8d3b9b1dc23be2a9599fe6240ab8c79bc0
4
+ data.tar.gz: 56e06944e6e42e05a6f4214767fa997eb1c114a0a11097b1f72e8f439cd09390
5
+ SHA512:
6
+ metadata.gz: 998e74e2febdcab74db03d4f12fa43e9705c96993b8b8416e2311c6073497e4a89f29eb49ccb3a67ed75c7bb107cc294540e2bca08a6459bb9ba084f4f9a9f1b
7
+ data.tar.gz: '0899b1bf4031f9a0385abeba1448062119010fe1916712311fbdf7108501f362803691336fa9b89a79675331447b6ee4c71a9bc427c7fa6444f6a305a24cbe6d'
@@ -0,0 +1,61 @@
1
+ require 'nokogiri'
2
+ require 'open-uri'
3
+ require 'net/http'
4
+ require 'uri'
5
+ require 'json'
6
+
7
+ module StoreRating
8
+
9
+ # Rating
10
+ #
11
+ # Helper method to return rating depending on parameters given, either for iOS or Android
12
+ def self.rating(app_id, country = nil)
13
+ if app_id.to_i > 0 && country != nil # iOS
14
+ return ios_rating(country, app_id)
15
+ else # Android
16
+ return android_rating(app_id)
17
+ end
18
+ end
19
+
20
+ # iOS Rating
21
+ #
22
+ # Fetches latest reviews from app store and calculates average rating
23
+ def self.ios_rating(country, app_id)
24
+ url = "https://itunes.apple.com/#{country}/rss/customerreviews/id=#{app_id}/sortBy=mostRecent/json"
25
+
26
+ url = URI.parse(url)
27
+ req = Net::HTTP::Get.new(url)
28
+ net = Net::HTTP.new(url.host, url.port)
29
+ net.use_ssl = true
30
+
31
+ res = net.start do |http|
32
+ http.request(req)
33
+ end
34
+
35
+ json = JSON.parse(res.body)
36
+
37
+ if json.has_key?("feed")
38
+ if json["feed"].has_key?("entry")
39
+ return (json["feed"]["entry"].sum { |o| o["im:rating"]["label"].to_f } / json["feed"]["entry"].length).round(2)
40
+ end
41
+ end
42
+
43
+ return 0
44
+ end
45
+
46
+ # Android rating
47
+ #
48
+ # Fetches rating from google play page
49
+ def self.android_rating(bundle_id)
50
+ url = "https://play.google.com/store/apps/details?id=#{bundle_id}"
51
+ prop = 'meta[itemprop="ratingValue"]'
52
+
53
+ doc = Nokogiri::HTML(open(url))
54
+
55
+ if doc.at_css(prop)
56
+ return doc.at_css(prop)[:content].strip.to_f.round(2)
57
+ end
58
+
59
+ return 0
60
+ end
61
+ end
metadata ADDED
@@ -0,0 +1,59 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: store-ratings
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Rasmus Styrk
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-12-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: nokogiri
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ description: This is a simple to use gem that does one thing; Returns the rating of
28
+ your iOS or Android app.
29
+ email: styrken@gmail.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - lib/store-rating.rb
35
+ homepage: http://rubygems.org/gems/store-ratings
36
+ licenses:
37
+ - MIT
38
+ metadata: {}
39
+ post_install_message:
40
+ rdoc_options: []
41
+ require_paths:
42
+ - lib
43
+ required_ruby_version: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ required_rubygems_version: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: '0'
53
+ requirements: []
54
+ rubyforge_project:
55
+ rubygems_version: 2.7.8
56
+ signing_key:
57
+ specification_version: 4
58
+ summary: A gem to return rating for your iOS or Android apps.
59
+ test_files: []