Skip to content

Instantly share code, notes, and snippets.

@imartinez
Last active February 28, 2017 09:02
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save imartinez/ea33735d7142ef1261a4c858b1d0e487 to your computer and use it in GitHub Desktop.
Save imartinez/ea33735d7142ef1261a4c858b1d0e487 to your computer and use it in GitHub Desktop.
Google Play Reviews Widget for Dashing

#Google Play Reviews Widget for Dashing.io

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

Preview

Don't miss the related Google Play Rating 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 ea33735d7142ef1261a4c858b1d0e487

(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_reviews.rb to configure the list of application packages.

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

Add gems to your Gemfile:

  • gem 'market_bot', :git=>'https://github.com/imartinez/market_bot.git', :branch => 'enhance-reviews', :ref => 'e0d6f8c'
  • gem 'json'
  • gem 'activesupport'

And run bundle to install these new gems.

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="reviews-1-com.first.app.package" data-view="PlayRatings" data-title="My App"></div>
</li>
  • Note 1: the data-id must be constructed as reviews-<number_of_review>-<application_package>. The <number_of_review> is 1 for the latest review, 2 for the previous one and so on.

  • Note 2: you must configure both the HTML data-id in your dashboard and the play_reviews.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.PlayReviews extends Dashing.Widget
ready: ->
@onData(this)
@accessor 'reviewTitleFixedChars', ->
originalReviewTitle = @get('reviewTitle')
if (originalReviewTitle.length > 20)
originalReviewTitle.substring(0,20) + '...'
else
originalReviewTitle
@accessor 'reviewTextFixedChars', ->
originalReviewText = @get('reviewText')
if (originalReviewText.length > 120)
originalReviewText.substring(0,120) + '...'
else
originalReviewText
@accessor 'bgColor', ->
if @get('rating') >= 4
"#96bf48"
else if @get('rating') >= 3
"#ff9618"
else if @get('rating') >= 0
"#D26771"
else
"#999999"
onData: (data) ->
widget = $(@node)
widget.fadeOut().css('background-color', @get('bgColor')).fadeIn()
currentRatingStar = widget.find(".current-rating")
currentRatingStar.css('width', 20 * @get('rating') + '%')
<div>
<div class="featured-review-star-rating">
<div class="review-info-star-rating">
<div class="star star-rating-non-editable-container">
<div class="current-rating"></div>
</div>
</div>
</div>
<div class="quoted-review">
<h3 data-bind="reviewTitleFixedChars" class="review-title"></h3>
<p data-bind="reviewTextFixedChars" class="review-text"></p>
</div>
<span data-bind="author" class="author-name"></span>,
<span data-bind="date" class="review-date"></span>
</div>
#!/usr/bin/env ruby
require 'active_support'
require 'rubygems'
require 'market_bot'
require 'json'
# 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|
apps_mapping.each do |app_identifier|
begin
app = MarketBot::Play::App.new(app_identifier)
reviews = MarketBot::Play::Reviews.new(app)
reviews.update
reviews.result.each_with_index do |review, index|
if defined?(send_event)
send_event("review" + "-" + (index + 1).to_s + "-" + app_identifier, {
author: review[:author],
date: review[:date],
reviewTitle: review[:title],
reviewText: review[:review],
rating: review[:rating],
})
end
end
rescue Exception => e
puts "Error: #{e}"
end
end
end
// ----------------------------------------------------------------------------
// Sass declarations
// ----------------------------------------------------------------------------
$background-color: #4b5f24;
// ----------------------------------------------------------------------------
// Widget-play-reviews styles
// ----------------------------------------------------------------------------
.widget-play-reviews {
background-color: $background-color;
font-size: 15px;
.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
}
.review-text {
font-style: italic;
font-size: 22px;
}
.review-title {
font-weight: bold;
font-style: italic;
}
.quoted-review {
margin: 10px 0;
width: 340px;
}
}
@joopdo
Copy link

joopdo commented Jan 10, 2017

Did not work for me. I suspect that the data-view="PlayRatings" doesn't match the class PlayReviews

@joopdo
Copy link

joopdo commented Jan 19, 2017

Ehm, it was simple fix.

<div data-id="review**s**-1-com.first.app.package" data-view="PlayRatings" data-title="My App"></div>

to

<div data-id="review-1-com.first.app.package" data-view="PlayRatings" data-title="My App"></div>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment