Sha256: 9b7e00186c2a13632f1d6acd14cd80fef669b4c8c24560fef89c36f306ce1931

Contents?: true

Size: 1.57 KB

Versions: 1

Compression:

Stored size: 1.57 KB

Contents

require 'sinatra'
require 'json'

class Robut::Plugin::Rdio < Robut::Plugin::Base
  
  # A simple server to communicate new Rdio sources to the Web
  # Playback API. The client will update
  # Robut::Plugin::Rdio::Server.queue with any new sources, and a call
  # to /queue.json will pull those new sources as a json object.
  class Server < Sinatra::Base

    set :root, File.dirname(__FILE__)
    
    class << self
      # A list of items that haven't been fetched by the web playback
      # API yet.
      attr_accessor :queue

      # The playback token for +domain+. If you're accessing Rdio over
      # localhost, you shouldn't need to change this. Otherwise,
      # download the rdio-python plugin:
      #
      #   https://github.com/rdio/rdio-python
      #
      # and generate a new token for your domain:
      #
      #   ./rdio-call --consumer-key=YOUR_CONSUMER_KEY --consumer-secret=YOUR_CONSUMER_SECRET getPlaybackToken domain=YOUR_DOMAIN
      attr_accessor :token

      # The domain associated with +token+. Defaults to localhost.
      attr_accessor :domain
    end
    self.queue = []

    # Renders a simple Rdio web player.
    get '/' do
      File.read(File.expand_path('public/index.html', File.dirname(__FILE__)))
    end

    get '/js/vars.js' do
      content_type 'text/javascript'
      <<END
var rdio_token = '#{self.class.token}';
var rdio_domain = '#{self.class.domain}';
END
    end

    # Returns the sources that haven't been fetched yet.
    get '/queue.json' do
      queue = self.class.queue.dup
      self.class.queue = []
      queue.to_json
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
robut-0.2.1 lib/robut/plugin/rdio/server.rb