rdio 0.0.92 → 0.0.93

Sign up to get free protection for your applications and to get access to all the features.
@@ -22,7 +22,7 @@ module Rdio
22
22
  def addToCollection(objs)
23
23
  method = 'addToCollection'
24
24
  type = true
25
- args = {:keys=>keys(objs)}
25
+ args = {:keys=>Rdio::keys(objs)}
26
26
  return_object type,method,args,true
27
27
  end
28
28
 
@@ -30,7 +30,7 @@ module Rdio
30
30
  def addToPlaylist(playlist,tracks)
31
31
  method = 'addToPlaylist'
32
32
  type = true
33
- args = {:playlist=>playlist, :tracks=>keys(tracks)}
33
+ args = {:playlist=>playlist, :tracks=>Rdio::keys(tracks)}
34
34
  return_object type,method,args,true
35
35
  end
36
36
 
@@ -41,7 +41,7 @@ module Rdio
41
41
  method = 'createPlaylist'
42
42
  type = Playlist
43
43
  args = {:name=>name,:description=>description,
44
- :tracks=>keys(tracks)}
44
+ :tracks=>Rdio::keys(tracks)}
45
45
  args[:extras] = extras if extras
46
46
  return_object type,method,args,true
47
47
  end
@@ -88,7 +88,7 @@ module Rdio
88
88
  end
89
89
  method = 'get'
90
90
  cls = type
91
- args = {:keys=>keys(objs)}
91
+ args = {:keys=>Rdio::keys(objs)}
92
92
  args[:extras] = extras if extras
93
93
  json = call method,args
94
94
  if Rdio::log_json
@@ -300,7 +300,7 @@ module Rdio
300
300
  def removeFromCollection(objs)
301
301
  method = 'removeFromCollection'
302
302
  type = Boolean
303
- args = {:keys=>keys(objs)}
303
+ args = {:keys=>Rdio::keys(objs)}
304
304
  return_object type,method,args
305
305
  end
306
306
 
@@ -309,7 +309,7 @@ module Rdio
309
309
  method = 'removeFromPlaylist'
310
310
  type = TODO
311
311
  args = {:playlist=>playlist,:index=>index,
312
- :count=>count,:tracks=>keys(tracks)}
312
+ :count=>count,:tracks=>Rdio::keys(tracks)}
313
313
  return_object type,method,args,truex
314
314
  end
315
315
 
@@ -19,80 +19,106 @@ class Class
19
19
  end
20
20
 
21
21
  module Rdio
22
- # string -> string
23
- #
24
- # Converts camel-case string to underscore-delimited one.
25
- #
26
- def camel2underscores(s)
27
- return s if not s
28
- return s if s == ''
29
- def decapitilize(s)
30
- s[0,1].downcase + s[1,s.length-1].to_s
31
- end
32
- s = decapitilize s
33
- while s.match /([A-Z]+)/
34
- s = s.gsub /#{$1}/,'_'+ decapitilize($1)
35
- end
36
- s
37
- end
38
22
 
39
- # Adds 'str' to the array or string 'arr'
40
- def add_to_array(arr,str)
41
- if arr == nil
42
- return [str.to_s]
43
- end
44
- if arr == ''
45
- return [str.to_s]
46
- end
47
- if arr.is_a? Array
48
- return arr + [str.to_s]
49
- end
50
- return arr.to_s + ',' + str.to_s
51
- end
52
-
53
- # array -> string
54
- #
55
- # Creates a ','-separated string of the value of 'to_k' from all the
56
- # values in 'objs'. We also remove the nils from the input array.
57
- #
58
- def keys(objs)
59
- (not objs) ? '' : objs.compact.map {|x| x.to_k}.join(',')
60
- end
23
+ class << self
61
24
 
62
- # object -> value
63
- #
64
- # Converts v which is probably a string, to a primitive value, so we
65
- # can have primitives other than strings as attributes of BaseObjs.
66
- #
67
- def to_o(v)
68
- if v == nil
69
- return nil
70
- end
71
- s = v.to_s
72
- if not s
73
- return nil
74
- end
75
- if s == 'nil'
76
- return nil
77
- end
78
- if s =~ /^\d+$/
79
- return s.to_i
25
+ # hash -> hash
26
+ #
27
+ # Uses the value of 'to_k' for all the iput hash values in the
28
+ # result hash. This is used to make sure that the arguments passed
29
+ # to create urls use keys for the values of objects like Artist,
30
+ # Track, etc. Also, we use the simple name of classes.
31
+ #
32
+ def convert_args(args)
33
+ return nil if not args
34
+ res = {}
35
+ args.each do |k,v|
36
+ if v.is_a? Array
37
+ v = keys v
38
+ else
39
+ v = v.to_k
40
+ end
41
+ res[k] = v
42
+ end
43
+ return res
80
44
  end
81
- if s =~ /^\d+\.?\d*$/
82
- return s.to_f
45
+
46
+ # string -> string
47
+ #
48
+ # Converts camel-case string to underscore-delimited one.
49
+ #
50
+ def camel2underscores(s)
51
+ return s if not s
52
+ return s if s == ''
53
+ def decapitilize(s)
54
+ s[0,1].downcase + s[1,s.length-1].to_s
55
+ end
56
+ s = decapitilize s
57
+ while s.match /([A-Z]+)/
58
+ s = s.gsub /#{$1}/,'_'+ decapitilize($1)
59
+ end
60
+ s
83
61
  end
84
- if s == 'true'
85
- return true
62
+
63
+ # Adds 'str' to the array or string 'arr'
64
+ def add_to_array(arr,str)
65
+ if arr == nil
66
+ return [str.to_s]
67
+ end
68
+ if arr == ''
69
+ return [str.to_s]
70
+ end
71
+ if arr.is_a? Array
72
+ return arr + [str.to_s]
73
+ end
74
+ return arr.to_s + ',' + str.to_s
86
75
  end
87
- if s == 'false'
88
- return false
76
+
77
+ # array -> string
78
+ #
79
+ # Creates a ','-separated string of the value of 'to_k' from all the
80
+ # values in 'objs'. We also remove the nils from the input array.
81
+ #
82
+ def keys(objs)
83
+ (not objs) ? '' : objs.compact.map {|x| x.to_k}.join(',')
89
84
  end
90
- if s =~ /^\[.*\]$/
91
- s = s.gsub /^\[/,''
92
- s = s.gsub /\]$/,''
93
- return s.split(',').map {|x| to_o x}
85
+
86
+ # object -> value
87
+ #
88
+ # Converts v which is probably a string, to a primitive value, so we
89
+ # can have primitives other than strings as attributes of BaseObjs.
90
+ #
91
+ def to_o(v)
92
+ if v == nil
93
+ return nil
94
+ end
95
+ s = v.to_s
96
+ if not s
97
+ return nil
98
+ end
99
+ if s == 'nil'
100
+ return nil
101
+ end
102
+ if s =~ /^\d+$/
103
+ return s.to_i
104
+ end
105
+ if s =~ /^\d+\.?\d*$/
106
+ return s.to_f
107
+ end
108
+ if s == 'true'
109
+ return true
110
+ end
111
+ if s == 'false'
112
+ return false
113
+ end
114
+ if s =~ /^\[.*\]$/
115
+ s = s.gsub /^\[/,''
116
+ s = s.gsub /\]$/,''
117
+ return s.split(',').map {|x| Rdio::to_o x}
118
+ end
119
+ return s
94
120
  end
95
- return s
121
+
96
122
  end
97
123
 
98
124
  class << self
@@ -118,6 +144,7 @@ module Rdio
118
144
  end
119
145
 
120
146
  def fill(x)
147
+ return self if not x
121
148
  syms_to_types = Rdio::symbols_to_types || {}
122
149
  x.each do |k,v|
123
150
  sym = Rdio::camel2underscores(k).to_sym
@@ -141,7 +168,7 @@ module Rdio
141
168
  o.fill v
142
169
  end
143
170
  else
144
- o = to_o v
171
+ o = Rdio::to_o v
145
172
  end
146
173
  begin
147
174
  sym_eq = (Rdio::camel2underscores(k)+'=').to_sym
@@ -236,32 +263,11 @@ module Rdio
236
263
  @oauth.get_pin
237
264
  end
238
265
 
239
- # hash -> hash
240
- #
241
- # Uses the value of 'to_k' for all the iput hash values in the
242
- # result hash. This is used to make sure that the arguments passed
243
- # to create urls use keys for the values of objects like Artist,
244
- # Track, etc. Also, we use the simple name of classes.
245
- #
246
- def self.convert_args(args)
247
- return nil if not args
248
- res = {}
249
- args.each do |k,v|
250
- if v.is_a? Array
251
- v = keys v
252
- else
253
- v = v.to_k
254
- end
255
- res[k] = v
256
- end
257
- return res
258
- end
259
-
260
266
  def call(method,args,requires_auth=false)
261
267
  #
262
268
  # Convert object with keys just to use their keys
263
269
  #
264
- args = BaseApi.convert_args args
270
+ args = Rdio::convert_args args
265
271
  if Rdio::log_methods
266
272
  Rdio::log "Called method: #{method}(#{args}) : auth=#{requires_auth}"
267
273
  end
@@ -327,7 +333,7 @@ module Rdio
327
333
  if type == Boolean or type == String or
328
334
  type == Fixnum or type == Float
329
335
  return false if not result
330
- return to_o result
336
+ return Rdio::to_o result
331
337
  end
332
338
  #
333
339
  # A mild hack, but for get the result is a hash of keys to
@@ -32,7 +32,7 @@ module Rdio
32
32
 
33
33
  # Returns an array of Album for the query and other params
34
34
  def self.search(query,never_or=nil,extras=nil,start=nil,count=nil)
35
- extras = add_to_array extras,'artists'
35
+ extras = Rdio::add_to_array extras,'artists'
36
36
  Search.search query,Artist,never_or,extras,start,count
37
37
  end
38
38
 
@@ -144,7 +144,7 @@ module Rdio
144
144
 
145
145
  # Returns an array of Album for the query and other params
146
146
  def self.search(query,never_or=nil,extras=nil,start=nil,count=nil)
147
- extras = add_to_array extras,'albums'
147
+ extras = Rdio::add_to_array extras,'albums'
148
148
  Search.search query,Album,never_or,extras,start,count
149
149
  end
150
150
 
@@ -262,7 +262,7 @@ module Rdio
262
262
 
263
263
  # Returns an array of Track for the query and other params
264
264
  def self.search(query,never_or=nil,extras=nil,start=nil,count=nil)
265
- extras = add_to_array extras,'tracks'
265
+ extras = Rdio::add_to_array extras,'tracks'
266
266
  Search.search query,Track,never_or,extras,start,count
267
267
  end
268
268
 
@@ -339,7 +339,7 @@ module Rdio
339
339
 
340
340
  # Returns an array of Playlist for the query and other params
341
341
  def self.search(query,never_or=nil,extras=nil,start=nil,count=nil)
342
- extras = add_to_array extras,'playlists'
342
+ extras = Rdio::add_to_array extras,'playlists'
343
343
  Search.search query,Playlist,never_or,extras,start,count
344
344
  end
345
345
 
@@ -431,7 +431,7 @@ module Rdio
431
431
 
432
432
  # Returns an array of User for the query and other params
433
433
  def self.search(query,never_or=nil,extras=nil,start=nil,count=nil)
434
- extras = add_to_array extras,'users'
434
+ extras = Rdio::add_to_array extras,'users'
435
435
  Search.search query,User,never_or,extras,start,count
436
436
  end
437
437
 
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: 167
4
+ hash: 165
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 92
10
- version: 0.0.92
9
+ - 93
10
+ version: 0.0.93
11
11
  platform: ruby
12
12
  authors:
13
13
  - Jeffrey Palm
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-05-15 00:00:00 -04:00
18
+ date: 2011-05-22 00:00:00 -04:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency