Sha256: 9841803d8e852a60d190d293e5170649915da1ca5f5451d2282f6cc4a125157a
Contents?: true
Size: 618 Bytes
Versions: 4
Compression:
Stored size: 618 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: }.merge(payload)) rescue JSON::ParserError => e Result.new(false, e) end private def parsed_body return body if body.empty? case body when Hash then body else JSON.parse(body, symbolize_names: true, quirks_mode: true) end end end
Version data entries
4 entries across 4 versions & 1 rubygems