Sha256: 8a5383d6b0c5e0c7856d5065f1f8486c7d3ae076504ac75c3fc076ac9b3968d0
Contents?: true
Size: 1.02 KB
Versions: 2
Compression:
Stored size: 1.02 KB
Contents
module SearchKit class Events # An extraction of the publication client action, which contains a certain # amount of logic in handling success/failure, parameter building and # API interaction. # class Publish SUCCESS = 202 attr_reader :channel, :connection, :payload def initialize(options = {}) @connection = options.fetch(:connection) @channel = options.fetch(:channel) @payload = options.fetch(:payload) end def perform body = JSON.parse(response.body, symbolize_names: true) if success? body else fail Errors::PublicationFailed, body.fetch(:error) end end private def success? response.status == SUCCESS end def response @response ||= connection.post("/api/events", params) end def params { type: 'events', data: { attributes: { channel: channel, payload: payload } } } end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
search-kit-0.0.2 | lib/search_kit/events/publish.rb |
search-kit-0.0.1 | lib/search_kit/events/publish.rb |