officialfm 0.1.2 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,251 +0,0 @@
1
- require 'cgi'
2
-
3
- module OfficialFM
4
- module Users
5
-
6
- # Search for users
7
- #
8
- # @param [String] search_param: a search parameter (eg. name of the user)
9
- # @param [Integer] limit (50) limit per page
10
- # @return [Hashie::Mash] User list
11
- def users(search_param, options={})
12
- response = connection.get do |req|
13
- req.url "/search/users/#{CGI::escape(search_param)}", simple_params(options)
14
- end
15
- response.body
16
- end
17
-
18
- # Retrieve information about a specific user
19
- #
20
- # @param [String] user_id: id or login
21
- # @return [Hashie::Mash] User
22
- def user(user_id)
23
- response = connection.get do |req|
24
- req.url "/user/#{user_id}", simple_params
25
- end
26
- response.body[0]
27
- end
28
-
29
- # Retrieve a list of the tracks of a given user
30
- #
31
- # @param [String] user_id: id or login
32
- # @param [Integer] limit (50) limit per page
33
- # @param [Bool] embed (false) should embed codes be included in the response
34
- # @return [Hashie::Mash] Track list
35
- def user_tracks(user_id, options={})
36
- response = connection.get do |req|
37
- req.url "/user/#{user_id}/tracks", simple_params(options)
38
- end
39
- response.body
40
- end
41
-
42
- # Retrieve a list of the tracks a given user has voted for
43
- #
44
- # @param [String] user_id: id or login
45
- # @param [Integer] limit (50) limit per page
46
- # @param [Bool] embed (false) should embed codes be included in the response
47
- # @return [Hashie::Mash] Track list
48
- def voted_tracks(user_id, options={})
49
- response = connection.get do |req|
50
- req.url "/user/#{user_id}/voted_tracks", simple_params(options)
51
- end
52
- response.body
53
- end
54
-
55
- # Retrieve a list of the playlists of a given user
56
- #
57
- # @param [String] user_id: id or login
58
- # @param [Integer] limit (50) limit per page
59
- # @param [Bool] embed (false) should embed codes be included in the response
60
- # @return [Hashie::Mash] Playlist list
61
- def user_playlists(user_id, options={})
62
- response = connection.get do |req|
63
- req.url "/user/#{user_id}/playlists", simple_params(options)
64
- end
65
- response.body
66
- end
67
-
68
- # Retrieve a list of the playlists a given user has voted for
69
- #
70
- # @param [String] user_id: id or login
71
- # @param [Integer] limit (50) limit per page
72
- # @param [Bool] embed (false) should embed codes be included in the response
73
- # @return [Hashie::Mash] Playlist list
74
- def voted_playlists(user_id, options={})
75
- response = connection.get do |req|
76
- req.url "/user/#{user_id}/voted_playlists", simple_params(options)
77
- end
78
- response.body
79
- end
80
-
81
- # Retrieve a list of the contacts of a given user
82
- #
83
- # @param [String] user_id: id or login
84
- # @param [Integer] limit (50) limit per page
85
- # @return [Hashie::Mash] User list
86
- def user_contacts(user_id, options={})
87
- response = connection.get do |req|
88
- req.url "/user/#{user_id}/contacts", simple_params(options)
89
- end
90
- response.body
91
- end
92
-
93
- # Retrieve a list of the subscribers of a given user
94
- #
95
- # @param [String] user_id: id or login
96
- # @param [Integer] limit (50) limit per page
97
- # @return [Hashie::Mash] User list
98
- def user_subscribers(user_id, options={})
99
- response = connection.get do |req|
100
- req.url "/user/#{user_id}/subscribers", simple_params(options)
101
- end
102
- response.body
103
- end
104
-
105
- # Retrieve a list of the subscriptions of a given user
106
- #
107
- # @param [String] user_id: id or login
108
- # @param [Integer] limit (50) limit per page
109
- # @return [Hashie::Mash] User list
110
- def user_subscriptions(user_id, options={})
111
- response = connection.get do |req|
112
- req.url "/user/#{user_id}/subscriptions", simple_params(options)
113
- end
114
- response.body
115
- end
116
-
117
- ####################################################################
118
- ######################### Advanced API methods #####################
119
- ####################################################################
120
-
121
- # Retrieve information about the logged in user
122
- #
123
- # @return [Hashie::Mash] User
124
- def profile
125
- check_auth :profile
126
-
127
- response = connection.post do |req|
128
- req.url '/user/profile'
129
- req.body = { :format => @format }
130
- end
131
- response.body[0]
132
- end
133
-
134
- # Retrieve tracks of the logged in user
135
- #
136
- # @return [Hashie::Mash] Track list
137
- def own_tracks
138
- check_auth :own_tracks
139
-
140
- response = connection.post do |req|
141
- req.url '/user/tracks'
142
- req.body = { :format => @format }
143
- end
144
- response
145
- end
146
-
147
- # Retrieve dropbox tracks of the logged in user
148
- #
149
- # @return [Hashie::Mash] Track list
150
- def dropbox
151
- check_auth :dropbox
152
-
153
- response = connection.post do |req|
154
- req.url '/user/dropbox'
155
- req.body = { :format => @format }
156
- end
157
- response
158
- end
159
-
160
- # Retrieve playlists of the logged in user
161
- #
162
- # @return [Hashie::Mash] Playlist list
163
- def own_playlists
164
- check_auth :own_playlists
165
-
166
- response = connection.post do |req|
167
- req.url '/user/playlists'
168
- req.body = { :format => @format }
169
- end
170
- response
171
- end
172
-
173
- # Retrieve events of the logged in user's newsfeed
174
- #
175
- # @return [Hashie::Mash] Event list
176
- def newsfeed
177
- check_auth :newsfeed
178
-
179
- response = connection.post do |req|
180
- req.url '/user/newsfeed'
181
- req.body = { :format => @format }
182
- end
183
- response
184
- end
185
-
186
- # Update information of the logged in user
187
- #
188
- # @param [String] email (optional)
189
- # @param [String] city (optional)
190
- # @param [String] country_id (optional)
191
- # @param [String] url (optional)
192
- # @param [String] profile (optional)
193
- # @param [String] birthdate (optional)
194
- # @param [String] gender (optional)
195
- # @return [Hashie::Mash] User
196
- def update_profile! (data = {})
197
- check_auth :update
198
-
199
- response = connection.put do |req|
200
- req.url '/user/update'
201
- req.body = { :format => @format }.merge(data)
202
- end
203
- response
204
- end
205
-
206
- # Subscribe the logged in user to a given user
207
- #
208
- # @param [String] user_id: the user to subscribe to
209
- # @return [Hashie::Mash] Success or error message
210
- def subscribe! (user_id)
211
- check_auth :subscribe
212
-
213
- response = connection.post do |req|
214
- req.url "/user/subscribe/#{user_id}"
215
- req.body = { :format => @format }
216
- end
217
- response
218
- end
219
-
220
- # Unsubscribe the logged in user from a given user
221
- #
222
- # @param [String] user_id: the user to unsubscribe from
223
- # @return [Hashie::Mash] Success or error message
224
- def unsubscribe! (user_id)
225
- check_auth :unsubscribe
226
-
227
- response = connection.post do |req|
228
- req.url "/user/unsubscribe/#{user_id}"
229
- req.body = { :format => @format }
230
- end
231
- response
232
- end
233
-
234
- # Upload a picture for authenticated user
235
- #
236
- # @param [String] path: path to a picture
237
- # @param [String] mime: the mime-type of the picture (e.g. image/jpeg, image/png, etc.)
238
- # @return [Hashie::Mash] Success or error message
239
- def picture! (path, mime)
240
- check_auth :picture
241
-
242
- response = connection.post do |req|
243
- req.url "/user/picture"
244
- req.body = { :file => Faraday::UploadIO.new(path, mime), :format => @format }
245
- end
246
- response
247
- end
248
-
249
- end
250
- end
251
-