Class: Rdio::SimpleRdio

Inherits:
Object show all
Defined in:
lib/rdio/simple_rdio.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(consumer, token = nil) ⇒ SimpleRdio

Returns a new instance of SimpleRdio.



37
38
39
40
# File 'lib/rdio/simple_rdio.rb', line 37

def initialize(consumer, token=nil)
  @consumer = consumer
  @token = token
end

Instance Attribute Details

#consumerObject

the consumer and token can be accessed



35
36
37
# File 'lib/rdio/simple_rdio.rb', line 35

def consumer
  @consumer
end

#tokenObject

the consumer and token can be accessed



35
36
37
# File 'lib/rdio/simple_rdio.rb', line 35

def token
  @token
end

Instance Method Details

#begin_authentication(callback_url) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
# File 'lib/rdio/simple_rdio.rb', line 42

def begin_authentication(callback_url)
  # request a request token from the server
  response = signed_post('http://api.rdio.com/oauth/request_token',
                         {'oauth_callback' => callback_url})
  # parse the response
  parsed = CGI.parse(response)
  # save the token
  @token = [parsed['oauth_token'][0], parsed['oauth_token_secret'][0]]
  # return an URL that the user can use to authorize this application
  return parsed['login_url'][0] + '?oauth_token=' + parsed['oauth_token'][0]
end

#call(method, params = {}) ⇒ Object



64
65
66
67
68
69
70
71
# File 'lib/rdio/simple_rdio.rb', line 64

def call(method, params={})
  # make a copy of the dict
  params = params.clone
  # put the method in the dict
  params['method'] = method
  # call to the server and parse the response
  return JSON.load(signed_post('http://api.rdio.com/1/', params))
end

#complete_authentication(verifier) ⇒ Object



54
55
56
57
58
59
60
61
62
# File 'lib/rdio/simple_rdio.rb', line 54

def complete_authentication(verifier)
  # request an access token
  response = signed_post('http://api.rdio.com/oauth/access_token',
                         {'oauth_verifier' => verifier})
  # parse the response
  parsed = CGI.parse(response)
  # save the token
  @token = [parsed['oauth_token'][0], parsed['oauth_token_secret'][0]]
end