Sha256: 3c4661b6b8001c5f414c79820fdb905ee34cba00e363fa2996372b40eca34db1

Contents?: true

Size: 808 Bytes

Versions: 1

Compression:

Stored size: 808 Bytes

Contents

module Arthropod
  class Request
    attr_reader :message, :client

    def initialize(client:, message:)
      @client = client
      @message = message
    end

    def body
      parsed_message_body["body"]
    end

    def return_queue_url
      parsed_message_body["return_queue_url"]
    end

    def state
      parsed_message_body["state"]
    end

    def respond(body = nil)
      send_message({ state: "open", body: body })
    end

    def close(body = nil)
      send_message({ state: "close", body: body })
    end

    private

    def send_message(message_body)
      client.send_message({
        queue_url: return_queue_url,
        message_body: JSON.dump(message_body)
      })
    end

    def parsed_message_body
      @parsed_message_body ||= JSON.parse(message.body)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
arthropod-0.0.1 lib/arthropod/request.rb