Module: SimpleSpotify::Actions::Browse

Defined in:
lib/simplespotify/actions/browse.rb

Instance Method Summary collapse

Instance Method Details

#categories(country: nil, locale: nil, limit: 20, offset: 0) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/simplespotify/actions/browse.rb', line 34

def categories country: nil, locale: nil, limit: 20, offset: 0
  options = {limit: limit, offset: offset}

  market = country || @market
  options[:country] = market if market

  locale ||= ENV['LANG'].split('.').first if ENV['LANG']
  options[:locale] = locale if locale

  response = get "browse/categories", options
  Model::Collection.of(Model::Category, response.body[:categories])
end

#category(category, country: nil, locale: nil) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
# File 'lib/simplespotify/actions/browse.rb', line 48

def category category, country: nil, locale: nil
  options = {}
  market = country || @market
  options[:country] = market if market

  locale ||= ENV['LANG'].split('.').first if ENV['LANG']
  options[:locale] = locale if locale

  response = get "browse/categories/#{id_for(category)}"
  Model::Category.new(response)
end

#category_playlists(category, country: nil, limit: 20, offset: 0) ⇒ Object



61
62
63
64
65
66
67
68
69
# File 'lib/simplespotify/actions/browse.rb', line 61

def category_playlists category, country: nil, limit: 20, offset: 0
  options = {limit: limit, offset: offset}

  market = country || @market
  options[:country] = market if market

  response = get "browse/categories/#{id_for(category)}/playlists", options
  Model::Collection.of(:playlists, response.body[:playlists])
end


6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/simplespotify/actions/browse.rb', line 6

def featured_playlists locale: nil, country: nil, timestamp: nil, limit: 20, offset: 0
  locale ||= ENV['LANG'].split('.').first if ENV['LANG']
  timestamp = timestamp.to_time if timestamp.is_a Date
  timestamp = timestamp.iso8601 if timestamp.is_a? Time

  options = {
    locale: locale,
    country: country || @market,
    timestamp: timestamp,
    limit: limit,
    offset: offset
  }.reject {|k,v| v.nil? || v==''}.to_h

  response = get "browse/featured-playlists", options
  Model::Collection.of(:playlists, response.body[:playlists])
end

#new_releases(country: nil, limit: 20, offset: 0) ⇒ Object



24
25
26
27
28
29
30
31
# File 'lib/simplespotify/actions/browse.rb', line 24

def new_releases country: nil, limit: 20, offset: 0
  options = {limit: limit, offset: offset}
  market = country || @market
  options[:country] = market if market

  response = get "browse/new-releases", options
  Model::Collection.of(:albums, response.body[:albums])
end