Class: Pandoru::Client::APIClient

Inherits:
BaseAPIClient show all
Defined in:
lib/pandoru/client.rb

Overview

High Level Pandora API Client The high level API client implements the entire functional API for Pandora. This is what clients should actually use.

Constant Summary

Constants inherited from BaseAPIClient

BaseAPIClient::ALL_QUALITIES, BaseAPIClient::HIGH_AUDIO_QUALITY, BaseAPIClient::LOW_AUDIO_QUALITY, BaseAPIClient::MED_AUDIO_QUALITY

Instance Attribute Summary

Attributes inherited from BaseAPIClient

#default_audio_quality, #device, #partner_password, #partner_user, #password, #transport, #username

Instance Method Summary collapse

Methods inherited from BaseAPIClient

#call, get_qualities, #initialize, #login

Constructor Details

This class inherits a constructor from Pandoru::Client::BaseAPIClient

Instance Method Details

#add_artist_bookmark(track_token) ⇒ Object



161
162
163
# File 'lib/pandoru/client.rb', line 161

def add_artist_bookmark(track_token)
  call("bookmark.addArtistBookmark", trackToken: track_token)
end

#add_feedback(track_token, positive) ⇒ Object



185
186
187
188
189
# File 'lib/pandoru/client.rb', line 185

def add_feedback(track_token, positive)
  call("station.addFeedback",
       trackToken: track_token,
       isPositive: positive)
end

#add_music(music_token, station_token) ⇒ Object



191
192
193
194
195
# File 'lib/pandoru/client.rb', line 191

def add_music(music_token, station_token)
  call("station.addMusic",
       musicToken: music_token,
       stationToken: station_token)
end

#add_song_bookmark(track_token) ⇒ Object



165
166
167
# File 'lib/pandoru/client.rb', line 165

def add_song_bookmark(track_token)
  call("bookmark.addSongBookmark", trackToken: track_token)
end

#create_station(search_token: nil, artist_token: nil, track_token: nil, song_token: nil) ⇒ Object



197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
# File 'lib/pandoru/client.rb', line 197

def create_station(search_token: nil, artist_token: nil, track_token: nil, song_token: nil)
  params = {}
  
  if search_token
    params[:musicToken] = search_token
  elsif artist_token
    params[:musicToken] = artist_token
  elsif track_token
    params[:musicToken] = track_token  
  elsif song_token
    params[:musicToken] = song_token
  else
    raise ArgumentError, "Must provide one of: search_token, artist_token, track_token, song_token"
  end

  data = call("station.createStation", **params)
  Models::Station.from_json(self, data)
end

#delete_artist_bookmark(bookmark_token) ⇒ Object



173
174
175
# File 'lib/pandoru/client.rb', line 173

def delete_artist_bookmark(bookmark_token)
  call("bookmark.deleteArtistBookmark", bookmarkToken: bookmark_token)
end

#delete_feedback(feedback_id) ⇒ Object



216
217
218
# File 'lib/pandoru/client.rb', line 216

def delete_feedback(feedback_id)
  call("station.deleteFeedback", feedbackId: feedback_id)
end

#delete_music(seed_id) ⇒ Object



220
221
222
# File 'lib/pandoru/client.rb', line 220

def delete_music(seed_id)
  call("station.deleteMusic", seedId: seed_id)
end

#delete_song_bookmark(bookmark_token) ⇒ Object



169
170
171
# File 'lib/pandoru/client.rb', line 169

def delete_song_bookmark(bookmark_token)
  call("bookmark.deleteSongBookmark", bookmarkToken: bookmark_token)
end

#delete_station(station_token) ⇒ Object



224
225
226
# File 'lib/pandoru/client.rb', line 224

def delete_station(station_token)
  call("station.deleteStation", stationToken: station_token)
end

#explain_track(track_token) ⇒ Object



244
245
246
247
# File 'lib/pandoru/client.rb', line 244

def explain_track(track_token)
  data = call("track.explainTrack", trackToken: track_token)
  Models::TrackExplanation.from_json(self, data)
end

#get_ad_item(station_id, ad_token) ⇒ Object



274
275
276
277
278
279
280
281
282
# File 'lib/pandoru/client.rb', line 274

def get_ad_item(station_id, ad_token)
  raise Errors::ParameterMissing, "station_id must be defined, got: '#{station_id}'" if station_id.nil? || station_id.empty?
  
  ad_data = (ad_token)
  ad_item = Models::AdItem.from_json(self, ad_data)
  ad_item.station_id = station_id
  ad_item.ad_token = ad_token
  ad_item
end

#get_ad_metadata(ad_token) ⇒ Object



284
285
286
287
288
289
# File 'lib/pandoru/client.rb', line 284

def (ad_token)
  call("ad.getAdMetadata",
       adToken: ad_token,
       returnAdTrackingTokens: true,
       supportAudioAds: true)
end

#get_bookmarksObject



149
150
151
152
# File 'lib/pandoru/client.rb', line 149

def get_bookmarks
  data = call("user.getBookmarks")
  Models::BookmarkList.from_json(self, data)
end

#get_genre_stationsObject



228
229
230
231
# File 'lib/pandoru/client.rb', line 228

def get_genre_stations
  data = call("station.getGenreStations")
  Models::GenreStationList.from_json(self, data)
end

#get_genre_stations_checksumObject



233
234
235
236
# File 'lib/pandoru/client.rb', line 233

def get_genre_stations_checksum
  data = call("station.getGenreStationsChecksum")
  data["checksum"]
end

#get_playlist(station_token, additional_urls: nil) ⇒ Object



116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
# File 'lib/pandoru/client.rb', line 116

def get_playlist(station_token, additional_urls: nil)
  params = { 
    stationToken: station_token,
    includeTrackLength: true,
    xplatformAdCapable: true,
    audioAdPodCapable: true
  }
  
  if additional_urls
    urls = additional_urls.map { |url| url.respond_to?(:value) ? url.value : url }
    params[:additionalAudioUrl] = urls.join(",")
  end
  
  data = call("station.getPlaylist", **params)
  
  # Add additional URLs parameter to each item for ad processing
  if additional_urls
    data["items"]&.each { |item| item["_paramAdditionalUrls"] = additional_urls }
  end
  
  playlist = Models::Playlist.from_json(self, data)
  
  # Process ad items
  playlist.each_with_index do |track, i|
    if track.is_ad?
      ad_track = get_ad_item(station_token, track.ad_token)
      playlist[i] = ad_track
    end
  end
  
  playlist
end

#get_station(station_token) ⇒ Object



154
155
156
157
158
159
# File 'lib/pandoru/client.rb', line 154

def get_station(station_token)
  data = call("station.getStation", 
             stationToken: station_token,
             includeExtendedAttributes: true)
  Models::Station.from_json(self, data)
end

#get_station_listObject



106
107
108
109
# File 'lib/pandoru/client.rb', line 106

def get_station_list
  data = call("user.getStationList", includeStationArtUrl: true)
  Models::StationList.from_json(self, data)
end

#get_station_list_checksumObject



111
112
113
114
# File 'lib/pandoru/client.rb', line 111

def get_station_list_checksum
  data = call("user.getStationListChecksum")
  data["checksum"]
end

#register_ad(station_id, tokens) ⇒ Object



291
292
293
294
295
# File 'lib/pandoru/client.rb', line 291

def register_ad(station_id, tokens)
  call("ad.registerAd",
       stationId: station_id,
       adTrackingTokens: tokens)
end

#rename_station(station_token, name) ⇒ Object



238
239
240
241
242
# File 'lib/pandoru/client.rb', line 238

def rename_station(station_token, name)
  call("station.renameStation",
       stationToken: station_token,
       stationName: name)
end

#search(search_text, include_near_matches: false, include_genre_stations: false) ⇒ Object



177
178
179
180
181
182
183
# File 'lib/pandoru/client.rb', line 177

def search(search_text, include_near_matches: false, include_genre_stations: false)
  data = call("music.search",
             searchText: search_text,
             includeNearMatches: include_near_matches,
             includeGenreStations: include_genre_stations)
  Models::SearchResult.from_json(self, data)
end

#set_quick_mix(*station_ids) ⇒ Object



249
250
251
# File 'lib/pandoru/client.rb', line 249

def set_quick_mix(*station_ids)
  call("user.setQuickMix", quickMixStationIds: station_ids.flatten)
end

#share_music(music_token, *emails) ⇒ Object



268
269
270
271
272
# File 'lib/pandoru/client.rb', line 268

def share_music(music_token, *emails)
  call("music.shareMusic",
       musicToken: music_token,
       emails: emails.flatten)
end

#share_station(station_id, station_token, *emails) ⇒ Object



257
258
259
260
261
262
# File 'lib/pandoru/client.rb', line 257

def share_station(station_id, station_token, *emails)
  call("station.shareStation",
       stationId: station_id,
       stationToken: station_token,
       emails: emails.flatten)
end

#sleep_song(track_token) ⇒ Object



253
254
255
# File 'lib/pandoru/client.rb', line 253

def sleep_song(track_token)
  call("user.sleepSong", trackToken: track_token)
end

#transform_shared_station(station_token) ⇒ Object



264
265
266
# File 'lib/pandoru/client.rb', line 264

def transform_shared_station(station_token)
  call("station.transformSharedStation", stationToken: station_token)
end