myspaceid-sdk 0.1.8 → 0.1.9

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,9 @@
1
+ = MySpaceID SDK
2
+
3
+ * http://myspaceid-sdk.rubyforge.org/
4
+
5
+ == DESCRIPTION:
6
+
1
7
  MySpaceID lets your users log on using their MySpace account info,
2
8
  after which their MySpaceID data becomes available; that is, your web
3
9
  servers will be able to communicate with our web servers and request
@@ -28,3 +34,6 @@ Documentation
28
34
  * Ruby SDK Documentation Summary: samples/rails/README
29
35
  * Ruby SDK - API Documentation: http://myspaceid-ruby-sdk.googlecode.com/svn/trunk/doc/index.html
30
36
 
37
+ == LICENSE:
38
+
39
+ MIT/X Consortium
data/lib/myspace.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  require 'rubygems'
2
- require 'oauth/consumer'
2
+ require 'oauth'
3
3
  require 'openid/consumer'
4
4
  require 'json'
5
5
  require 'logger'
@@ -7,9 +7,11 @@ require 'logger'
7
7
  require 'patches'
8
8
 
9
9
  module MySpace
10
+ VERSION = '0.1.9'
10
11
  end
11
12
 
13
+ require 'myspace/end_point'
12
14
  require 'myspace/myspace'
13
15
  require 'myspace/exceptions'
14
- require 'myspace/oauth'
16
+ require 'myspace/oauth_request'
15
17
 
@@ -0,0 +1,77 @@
1
+ module MySpace
2
+ class EndPoint
3
+ attr_reader :method
4
+
5
+ @@registry = {}
6
+ # Registers a new EndPoint named +name+.
7
+ #
8
+ # +path+ is the path on server which may include variables in braces, e.g.
9
+ #
10
+ # '/v1/users/{user_id}/profile'
11
+ #
12
+ # In this case, when you call +compute_path+ for this +EndPoint+,
13
+ # you must include +user_id+ in +params+, which will be
14
+ # substituted into the url.
15
+ def self.define(name, path, method, *options)
16
+ @@registry[name] = EndPoint.new(path, method, options)
17
+ end
18
+
19
+ # Returns the EndPoint named +name+.
20
+ def self.find(name)
21
+ return @@registry[name]
22
+ end
23
+
24
+ def initialize(path, method = :get, options = [])
25
+ @components = EndPoint.parse_path(path)
26
+ @method = method
27
+ @options = options.dup
28
+ @options.delete(:v1_json)
29
+ @v1_json = options.detect(:v1_json)
30
+ end
31
+
32
+ def self.parse_path(path)
33
+ # parse the path string looking for {var} to substitute
34
+ fragments = []
35
+ pos = 0
36
+ while pos < path.length
37
+ lbrace = path.index('{', pos)
38
+ unless lbrace
39
+ fragments.push(path[pos, path.length - pos])
40
+ break
41
+ end
42
+ rbrace = path.index('}', lbrace)
43
+ raise "unmatched left brace in '#{path}'" unless rbrace
44
+ fragments.push(path[pos, lbrace - pos])
45
+ var = path[lbrace + 1, rbrace - lbrace - 1].to_sym
46
+ fragments.push(var)
47
+ pos = rbrace + 1
48
+ end
49
+
50
+ fragments
51
+ end
52
+
53
+ # Computes the path to the EndPoint by substituting parameters
54
+ # from +params+ into the path.
55
+ #
56
+ # WARNING: This function DESTRUCTIVELY modifies the +params+ hash
57
+ # that you pass to it. This is normally what you want, since you
58
+ # don't want to substitute a parameter into the path and also pass
59
+ # it in the query string, but make sure to make a copy first if
60
+ # you're just passing in parameters from another caller.
61
+ def compute_path(params)
62
+ path = @components.inject("") do |result, cur|
63
+ if cur.class == String
64
+ result + cur
65
+ elsif cur.class == Symbol
66
+ val = params.delete(cur)
67
+ raise "Required parameter '#{cur}' omitted" unless val
68
+ result + val
69
+ else
70
+ raise "Bad path component: #{cur}"
71
+ end
72
+ end
73
+ path << '.json' if @v1_json && params[:v1_json]
74
+ path
75
+ end
76
+ end
77
+ end
@@ -1,7 +1,11 @@
1
1
  module MySpace
2
+ # Parent class of our local exceptions
2
3
  class MySpaceException < Exception
3
4
  end
4
5
 
6
+ # You tried to pass an invalid value as a parameter to a REST call.
7
+ # The REST error responses are not very elucidating, so we try to
8
+ # catch these before sending them off.
5
9
  class BadIdentifier < MySpaceException
6
10
  attr_reader :parameter, :identifier
7
11
  def initialize(parameter, identifier)
@@ -10,6 +14,7 @@ module MySpace
10
14
  end
11
15
  end
12
16
 
17
+ # A REST call failed for some reason.
13
18
  class RestException < MySpaceException
14
19
  attr_reader :code, :message, :url
15
20
  def initialize(code, message, url)
@@ -23,9 +28,16 @@ module MySpace
23
28
  end
24
29
  end
25
30
 
31
+ # A REST call failed because the caller doesn't have permission to
32
+ # call it.
26
33
  class PermissionDenied < RestException
27
34
  def to_s
28
35
  "#<PermissionDenied loading '#{url}'>"
29
36
  end
30
37
  end
38
+
39
+ # A REST call timed out. Should probably just try again.
40
+ class TimeoutException < Interrupt
41
+ attr_accessor :url, :timeout
42
+ end
31
43
  end
@@ -13,21 +13,34 @@ module MySpace
13
13
  OAUTH_AUTHORIZATION_URL = '/authorize' unless const_defined?('OAUTH_AUTHORIZATION_URL')
14
14
  OAUTH_ACCESS_TOKEN_URL = '/access_token' unless const_defined?('OAUTH_ACCESS_TOKEN_URL')
15
15
 
16
- API_USERINFO_URL = '/v1/user.json' unless const_defined?('API_USERINFO_URL')
17
- API_ALBUMS_URL = '/v1/users/%s/albums.json' unless const_defined?('API_ALBUMS_URL')
18
- API_ALBUM_URL = '/v1/users/%s/albums/%s/photos.json' unless const_defined?('API_ALBUM_URL')
19
- API_FRIENDS_URL = '/v1/users/%s/friends.json' unless const_defined?('API_FRIENDS_URL')
20
- API_FRIENDSHIP_URL = '/v1/users/%s/friends/%s.json' unless const_defined?('API_FRIENDSHIP_URL')
21
- API_MOOD_URL = '/v1/users/%s/mood.json' unless const_defined?('API_MOOD_URL')
22
- API_PHOTOS_URL = '/v1/users/%s/photos.json' unless const_defined?('API_PHOTOS_URL')
23
- API_PHOTO_URL = '/v1/users/%s/photos/%s.json' unless const_defined?('API_PHOTO_URL')
24
- API_PROFILE_URL = '/v1/users/%s/profile.json' unless const_defined?('API_PROFILE_URL')
25
- API_STATUS_URL = '/v1/users/%s/status.json' unless const_defined?('API_STATUS_URL')
26
- API_STATUS_PUT_URL = '/v1/users/%s/status' unless const_defined?('API_STATUS_PUT_URL')
27
- API_VIDEOS_URL = '/v1/users/%s/videos.json' unless const_defined?('API_VIDEOS_URL')
28
- API_VIDEO_URL = '/v1/users/%s/videos/%s.json' unless const_defined?('API_VIDEO_URL')
29
- API_ACTIVITIES_URL = '/v1/users/%s/activities.atom' unless const_defined?('API_ACTIVITIES_URL')
30
- API_FRIENDS_ACTIVITIES_URL = '/v1/users/%s/friends/activities.atom' unless const_defined?('API_FRIENDS_ACTIVITIES_URL')
16
+ # tests regularly timeout at 2 seconds
17
+ TIMEOUT_SECS = 3 unless const_defined?('TIMEOUT_SECS')
18
+
19
+ EndPoint.define(:user_info, '/v1/user', :get, :v1_json)
20
+ EndPoint.define(:albums, '/v1/users/{user_id}/albums', :get, :v1_json)
21
+ EndPoint.define(:album, '/v1/users/{user_id}/albums/{album_id}/photos', :get, :v1_json)
22
+ EndPoint.define(:friends, '/v1/users/{user_id}/friends', :get, :v1_json)
23
+ EndPoint.define(:friendship, '/v1/users/{user_id}/friends/{friend_ids}', :get, :v1_json)
24
+ EndPoint.define(:mood, '/v1/users/{user_id}/mood', :get, :v1_json)
25
+ EndPoint.define(:photos, '/v1/users/{user_id}/photos', :get, :v1_json)
26
+ EndPoint.define(:photo, '/v1/users/{user_id}/photos/{photo_id}', :get, :v1_json)
27
+ EndPoint.define(:profile, '/v1/users/{user_id}/profile', :get, :v1_json)
28
+ EndPoint.define(:status_get, '/v1/users/{user_id}/status', :get, :v1_json)
29
+ EndPoint.define(:status_put, '/v1/users/{user_id}/status', :put)
30
+ EndPoint.define(:videos, '/v1/users/{user_id}/videos', :get, :v1_json)
31
+ EndPoint.define(:video, '/v1/users/{user_id}/videos/{video_id}', :get, :v1_json)
32
+ EndPoint.define(:activities, '/v1/users/{user_id}/activities.atom', :get)
33
+ EndPoint.define(:friends_activities, '/v1/users/{user_id}/friends/activities.atom', :get)
34
+ EndPoint.define(:appdata_global_get, '/v1/appdata/global', :get, :v1_json)
35
+ EndPoint.define(:appdata_global_keys_get, '/v1/appdata/global/{keys}', :get, :v1_json)
36
+ EndPoint.define(:appdata_global_put, '/v1/appdata/global', :put)
37
+ EndPoint.define(:appdata_global_delete, '/v1/appdata/global/{keys}', :delete)
38
+ EndPoint.define(:appdata_user_get, '/v1/users/{user_id}/appdata', :get, :v1_json)
39
+ EndPoint.define(:appdata_user_keys_get, '/v1/users/{user_id}/appdata/{keys}', :get, :v1_json)
40
+ EndPoint.define(:appdata_user_put, '/v1/users/{user_id}/appdata', :put)
41
+ EndPoint.define(:appdata_user_delete, '/v1/users/{user_id}/appdata/{keys}', :delete)
42
+ EndPoint.define(:appdata_friends_get, '/v1/users/{user_id}/friends/appdata', :get, :v1_json)
43
+ EndPoint.define(:appdata_friends_keys_get, '/v1/users/{user_id}/friends/appdata/{keys}', :get, :v1_json)
31
44
 
32
45
  attr_reader :consumer
33
46
  attr_accessor :http_logger
@@ -107,7 +120,7 @@ module MySpace
107
120
 
108
121
  # Get the user id of the currently logged in user.
109
122
  def get_userid()
110
- user_info = call_myspace_api_json(API_USERINFO_URL)
123
+ user_info = call_myspace_api(:user_info, :v1_json => true)
111
124
  user_info['userId'].to_s
112
125
  end
113
126
 
@@ -148,8 +161,7 @@ module MySpace
148
161
  def get_albums(user_id, params = {})
149
162
  user_id = user_id.to_s
150
163
  validate_identifier(:user_id, user_id)
151
- url = sprintf(API_ALBUMS_URL, user_id)
152
- call_myspace_api_json(url, :get, params)
164
+ call_myspace_api(:albums, params.dup.update(:user_id => user_id, :v1_json => true))
153
165
  end
154
166
 
155
167
  # Get the photo descriptions for the photos of album +album_id+
@@ -187,13 +199,12 @@ module MySpace
187
199
  # "userId"=>456073223,
188
200
  # "image"=>
189
201
  # "http://c1.ac-images.myspacecdn.com/images02/45/s_f820313641924f0f90004932c8bc310c.jpg"}}
190
- def get_album(user_id, album_id)
202
+ def get_album(user_id, album_id, params = {})
191
203
  user_id = user_id.to_s
192
204
  validate_identifier(:user_id, user_id)
193
205
  album_id = album_id.to_s
194
206
  validate_identifier(:album_id, album_id)
195
- url = sprintf(API_ALBUM_URL, user_id, album_id)
196
- call_myspace_api_json(url)
207
+ call_myspace_api(:album, params.dup.update(:user_id => user_id, :album_id => album_id, :v1_json => true))
197
208
  end
198
209
 
199
210
  # Gets the list of friends for the user +user_id+:
@@ -221,8 +232,7 @@ module MySpace
221
232
  def get_friends(user_id, params = {})
222
233
  user_id = user_id.to_s
223
234
  validate_identifier(:user_id, user_id)
224
- url = sprintf(API_FRIENDS_URL, user_id)
225
- call_myspace_api_json(url, :get, params)
235
+ call_myspace_api(:friends, params.dup.update(:user_id => user_id, :v1_json => true))
226
236
  end
227
237
 
228
238
  # Tests whether user +user_id+ is friends with one or more other users:
@@ -248,8 +258,7 @@ module MySpace
248
258
  friend_id = friend_id.to_s
249
259
  validate_identifier(:friend_ids, friend_id)
250
260
  end
251
- url = sprintf(API_FRIENDSHIP_URL, user_id, friend_ids.join(';'))
252
- call_myspace_api_json(url)
261
+ call_myspace_api(:friendship, :user_id => user_id, :friend_ids => friend_ids.join(';'), :v1_json => true)
253
262
  end
254
263
 
255
264
  # Gets the mood of user +user_id+:
@@ -268,11 +277,10 @@ module MySpace
268
277
  # "userId"=>456073223,
269
278
  # "image"=>
270
279
  # "http://c1.ac-images.myspacecdn.com/images02/45/s_f820313641924f0f90004932c8bc310c.jpg"}}
271
- def get_mood(user_id)
280
+ def get_mood(user_id, params = {})
272
281
  user_id = user_id.to_s
273
282
  validate_identifier(:user_id, user_id)
274
- url = sprintf(API_MOOD_URL, user_id)
275
- call_myspace_api_json(url)
283
+ call_myspace_api(:mood, params.dup.update(:user_id => user_id, :v1_json => true))
276
284
  end
277
285
 
278
286
  # Gets the photo descriptions for the photos that belong to user +user_id+:
@@ -311,8 +319,7 @@ module MySpace
311
319
  def get_photos(user_id, params = {})
312
320
  user_id = user_id.to_s
313
321
  validate_identifier(:user_id, user_id)
314
- url = sprintf(API_PHOTOS_URL, user_id)
315
- call_myspace_api_json(url, :get, params)
322
+ call_myspace_api(:photos, params.dup.update(:user_id => user_id, :v1_json => true))
316
323
  end
317
324
 
318
325
  # Gets the photo description for photo +photo_id+ for user +user_id+:
@@ -336,13 +343,12 @@ module MySpace
336
343
  # "userId"=>456073223,
337
344
  # "image"=>
338
345
  # "http://c1.ac-images.myspacecdn.com/images02/45/s_f820313641924f0f90004932c8bc310c.jpg"}}
339
- def get_photo(user_id, photo_id)
346
+ def get_photo(user_id, photo_id, params = {})
340
347
  user_id = user_id.to_s
341
348
  validate_identifier(:user_id, user_id)
342
349
  photo_id = photo_id.to_s
343
350
  validate_identifier(:photo_id, photo_id)
344
- url = sprintf(API_PHOTO_URL, user_id, photo_id)
345
- call_myspace_api_json(url)
351
+ call_myspace_api(:photo, params.dup.update(:user_id => user_id, :photo_id => photo_id, :v1_json => true))
346
352
  end
347
353
 
348
354
  # Gets the profile info for user +user_id+:
@@ -371,8 +377,7 @@ module MySpace
371
377
  def get_profile(user_id, params = {})
372
378
  user_id = user_id.to_s
373
379
  validate_identifier(:user_id, user_id)
374
- url = sprintf(API_PROFILE_URL, user_id)
375
- call_myspace_api_json(url, :get, params)
380
+ call_myspace_api(:profile, params.dup.update(:user_id => user_id, :v1_json => true))
376
381
  end
377
382
 
378
383
  # Gets the status of user +user_id+:
@@ -392,11 +397,17 @@ module MySpace
392
397
  # "image"=>
393
398
  # "http://c1.ac-images.myspacecdn.com/images02/45/s_f820313641924f0f90004932c8bc310c.jpg"},
394
399
  # "status"=>"Testing"}
395
- def get_status(user_id)
400
+ def get_status(user_id, params = {})
396
401
  user_id = user_id.to_s
397
402
  validate_identifier(:user_id, user_id)
398
- url = sprintf(API_STATUS_URL, user_id)
399
- call_myspace_api_json(url)
403
+ call_myspace_api(:status_get, params.dup.update(:user_id => user_id, :v1_json => true))
404
+ end
405
+
406
+ # Sets the status of the user +user_id+
407
+ def set_status(user_id, status)
408
+ user_id = user_id.to_s
409
+ validate_identifier(:user_id, user_id)
410
+ call_myspace_api(:status_put, :user_id => user_id, :body => {:status => status})
400
411
  end
401
412
 
402
413
  # Gets the video descriptions for the videos of user +user_id+:
@@ -442,11 +453,10 @@ module MySpace
442
453
  # "userId"=>456073223,
443
454
  # "image"=>
444
455
  # "http://c1.ac-images.myspacecdn.com/images02/45/s_f820313641924f0f90004932c8bc310c.jpg"}}
445
- def get_videos(user_id)
456
+ def get_videos(user_id, params = {})
446
457
  user_id = user_id.to_s
447
458
  validate_identifier(:user_id, user_id)
448
- url = sprintf(API_VIDEOS_URL, user_id)
449
- call_myspace_api_json(url)
459
+ call_myspace_api(:videos, params.dup.update(:user_id => user_id, :v1_json => true))
450
460
  end
451
461
 
452
462
  # Gets the video description for the video +video_id+ of user +user_id+:
@@ -480,65 +490,156 @@ module MySpace
480
490
  # "http://c1.ac-images.myspacecdn.com/images02/45/s_f820313641924f0f90004932c8bc310c.jpg"},
481
491
  # "totalvotes"=>"0",
482
492
  # "videoUri"=>"http://api.myspace.com/v1/users/456073223/videos/53551799"}
483
- def get_video(user_id, video_id)
493
+ def get_video(user_id, video_id, params = {})
484
494
  user_id = user_id.to_s
485
495
  validate_identifier(:user_id, user_id)
486
496
  video_id = video_id.to_s
487
497
  validate_identifier(:video_id, video_id)
488
- url = sprintf(API_VIDEO_URL, user_id, video_id)
489
- call_myspace_api_json(url)
498
+ call_myspace_api(:video, params.dup.update(:user_id => user_id, :video_id => video_id, :v1_json => true))
490
499
  end
491
500
 
492
- def get_activities(user_id)
501
+ def get_activities(user_id, params = {})
493
502
  user_id = user_id.to_s
494
503
  validate_identifier(:user_id, user_id)
495
- url = sprintf(API_ACTIVITIES_URL, user_id)
496
- call_myspace_api_xml(url)
504
+ call_myspace_api(:activities, params.dup.update(:user_id => user_id))
497
505
  end
498
506
 
499
- def get_friends_activities(user_id)
507
+ def get_friends_activities(user_id, params = {})
500
508
  user_id = user_id.to_s
501
509
  validate_identifier(:user_id, user_id)
502
- url = sprintf(API_FRIENDS_ACTIVITIES_URL, user_id)
503
- call_myspace_api_xml(url)
510
+ call_myspace_api(:friends_activities, params.dup.update(:user_id => user_id))
504
511
  end
505
512
 
506
- def set_status(user_id, status)
513
+ def get_global_appdata(*keys)
514
+ appdata_to_hash do
515
+ if keys.length > 0
516
+ call_myspace_api(:appdata_global_keys_get, :keys => keys.join(';'), :v1_json => true)
517
+ else
518
+ call_myspace_api(:appdata_global_get, :v1_json => true)
519
+ end
520
+ end
521
+ end
522
+
523
+ def self.remove_null_values(hash)
524
+ hash.keys.inject([]) do |nulls, key|
525
+ unless hash[key]
526
+ hash.delete(key)
527
+ nulls << key
528
+ end
529
+ nulls
530
+ end
531
+ end
532
+
533
+ def set_global_appdata(params = {})
534
+ deletes = MySpace.remove_null_values(params)
535
+
536
+ call_myspace_api(:appdata_global_put, :body => params) if params.length > 0
537
+ call_myspace_api(:appdata_global_delete, :keys => deletes.join(';')) if deletes.length > 0
538
+ end
539
+
540
+ def clear_global_appdata(*keys)
541
+ call_myspace_api(:appdata_global_delete, :keys => keys.join(';'))
542
+ end
543
+
544
+ def get_user_appdata(user_id, *keys)
507
545
  user_id = user_id.to_s
508
546
  validate_identifier(:user_id, user_id)
509
- url = sprintf(API_STATUS_PUT_URL, user_id)
510
- call_myspace_api_xml(url, :put, {:body => {:status => status}})
547
+ appdata_to_hash do
548
+ if keys.length > 0
549
+ call_myspace_api(:appdata_user_keys_get, :user_id => user_id, :keys => keys.join(';'), :v1_json => true)
550
+ else
551
+ call_myspace_api(:appdata_user_get, :user_id => user_id, :v1_json => true)
552
+ end
553
+ end
511
554
  end
512
555
 
513
- def call_myspace_api(url, method = :get, params = {}, &block)
556
+ def set_user_appdata(user_id, params = {})
557
+ user_id = user_id.to_s
558
+ validate_identifier(:user_id, user_id)
559
+ deletes = MySpace.remove_null_values(params)
560
+ call_myspace_api(:appdata_user_put, :user_id => user_id, :body => params) if params.length > 0
561
+ call_myspace_api(:appdata_user_delete, :user_id => user_id, :keys => deletes.join(';')) if deletes.length > 0
562
+ end
563
+
564
+ def clear_user_appdata(user_id, *keys)
565
+ user_id = user_id.to_s
566
+ validate_identifier(:user_id, user_id)
567
+ call_myspace_api(:appdata_user_delete, :user_id => user_id, :keys => keys.join(';'))
568
+ end
569
+
570
+ def get_user_friends_appdata(user_id, *keys)
571
+ user_id = user_id.to_s
572
+ validate_identifier(:user_id, user_id)
573
+ appdata_to_hash do
574
+ if keys.length > 0
575
+ call_myspace_api(:appdata_friends_get, :user_id => user_id, :v1_json => true)
576
+ else
577
+ call_myspace_api(:appdata_friends_keys_get, :user_id => user_id, :keys => keys.join(';'), :v1_json => true)
578
+ end
579
+ end
580
+ end
581
+
582
+ def appdata_to_hash(&block)
583
+ appdata = yield
584
+ return {} unless appdata['keyvaluecollection']
585
+ appdata['keyvaluecollection'].inject({}) do |hash, entry|
586
+ hash.update(entry['key'].to_sym => entry['value'])
587
+ end
588
+ end
589
+
590
+
591
+ def call_myspace_api(name, params = {}, &block)
514
592
  params = params.dup
593
+ ep = EndPoint.find(name)
594
+ url = ep.compute_path(params)
595
+ timeout = params.delete(:timeout) || TIMEOUT_SECS
515
596
  body = params.delete(:body)
516
597
  headers = params.delete(:headers)
598
+ params.delete(:v1_json)
517
599
  query_str = params.collect do |key, value|
518
600
  CGI.escape(key.to_s) + '=' + CGI.escape(value.to_s)
519
601
  end.join('&')
520
602
 
521
603
  url << '?' + query_str if query_str.length > 0
522
604
 
605
+ resp = nil
523
606
  @http_logger.info("sending: '#{url}'") if @http_logger
524
- resp = @access_token.request(method, url, body, headers)
607
+ begin
608
+ Timeout::timeout(timeout, TimeoutException) do
609
+ resp = @access_token.request(ep.method, url, body, headers)
610
+ end
611
+ rescue TimeoutException => e
612
+ e.timeout = timeout
613
+ e.url = url
614
+ raise e
615
+ end
525
616
  @http_logger.info("received: '#{resp.code}': '#{resp.body}'") if @http_logger
526
617
 
527
618
  validate_response(resp, url)
528
- yield(resp.body)
529
- end
530
619
 
531
- def call_myspace_api_json(url, method = :get, params = {})
532
- call_myspace_api(url, method, params) do |body|
533
- JSON::parse(body)
620
+ content_type = resp['content-type']
621
+ if content_type
622
+ if content_type =~ /json/
623
+ return JSON::parse(resp.body)
624
+ elsif content_type =~ /xml/
625
+ return REXML::Document.new(resp.body)
626
+ end
627
+
628
+ raise "unknown content type: #{content_type}"
534
629
  end
535
630
  end
536
631
 
537
- def call_myspace_api_xml(url, method = :get, params = {})
538
- call_myspace_api(url, method, params) do |body|
539
- REXML::Document.new(body)
540
- end
541
- end
632
+ # def call_myspace_api_json(url, method = :get, params = {})
633
+ # call_myspace_api(url, method, params) do |body|
634
+ # JSON::parse(body)
635
+ # end
636
+ # end
637
+
638
+ # def call_myspace_api_xml(url, method = :get, params = {})
639
+ # call_myspace_api(url, method, params) do |body|
640
+ # REXML::Document.new(body)
641
+ # end
642
+ # end
542
643
 
543
644
  protected
544
645
 
File without changes
data/test/myspace_test.rb CHANGED
@@ -8,6 +8,25 @@ module MySpaceTest
8
8
  include TestData
9
9
 
10
10
  def setup
11
- @myspace = MySpace::MySpace.new(CONSUMER_KEY, CONSUMER_SECRET, :access_token => TOKEN, :access_token_secret => SECRET)
11
+ @myspace = MySpace::MySpace.new(CONSUMER_KEY, CONSUMER_SECRET,
12
+ :access_token => TOKEN, :access_token_secret => SECRET,
13
+ :logger => Logger.new($stdout))
14
+ end
15
+
16
+ class Tester
17
+ attr_accessor :passed
18
+ def initialize(default = false)
19
+ @passed = default
20
+ end
21
+ end
22
+
23
+ def assert_passes_eventually(max_iterations = 10, sleep_time = 0.1, &block)
24
+ tester = Tester.new
25
+ max_iterations.times do
26
+ yield(tester)
27
+ break if tester.passed
28
+ sleep(sleep_time)
29
+ end
30
+ assert(tester.passed)
12
31
  end
13
32
  end
data/test/tc_albums.rb CHANGED
@@ -85,7 +85,7 @@ class TC_Albums < Test::Unit::TestCase
85
85
  photo = photos[0]
86
86
  assert_instance_of(Hash, photo)
87
87
  photo_id = photo['id'].to_s
88
- assert_equal('100809', photo_id)
88
+ assert_equal(PHOTO_ID, photo_id)
89
89
  caption = photo['caption']
90
90
  assert_instance_of(String, caption)
91
91
  assert_equal('', caption)
data/test/tc_friends.rb CHANGED
@@ -11,7 +11,7 @@ class TC_Friends < Test::Unit::TestCase
11
11
  obj = @myspace.get_friends(value)
12
12
  end
13
13
  end
14
- assert_raise(MySpace::PermissionDenied) do
14
+ assert_raise(OAuth::Problem) do
15
15
  obj = @myspace.get_friends("6221")
16
16
  end
17
17
  assert_nothing_raised do
data/test/tc_profile.rb CHANGED
@@ -78,27 +78,37 @@ class TC_Profile < Test::Unit::TestCase
78
78
  assert_instance_of(Hash, obj)
79
79
  status = obj['status']
80
80
  assert_instance_of(String, status)
81
- assert_equal("Testing", status)
81
+ # assert_equal("Testing", status)
82
82
 
83
83
  assert_nothing_raised do
84
84
  @myspace.set_status(USER_ID, "Updating!")
85
85
  end
86
86
 
87
- passed = false
88
- 10.times do
87
+ assert_passes_eventually do |result|
89
88
  assert_nothing_raised do
90
89
  obj = @myspace.get_status(USER_ID)
91
90
  end
92
91
  assert_instance_of(Hash, obj)
93
92
  status = obj['status']
94
93
  assert_instance_of(String, status)
95
- if status == "Updating!"
96
- passed = true
97
- break
98
- end
99
- sleep(0.1)
94
+ result.passed = true if status == "Updating!"
100
95
  end
101
- assert(passed)
96
+
97
+ # passed = false
98
+ # 10.times do
99
+ # assert_nothing_raised do
100
+ # obj = @myspace.get_status(USER_ID)
101
+ # end
102
+ # assert_instance_of(Hash, obj)
103
+ # status = obj['status']
104
+ # assert_instance_of(String, status)
105
+ # if status == "Updating!"
106
+ # passed = true
107
+ # break
108
+ # end
109
+ # sleep(0.1)
110
+ # end
111
+ # assert(passed)
102
112
 
103
113
  assert_nothing_raised do
104
114
  @myspace.set_status(USER_ID, "Testing")
data/test/test_data.rb CHANGED
@@ -7,6 +7,7 @@ module TestData
7
7
 
8
8
  USER_ID = '456073223' unless const_defined?('USER_ID')
9
9
  ALBUM_ID = '40418' unless const_defined?('ALBUM_ID')
10
+ PHOTO_ID = '100809' unless const_defined?('PHOTO_ID')
10
11
  VIDEO_ID = '53551799' unless const_defined?('VIDEO_ID')
11
12
  VIDEO_TITLE = '110403na' unless const_defined?('VIDEO_TITLE')
12
13
 
data/test/ts_alltests.rb CHANGED
@@ -4,4 +4,5 @@ require 'tc_profile'
4
4
  require 'tc_friends'
5
5
  require 'tc_albums'
6
6
  require 'tc_videos'
7
+ require 'tc_appdata'
7
8
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: myspaceid-sdk
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.8
4
+ version: 0.1.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Christopher B. Baker
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-03-24 00:00:00 -07:00
12
+ date: 2009-04-03 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -42,21 +42,33 @@ dependencies:
42
42
  - !ruby/object:Gem::Version
43
43
  version: "0"
44
44
  version:
45
- description: The MySpaceID SDK provides a library for implementing MySpaceID and accessing MySpace users account data.
45
+ - !ruby/object:Gem::Dependency
46
+ name: hoe
47
+ type: :development
48
+ version_requirement:
49
+ version_requirements: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: 1.11.0
54
+ version:
55
+ description: "MySpaceID lets your users log on using their MySpace account info, after which their MySpaceID data becomes available; that is, your web servers will be able to communicate with our web servers and request user data. This SDK project contains examples of the base API code necessary to make signed requests against the MySpaceID REST API. To use the MySpaceID API, you first need to register on the MySpace Developer Site, create an app, and obtain a consumer key and secret. Information about these procedures, and about MySpaceID in general, is available at the MySpaceID Developer Wiki: http://wiki.developer.myspace.com/index.php?title=Category:MySpaceID The MySpaceID Ruby SDK enables you to work with MySpace data using the OpenStack (OpenID, OAuth etc) and the MySpace REST APIs via easy-to-use high level interfaces. The best way to implement your own application is to take an existing sample and customize it. Working Examples in this SDK: * OAuth - make signed requests * OpenID + OAuth Hybrid - delegated login, and making signed requests Documentation * Ruby SDK Documentation Summary: samples/rails/README * Ruby SDK - API Documentation: http://myspaceid-ruby-sdk.googlecode.com/svn/trunk/doc/index.html"
46
56
  email: cbaker@myspace.com
47
57
  executables: []
48
58
 
49
59
  extensions: []
50
60
 
51
- extra_rdoc_files: []
52
-
61
+ extra_rdoc_files:
62
+ - README.txt
63
+ - samples/rails/sample/public/robots.txt
53
64
  files:
54
- - README
65
+ - README.txt
55
66
  - lib/myspace.rb
56
67
  - lib/myspace
68
+ - lib/myspace/oauth_request.rb
57
69
  - lib/myspace/myspace.rb
70
+ - lib/myspace/end_point.rb
58
71
  - lib/myspace/exceptions.rb
59
- - lib/myspace/oauth.rb
60
72
  - lib/patches.rb
61
73
  - test/tc_profile.rb
62
74
  - test/myspace_test.rb
@@ -143,7 +155,6 @@ files:
143
155
  - samples/rails/sample/public/stylesheets/openid.css
144
156
  - samples/rails/sample/public/stylesheets/base.css
145
157
  - samples/rails/sample/public/stylesheets/main.css
146
- - samples/rails/sample/public/doc
147
158
  - samples/rails/sample/test
148
159
  - samples/rails/sample/test/test_helper.rb
149
160
  - samples/rails/sample/test/performance
@@ -154,6 +165,7 @@ files:
154
165
  - samples/rails/sample/test/functional/user_controller_test.rb
155
166
  - samples/rails/sample/db
156
167
  - samples/rails/sample/db/development.sqlite3
168
+ - samples/rails/sample/log
157
169
  - samples/rails/sample/config
158
170
  - samples/rails/sample/config/locales
159
171
  - samples/rails/sample/config/locales/en.yml
@@ -193,10 +205,11 @@ files:
193
205
  - samples/rails/consumer_key.rb-copyme
194
206
  - samples/rails/README
195
207
  has_rdoc: true
196
- homepage: http://developer.myspace.com/
208
+ homepage: http://myspaceid-sdk.rubyforge.org/
197
209
  post_install_message:
198
- rdoc_options: []
199
-
210
+ rdoc_options:
211
+ - --main
212
+ - README.txt
200
213
  require_paths:
201
214
  - lib
202
215
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -217,6 +230,6 @@ rubyforge_project: myspaceid-sdk
217
230
  rubygems_version: 1.3.1
218
231
  signing_key:
219
232
  specification_version: 2
220
- summary: Official SDK for MySpaceID and MySpace Data Accessibility.
221
- test_files: []
222
-
233
+ summary: MySpaceID lets your users log on using their MySpace account info, after which their MySpaceID data becomes available; that is, your web servers will be able to communicate with our web servers and request user data
234
+ test_files:
235
+ - test/test_data.rb