Class: Songdrop::Client
- Inherits:
-
Object
- Object
- Songdrop::Client
- Defined in:
- lib/songdrop/client.rb,
lib/songdrop/client/methods.rb
Instance Attribute Summary collapse
-
#auth_token ⇒ Object
Returns the value of attribute auth_token.
Instance Method Summary collapse
- #delete(path, params = {}, &block) ⇒ Object
- #get(path, params = {}, &block) ⇒ Object
-
#initialize(options = {}) ⇒ Client
constructor
A new instance of Client.
- #login(params, &block) ⇒ Object
- #post(path, params = {}, &block) ⇒ Object
- #put(path, params = {}, &block) ⇒ Object
- #signup(params, &block) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Client
Returns a new instance of Client.
5 6 7 8 9 |
# File 'lib/songdrop/client.rb', line 5 def initialize(={}) @token = [:token] @endpoint = [:endpoint] || 'https://songdrop.com/v1' @auth_token = [:auth_token] end |
Instance Attribute Details
#auth_token ⇒ Object
Returns the value of attribute auth_token.
3 4 5 |
# File 'lib/songdrop/client.rb', line 3 def auth_token @auth_token end |
Instance Method Details
#delete(path, params = {}, &block) ⇒ Object
35 36 37 38 39 40 41 |
# File 'lib/songdrop/client.rb', line 35 def delete(path, params={}, &block) puts "[Songdrop::Client] DELETE #{path} with #{params.inspect} block? #{block_given?}" params.merge!(:client => @token, :token => @auth_token) HTTP.delete(full_url(path), params) do |response, headers, error| handle_response(response, headers, error, &block) end end |
#get(path, params = {}, &block) ⇒ Object
11 12 13 14 15 16 17 |
# File 'lib/songdrop/client.rb', line 11 def get(path, params={}, &block) puts "[Songdrop::Client] GET #{path} with #{params.inspect} block? #{block_given?}" params.merge!(:client => @token, :token => @auth_token) HTTP.get(full_url(path), params) do |response, headers, error| handle_response(response, headers, error, &block) end end |
#login(params, &block) ⇒ Object
4 5 6 7 8 9 10 |
# File 'lib/songdrop/client/methods.rb', line 4 def login(params, &block) post('/session', params) do |user| @auth_token = user.auth_token block.call user if block user end end |
#post(path, params = {}, &block) ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/songdrop/client.rb', line 27 def post(path, params={}, &block) puts "[Songdrop::Client] POST #{path} with #{params.inspect} block? #{block_given?}" params.merge!(:client => @token, :token => @auth_token) HTTP.post(full_url(path), params) do |response, headers, error| handle_response(response, headers, error, &block) end end |
#put(path, params = {}, &block) ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/songdrop/client.rb', line 19 def put(path, params={}, &block) puts "[Songdrop::Client] PUT #{path} with #{params.inspect} block? #{block_given?}" params.merge!(:client => @token, :token => @auth_token) HTTP.put(full_url(path), params) do |response, headers, error| handle_response(response, headers, error, &block) end end |
#signup(params, &block) ⇒ Object
12 13 14 15 16 17 18 |
# File 'lib/songdrop/client/methods.rb', line 12 def signup(params, &block) post('/users', params) do |user| @auth_token = user.auth_token block.call user if block user end end |