class Rubybrainz::Interactors::BuildResponse

This is how we will build a reasonable Rubybrainz response for each request

Public Instance Methods

call(httparty_response:) click to toggle source
# File lib/rubybrainz/interactors/build_response.rb, line 10
def call(httparty_response:)
  if httparty_response.code == 200
    body = JSON.parse(httparty_response.body)
    Rubybrainz::Entities::Response.new(
      success: true,
      message: httparty_response.message,
      created: body['created'],
      count: body['count'],
      offset: body['offset'],
      artists: body['artists'].map { |artist| json_to_artist.call(json_artist: artist) }
    )
  else
    Rubybrainz::Entities::Response.new(
      success: false,
      message: httparty_response.message,
      created: body['created'],
      count: body['count'],
      offset: body['offset']
    )
  end
end

Private Instance Methods

json_to_artist() click to toggle source
# File lib/rubybrainz/interactors/build_response.rb, line 34
def json_to_artist
  @json_to_artist ||= Rubybrainz::Transforms::JsonToArtist.new
end