Skip to content

Instantly share code, notes, and snippets.

@imikerussell
Last active January 3, 2016 13:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save imikerussell/e20eb4de6d60457d5899 to your computer and use it in GitHub Desktop.
Save imikerussell/e20eb4de6d60457d5899 to your computer and use it in GitHub Desktop.
Spreaker Podcast Plays Widget

#Spreaker Podcast Plays Widget

Dashing Widget to display the amount of plays on your latest Spreaker podcast episode.

##Usage

To use this widget, put the spreaker.rb file in your /jobs folder.

To include this 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="spreaker" data-view="Number" data-title="Podcast Plays" style="background-color:#f5c300;"></div>
</li>

##Settings

Get your Spreaker show ID by replacing www in your show URL with api:

http://www.spreaker.com/show/musicradiocreative becomes http://api.spreaker.com/show/musicradiocreative

You'll see the show_ID displayed (in the above example the show ID is 921848).

Change [ENTER_SHOW_ID HERE] in spreaker.rb to your numerical show ID.

The widget will update the plays of your latest Spreaker episode every 5 minutes using the "Number" data view.

require 'net/http'
require 'json'
current_plays = 0
SCHEDULER.every '5m', :first_in => 0 do |job|
last_plays = current_plays
server = "http://api.spreaker.com"
uri = URI("#{server}/show/[ENTER_SHOW_ID HERE]/episodes") # <--- Enter your Spreaker show_ID in place of [ENTER_SHOW_ID HERE]
res = Net::HTTP.get(uri)
j = JSON[res]
current_plays = j['response']['pager']['results'][0]['stats']['plays']
send_event('spreaker', { current: current_plays, last: last_plays })
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment