Class: Kapellmeister::Responder

Inherits:
Object
  • Object
show all
Defined in:
lib/kapellmeister/responder.rb

Defined Under Namespace

Classes: Result

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response, **args) ⇒ Responder

Returns a new instance of Responder.



7
8
9
10
# File 'lib/kapellmeister/responder.rb', line 7

def initialize(response, **args)
  @response = response
  @payload = args.merge(status: status) # rubocop:disable Style/HashSyntax (for support ruby 2.4+)
end

Instance Attribute Details

#payloadObject (readonly)

Returns the value of attribute payload.



3
4
5
# File 'lib/kapellmeister/responder.rb', line 3

def payload
  @payload
end

#responseObject (readonly)

Returns the value of attribute response.



3
4
5
# File 'lib/kapellmeister/responder.rb', line 3

def response
  @response
end

Instance Method Details

#resultObject



12
13
14
15
16
17
18
# File 'lib/kapellmeister/responder.rb', line 12

def result
  error = !/2\d{2}/.match?(status.to_s)

  Result.new(!error, parsed_body, payload)
rescue JSON::ParserError => e
  Result.new(false, { message: e.message }, payload)
end