Class: Genius::Artist

Inherits:
Resource show all
Defined in:
lib/genius/artist.rb

Instance Attribute Summary collapse

Attributes inherited from Resource

#raw_response, #resource

Instance Method Summary collapse

Methods inherited from Resource

default_headers, default_params, find, from_hash, handle_response, http_delete, http_get, http_post, http_put, #initialize, #reload, resource_name

Constructor Details

This class inherits a constructor from Genius::Resource

Instance Attribute Details

#descriptionObject (readonly)

Returns the value of attribute description.



3
4
5
# File 'lib/genius/artist.rb', line 3

def description
  @description
end

#idObject (readonly)

Returns the value of attribute id.



3
4
5
# File 'lib/genius/artist.rb', line 3

def id
  @id
end

#image_urlObject (readonly)

Returns the value of attribute image_url.



3
4
5
# File 'lib/genius/artist.rb', line 3

def image_url
  @image_url
end

#nameObject (readonly)

Returns the value of attribute name.



3
4
5
# File 'lib/genius/artist.rb', line 3

def name
  @name
end

#tracking_pathsObject (readonly)

Returns the value of attribute tracking_paths.



3
4
5
# File 'lib/genius/artist.rb', line 3

def tracking_paths
  @tracking_paths
end

#urlObject (readonly)

Returns the value of attribute url.



3
4
5
# File 'lib/genius/artist.rb', line 3

def url
  @url
end

#userObject (readonly)

Returns the value of attribute user.



3
4
5
# File 'lib/genius/artist.rb', line 3

def user
  @user
end

Instance Method Details

#parse_resource!Object



5
6
7
8
9
10
11
12
13
# File 'lib/genius/artist.rb', line 5

def parse_resource!
  @id = resource["id"]
  @name = resource["name"]
  @image_url = resource["image_url"]
  @url = resource["url"]
  @user = Account.from_hash(resource["user"])
  @description = formatted_attribute("description")
  @tracking_paths = resource["tracking_paths"]
end

#songs(params: {}, headers: {}) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/genius/artist.rb', line 15

def songs(params: {}, headers: {})
  headers = self.class.default_headers.merge(headers)
  params = self.class.default_params.merge(id: id).merge(params)

  response = self.class.http_get("/#{resource_name}s/#{id}/songs", query: params,
                                                                   headers: headers)

  response.parsed_response["response"]["songs"].map do |song|
    Song.from_hash(song, text_format: text_format)
  end
end