Sha256: e30f5cc32d3b452eaa2dcb254a0020f09118e9dafebd24c8ad759fdbc4a9bb63

Contents?: true

Size: 883 Bytes

Versions: 2

Compression:

Stored size: 883 Bytes

Contents

# frozen_string_literal: true

# https://upstash.com/docs/qstash/api/publish
module Qstash
  module Message
    class Publish
      attr_reader :destination, :body, :headers
      ENDPOINT = "v2/publish"

      class << self
        def call(destination:, body:, headers: {})
          new(
            destination: destination,
            body: body,
            headers: headers
          ).call
        end
      end

      def initialize(destination:, body:, headers: {})
        @destination = destination
        @body = body
        @headers = headers
      end

      def call
        uri = URI(endpoint)
        client = Qstash::HttpClient.new(uri)
        client.post(body, headers)
      end

      private

      def endpoint
        [
          Qstash.config.url.sub(/\/$/, ""),
          ENDPOINT,
          destination
        ].join("/")
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
qstash-rb-0.1.1 lib/qstash/message/publish.rb
qstash-rb-0.1.0 lib/qstash/message/publish.rb