Module: Radio5::Client::Tracks

Includes:
Radio5::Constants
Included in:
Radio5::Client
Defined in:
lib/radio5/client/tracks.rb

Defined Under Namespace

Modules: Parser

Constant Summary

Constants included from Radio5::Constants

Radio5::Constants::ASSET_HOST, Radio5::Constants::DECADES, Radio5::Constants::IMAGE_SIZES, Radio5::Constants::MAX_PAGE_SIZE, Radio5::Constants::MOODS, Radio5::Constants::MOODS_MAPPING, Radio5::Constants::USER_TRACK_STATUSES, Radio5::Constants::USER_TRACK_STATUSES_MAPPING

Instance Method Summary collapse

Instance Method Details

#island_track(island_id:, moods: MOODS) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/radio5/client/tracks.rb', line 43

def island_track(island_id:, moods: MOODS)
  validate_island_id!(island_id)
  validate_moods!(moods)

  body = {
    mode:   "islands",
    island: island_id,
    moods:  stringify_moods(moods).uniq
  }.to_json

  _, json = api.post("/play", body: body)

  Parser.track_info(json)
rescue Api::MatchingTrackNotFound
  nil
end

#random_track(country: nil, decades: [], moods: MOODS) ⇒ Object

TODO: technically, API accepts an array of countries, but without premium account only the first one is used during filtering.

`country` should be used for now
`countries` might be added in a future after implementation of auth


22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/radio5/client/tracks.rb', line 22

def random_track(country: nil, decades: [], moods: MOODS)
  iso_codes = country ? [country] : []

  validate_country_iso_codes!(iso_codes)
  validate_decades!(decades)
  validate_moods!(moods)

  body = {
    mode:     "explore",
    isocodes: iso_codes,
    decades:  decades.uniq,
    moods:    stringify_moods(moods).uniq
  }.to_json

  _, json = api.post("/play", body: body)

  Parser.track_info(json)
rescue Api::MatchingTrackNotFound
  nil
end

#track(track_id) ⇒ Object



8
9
10
11
12
13
14
15
16
# File 'lib/radio5/client/tracks.rb', line 8

def track(track_id)
  validate_track_id!(track_id)

  _, json = api.get("/track/play/#{track_id}")

  Parser.track_info(json)
rescue Api::TrackNotFound
  nil
end