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_api_endpoint, #get_response, version, #which

Constructor Details

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

Returns a new instance of Artist.



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

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.



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

def foreign_ids
  @foreign_ids
end

#idObject

Returns the value of attribute id.



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

def id
  @id
end

#nameObject

Returns the value of attribute name.



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

def name
  @name
end

Instance Method Details

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



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

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

Stuff from blogspot, etc



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

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



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

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

#genresObject



65
66
67
68
69
# File 'lib/echonest-ruby-api/artist.rb', line 65

def genres
  genres = []
  response = get('artist/profile', {name: @name, bucket: 'genre'})
  return response[:artist][:genres].collect {|g| g[:name]}
end

#hotttnesss(options = {}) ⇒ Object



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

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

#images(options = { results: 15 }) ⇒ Object



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

def images(options = { results: 15 })
  response = get_response(results: options[:results], name: @name)
  images = []
  response[:images].each do |i|
    images << i[:url]
  end
  images
end

#list_genresObject



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

def list_genres
  get_response[:genres]
end

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

This appears to be from more “reputable” sources?



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

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

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

#profile(options = {}) ⇒ Object



132
133
134
135
136
# File 'lib/echonest-ruby-api/artist.rb', line 132

def profile(options = {})
  options = (@id ? {id: @id} : {name: @name}).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



89
90
91
92
93
94
95
96
# File 'lib/echonest-ruby-api/artist.rb', line 89

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

#similar(options = { results: 20 }) ⇒ Object



98
99
100
101
102
103
104
105
# File 'lib/echonest-ruby-api/artist.rb', line 98

def similar(options = { results: 20 })
  artists = []
  response = get('artist/similar', {name: @name, results: options[:results]})
  response[:artists].each do |a|
    artists << a
  end
  return artists
end

#songs(options = { results: 15 }) ⇒ Object



124
125
126
127
128
129
130
# File 'lib/echonest-ruby-api/artist.rb', line 124

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

#suggest(options = {}) ⇒ Object



107
108
109
110
111
112
113
114
# File 'lib/echonest-ruby-api/artist.rb', line 107

def suggest(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

#terms(options = {}) ⇒ Object



138
139
140
141
# File 'lib/echonest-ruby-api/artist.rb', line 138

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

#top_hottt(options = {}) ⇒ Object



116
117
118
119
120
121
122
# File 'lib/echonest-ruby-api/artist.rb', line 116

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

#urlsObject



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

def urls
  get_response(name: @name)[:urls]
end

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



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

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

  response[:video].collect do |v|
    Video.new(title: v[:title], site: v[:site], url: v[:url], date_found: v[:date_found], image_url: v[:image_url])
  end
end