Module: Radio5::Client::Countries

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

Defined Under Namespace

Modules: Fetcher

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

#countriesObject



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

def countries
  _, json = api.get("/language/countries/en.json")

  json.each_with_object({}) do |(iso_code, name, exist, rank), countries|
    countries[iso_code] = {
      name: name,
      exist: exist,
      rank: rank
    }
  end
end

#countries_for_decade(decade, group_by: :country) ⇒ Object



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

def countries_for_decade(decade, group_by: :country)
  validate_decade!(decade)

  case group_by
  when :mood
    Fetcher.grouped_by_mood(api, decade)
  when :country
    grouped_by_mood = Fetcher.grouped_by_mood(api, decade)
    grouped_by_country = Hash.new { |hash, country| hash[country] = [] }

    MOODS.each_with_object(grouped_by_country) do |mood, grouped_by_country|
      grouped_by_mood[mood].each do |country|
        grouped_by_country[country] << mood
      end
    end
  else
    raise ArgumentError, "invalid `group_by` value: #{group_by.inspect}"
  end
end