Class: Songdrop::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/songdrop/client.rb,
lib/songdrop/client/methods.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Client

Returns a new instance of Client.



5
6
7
8
9
10
# File 'lib/songdrop/client.rb', line 5

def initialize(options={})
  @token = options[:token]
  @endpoint = options[:endpoint] || 'https://songdrop.com/v1'
  @auth_token = options[:auth_token]
  @ip_address = options[:ip_address] # if the client is proxying for the user
end

Instance Attribute Details

#auth_tokenObject

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



36
37
38
39
40
41
42
# File 'lib/songdrop/client.rb', line 36

def delete(path, params={}, &block)
  puts "[Songdrop::Client] DELETE #{path} with #{params.inspect} block? #{block_given?}"
  params.merge!(:client => @token, :token => @auth_token, :ip => @ip_address)
  HTTP.delete(full_url(path), params) do |response, headers, error|
    handle_response(response, headers, error, &block)
  end
end

#get(path, params = {}, &block) ⇒ Object



12
13
14
15
16
17
18
# File 'lib/songdrop/client.rb', line 12

def get(path, params={}, &block)
  puts "[Songdrop::Client] GET #{path} with #{params.inspect} block? #{block_given?}"
  params.merge!(:client => @token, :token => @auth_token, :ip => @ip_address)
  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 (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



28
29
30
31
32
33
34
# File 'lib/songdrop/client.rb', line 28

def post(path, params={}, &block)
  puts "[Songdrop::Client] POST #{path} with #{params.inspect} block? #{block_given?}"
  params.merge!(:client => @token, :token => @auth_token, :ip => @ip_address)
  HTTP.post(full_url(path), params) do |response, headers, error|
    handle_response(response, headers, error, &block)
  end
end

#put(path, params = {}, &block) ⇒ Object



20
21
22
23
24
25
26
# File 'lib/songdrop/client.rb', line 20

def put(path, params={}, &block)
  puts "[Songdrop::Client] PUT #{path} with #{params.inspect} block? #{block_given?}"
  params.merge!(:client => @token, :token => @auth_token, :ip => @ip_address)
  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 (params, &block)
  post('/users', params) do |user|
    @auth_token = user.auth_token
    block.call user if block
    user
  end
end