Sha256: 99135e84bd686c93d700a56d7ed05d0797b887bf89ba4c43d8b0e96a0cc8f12f

Contents?: true

Size: 992 Bytes

Versions: 50

Compression:

Stored size: 992 Bytes

Contents

# frozen_string_literal: true

module PlatformSdk
  module Events
    # Event Platform Client
    class Client
      def initialize(base_url, auth_client, conn: nil)
        @auth_client = auth_client
        @base_url = base_url
        @conn = conn || build_connection
      end

      def send_event(event)
        send_message(event)
      end

      private

      def build_connection
        Faraday.new(@base_url) do |faraday|
          faraday.headers = headers
          faraday.adapter Faraday.default_adapter
          faraday.response :json, content_type: /\bjson$/, parser_options: { symbolize_names: true }
          faraday.response :raise_error
        end
      end

      def headers
        {
          'Authorization': "Bearer #{@auth_client.auth_token}",
          'Content-Type': "application/cloudevents+json; charset=utf-8"
        }
      end

      def send_message(message, path: 'events/v1/')
        @conn.post(path, message.to_json)
      end
    end
  end
end

Version data entries

50 entries across 50 versions & 1 rubygems

Version Path
strongmind-platform-sdk-3.22.1 lib/platform_sdk/events/client.rb
strongmind-platform-sdk-3.22.0 lib/platform_sdk/events/client.rb
strongmind-platform-sdk-3.21.8 lib/platform_sdk/events/client.rb
strongmind-platform-sdk-3.21.7 lib/platform_sdk/events/client.rb
strongmind-platform-sdk-3.21.6 lib/platform_sdk/events/client.rb
strongmind-platform-sdk-3.21.5 lib/platform_sdk/events/client.rb
strongmind-platform-sdk-3.21.4 lib/platform_sdk/events/client.rb
strongmind-platform-sdk-3.21.3 lib/platform_sdk/events/client.rb
strongmind-platform-sdk-3.21.2 lib/platform_sdk/events/client.rb
strongmind-platform-sdk-3.21.1 lib/platform_sdk/events/client.rb
strongmind-platform-sdk-3.21.0 lib/platform_sdk/events/client.rb
strongmind-platform-sdk-3.20.3 lib/platform_sdk/events/client.rb
strongmind-platform-sdk-3.20.2 lib/platform_sdk/events/client.rb
strongmind-platform-sdk-3.20.1 lib/platform_sdk/events/client.rb
strongmind-platform-sdk-3.20.0 lib/platform_sdk/events/client.rb
strongmind-platform-sdk-3.19.40 lib/platform_sdk/events/client.rb
strongmind-platform-sdk-3.19.39 lib/platform_sdk/events/client.rb
strongmind-platform-sdk-3.19.38 lib/platform_sdk/events/client.rb
strongmind-platform-sdk-3.19.37 lib/platform_sdk/events/client.rb
strongmind-platform-sdk-3.19.36 lib/platform_sdk/events/client.rb