Class: Rubybrainz::Interactors::BuildResponse

Inherits:
Object
  • Object
show all
Defined in:
lib/rubybrainz/interactors/build_response.rb

Overview

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

Instance Method Summary collapse

Instance Method Details

#call(httparty_response:) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# 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