Sha256: 3c52f899fe3dd9fa7cb911f418be8a770614bce9997de055fe8fa238cd0a1ed1
Contents?: true
Size: 630 Bytes
Versions: 8
Compression:
Stored size: 630 Bytes
Contents
class Kapellmeister::Responder Result = Struct.new(:success?, :response, :payload) attr_reader :response, :payload delegate :body, :status, to: :response def initialize(response, **args) @response = response @payload = args end def result error = !/2\d{2}/.match?(status.to_s) Result.new(!error, parsed_body, { status: status }.merge(payload)) rescue JSON::ParserError => e Result.new(false, e) end private def parsed_body return body if body.length == 0 case body when Hash then body else JSON.parse(body, symbolize_names: true, quirks_mode: true) end end end
Version data entries
8 entries across 8 versions & 1 rubygems