Module: OfficialFM::Users

Included in:
Client
Defined in:
lib/officialfm/users.rb

Instance Method Summary collapse

Instance Method Details

#dropboxHashie::Mash

Retrieve dropbox tracks of the logged in user

Returns:

  • (Hashie::Mash)

    Track list



150
151
152
153
154
155
156
157
158
# File 'lib/officialfm/users.rb', line 150

def dropbox
  check_auth :dropbox
  
  response = connection.post do |req|
    req.url '/user/dropbox'
    req.body = { :format => @format }
  end
  response
end

#newsfeedHashie::Mash

Retrieve events of the logged in user’s newsfeed

Returns:

  • (Hashie::Mash)

    Event list



176
177
178
179
180
181
182
183
184
# File 'lib/officialfm/users.rb', line 176

def newsfeed
  check_auth :newsfeed
  
  response = connection.post do |req|
    req.url '/user/newsfeed'
    req.body = { :format => @format }
  end
  response
end

#own_playlistsHashie::Mash

Retrieve playlists of the logged in user

Returns:

  • (Hashie::Mash)

    Playlist list



163
164
165
166
167
168
169
170
171
# File 'lib/officialfm/users.rb', line 163

def own_playlists
  check_auth :own_playlists
  
  response = connection.post do |req|
    req.url '/user/playlists'
    req.body = { :format => @format }
  end
  response
end

#own_tracksHashie::Mash

Retrieve tracks of the logged in user

Returns:

  • (Hashie::Mash)

    Track list



137
138
139
140
141
142
143
144
145
# File 'lib/officialfm/users.rb', line 137

def own_tracks
  check_auth :own_tracks
  
  response = connection.post do |req|
    req.url '/user/tracks'
    req.body = { :format => @format }
  end
  response
end

#picture!(path, mime) ⇒ Hashie::Mash

Upload a picture for authenticated user

Parameters:

  • path: (String)

    path to a picture

  • mime: (String)

    the mime-type of the picture (e.g. image/jpeg, image/png, etc.)

Returns:

  • (Hashie::Mash)

    Success or error message



239
240
241
242
243
244
245
246
247
# File 'lib/officialfm/users.rb', line 239

def picture! (path, mime)
  check_auth :picture

  response = connection.post  do |req|
    req.url "/user/picture"
    req.body = { :file => Faraday::UploadIO.new(path, mime), :format => @format }
  end
  response
end

#profileHashie::Mash

Retrieve information about the logged in user

Returns:

  • (Hashie::Mash)

    User



124
125
126
127
128
129
130
131
132
# File 'lib/officialfm/users.rb', line 124

def profile
  check_auth :profile

  response = connection.post do |req|
    req.url '/user/profile'
    req.body = { :format => @format }
  end
  response.body[0]
end

#subscribe!(user_id) ⇒ Hashie::Mash

Subscribe the logged in user to a given user

Parameters:

  • user_id: (String)

    the user to subscribe to

Returns:

  • (Hashie::Mash)

    Success or error message



210
211
212
213
214
215
216
217
218
# File 'lib/officialfm/users.rb', line 210

def subscribe! (user_id)
  check_auth :subscribe

  response = connection.post  do |req|
    req.url "/user/subscribe/#{user_id}"
    req.body = { :format => @format }
  end
  response
end

#unsubscribe!(user_id) ⇒ Hashie::Mash

Unsubscribe the logged in user from a given user

Parameters:

  • user_id: (String)

    the user to unsubscribe from

Returns:

  • (Hashie::Mash)

    Success or error message



224
225
226
227
228
229
230
231
232
# File 'lib/officialfm/users.rb', line 224

def unsubscribe! (user_id)
  check_auth :unsubscribe

  response = connection.post  do |req|
    req.url "/user/unsubscribe/#{user_id}"
    req.body = { :format => @format }
  end
  response
end

#update_profile!(data = {}) ⇒ Hashie::Mash

Update information of the logged in user

Parameters:

  • email (String)

    (optional)

  • city (String)

    (optional)

  • country_id (String)

    (optional)

  • url (String)

    (optional)

  • profile (String)

    (optional)

  • birthdate (String)

    (optional)

  • gender (String)

    (optional)

Returns:

  • (Hashie::Mash)

    User



196
197
198
199
200
201
202
203
204
# File 'lib/officialfm/users.rb', line 196

def update_profile! (data = {})
  check_auth :update

  response = connection.put do |req|
    req.url '/user/update'
    req.body = { :format => @format }.merge(data)
  end
  response
end

#user(user_id) ⇒ Hashie::Mash

Retrieve information about a specific user

Parameters:

  • user_id: (String)

    id or login

Returns:

  • (Hashie::Mash)

    User



22
23
24
25
26
27
# File 'lib/officialfm/users.rb', line 22

def user(user_id)
  response = connection.get do |req|
    req.url "/user/#{user_id}", simple_params
  end
  response.body[0]
end

#user_contacts(user_id, options = {}) ⇒ Hashie::Mash

Retrieve a list of the contacts of a given user

Parameters:

  • user_id: (String)

    id or login

  • limit (Integer)

    (50) limit per page

Returns:

  • (Hashie::Mash)

    User list



86
87
88
89
90
91
# File 'lib/officialfm/users.rb', line 86

def user_contacts(user_id, options={})
  response = connection.get do |req|
    req.url "/user/#{user_id}/contacts", simple_params(options)
  end
  response.body
end

#user_playlists(user_id, options = {}) ⇒ Hashie::Mash

Retrieve a list of the playlists of a given user

Parameters:

  • user_id: (String)

    id or login

  • limit (Integer)

    (50) limit per page

  • embed (Bool)

    (false) should embed codes be included in the response

Returns:

  • (Hashie::Mash)

    Playlist list



61
62
63
64
65
66
# File 'lib/officialfm/users.rb', line 61

def user_playlists(user_id, options={})
  response = connection.get do |req|
    req.url "/user/#{user_id}/playlists", simple_params(options)
  end
  response.body
end

#user_subscribers(user_id, options = {}) ⇒ Hashie::Mash

Retrieve a list of the subscribers of a given user

Parameters:

  • user_id: (String)

    id or login

  • limit (Integer)

    (50) limit per page

Returns:

  • (Hashie::Mash)

    User list



98
99
100
101
102
103
# File 'lib/officialfm/users.rb', line 98

def user_subscribers(user_id, options={})
  response = connection.get do |req|
    req.url "/user/#{user_id}/subscribers", simple_params(options)
  end
  response.body
end

#user_subscriptions(user_id, options = {}) ⇒ Hashie::Mash

Retrieve a list of the subscriptions of a given user

Parameters:

  • user_id: (String)

    id or login

  • limit (Integer)

    (50) limit per page

Returns:

  • (Hashie::Mash)

    User list



110
111
112
113
114
115
# File 'lib/officialfm/users.rb', line 110

def user_subscriptions(user_id, options={})
  response = connection.get do |req|
    req.url "/user/#{user_id}/subscriptions", simple_params(options)
  end
  response.body
end

#user_tracks(user_id, options = {}) ⇒ Hashie::Mash

Retrieve a list of the tracks of a given user

Parameters:

  • user_id: (String)

    id or login

  • limit (Integer)

    (50) limit per page

  • embed (Bool)

    (false) should embed codes be included in the response

Returns:

  • (Hashie::Mash)

    Track list



35
36
37
38
39
40
# File 'lib/officialfm/users.rb', line 35

def user_tracks(user_id, options={})
  response = connection.get do |req|
    req.url "/user/#{user_id}/tracks", simple_params(options)
  end
  response.body
end

#users(search_param, options = {}) ⇒ Hashie::Mash

Search for users

Parameters:

  • search_param: (String)

    a search parameter (eg. name of the user)

  • limit (Integer)

    (50) limit per page

Returns:

  • (Hashie::Mash)

    User list



11
12
13
14
15
16
# File 'lib/officialfm/users.rb', line 11

def users(search_param, options={})
  response = connection.get do |req|
    req.url "/search/users/#{CGI::escape(search_param)}", simple_params(options)
  end
  response.body
end

#voted_playlists(user_id, options = {}) ⇒ Hashie::Mash

Retrieve a list of the playlists a given user has voted for

Parameters:

  • user_id: (String)

    id or login

  • limit (Integer)

    (50) limit per page

  • embed (Bool)

    (false) should embed codes be included in the response

Returns:

  • (Hashie::Mash)

    Playlist list



74
75
76
77
78
79
# File 'lib/officialfm/users.rb', line 74

def voted_playlists(user_id, options={})
  response = connection.get do |req|
    req.url "/user/#{user_id}/voted_playlists", simple_params(options)
  end
  response.body
end

#voted_tracks(user_id, options = {}) ⇒ Hashie::Mash

Retrieve a list of the tracks a given user has voted for

Parameters:

  • user_id: (String)

    id or login

  • limit (Integer)

    (50) limit per page

  • embed (Bool)

    (false) should embed codes be included in the response

Returns:

  • (Hashie::Mash)

    Track list



48
49
50
51
52
53
# File 'lib/officialfm/users.rb', line 48

def voted_tracks(user_id, options={})
  response = connection.get do |req|
    req.url "/user/#{user_id}/voted_tracks", simple_params(options)
  end
  response.body
end