Sha256: d8bf9d9a060732e18d1e2de4f4583fb72b4394c1a718db8352dbd809639851bf
Contents?: true
Size: 628 Bytes
Versions: 29
Compression:
Stored size: 628 Bytes
Contents
class <%= class_name %>::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.length.zero? case body when Hash then body else JSON.parse(body, symbolize_names: true, quirks_mode: true) end end end
Version data entries
29 entries across 29 versions & 1 rubygems