Skip to content

Instantly share code, notes, and snippets.

@pezholio
Last active December 16, 2015 15:59
Show Gist options
  • Save pezholio/5460036 to your computer and use it in GitHub Desktop.
Save pezholio/5460036 to your computer and use it in GitHub Desktop.
Dashing Job to show total Soundcloud listens

Description

A Dashing widget to show the total number of plays on your Soundcloud account.

Dependencies

https://github.com/soundcloud/soundcloud-ruby

Add it to your gemfile:

gem 'soundcloud'

And run bundle install

The client IDs are all in ENV variables too. To get these to work, just add the [https://github.com/bkeepers/dotenv](Dotenv gem) to your gemfile, run Bundler and then add:

require 'dotenv'

Dotenv.load

To your config.ru file.

Usage

This job uses the default Number widget. Just add something like:

<li data-row="1" data-col="2" data-sizex="1" data-sizey="1">
  <div data-id="soundcloud-listens" data-view="Number" data-unordered="true" data-title="Listens on Soundcloud"></div>
</li>

To your dashboard layout file, and then copy the soundcloud-listens.rb file to your jobs folder.

Settings

Assuming you've got Dotenv set up, just add the following to a .env file in your project folder:

SOUNDCLOUD_CLIENT_ID='YOUR_CLIENT_ID'
SOUNDCLOUD_SECRET='YOUR_CLIENT_SECRET'
SOUNDCLOUD_USERNAME='YOUR_SOUNDCLOUD_USERNAME'
SOUNDCLOUD_PASSWORD='YOUR_SOUNDCLOUD_PASSWORD'
SCHEDULER.every '30m', :first_at => Time.now do
client = Soundcloud.new(
:client_id => ENV['SOUNDCLOUD_CLIENT_ID'],
:client_secret => ENV['SOUNDCLOUD_SECRET'],
:username => ENV['SOUNDCLOUD_USERNAME'],
:password => ENV['SOUNDCLOUD_PASSWORD']
)
count = 0
client.get('/me/tracks').each do |track|
count += track['playback_count']
end
send_event('soundcloud-listens', { current: count } )
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment