rdio 0.0.94 → 0.0.96

Sign up to get free protection for your applications and to get access to all the features.
data/README CHANGED
@@ -27,6 +27,20 @@ see the options. Here's an example:
27
27
  ....
28
28
 
29
29
 
30
- * TODO
30
+ * TESTS
31
+
32
+ In order to run the rests, you must define the following environmental
33
+ variables to the appropriate values:
34
+
35
+ RDIO_KEY
36
+ RDIO_SECRET
37
+
38
+ You must also serialize an authrozied access token to the file
39
+ .rdio_access_token. This can be done with:
40
+
41
+ make .rdio_access_token
42
+
43
+ -or-
44
+
45
+ ./create_access_token
31
46
 
32
- Lots
data/lib/rdio.rb CHANGED
@@ -37,14 +37,26 @@ module Rdio
37
37
  VERSION
38
38
  end
39
39
 
40
+ # String[key] String[secret] -> Api
41
+ #
40
42
  # Initializes and returns the shared Api instance and overwrites the
41
43
  # existing one.
44
+ #
42
45
  def self.init(key,secret)
43
46
  @api = Api.new key,secret
44
47
  end
45
48
 
49
+ # AccessToken[token] => Api
50
+ #
51
+ # Initializes and returns the shared Api instance from the passed in
52
+ # access_token instance
53
+ #
54
+ def self.init_with_token(token)
55
+ @api = Api.from_token token
56
+ end
57
+
46
58
  # Resets shared API to nil
47
- def reset
59
+ def self.reset
48
60
  @api = nil
49
61
  end
50
62
 
data/lib/rdio/api.rb CHANGED
@@ -6,9 +6,20 @@ module Rdio
6
6
  # ----------------------------------------------------------------------
7
7
  class Api < BaseApi
8
8
 
9
- def initialize(key,secret)
9
+ def initialize(key=nil,secret=nil)
10
10
  super key,secret
11
11
  end
12
+
13
+ # AccessToken[token] -> Api
14
+ #
15
+ # Returns a new instance initialized from the passed in access
16
+ # token
17
+ #
18
+ def self.from_token(token)
19
+ api = Api.new
20
+ api.access_token = token
21
+ return api
22
+ end
12
23
 
13
24
  # Add a friend to the current user.
14
25
  def addFriend(user)
data/lib/rdio/base.rb CHANGED
@@ -247,7 +247,12 @@ module Rdio
247
247
 
248
248
  attr_reader :oauth
249
249
 
250
- def initialize(key,secret)
250
+ # string[key] string[secret]
251
+ #
252
+ # key and secret can be 'nil' because users can now set the
253
+ # access_token directly
254
+ #
255
+ def initialize(key=nil,secret=nil)
251
256
  @oauth = RdioOAuth.new key,secret
252
257
  @access_token_auth = nil
253
258
  @access_token_no_auth = nil
@@ -266,6 +271,15 @@ module Rdio
266
271
  @oauth.get_pin
267
272
  end
268
273
 
274
+ # Token -> Void
275
+ #
276
+ # Sets both unauthorized and authorized tokens to token
277
+ #
278
+ def access_token=(token)
279
+ @access_token_auth = token
280
+ @access_token_no_auth = token
281
+ end
282
+
269
283
  def call(method,args,requires_auth=false)
270
284
  #
271
285
  # Convert object with keys just to use their keys
@@ -295,6 +309,11 @@ module Rdio
295
309
  create_object type,json
296
310
  end
297
311
 
312
+ # Forces authorization
313
+ def authorize
314
+ access_token true
315
+ end
316
+
298
317
  private
299
318
 
300
319
  def fill_obj(type,x)
@@ -359,16 +378,28 @@ module Rdio
359
378
  def access_token(requires_auth)
360
379
  if requires_auth
361
380
  if not @access_token_auth
381
+ if not @oauth.key or not @oauth.secret
382
+ raise 'You must set the access_token directly or ' +
383
+ 'initialize this instance with a valid key/secret pair'
384
+ end
362
385
  @access_token_auth = @oauth.access_token requires_auth
363
386
  end
364
387
  res = @access_token_auth
365
388
  else
366
- if not @access_token_no_auth
367
- @access_token_no_auth = @oauth.access_token requires_auth
389
+ if @access_token_auth
390
+ res = @access_token_auth
391
+ else
392
+ if not @access_token_no_auth
393
+ if not @oauth.key or not @oauth.secret
394
+ raise 'You must set the access_token directly or ' +
395
+ 'initialize this instance with a valid key/secret pair'
396
+ end
397
+ @access_token_no_auth = @oauth.access_token requires_auth
398
+ end
399
+ res = @access_token_no_auth
368
400
  end
369
- res = @access_token_no_auth
370
401
  end
371
- res
402
+ return res
372
403
  end
373
404
 
374
405
  end
data/lib/rdio/oauth.rb CHANGED
@@ -4,11 +4,13 @@ require 'oauth'
4
4
  module Rdio
5
5
 
6
6
  # ----------------------------------------------------------------------
7
- # Performs OAuth authentication based on a key and secret
7
+ # Performs oob OAuth authentication based on a key and secret
8
8
  # ----------------------------------------------------------------------
9
9
  class RdioOAuth
10
10
 
11
11
  SITE = 'http://api.rdio.com'
12
+
13
+ attr_accessor :key, :secret
12
14
 
13
15
  # string[url] -> string
14
16
  #
@@ -23,7 +25,8 @@ module Rdio
23
25
  @secret = secret
24
26
  @get_pin = lambda do |url|
25
27
 
26
- # Try to open using launchy, then if this doesn't work us open
28
+ # Try to open using launchy, then if this doesn't work use
29
+ # system open
27
30
  begin
28
31
  require 'rubygems'
29
32
  require 'launchy'
@@ -31,6 +34,7 @@ module Rdio
31
34
  rescue Exception => e
32
35
  Rdio::log.error e
33
36
  Rdio::log.info 'Install the \'launchy\' gem to avoid this error'
37
+ Rdio::log.info 'Trying system \'open\''
34
38
  system 'open',url
35
39
  end
36
40
 
@@ -44,6 +48,13 @@ module Rdio
44
48
  end
45
49
  end
46
50
 
51
+ # boolean[requires_auth] -> AccessToken
52
+ #
53
+ # Returns an appropriate oob access token. If requires_auth is
54
+ # true we'll return one needed for authenticated requests.
55
+ # Otherwise (default), we'll return one needed for unauthenticated
56
+ # requests.
57
+ #
47
58
  def access_token(requires_auth=false)
48
59
  requires_auth ? access_token_auth : access_token_no_auth
49
60
  end
@@ -53,7 +64,7 @@ module Rdio
53
64
  def access_token_no_auth
54
65
  consumer = OAuth::Consumer.new @key, @secret, {:site => SITE}
55
66
  consumer.http.read_timeout = 600
56
- OAuth::AccessToken.new consumer
67
+ return OAuth::AccessToken.new consumer
57
68
  end
58
69
 
59
70
  def access_token_auth
@@ -69,7 +80,7 @@ module Rdio
69
80
  url = 'https://www.rdio.com/oauth/authorize?oauth_token=' +
70
81
  request_token.token.to_s
71
82
  oauth_verifier = @get_pin.call url
72
- request_token.get_access_token({:oauth_verifier => oauth_verifier})
83
+ return request_token.get_access_token({:oauth_verifier => oauth_verifier})
73
84
  end
74
85
  end
75
86
 
data/lib/rdio/types.rb CHANGED
@@ -511,7 +511,8 @@ module Rdio
511
511
  end
512
512
 
513
513
  # Get all of the tracks in the user's collection.
514
- def tracks_in_collection(start=nil,count=nil,sort=nil,query=nil,extras=nil)
514
+ def tracks_in_collection(start=nil,count=nil,sort=nil,
515
+ query=nil,extras=nil)
515
516
  api.getTracksInCollection self,start,count,sort,query,extras
516
517
  end
517
518
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rdio
3
3
  version: !ruby/object:Gem::Version
4
- hash: 163
4
+ hash: 223
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 94
10
- version: 0.0.94
9
+ - 96
10
+ version: 0.0.96
11
11
  platform: ruby
12
12
  authors:
13
13
  - Jeffrey Palm
@@ -15,8 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-07-03 00:00:00 -04:00
19
- default_executable:
18
+ date: 2011-08-15 00:00:00 Z
20
19
  dependencies:
21
20
  - !ruby/object:Gem::Dependency
22
21
  name: oauth
@@ -53,7 +52,6 @@ files:
53
52
  - lib/rdio/datatypes.rb
54
53
  - lib/rdio/types.rb
55
54
  - lib/rdio/call.rb
56
- has_rdoc: true
57
55
  homepage: http://github.com/spudtrooper/rdiorb
58
56
  licenses: []
59
57
 
@@ -83,7 +81,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
83
81
  requirements:
84
82
  - launchy gem to use authorized calls
85
83
  rubyforge_project: "%NAME"
86
- rubygems_version: 1.6.1
84
+ rubygems_version: 1.8.6
87
85
  signing_key:
88
86
  specification_version: 2
89
87
  summary: Rdio