Class: Echonest::Artist

Inherits:
Base
  • Object
show all
Defined in:
lib/echonest-ruby-api/artist.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

base_uri, #endpoint, #entity_name, #get, #get_response, version, #which

Constructor Details

#initialize(api_key, name = nil, foreign_ids = nil, id = nil) ⇒ Artist

Returns a new instance of Artist.



14
15
16
17
18
19
# File 'lib/echonest-ruby-api/artist.rb', line 14

def initialize(api_key, name = nil, foreign_ids = nil, id = nil)
  @id = id
  @name = name
  @api_key = api_key
  @foreign_ids = ForeignId.parse_array(foreign_ids) if foreign_ids
end

Instance Attribute Details

#foreign_idsObject

Returns the value of attribute foreign_ids.



12
13
14
# File 'lib/echonest-ruby-api/artist.rb', line 12

def foreign_ids
  @foreign_ids
end

#idObject

Returns the value of attribute id.



12
13
14
# File 'lib/echonest-ruby-api/artist.rb', line 12

def id
  @id
end

#nameObject

Returns the value of attribute name.



12
13
14
# File 'lib/echonest-ruby-api/artist.rb', line 12

def name
  @name
end

Instance Method Details

#biographies(options = { results: 1 }) ⇒ Object



21
22
23
24
25
26
27
# File 'lib/echonest-ruby-api/artist.rb', line 21

def biographies(options = { results: 1 })
  response = get_response(results: options[:results], name: @name)

  response[:biographies].collect do |b|
    Biography.new(text: b[:text], site: b[:site], url: b[:url])
  end
end

#blogs(options = { results: 1 }) ⇒ Object



29
30
31
32
33
34
35
# File 'lib/echonest-ruby-api/artist.rb', line 29

def blogs(options = { results: 1 })
  response = get_response(results: options[:results], name: @name)

  response[:blogs].collect do |b|
    Blog.new(name: b[:name], site: b[:site], url: b[:url])
  end
end

#familiarityObject



37
38
39
40
# File 'lib/echonest-ruby-api/artist.rb', line 37

def familiarity
  response = get_response(name: @name)
  response[entity_name.to_sym][__method__.to_sym]
end

#hotttnesss(options = {}) ⇒ Object



42
43
44
45
# File 'lib/echonest-ruby-api/artist.rb', line 42

def hotttnesss(options = {})
  response = get_response(name: @name, type: options.fetch(:type, 'overall'))
  response[entity_name.to_sym][__method__.to_sym]
end

#imagesObject



47
48
49
50
51
52
53
54
# File 'lib/echonest-ruby-api/artist.rb', line 47

def images
  response = get_response(name: @name)
  images = []
  response[:images].each do |i|
    images << i[:url]
  end
  images
end

#list_genresObject



56
57
58
# File 'lib/echonest-ruby-api/artist.rb', line 56

def list_genres
  get_response[:genres]
end

#profile(options = {}) ⇒ Object



77
78
79
80
81
# File 'lib/echonest-ruby-api/artist.rb', line 77

def profile(options = {})
  options = {name: @name, id: @id}.merge(options)
  artist_data = get_response(options)[:artist]
  Artist.new(@api_key, artist_data[:name], artist_data[:foreign_ids], artist_data[:id])
end

#search(options = {}) ⇒ Object



60
61
62
63
64
65
66
67
# File 'lib/echonest-ruby-api/artist.rb', line 60

def search(options = {})
  options = {name: @name}.merge(options)
  artists = []
  get_response(options)[:artists].each do |a|
    artists << Artist.new(@api_key, a[:name], a[:foreign_ids], a[:id])
  end
  artists
end

#songsObject



69
70
71
72
73
74
75
# File 'lib/echonest-ruby-api/artist.rb', line 69

def songs
  songs = []
  get_response(name: @name)[:songs].each do |s|
    songs << { s[:id] => s[:title] }
  end
  songs
end

#terms(options = {}) ⇒ Object



83
84
85
86
# File 'lib/echonest-ruby-api/artist.rb', line 83

def terms(options = {})
  options = {name: @name, id: @id}.merge(options)
  get_response(options)[:terms]
end