Sha256: 2152f1ec6b2a733f1c79d0b064f10d51b7facf0eef92a9017780143e8cb2f65e

Contents?: true

Size: 1.57 KB

Versions: 1

Compression:

Stored size: 1.57 KB

Contents

require 'sinatra'
require 'json'

class Robut::Plugin::Rdio
  include Robut::Plugin

  # 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.3.0 lib/robut/plugin/rdio/server.rb