Sha256: aa727ca32b7a59dd82840e711ee49262aba2e144e2ea9f2d8a44af8da7d86983

Contents?: true

Size: 654 Bytes

Versions: 2

Compression:

Stored size: 654 Bytes

Contents

module RDStation
  class Events
    include HTTParty

    EVENTS_ENDPOINT = 'https://api.rd.services/platform/events'.freeze

    def initialize(authorization_header:)
      @authorization_header = authorization_header
    end

    def create(payload)
      response = self.class.post(EVENTS_ENDPOINT, headers: @authorization_header.to_h, body: payload.to_json)
      response_body = JSON.parse(response.body)
      return response_body unless errors?(response_body)
      RDStation::ErrorHandler.new(response).raise_error
    end

    private

    def errors?(response_body)
      response_body.is_a?(Array) || response_body['errors']
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rdstation-ruby-client-2.1.0 lib/rdstation/events.rb
rdstation-ruby-client-2.0.0 lib/rdstation/events.rb