Skip to content

Instantly share code, notes, and snippets.

@imartinez
Last active February 22, 2017 05:38
Show Gist options
  • Save imartinez/a1c8ba1137465079720588f405c08461 to your computer and use it in GitHub Desktop.
Save imartinez/a1c8ba1137465079720588f405c08461 to your computer and use it in GitHub Desktop.
Google Play Rating Widget for Dashing

#Google Play Rating Widget for Dashing.io

Dashing Widget for displaying current Google Play Ratings of Android apps. Supports any number of apps. It shows fancy stars and its background color changes depending on the app's rating.

Preview

Don't miss the related Google Play Reviews Widget for Dashing!

Attribution: Based on Android Google Play Dashing Widget.Thanks for your work x2on!

##Usage

To use this widget you have two options:

  • Let Dashing do the hard work for you: run
dashing install a1c8ba1137465079720588f405c08461

(this will copy all files in place but the images). Then copy star_empty.png and star_full.png in /assets/images folder. Edit play_ratings.rb to configure the list of application packages.

  • Or do it all yourself: copy play_ratings.html, play_ratings.coffee, and play_ratings.scss into the /widgets/play_ratings directory. Put the play_ratings.rb file in your /jobs folder. Copy star_empty.png and star_full.png in /assets/images folder. Edit play_ratings.rb to configure the list of application packages.

Add gem 'market_bot', :git=>'https://github.com/imartinez/market_bot.git', :branch => 'enhance-reviews', :ref => 'e0d6f8c' to your Gemfile and run bundle

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

<li data-row="1" data-col="2" data-sizex="1" data-sizey="1">
    <div data-id="com.first.app.package" data-view="PlayRatings" data-title="My App"></div>
</li>

Note: you must configure both the HTML data-id in your dashboard and the play_ratings.rb job with the proper application packages. Find your app's package as part as Google Play url. i.e. Chrome's Google Play url is https://play.google.com/store/apps/details?id=com.android.chrome then Chrome's application package is com.android.chrome

class Dashing.PlayRatings extends Dashing.Widget
ready: ->
@onData(this)
@accessor 'bgColor', ->
if @get('last_version.average_rating') >= 4
"#96bf48"
else if @get('last_version.average_rating') >= 3
"#ff9618"
else if @get('last_version.average_rating') >= 0
"#D26771"
else
"#999999"
onData: (data) ->
widget = $(@node)
widget.fadeOut().css('background-color', @get('bgColor')).fadeIn()
last_version = @get('last_version')
rating = last_version.average_rating
rating_detail = last_version.average_rating_detail
voters_count = last_version.voters_count
currentRatingStar = $(@node).find(".current-rating")
currentRatingStar.css('width', 20 * rating + '%')
if rating_detail then widget.find('.google-rating-detail-value').html( '<span id="google-rating-integer-value">(' + rating_detail + ')</span>')
widget.find('.google-voters-count').html( '<span id="google-voters-count-value">' + voters_count + '</span> Votes' )
<h1 class="title" data-bind="title"></h1>
<div class="google-rating-container">
<div class="star star-rating-non-editable-container">
<div class="current-rating" ></div>
</div>
<div class="google-rating-detail-value" data-bind='google'></div>
<div class="google-voters-count" data-bind='google'></div>
</div>
#!/usr/bin/env ruby
require 'rubygems'
require 'market_bot'
# Find your apps package as part as Google Play url. i.e.
# Chrome's Google Play url is https://play.google.com/store/apps/details?id=com.android.chrome
# then Chrome's application package is com.android.chrome
apps_mapping = [
'com.first.app.package',
'com.second.app.package'
]
SCHEDULER.every '60s', :first_in => 0 do |job|
data = {
:last_version => {
average_rating: 0.0,
voters_count: 0
}
}
begin
apps_mapping.each do |app_identifier|
app = MarketBot::Play::App.new(app_identifier)
app.update
data[:last_version][:average_rating] = app.rating
rating_detail = 0.0
number_of_votes = 0
app.rating_distribution.each { |rating_distribution|
rating_detail += rating_distribution[0] * rating_distribution[1]
number_of_votes += rating_distribution[1]
}
if number_of_votes > 0
rating_detail = "%.4f" % (rating_detail / number_of_votes)
end
data[:last_version][:average_rating_detail] = rating_detail
data[:last_version][:voters_count] = app.votes
if defined?(send_event)
send_event(app_identifier, data)
end
end
rescue Exception => e
puts "Error: #{e}"
end
end
// ----------------------------------------------------------------------------
// Sass declarations
// ----------------------------------------------------------------------------
$background-color: #999;
$title-color: #FFF;
// ----------------------------------------------------------------------------
// Widget-play-ratings styles
// ----------------------------------------------------------------------------
.widget-play-ratings {
background: $background-color;
.title {
font-size: 50px;
font-weight: bold;
color: $title-color;
opacity: .9
}
.google-rating-container {
div > div {
font-size: 22px
}
}
.google-rating-value {
font-size: 90px;
color: $title-color;
#google-rating-integer-value {
font-weight: bold;
}
}
.google-voters-count {
font-size: 40px;
color: $title-color;
#google-voters-count-value {
font-weight: bold
}
}
.star.star-rating-non-editable-container {
height: 48px;
width: 240px;
margin: 0 auto;
background-image: url('../assets/star_empty.png');
-webkit-background-size: contain;
background-size: contain
}
.star .current-rating {
height: 48px;
width: 0%;
background-image: url('../assets/star_full.png');
-webkit-background-size: contain;
background-size: contain
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment