Class: AppleMusic::Chart

Inherits:
Object
  • Object
show all
Defined in:
lib/apple_music/chart.rb

Overview

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(props = {}) ⇒ Chart

Returns a new instance of Chart.



8
9
10
11
12
13
14
# File 'lib/apple_music/chart.rb', line 8

def initialize(props = {})
  @chart = props['chart'] # required
  @data = Array(props['data']).map { |attrs| Resource.build(attrs) } # required
  @href = props['href'] # required
  @name = props['name'] # required
  @next = props['next']
end

Instance Attribute Details

#chartObject (readonly)

Returns the value of attribute chart.



6
7
8
# File 'lib/apple_music/chart.rb', line 6

def chart
  @chart
end

#dataObject (readonly)

Returns the value of attribute data.



6
7
8
# File 'lib/apple_music/chart.rb', line 6

def data
  @data
end

#hrefObject (readonly)

Returns the value of attribute href.



6
7
8
# File 'lib/apple_music/chart.rb', line 6

def href
  @href
end

#nameObject (readonly)

Returns the value of attribute name.



6
7
8
# File 'lib/apple_music/chart.rb', line 6

def name
  @name
end

#nextObject (readonly)

Returns the value of attribute next.



6
7
8
# File 'lib/apple_music/chart.rb', line 6

def next
  @next
end

Class Method Details

.list(**options) ⇒ Object

e.g. AppleMusic::Chart.list(types: [‘songs’, ‘albums’, ‘playlists’], genre: 20, limit: 30) developer.apple.com/documentation/applemusicapi/get_catalog_charts

Raises:



19
20
21
22
23
24
25
26
# File 'lib/apple_music/chart.rb', line 19

def list(**options)
  raise ParameterMissing, 'required parameter :types is missing' unless options[:types]

  types = options[:types].is_a?(Array) ? options[:types].join(',') : options[:types]
  storefront = Storefront.lookup(options.delete(:storefront))
  response = AppleMusic.get("catalog/#{storefront}/charts", options.merge(types: types))
  ChartResponse.new(response.body['results'] || {})
end

.search(**_options) ⇒ Object



28
29
30
# File 'lib/apple_music/chart.rb', line 28

def search(**_options)
  warn 'WARN: :charts is not searchable resource'
end