Class: Beats::Client
- Inherits:
-
Object
- Object
- Beats::Client
- Defined in:
- lib/beats/client.rb
Constant Summary collapse
- DEFAULT_OPTIONS =
{ :base_url => ENV['BEATS_URL'] || 'http://prdaisy.com/' }
Instance Method Summary collapse
-
#account ⇒ Hash
Retrieves the representation of the currently authenticated user.
-
#add_history(uri) ⇒ Object
Adds a resource (e.g. a track) to the currently authenticated users history.
-
#add_release(release) ⇒ Hash
Adds a release to the catalogue.
-
#index ⇒ Hash
Retrieves the resource discovery index.
-
#initialize(options = {}) ⇒ Client
constructor
Creates a client object that can be used to interact with the Beats API.
-
#resource(uri) ⇒ Hash
Retrieves the representation of a resource.
-
#search(query) ⇒ Hash
Performs a search in the music catalogue and returns the results.
-
#sentence ⇒ Hash
Retrieves the building blocks for "The Sentence".
- #stream(uri) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Client
Creates a client object that can be used to interact with the Beats API
21 22 23 24 25 |
# File 'lib/beats/client.rb', line 21 def initialize( = {}) = DEFAULT_OPTIONS.merge() @base_url = [:base_url] @access_token = [:access_token] end |
Instance Method Details
#account ⇒ Hash
Retrieves the representation of the currently authenticated user. Requires authentication.
41 42 43 |
# File 'lib/beats/client.rb', line 41 def account decode_json(get(resolve_uri(@base_url, href(:account)))) end |
#add_history(uri) ⇒ Object
Adds a resource (e.g. a track) to the currently authenticated users history. Requires authentication.
71 72 73 74 |
# File 'lib/beats/client.rb', line 71 def add_history(uri) post(resolve_uri(@base_url, href(:history)), :uri => uri) end |
#add_release(release) ⇒ Hash
Adds a release to the catalogue.
55 56 57 |
# File 'lib/beats/client.rb', line 55 def add_release(release) decode_json(post(resolve_uri(@base_url, href(:catalogue)), release)) end |
#index ⇒ Hash
Retrieves the resource discovery index. The index is a set of links to other resources.
31 32 33 34 35 36 |
# File 'lib/beats/client.rb', line 31 def index return @index if @index get(@base_url) rescue RestClient::MultipleChoices => e @index = decode_json(e.response.body) end |
#resource(uri) ⇒ Hash
Retrieves the representation of a resource.
48 49 50 |
# File 'lib/beats/client.rb', line 48 def resource(uri) decode_json(get(resolve_uri(@base_url, uri))) end |
#search(query) ⇒ Hash
Performs a search in the music catalogue and returns the results.
63 64 65 66 |
# File 'lib/beats/client.rb', line 63 def search(query) decode_json(get(resolve_uri(@base_url, href(:search)), :params => { :q => query })) end |
#sentence ⇒ Hash
Retrieves the building blocks for "The Sentence".
78 79 80 |
# File 'lib/beats/client.rb', line 78 def sentence decode_json(get(resolve_uri(@base_url, href(:sentence)))) end |
#stream(uri) ⇒ Object
82 83 84 85 86 87 88 89 90 91 |
# File 'lib/beats/client.rb', line 82 def stream(uri) url = "#{@base_url}#{uri}/stream" RestClient.get(url) do |response, request, result, &block| if response.code == 302 return response.headers[:location] else return nil end end end |