myspace-ruby 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. data/README +284 -0
  2. data/doc/classes/MySpace.html +666 -0
  3. data/doc/classes/MySpace/Album.html +225 -0
  4. data/doc/classes/MySpace/Connection.html +427 -0
  5. data/doc/classes/MySpace/Detail.html +191 -0
  6. data/doc/classes/MySpace/FriendStatus.html +131 -0
  7. data/doc/classes/MySpace/Friends.html +141 -0
  8. data/doc/classes/MySpace/Friendship.html +205 -0
  9. data/doc/classes/MySpace/Group.html +301 -0
  10. data/doc/classes/MySpace/Groups.html +146 -0
  11. data/doc/classes/MySpace/Interest.html +156 -0
  12. data/doc/classes/MySpace/InvalidClassDefinition.html +111 -0
  13. data/doc/classes/MySpace/InvalidCredentials.html +111 -0
  14. data/doc/classes/MySpace/InvalidDataFormat.html +111 -0
  15. data/doc/classes/MySpace/InvalidObjectMap.html +111 -0
  16. data/doc/classes/MySpace/InvalidRequest.html +111 -0
  17. data/doc/classes/MySpace/InvalidRequestParams.html +111 -0
  18. data/doc/classes/MySpace/InvalidResponse.html +111 -0
  19. data/doc/classes/MySpace/Mood.html +131 -0
  20. data/doc/classes/MySpace/Object.html +348 -0
  21. data/doc/classes/MySpace/Photo.html +146 -0
  22. data/doc/classes/MySpace/Photos.html +136 -0
  23. data/doc/classes/MySpace/Profile.html +176 -0
  24. data/doc/classes/MySpace/Status.html +131 -0
  25. data/doc/classes/MySpace/UnknownDataType.html +111 -0
  26. data/doc/classes/MySpace/User.html +162 -0
  27. data/doc/classes/MySpace/Video.html +256 -0
  28. data/doc/classes/MySpace/Videos.html +126 -0
  29. data/doc/classes/MySpaceAPITest.html +916 -0
  30. data/doc/created.rid +1 -0
  31. data/doc/files/lib/myspace_rb.html +185 -0
  32. data/doc/files/tests/test_rb.html +109 -0
  33. data/doc/fr_class_index.html +28 -0
  34. data/doc/fr_file_index.html +29 -0
  35. data/doc/fr_method_index.html +54 -0
  36. data/doc/index.html +24 -0
  37. data/doc/rdoc-style.css +208 -0
  38. data/lib/myspace.rb +45 -0
  39. data/lib/myspace/classes/album.rb +25 -0
  40. data/lib/myspace/classes/detail.rb +22 -0
  41. data/lib/myspace/classes/friends.rb +16 -0
  42. data/lib/myspace/classes/friendship.rb +27 -0
  43. data/lib/myspace/classes/group.rb +55 -0
  44. data/lib/myspace/classes/interest.rb +16 -0
  45. data/lib/myspace/classes/mood.rb +9 -0
  46. data/lib/myspace/classes/photo.rb +21 -0
  47. data/lib/myspace/classes/profile.rb +22 -0
  48. data/lib/myspace/classes/status.rb +9 -0
  49. data/lib/myspace/classes/user.rb +17 -0
  50. data/lib/myspace/classes/video.rb +41 -0
  51. data/lib/myspace/connection.rb +110 -0
  52. data/lib/myspace/error.rb +12 -0
  53. data/lib/myspace/loader.rb +74 -0
  54. data/lib/myspace/object.rb +116 -0
  55. data/tests/test.rb +148 -0
  56. metadata +108 -0
data/lib/myspace.rb ADDED
@@ -0,0 +1,45 @@
1
+ base = File.expand_path(File.dirname(__FILE__))
2
+
3
+ $:.unshift base + "/myspace"
4
+ $:.unshift base + "/myspace/classes"
5
+
6
+ load "loader.rb"
7
+ load "error.rb"
8
+
9
+ # :include:../README
10
+ module MySpace
11
+ VERSION = "0.7"
12
+ API_FORMATS = ["json","xml"]
13
+ API_HOST = "api.msappspace.com"
14
+ API_VERSION = "v1"
15
+ API_CONF = if File.exist?("myspace.conf")
16
+ "myspace.conf"
17
+ elsif ENV["MYSPACE_CONF"] && File.exist?(ENV["MYSPACE_CONF"])
18
+ ENV["MYSPACE_CONF"]
19
+ else
20
+ File.dirname(__FILE__)+"/myspace.conf"
21
+ end
22
+
23
+ # Load YAML configuration from a file and use those parameters
24
+ CONF = YAML.load(File.open(API_CONF)) or {} rescue CONF = {}
25
+
26
+ # Connect to MySpace's API servers
27
+ def self.connect(apiKey=CONF["apiKey"],secretKey=CONF["secretKey"])
28
+ raise InvalidCredentials.new("No apiKey or secretKey, aborting connect.
29
+ You need to pass them to MySpace.connect or put them in myspace.conf") \
30
+ if apiKey.empty? || secretKey.empty? ||
31
+ apiKey =~ /x{7}/ || secretKey =~ /x{7}/
32
+
33
+ @connection = Connection.new(:apiKey => apiKey, :secretKey => secretKey)
34
+
35
+ yield @connection if block_given?
36
+ @connection
37
+ end
38
+
39
+ def self.connection
40
+ @connection ||= self.connect
41
+ end
42
+ end
43
+
44
+ fail "This is a library, not a command line app" if $0 == __FILE__
45
+
@@ -0,0 +1,25 @@
1
+ class MySpace::Album < MySpace::Object
2
+ @pathFormat = "/users/%s/albums/%s".freeze
3
+ @numParams = 2.freeze
4
+ @dataType = "Hash".freeze
5
+
6
+ attr_accessor :albumUri
7
+ attr_accessor :defaultImage
8
+ attr_accessor :id
9
+ attr_accessor :location
10
+ attr_accessor :photoCount
11
+ attr_accessor :photosUri
12
+ attr_accessor :privacy
13
+ attr_accessor :title
14
+ attr_accessor :user
15
+
16
+ def self.get(userId,albumId)
17
+ super([userId,albumId])
18
+ end
19
+
20
+ def self.get_raw(userId,albumId,format="json")
21
+ super([userId,albumId],nil,format)
22
+ end
23
+ end
24
+
25
+ fail "This is a library, not a command line app\n" if $0 == __FILE__
@@ -0,0 +1,22 @@
1
+ class MySpace::Detail < MySpace::Object
2
+ @pathFormat = "/users/%s/details".freeze
3
+ @dataType = "Hash".freeze
4
+
5
+ attr_accessor :user
6
+ attr_accessor :status
7
+ attr_accessor :ethnicity
8
+ attr_accessor :drink
9
+ attr_accessor :zodiacsign
10
+ attr_accessor :orientation
11
+ attr_accessor :religion
12
+ attr_accessor :herefor
13
+ attr_accessor :smoke
14
+ attr_accessor :education
15
+ attr_accessor :income
16
+ attr_accessor :children
17
+ attr_accessor :hometown
18
+ attr_accessor :bodyType
19
+
20
+ end
21
+
22
+ fail "This is a library, not a command line app\n" if $0 == __FILE__
@@ -0,0 +1,16 @@
1
+ class MySpace::Friends < MySpace::Object
2
+ @pathFormat = "/users/%s/friends".freeze
3
+ @numParams = 1.freeze
4
+ @optParams = { :page => nil,
5
+ :page_size => nil }.freeze
6
+ @dataType = "Array".freeze
7
+ @childType = "User".freeze
8
+ @childBase = "friends".freeze
9
+
10
+ attr_accessor :user
11
+ attr_accessor :topFriends
12
+ attr_accessor :friends
13
+ attr_accessor :count
14
+ end
15
+
16
+ fail "This is a library, not a command line app\n" if $0 == __FILE__
@@ -0,0 +1,27 @@
1
+ class MySpace::FriendStatus < MySpace::Object
2
+ attr_accessor :friendId
3
+ attr_accessor :areFriends
4
+ end
5
+
6
+ class MySpace::Friendship < MySpace::Object
7
+ @pathFormat = "/users/%s/friends/%s".freeze
8
+ @numParams = 2.freeze
9
+ @dataType = "Hash".freeze
10
+
11
+ attr_accessor :user
12
+ attr_accessor :friendship
13
+
14
+ alias :friends :friendship
15
+
16
+ def self.get(userId,friendId)
17
+ o = super([userId,friendId])
18
+ o.friendship = o.friendship.collect {|f| MySpace::FriendStatus.new(f) }
19
+ o
20
+ end
21
+
22
+ def self.get_raw(userId,friendId,format="json")
23
+ super([userId,friendId],nil,format)
24
+ end
25
+ end
26
+
27
+ fail "This is a library, not a command line app\n" if $0 == __FILE__
@@ -0,0 +1,55 @@
1
+ class MySpace::Groups < MySpace::Object
2
+ @pathFormat = "/users/%s/groups".freeze
3
+ @numParams = 1.freeze
4
+ @dataType = "Array".freeze
5
+ @childType = "Group".freeze
6
+ @childBase = "groups".freeze
7
+
8
+ attr_accessor :user
9
+ attr_accessor :prev
10
+ attr_accessor :groups
11
+ attr_accessor :next
12
+ attr_accessor :count
13
+ end
14
+
15
+ class MySpace::Group < MySpace::Object
16
+ attr_accessor :user
17
+ attr_accessor :prev
18
+ attr_accessor :groups
19
+ attr_accessor :next
20
+ attr_accessor :count
21
+
22
+ attr_accessor :approveMembers
23
+ attr_accessor :categoryId
24
+ attr_accessor :categoryName
25
+ attr_accessor :city
26
+ attr_accessor :country
27
+ attr_accessor :createDate
28
+ attr_accessor :description
29
+ attr_accessor :descriptionShort
30
+ attr_accessor :groupId
31
+ attr_accessor :groupName
32
+ attr_accessor :groupUri
33
+ attr_accessor :groupUrl
34
+ attr_accessor :imageId
35
+ attr_accessor :imageType
36
+ attr_accessor :isAdult
37
+ attr_accessor :isPrivate
38
+ attr_accessor :isPublic
39
+ attr_accessor :memberBulletins
40
+ attr_accessor :memberCount
41
+ attr_accessor :memberImages
42
+ attr_accessor :membersCanInvite
43
+ attr_accessor :moderatorUserId
44
+ attr_accessor :nonMemberBoardPosting
45
+ attr_accessor :postalCode
46
+ attr_accessor :region
47
+ attr_accessor :user
48
+ attr_accessor :image
49
+ attr_accessor :name
50
+ attr_accessor :onlineNow
51
+ attr_accessor :uri
52
+ attr_accessor :userId
53
+ end
54
+
55
+ fail "This is a library, not a command line app\n" if $0 == __FILE__
@@ -0,0 +1,16 @@
1
+ class MySpace::Interest < MySpace::Object
2
+ @pathFormat = "/users/%s/interests".freeze
3
+ @numParams = 1.freeze
4
+ @dataType = "Hash".freeze
5
+
6
+ attr_accessor :user
7
+ attr_accessor :heroes
8
+ attr_accessor :general
9
+ attr_accessor :music
10
+ attr_accessor :television
11
+ attr_accessor :movies
12
+ attr_accessor :books
13
+
14
+ end
15
+
16
+ fail "This is a library, not a command line app\n" if $0 == __FILE__
@@ -0,0 +1,9 @@
1
+ class MySpace::Mood < MySpace::Object
2
+ @pathFormat = "/users/%s/mood".freeze
3
+ @dataType = "Hash".freeze
4
+
5
+ attr_accessor :user
6
+ attr_accessor :mood
7
+ end
8
+
9
+ fail "This is a library, not a command line app\n" if $0 == __FILE__
@@ -0,0 +1,21 @@
1
+ class MySpace::Photos < MySpace::Object
2
+ @pathFormat = "/users/%s/photos".freeze
3
+ @dataType = "Array".freeze
4
+ @childType = "Photo".freeze
5
+ @childBase = "photos".freeze
6
+
7
+ attr_accessor :user
8
+ attr_accessor :photos
9
+ attr_accessor :count
10
+ end
11
+
12
+ class MySpace::Photo < MySpace::Object
13
+ attr_accessor :caption
14
+ attr_accessor :id
15
+ attr_accessor :imageUri
16
+ attr_accessor :photoUri
17
+ attr_accessor :user
18
+
19
+ end
20
+
21
+ fail "This is a library, not a command line app\n" if $0 == __FILE__
@@ -0,0 +1,22 @@
1
+ class MySpace::Profile < MySpace::Object
2
+ @pathFormat = "/users/%s/profile".freeze
3
+ @dataType = "Hash".freeze
4
+ @numParams = 1.freeze
5
+ @optParams = {"page" => "",
6
+ "page_size" => "",
7
+ "list" => ""}.freeze
8
+
9
+ attr_accessor :city
10
+ attr_accessor :region
11
+ attr_accessor :country
12
+ attr_accessor :gender
13
+ attr_accessor :postalcode
14
+ attr_accessor :culture
15
+ attr_accessor :basicprofile
16
+ attr_accessor :age
17
+ attr_accessor :aboutme
18
+ attr_accessor :maritalstatus
19
+ attr_accessor :hometown
20
+ end
21
+
22
+ fail "This is a library, not a command line app\n" if $0 == __FILE__
@@ -0,0 +1,9 @@
1
+ class MySpace::Status < MySpace::Object
2
+ @pathFormat = "/users/%s/status".freeze
3
+ @dataType = "Hash".freeze
4
+
5
+ attr_accessor :user
6
+ attr_accessor :status
7
+ end
8
+
9
+ fail "This is a library, not a command line app\n" if $0 == __FILE__
@@ -0,0 +1,17 @@
1
+ class MySpace::User < MySpace::Object
2
+ @pathFormat = "/users/%s".freeze
3
+ @dataType = "Hash".freeze
4
+
5
+ # the name the user specified for the profile (not username/vanity url)
6
+ attr_accessor :name
7
+ # the URL of the user's profile page
8
+ attr_accessor :uri
9
+ attr_accessor :webUri
10
+ attr_accessor :userType
11
+ attr_accessor :userId
12
+ attr_accessor :onlineNow
13
+ attr_accessor :image
14
+
15
+ end
16
+
17
+ fail "This is a library, not a command line app\n" if $0 == __FILE__
@@ -0,0 +1,41 @@
1
+ class MySpace::Videos < MySpace::Object
2
+ @pathFormat = "/users/%s/videos".freeze
3
+ @numParams = 1.freeze
4
+ @dataType = "Array".freeze
5
+ @childType = "Video".freeze
6
+ @childBase = "videos".freeze
7
+
8
+ attr_accessor :videos
9
+ end
10
+
11
+ class MySpace::Video < MySpace::Object
12
+ attr_accessor :country
13
+ attr_accessor :datecreated
14
+ attr_accessor :dateupdated
15
+ attr_accessor :description
16
+ attr_accessor :id
17
+ attr_accessor :image
18
+ attr_accessor :language
19
+ attr_accessor :mediastatus
20
+ attr_accessor :mediatype
21
+ attr_accessor :name
22
+ attr_accessor :onlineNow
23
+ attr_accessor :privacy
24
+ attr_accessor :resourceuserid
25
+ attr_accessor :runtime
26
+ attr_accessor :thumbnail
27
+ attr_accessor :title
28
+ attr_accessor :totalrating
29
+ attr_accessor :totalviews
30
+ attr_accessor :totalvotes
31
+ attr_accessor :uri
32
+ attr_accessor :uri
33
+ attr_accessor :user
34
+ attr_accessor :userId
35
+ attr_accessor :userType
36
+ attr_accessor :videos
37
+ attr_accessor :videoUri
38
+ attr_accessor :webUri
39
+ end
40
+
41
+ fail "This is a library, not a command line app\n" if $0 == __FILE__
@@ -0,0 +1,110 @@
1
+ require "net/http"
2
+ require "oauth/consumer"
3
+
4
+ module MySpace
5
+ # MySpace::Connection connects to the MySpace API servers, and performs
6
+ # connection oriented tasks. Most attributes map directly
7
+ # to their configuration file counterparts unless they're specified during
8
+ # initialization.
9
+ class Connection
10
+ include Net
11
+ # API username
12
+ attr_accessor :username
13
+ # API password
14
+ attr_accessor :apiSecret
15
+ # API key
16
+ attr_accessor :apiKey
17
+ # host to connect
18
+ attr_accessor :host
19
+ # preferred output format
20
+ attr_accessor :format
21
+
22
+ # Constructor for the MySpace::Connection class
23
+ def initialize(attributes={})
24
+ @apiKey = attributes[:apiKey] ||= CONF["apiKey"]
25
+ @secretKey = attributes[:apiSecret] ||= CONF["secretKey"]
26
+ @host = attributes[:host] ||= API_HOST
27
+ @format = attributes[:format] ||= "json"
28
+
29
+ @oauthOptions = {
30
+ :scheme => :query_string,
31
+ :nonce => rand(65535).to_s,
32
+ :timestamp => Time.now.to_i.to_s,
33
+ :site => "http://#{API_HOST}",
34
+ }
35
+
36
+ yield self if block_given?
37
+ end
38
+
39
+ # Returns an rfc1123 format string
40
+ def timestamp
41
+ Time.now.utc.strftime("%a, %d %b %Y %H:%M:%S GMT")
42
+ end
43
+
44
+ def consumer
45
+ OAuth::Consumer.new(CGI.escape(@apiKey),@secretKey,@oauthOptions)
46
+ end
47
+
48
+ # Connects to the MySapce API servers, returning a Net::HTTP class
49
+ # instance. If a block is given, then that instance is yielded.
50
+ def connect
51
+ # require "net/https"
52
+ # http = Net::HTTP.new(MYSPACE_API_HOST, 443)
53
+ # http.use_ssl = true
54
+ @http = HTTP.start(@host)
55
+ yield @http if block_given?
56
+ end
57
+
58
+ # Perform a POST operation against the MySpace API servers.
59
+ # You can pass a 'path', post data 'data' and a 'content_type'
60
+ # optionally.
61
+ # application/x-www-form-urlencoded
62
+ # text/xml; charset=utf-8
63
+ def post(path="/",data="",headers={},content_type="application/x-www-form-urlencoded")
64
+ connect if !@http
65
+
66
+ req = HTTP::Post.new(path,headers)
67
+ req.set_form_data({ }, ';')
68
+ req.body = data
69
+ req.content_type = content_type
70
+
71
+ yield @http.request(req) if block_given?
72
+ end
73
+
74
+ # Fetches the response body from the API servers
75
+ def get_body(path)
76
+ connect if !@http
77
+
78
+ get(path) {|res|
79
+ case res.code
80
+ when "200"
81
+ return res.body
82
+ when "401"
83
+ raise InvalidCredentials,
84
+ "Access denied. (#{res.code})\n#{res.body}"
85
+ else
86
+ raise InvalidResponse,"(#{res.code})\n#{res.body}"
87
+ end
88
+ }
89
+ end
90
+
91
+
92
+ # Performs a GET request against the MySpace API servers.
93
+ # The 'path' is the first argument, and the second argument 'http'
94
+ # is an optional, existing Net::HTTP connection.
95
+ # Returns or yields a Net::HTTP::Response instance, depending on how it's
96
+ # called.
97
+ def get(path="/")
98
+ req = HTTP::Get.new(path)
99
+
100
+ connect if !@http
101
+
102
+ la = lambda { req.oauth!(@http,consumer,nil,@oauthOptions)
103
+ @http.request(req) }
104
+
105
+ yield la.call if block_given?
106
+ end
107
+ end # end class
108
+ end # end namespace
109
+
110
+ fail "This is a library, not a command line app\n" if $0 == __FILE__