class Muzooka

Constants

BIO
DATA
IMAGE
URL

Attributes

artist_name[R]
muzooka_api_key[R]

Public Class Methods

new(muzooka_api_key:, artist_name:) click to toggle source
# File lib/muzooka.rb, line 12
def initialize(muzooka_api_key:, artist_name:)
  @artist_name = artist_name.strip
  @muzooka_api_key = muzooka_api_key
end

Public Instance Methods

bio() click to toggle source
# File lib/muzooka.rb, line 17
def bio
  response_body&.fetch(BIO, nil)
end
images() click to toggle source
# File lib/muzooka.rb, line 21
def images
  response_body&.fetch(IMAGE, nil)
end

Private Instance Methods

response() click to toggle source
# File lib/muzooka.rb, line 33
def response
  url = URI.parse(URL)
  http = Net::HTTP.new(url.host, url.port)
  http.use_ssl = true
  req = Net::HTTP::Get.new(url.request_uri + url_query)
  req['X-api-key'] = muzooka_api_key
  @response ||= http.request(req)
end
response_body() click to toggle source
# File lib/muzooka.rb, line 46
def response_body
  raise("Invalid response: #{response.to_s}") unless response.is_a?(Net::HTTPSuccess)
  @response_body ||= ActiveSupport::JSON.decode(response.body).fetch(DATA, nil)&.first
end
url_query() click to toggle source
# File lib/muzooka.rb, line 42
def url_query
  @url_query ||= "?name=#{artist_name.gsub(/\s/,'+')}"
end