Skip to content

Instantly share code, notes, and snippets.

@cmaron
Last active August 29, 2015 14:02
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cmaron/c600acdfa2db0aec64bf to your computer and use it in GitHub Desktop.
Save cmaron/c600acdfa2db0aec64bf to your computer and use it in GitHub Desktop.
Android App Rating widget for Dashing

##Preview

See here and here for the gists that inspired/provided most of the code for this widget.

Description

Display your Android App Rating info, using the google play store.

##Usage

To use this widget, copy googleplay.html, googleplay.coffee, and googleplay.scss into the /widgets/googleplay directory. Put the google_play.rb file in your /jobs folder.

You'll also need the Google play store logo. Download it, and put it in your /assets/images folder.

To include the widget in a dashboard, add the following snippet to the dashboard layout file:

<li data-row="1" data-col="1" data-sizex="1" data-sizey="1">
  <div data-id="google_play_store_rating" data-view="Googleplay" data-title="Instagram - Android"></div>
</li>

##Settings

The main piece of data you need to provide here is the ID for your app in the google play store. It's relatively easy to find, simply lookup your app via https://play.google.com/store, click the link, and copy the text in the URL after "?id=". So for this example, we search for Instagram, find the URL:

https://play.google.com/store/apps/details?id=com.instagram.android

And set appId to...

appId = ENV['GOOGLE_PLAY_ID'] || 'com.instagram.android' 
class Dashing.Googleplay extends Dashing.Widget
ready: ->
@onData(this)
onData: (data) ->
widget = $(@node)
rating = @get('average_rating')
voters_count = @get('voters_count')
widget.find('.googleplay-rating-value').html( '<div>Average Rating</div><span id="googleplay-rating-integer-value">' + rating + '</span>')
widget.find('.googleplay-voters-count').html( '<span id="googleplay-voters-count-value">' + voters_count + '</span> Votes' )
<h1 class="title" data-bind="title"></h1>
<div class="googleplay-rating-container">
<div class="googleplay-rating-value" data-bind='googleplay'></div>
<div class="googleplay-voters-count" data-bind='googleplay'></div>
</div>
#!/usr/bin/env ruby
require 'net/http'
require 'openssl'
appId = ENV['GOOGLE_PLAY_ID'] || 'com.instagram.android'
SCHEDULER.every '30m', :first_in => 0 do |job|
# prepare request
http = Net::HTTP.new("play.google.com", Net::HTTP.https_default_port())
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE # disable ssl certificate check
# scrape detail page of app with appId
response = http.request(Net::HTTP::Get.new("/store/apps/details?id=#{appId}"))
if response.code != "200"
puts "google play store website communication (status-code: #{response.code})\n#{response.body}"
else
data = {
average_rating: 0.0,
voters_count: 0
}
# capture average rating using regexp
average_rating = /class=[\"\']score[\"\']>([\d,.]+)</.match(response.body)
average_rating = average_rating[1].gsub(",", ".").to_f
data[:average_rating] = average_rating
# capture total number of votes
voters_count = /class=[\"\']reviews-num[\"\']>([\d,.]+)</.match(response.body)
voters_count = voters_count[1]
data[:voters_count] = voters_count
send_event('google_play_store_rating', data)
end
end
// ----------------------------------------------------------------------------
// Sass declarations
// ----------------------------------------------------------------------------
$background-color: #999;
$title-color: #FFF;
// ----------------------------------------------------------------------------
// Widget-comment styles
// ----------------------------------------------------------------------------
.widget-googleplay {
background: $background-color url('../assets/googleplay_logo.png') no-repeat 50% 50%;
.title {
font-weight: bold;
color: $title-color;
opacity: .9
}
.googleplay-rating-container {
div > div {
font-size: 24px
}
}
.googleplay-rating-value {
font-size: 76px;
#googleplay-rating-integer-value {
font-weight: bold;
}
}
.googleplay-voters-count {
font-size: 1.5em;
#googleplay-voters-count-value {
font-weight: bold
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment