Class: MySpace::MySpace

Inherits:
Object
  • Object
show all
Defined in:
lib/myspace/myspace.rb

Overview

The MySpace API object provides access to the MySpace REST API.

Constant Summary collapse

APPLICATION_TYPE_ONSITE =
'onsite'
APPLICATION_TYPE_OFFSITE =
'offsite'
OAUTH_SITES =
{
  :prod => 'http://api.myspace.com',
  :stage => 'http://stage-api.myspace.com'
}
OAUTH_REQUEST_TOKEN_URL =
'/request_token'
OAUTH_AUTHORIZATION_URL =
'/authorize'
OAUTH_ACCESS_TOKEN_URL =
'/access_token'
TIMEOUT_SECS =

tests regularly timeout at 2 seconds

3
ID_REGEXP =
/[0-9]+/

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(oauth_token_key, oauth_token_secret, params = {}) ⇒ MySpace

Save the application key/secret(s) and initialize OAuth code.

If optional param :application_type is passed, it must be one of MySpace::APPLICATION_TYPE_ONSITE or MySpace::APPLICATION_TYPE_OFFSITE. If the application is an onsite application, an access token is not required, since the user must separately give your application permission to access their data. If the application is an offsite application, it must get an access token from the user to access their data.

If optional param :request_token is passed :request_token_secret must also be passed, and they will be used to create the default argument to MySpace#get_access_token below. If optional param :access_token is passed, :access_token_secret must also be passed, and they will be used to create the access token for the REST API calls.

If optional param :site is passed, it must be either :prod or :stage, and MySpace OAuth calls will be directed to either the production or stage API server accordingly.



78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/myspace/myspace.rb', line 78

def initialize(oauth_token_key, oauth_token_secret, params = {})
  @http_logger = params[:logger]
  site = params[:site] || :prod
  @consumer = ::OAuth::Consumer.new(oauth_token_key,
                                    oauth_token_secret,
                                    :scheme => :query_string,
                                    # :scheme => :header,
                                    :http_method => :get,
                                    :site => OAUTH_SITES[site],
                                    :request_token_path => OAUTH_REQUEST_TOKEN_URL,
                                    :access_token_path => OAUTH_ACCESS_TOKEN_URL,
                                    :authorize_path => OAUTH_AUTHORIZATION_URL)

  if params[:application_type] == APPLICATION_TYPE_ONSITE
    @access_token = ::OAuth::AccessToken.new(@consumer, "", "")
  elsif params[:access_token]
    @access_token = ::OAuth::AccessToken.new(@consumer,
                                             params[:access_token],
                                             params[:access_token_secret])
  end
  if params[:request_token]
    @request_token = ::OAuth::RequestToken.new(@consumer,
                                               params[:request_token],
                                               params[:request_token_secret])
  end
end

Instance Attribute Details

#access_tokenObject

Returns the value of attribute access_token.



55
56
57
# File 'lib/myspace/myspace.rb', line 55

def access_token
  @access_token
end

#consumerObject (readonly)

Returns the value of attribute consumer.



52
53
54
# File 'lib/myspace/myspace.rb', line 52

def consumer
  @consumer
end

#http_loggerObject

Returns the value of attribute http_logger.



53
54
55
# File 'lib/myspace/myspace.rb', line 53

def http_logger
  @http_logger
end

#request_tokenObject

Returns the value of attribute request_token.



54
55
56
# File 'lib/myspace/myspace.rb', line 54

def request_token
  @request_token
end

Instance Method Details

#call_myspace_api(name, params = {}, &block) ⇒ Object



696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
# File 'lib/myspace/myspace.rb', line 696

def call_myspace_api(name, params = {}, &block)
  params = params.dup
  ep = EndPoint.find(name)
  url = ep.compute_path(params)
  timeout = params.delete(:timeout) || TIMEOUT_SECS
  body = params.delete(:body)
  headers = params.delete(:headers)
  params.delete(:v1_json)
  query_str = params.collect do |key, value|
    CGI.escape(key.to_s) + '=' + CGI.escape(value.to_s)
  end.join('&')

  url << '?' + query_str if query_str.length > 0

  resp = nil
  @http_logger.info("sending: '#{url}'") if @http_logger
  begin
    Timeout::timeout(timeout, TimeoutException) do
      resp = @access_token.request(ep.method, url, body, headers)
    end
  rescue TimeoutException => e
    e.timeout = timeout
    e.url = url
    raise e
  end
  @http_logger.info("received: '#{resp.code}': '#{resp.body}'") if @http_logger

  validate_response(resp, url)

  content_type = resp['content-type']
  if content_type
    if content_type =~ /json/
      return JSON::parse(resp.body)
    elsif content_type =~ /xml/
      return REXML::Document.new(resp.body)
    end
    
    raise "unknown content type: #{content_type}"
  end
end

#clear_global_appdata(*keys) ⇒ Object



626
627
628
# File 'lib/myspace/myspace.rb', line 626

def clear_global_appdata(*keys)
  call_myspace_api(:appdata_global_delete, :keys => keys.join(';'))
end

#clear_user_appdata(user_id, *keys) ⇒ Object



650
651
652
653
654
# File 'lib/myspace/myspace.rb', line 650

def clear_user_appdata(user_id, *keys)
  user_id = user_id.to_s
  validate_identifier(:user_id, user_id)
  call_myspace_api(:appdata_user_delete, :user_id => user_id, :keys => keys.join(';'))
end

#get_access_token(request_token = @request_token) ⇒ Object

Get an access token once the user has authorized us.



118
119
120
121
122
123
124
125
126
127
# File 'lib/myspace/myspace.rb', line 118

def get_access_token(request_token = @request_token)
  # response = @consumer.token_request(@consumer.http_method,
  #                                    (@consumer.access_token_url? ? @consumer.access_token_url : @consumer.access_token_path),
  #                                    request_token,
  #                                    {},
  #                                    headers)

  # @access_token = ::OAuth::AccessToken.new(@consumer, response[:oauth_token], response[:oauth_token_secret])
  @access_token = request_token.get_access_token
end

#get_activities(user_id, params = {}) ⇒ Object

Gets the activity stream of user user_id



593
594
595
596
597
# File 'lib/myspace/myspace.rb', line 593

def get_activities(user_id, params = {})
  user_id = user_id.to_s
  validate_identifier(:user_id, user_id)
  call_myspace_api(:activities, params.dup.update(:user_id => user_id))
end

#get_album(user_id, album_id, params = {}) ⇒ Object

Get the photo descriptions for the photos of album album_id for the user user_id:

[{“smallImageUri”=> “”, “photoUri”=> “api.myspace.com/v1/users/456073223/albums/40418/photos/100809”, “id”=>100809, “uploadDate”=>“2/27/2009 10:14:12 AM”, “caption”=>“”, “lastUpdatedDate”=>“”, “imageUri”=> “”, “user”=> {“name”=>“Bob”, “uri”=>“api.myspace.com/v1/users/456073223”, “webUri”=>“www.myspace.com/bobvontestacount”, “largeImage”=> “”, “userType”=>“RegularUser”, “userId”=>456073223, “image”=> “”}], “count”=>1, “user”=> “uri”=>“api.myspace.com/v1/users/456073223”, “webUri”=>“www.myspace.com/bobvontestacount”, “largeImage”=> “”, “userType”=>“RegularUser”, “userId”=>456073223, “image”=> “”}



239
240
241
242
243
244
245
# File 'lib/myspace/myspace.rb', line 239

def get_album(user_id, album_id, params = {})
  user_id = user_id.to_s
  validate_identifier(:user_id, user_id)
  album_id = album_id.to_s
  validate_identifier(:album_id, album_id)
  call_myspace_api(:album, params.dup.update(:user_id => user_id, :album_id => album_id, :v1_json => true))
end

#get_album_info(user_id, album_id, params = {}) ⇒ Object

Get the photo album description for user user_id and album album_id

href="http://api.myspace.com/v1/users/456073223/albums/40418/photos">api.myspace.com/v1/users/456073223/albums/40418/photos”,

"photoCount"=>1,
"location"=>"",
"title"=>"My Photos",
"id"=>40418,
"defaultImage"=>
  "http://c1.ac-images.myspacecdn.com/images02/45/m_f820313641924f0f90004932c8bc310c.jpg",
"privacy"=>"Everyone",
"user"=>
  {"name"=>"Bob",
  "uri"=>"http://api.myspace.com/v1/users/456073223",
  "webUri"=>"http://www.myspace.com/bobvontestacount",
  "largeImage"=>
  "http://c1.ac-images.myspacecdn.com/images02/45/l_f820313641924f0f90004932c8bc310c.jpg",
  "userType"=>"RegularUser",
  "userId"=>456073223,
  "image"=>
  "http://c1.ac-images.myspacecdn.com/images02/45/s_f820313641924f0f90004932c8bc310c.jpg",
"albumUri"=>"http://api.myspace.com/v1/users/456073223/albums/40418"}


196
197
198
199
200
201
202
# File 'lib/myspace/myspace.rb', line 196

def get_album_info(user_id, album_id, params = {})
  user_id = user_id.to_s
  validate_identifier(:user_id, user_id)
  album_id = album_id.to_s
  validate_identifier(:album_id, album_id)
  call_myspace_api(:album_info, params.dup.update(:user_id => user_id, :album_id => album_id, :v1_json => true))
end

#get_albums(user_id, params = {}) ⇒ Object

Get the photo album descriptions for the user user_id:

[{“photosUri”=> “api.myspace.com/v1/users/456073223/albums/40418/photos”, “photoCount”=>1, “location”=>“”, “title”=>“My Photos”, “id”=>40418, “defaultImage”=> “”, “privacy”=>“Everyone”, “user”=> {“name”=>“Bob”, “uri”=>“api.myspace.com/v1/users/456073223”, “webUri”=>“www.myspace.com/bobvontestacount”, “largeImage”=> “”, “userType”=>“RegularUser”, “userId”=>456073223, “image”=> “”, “albumUri”=>“api.myspace.com/v1/users/456073223/albums/40418”}], “count”=>1, “user”=> “uri”=>“api.myspace.com/v1/users/456073223”, “webUri”=>“www.myspace.com/bobvontestacount”, “largeImage”=> “”, “userType”=>“RegularUser”, “userId”=>456073223, “image”=> “”}



169
170
171
172
173
# File 'lib/myspace/myspace.rb', line 169

def get_albums(user_id, params = {})
  user_id = user_id.to_s
  validate_identifier(:user_id, user_id)
  call_myspace_api(:albums, params.dup.update(:user_id => user_id, :v1_json => true))
end

#get_authorization_url(request_token, callback_url) ⇒ Object

Get the url to which to redirect the user in order to authorize our access to their account. This url will redirect back to callback_url once the user authorizes us.



113
114
115
# File 'lib/myspace/myspace.rb', line 113

def get_authorization_url(request_token, callback_url)
  "#{request_token.authorize_url}&oauth_callback=#{CGI::escape(callback_url)}"
end

#get_friends(user_id, params = {}) ⇒ Object

Gets the list of friends for the user user_id:

href="http://api.myspace.com/v1/users/456073223/friends?list=top">api.myspace.com/v1/users/456073223/friends?list=top”, “Friends”=> [{“name”=>“Tom”, “uri”=>“api.myspace.com/v1/users/6221”, “webUri”=>“www.myspace.com/tom”, “largeImage”=>“”, “userType”=>“RegularUser”, “userId”=>6221, “image”=>“”], “count”=>1, “user”=> “uri”=>“api.myspace.com/v1/users/456073223”, “webUri”=>“www.myspace.com/bobvontestacount”, “largeImage”=> “”, “userType”=>“RegularUser”, “userId”=>456073223, “image”=> “”}



269
270
271
272
273
# File 'lib/myspace/myspace.rb', line 269

def get_friends(user_id, params = {})
  user_id = user_id.to_s
  validate_identifier(:user_id, user_id)
  call_myspace_api(:friends, params.dup.update(:user_id => user_id, :v1_json => true))
end

#get_friends_activities(user_id, params = {}) ⇒ Object

Gets the activity streams of the friends of user user_id



600
601
602
603
604
# File 'lib/myspace/myspace.rb', line 600

def get_friends_activities(user_id, params = {})
  user_id = user_id.to_s
  validate_identifier(:user_id, user_id)
  call_myspace_api(:friends_activities, params.dup.update(:user_id => user_id))
end

#get_friends_list(user_id, *friend_ids) ⇒ Object

Gets the list of friends for the user user_id, for the friends in friend_ids. Use this call if you only need information about a specific set of friends whose ids you already know.



304
305
306
307
308
309
310
311
312
# File 'lib/myspace/myspace.rb', line 304

def get_friends_list(user_id, *friend_ids)
  user_id = user_id.to_s
  validate_identifier(:user_id, user_id)
  friend_ids.each do |friend_id|
    friend_id = friend_id.to_s
    validate_identifier(:friend_ids, friend_id)
  end
  call_myspace_api(:friends_list, :user_id => user_id, :friend_ids => friend_ids.join(';'), :v1_json => true)
end

#get_friendship(user_id, *friend_ids) ⇒ Object

Tests whether user user_id is friends with one or more other users:

[{“areFriends”=>true, “friendId”=>6221, “friendId”=>12341234, “friendId”=>456073223], “user”=> “uri”=>“api.myspace.com/v1/users/456073223”, “webUri”=>“www.myspace.com/bobvontestacount”, “largeImage”=> “”, “userType”=>“RegularUser”, “userId”=>456073223, “image”=> “”}



291
292
293
294
295
296
297
298
299
# File 'lib/myspace/myspace.rb', line 291

def get_friendship(user_id, *friend_ids)
  user_id = user_id.to_s
  validate_identifier(:user_id, user_id)
  friend_ids.each do |friend_id|
    friend_id = friend_id.to_s
    validate_identifier(:friend_ids, friend_id)
  end
  call_myspace_api(:friendship, :user_id => user_id, :friend_ids => friend_ids.join(';'), :v1_json => true)
end

#get_global_appdata(*keys) ⇒ Object

Gets the global application data. This can be anything the application wants. If you pass keys, only return data corresponding to the passed keys.



609
610
611
612
613
614
615
616
617
# File 'lib/myspace/myspace.rb', line 609

def get_global_appdata(*keys)
  MySpace.appdata_to_hash do
    if keys.length > 0
      call_myspace_api(:appdata_global_keys_get, :keys => keys.join(';'), :v1_json => true)
    else
      call_myspace_api(:appdata_global_get, :v1_json => true)
    end
  end
end

#get_indicators(user_id) ⇒ Object



690
691
692
693
694
# File 'lib/myspace/myspace.rb', line 690

def get_indicators(user_id)
  user_id = user_id.to_s
  validate_identifier(:user_id, user_id)
  call_myspace_api(:indicators, :user_id => user_id, :v1_json => true)
end

#get_mood(user_id, params = {}) ⇒ Object

Gets the mood of user user_id:

“moodImageUrl”=> “”, “moodLastUpdated”=>“2/27/2009 10:19:25 AM”, “user”=> {“name”=>“Bob”, “uri”=>“api.myspace.com/v1/users/456073223”, “webUri”=>“www.myspace.com/bobvontestacount”, “largeImage”=> “”, “userType”=>“RegularUser”, “userId”=>456073223, “image”=> “”}



330
331
332
333
334
# File 'lib/myspace/myspace.rb', line 330

def get_mood(user_id, params = {})
  user_id = user_id.to_s
  validate_identifier(:user_id, user_id)
  call_myspace_api(:mood_get, params.dup.update(:user_id => user_id, :v1_json => true))
end

#get_moods(user_id, params = {}) ⇒ Object

Gets the list of available moods for user user_id.



370
371
372
373
374
375
# File 'lib/myspace/myspace.rb', line 370

def get_moods(user_id, params = {})
  user_id = user_id.to_s
  validate_identifier(:user_id, user_id)
  moods = call_myspace_api(:moods, params.dup.update(:user_id => user_id, :v1_json => true))
  moods['moods']
end

#get_photo(user_id, photo_id, params = {}) ⇒ Object

Gets the photo description for photo photo_id for user user_id:

”, “photoUri”=>“api.myspace.com/v1/users/456073223/photos/100809”, “id”=>100809, “uploadDate”=>“2/27/2009 10:14:12 AM”, “caption”=>“”, “lastUpdatedDate”=>“”, “imageUri”=> “”, “user”=> {“name”=>“Bob”, “uri”=>“api.myspace.com/v1/users/456073223”, “webUri”=>“www.myspace.com/bobvontestacount”, “largeImage”=> “”, “userType”=>“RegularUser”, “userId”=>456073223, “image”=> “”}



437
438
439
440
441
442
443
# File 'lib/myspace/myspace.rb', line 437

def get_photo(user_id, photo_id, params = {})
  user_id = user_id.to_s
  validate_identifier(:user_id, user_id)
  photo_id = photo_id.to_s
  validate_identifier(:photo_id, photo_id)
  call_myspace_api(:photo, params.dup.update(:user_id => user_id, :photo_id => photo_id, :v1_json => true))
end

#get_photos(user_id, params = {}) ⇒ Object

Gets the photo descriptions for the photos that belong to user user_id:

[{“smallImageUri”=> “”, “photoUri”=>“api.myspace.com/v1/users/456073223/photos/100809”, “id”=>100809, “uploadDate”=>“2/27/2009 10:14:12 AM”, “caption”=>“”, “lastUpdatedDate”=>“”, “imageUri”=> “”, “user”=> {“name”=>“Bob”, “uri”=>“api.myspace.com/v1/users/456073223”, “webUri”=>“www.myspace.com/bobvontestacount”, “largeImage”=> “”, “userType”=>“RegularUser”, “userId”=>456073223, “image”=> “”}], “count”=>1, “user”=> “uri”=>“api.myspace.com/v1/users/456073223”, “webUri”=>“www.myspace.com/bobvontestacount”, “largeImage”=> “”, “userType”=>“RegularUser”, “userId”=>456073223, “image”=> “”}



410
411
412
413
414
# File 'lib/myspace/myspace.rb', line 410

def get_photos(user_id, params = {})
  user_id = user_id.to_s
  validate_identifier(:user_id, user_id)
  call_myspace_api(:photos, params.dup.update(:user_id => user_id, :v1_json => true))
end

#get_profile(user_id, params = {}) ⇒ Object

Gets the profile info for user user_id:

“city”=>“BEVERLY HILLS”, “country”=>“US”, “postalcode”=>“90210”, “gender”=>“Male”, “type”=>“full”, “culture”=>“en-US”, “aboutme”=>“”, “hometown”=>“”, “basicprofile”=> {“name”=>“Bob”, “uri”=>“api.myspace.com/v1/users/456073223”, “webUri”=>“www.myspace.com/bobvontestacount”, “largeImage”=> “”, “userId”=>456073223, “lastUpdatedDate”=>“2/27/2009 10:20:02 AM”, “image”=> “”, “age”=>88, “maritalstatus”=>“Single”}



468
469
470
471
472
# File 'lib/myspace/myspace.rb', line 468

def get_profile(user_id, params = {})
  user_id = user_id.to_s
  validate_identifier(:user_id, user_id)
  call_myspace_api(:profile, params.dup.update(:user_id => user_id, :v1_json => true))
end

#get_request_tokenObject

Get an unauthorized request token from MySpace.



106
107
108
# File 'lib/myspace/myspace.rb', line 106

def get_request_token
  @consumer.get_request_token
end

#get_status(user_id, params = {}) ⇒ Object

Gets the status of user user_id:

“moodImageUrl”=> “”, “moodLastUpdated”=>“2/27/2009 10:19:25 AM”, “user”=> {“name”=>“Bob”, “uri”=>“api.myspace.com/v1/users/456073223”, “webUri”=>“www.myspace.com/bobvontestacount”, “largeImage”=> “”, “userType”=>“RegularUser”, “userId”=>456073223, “image”=> “”, “status”=>“Testing”}



491
492
493
494
495
# File 'lib/myspace/myspace.rb', line 491

def get_status(user_id, params = {})
  user_id = user_id.to_s
  validate_identifier(:user_id, user_id)
  call_myspace_api(:status_get, params.dup.update(:user_id => user_id, :v1_json => true))
end

#get_user_appdata(user_id, *keys) ⇒ Object



630
631
632
633
634
635
636
637
638
639
640
# File 'lib/myspace/myspace.rb', line 630

def get_user_appdata(user_id, *keys)
  user_id = user_id.to_s
  validate_identifier(:user_id, user_id)
  MySpace.appdata_to_hash do
    if keys.length > 0
      call_myspace_api(:appdata_user_keys_get, :user_id => user_id, :keys => keys.join(';'), :v1_json => true)
    else
      call_myspace_api(:appdata_user_get, :user_id => user_id, :v1_json => true)
    end
  end
end

#get_user_friends_appdata(user_id, *keys) ⇒ Object



656
657
658
659
660
661
662
663
664
665
666
# File 'lib/myspace/myspace.rb', line 656

def get_user_friends_appdata(user_id, *keys)
  user_id = user_id.to_s
  validate_identifier(:user_id, user_id)
  if keys.length > 0
    call_myspace_api(:appdata_friends_keys_get, :user_id => user_id, :keys => keys.join(';'), :v1_json => true)
  else
    call_myspace_api(:appdata_friends_get, :user_id => user_id, :v1_json => true)
  end.inject({}) do |hash, friend|
    hash.update(friend['userid'].to_s => MySpace.appdata_to_hash(friend))
  end
end

#get_useridObject

Get the user id of the currently logged in user.



130
131
132
133
# File 'lib/myspace/myspace.rb', line 130

def get_userid()
   = call_myspace_api(:user_info, :v1_json => true)
  ['userId'].to_s
end

#get_video(user_id, video_id, params = {}) ⇒ Object

Gets the video description for the video video_id of user user_id:

“title”=>“110403na”, “resourceuserid”=>“456073223”, “mediastatus”=>“ProcessingSuccessful”, “dateupdated”=>“3/5/2009 11:24:23 AM”, “country”=>“US”, “totalviews”=>“0”, “thumbnail”=> “”, “language”=>“en”, “id”=>53551799, “totalcomments”=>“0”, “runtime”=>“219”, “datecreated”=>“3/5/2009 11:24:23 AM”, “privacy”=>“Public”, “mediatype”=>“4”, “description”=>“110403na”, “user”=> {“name”=>“Bob”, “uri”=>“api.myspace.com/v1/users/456073223”, “webUri”=>“www.myspace.com/bobvontestacount”, “largeImage”=> “”, “userType”=>“RegularUser”, “userId”=>456073223, “image”=> “”, “totalvotes”=>“0”, “videoUri”=>“api.myspace.com/v1/users/456073223/videos/53551799”}



584
585
586
587
588
589
590
# File 'lib/myspace/myspace.rb', line 584

def get_video(user_id, video_id, params = {})
  user_id = user_id.to_s
  validate_identifier(:user_id, user_id)
  video_id = video_id.to_s
  validate_identifier(:video_id, video_id)
  call_myspace_api(:video, params.dup.update(:user_id => user_id, :video_id => video_id, :v1_json => true))
end

#get_videos(user_id, params = {}) ⇒ Object

Gets the video descriptions for the videos of user user_id:

[{“totalrating”=>“0”, “title”=>“110403na”, “resourceuserid”=>“456073223”, “mediastatus”=>“ProcessingSuccessful”, “dateupdated”=>“3/5/2009 11:24:23 AM”, “country”=>“US”, “totalviews”=>“0”, “thumbnail”=> “”, “language”=>“en”, “id”=>53551799, “totalcomments”=>“0”, “runtime”=>“219”, “datecreated”=>“3/5/2009 11:24:23 AM”, “privacy”=>“Public”, “mediatype”=>“4”, “description”=>“110403na”, “user”=> {“name”=>“Bob”, “uri”=>“api.myspace.com/v1/users/456073223”, “webUri”=>“www.myspace.com/bobvontestacount”, “largeImage”=> “”, “userType”=>“RegularUser”, “userId”=>456073223, “image”=> “”, “totalvotes”=>“0”, “videoUri”=>“api.myspace.com/v1/users/456073223/videos/53551799”}], “count”=>1, “user”=> “uri”=>“api.myspace.com/v1/users/456073223”, “webUri”=>“www.myspace.com/bobvontestacount”, “largeImage”=> “”, “userType”=>“RegularUser”, “userId”=>456073223, “image”=> “”}



547
548
549
550
551
# File 'lib/myspace/myspace.rb', line 547

def get_videos(user_id, params = {})
  user_id = user_id.to_s
  validate_identifier(:user_id, user_id)
  call_myspace_api(:videos, params.dup.update(:user_id => user_id, :v1_json => true))
end

#mood_id(user_id, name) ⇒ Object

Given a user_id and the name of a mood, returns the corresponding mood id



363
364
365
366
367
# File 'lib/myspace/myspace.rb', line 363

def mood_id(user_id, name)
  moods(user_id).each do |mood|
    return mood['moodId'] if mood['moodName'] == name
  end
end

#mood_names(user_id) ⇒ Object

Gets the mood names available for user user_id.



355
356
357
358
359
# File 'lib/myspace/myspace.rb', line 355

def mood_names(user_id)
  moods(user_id).collect do |mood|
    mood['moodName']
  end
end

#moods(user_id) ⇒ Object

Gets and caches the list of available moods for user user_id.



349
350
351
352
# File 'lib/myspace/myspace.rb', line 349

def moods(user_id)
  @moods ||= {}
  @moods[user_id] ||= get_moods(user_id)
end

#set_global_appdata(params = {}) ⇒ Object



619
620
621
622
623
624
# File 'lib/myspace/myspace.rb', line 619

def set_global_appdata(params = {})
  deletes = MySpace.remove_null_values(params)

  call_myspace_api(:appdata_global_put, :body => params) if params.length > 0
  call_myspace_api(:appdata_global_delete, :keys => deletes.join(';')) if deletes.length > 0
end

#set_mood(user_id, mood_id) ⇒ Object

Sets the mood of the user user_id to mood_id, which must be a number from this list:

wiki.developer.myspace.com/index.php?title=Myspace_mood_data_names_codes_images



340
341
342
343
344
345
346
# File 'lib/myspace/myspace.rb', line 340

def set_mood(user_id, mood_id)
  user_id = user_id.to_s
  validate_identifier(:user_id, user_id)
  mood_id = mood_id.to_s
  validate_identifier(:mood_id, mood_id)
  call_myspace_api(:mood_put, :user_id => user_id, :body => {:mood => mood_id})
end

#set_status(user_id, status) ⇒ Object

Sets the status of the user user_id



498
499
500
501
502
# File 'lib/myspace/myspace.rb', line 498

def set_status(user_id, status)
  user_id = user_id.to_s
  validate_identifier(:user_id, user_id)
  call_myspace_api(:status_put, :user_id => user_id, :body => {:status => status})
end

#set_user_appdata(user_id, params = {}) ⇒ Object



642
643
644
645
646
647
648
# File 'lib/myspace/myspace.rb', line 642

def set_user_appdata(user_id, params = {})
  user_id = user_id.to_s
  validate_identifier(:user_id, user_id)
  deletes = MySpace.remove_null_values(params)
  call_myspace_api(:appdata_user_put, :user_id => user_id, :body => params) if params.length > 0
  call_myspace_api(:appdata_user_delete, :user_id => user_id, :keys => deletes.join(';')) if deletes.length > 0
end