Sha256: a3c5662111294aceef56b673cdcfc98629622b673c6082110e11b95e54194597

Contents?: true

Size: 1.26 KB

Versions: 56

Compression:

Stored size: 1.26 KB

Contents

# frozen_string_literal: true

module PlatformSdk
  module DataPipeline
    # DataPipeline::Client
    class Client
      attr_reader :credentials, :conn

      def initialize(credentials)
        @credentials = credentials

        raise ArgumentError, "pipeline_host is required" if @credentials[:pipeline_host].nil?
        raise ArgumentError, "pipeline_username is required" if @credentials[:pipeline_username].nil?
        raise ArgumentError, "pipeline_password is required" if @credentials[:pipeline_password].nil?

        @conn = Faraday.new(url: "https://#{@credentials[:pipeline_host]}") do |faraday|
          faraday.request(:retry, retry_options)
          faraday.request(:authorization, :basic, @credentials[:pipeline_username], @credentials[:pipeline_password])
          faraday.headers = headers
          faraday.response :raise_error
          faraday.adapter(:net_http)
        end
      end

      private

      def headers
        { "Content-Type" => "application/json" }
      end

      def retry_options
        {
          max: 3,
          interval: 0.05,
          interval_randomness: 0.5,
          backoff_factor: 2
        }
      end

      public

      def post(message)
        @conn.post("messages", message.to_json)
      end
    end
  end
end

Version data entries

56 entries across 56 versions & 1 rubygems

Version Path
strongmind-platform-sdk-3.25.0 lib/platform_sdk/data_pipeline/data_pipeline_client.rb
strongmind-platform-sdk-3.24.0 lib/platform_sdk/data_pipeline/data_pipeline_client.rb
strongmind-platform-sdk-3.23.7 lib/platform_sdk/data_pipeline/data_pipeline_client.rb
strongmind-platform-sdk-3.23.6 lib/platform_sdk/data_pipeline/data_pipeline_client.rb
strongmind-platform-sdk-3.23.5 lib/platform_sdk/data_pipeline/data_pipeline_client.rb
strongmind-platform-sdk-3.23.4 lib/platform_sdk/data_pipeline/data_pipeline_client.rb
strongmind-platform-sdk-3.23.3 lib/platform_sdk/data_pipeline/data_pipeline_client.rb
strongmind-platform-sdk-3.23.2 lib/platform_sdk/data_pipeline/data_pipeline_client.rb
strongmind-platform-sdk-3.23.1 lib/platform_sdk/data_pipeline/data_pipeline_client.rb
strongmind-platform-sdk-3.23.0 lib/platform_sdk/data_pipeline/data_pipeline_client.rb
strongmind-platform-sdk-3.22.1 lib/platform_sdk/data_pipeline/data_pipeline_client.rb
strongmind-platform-sdk-3.22.0 lib/platform_sdk/data_pipeline/data_pipeline_client.rb
strongmind-platform-sdk-3.21.8 lib/platform_sdk/data_pipeline/data_pipeline_client.rb
strongmind-platform-sdk-3.21.7 lib/platform_sdk/data_pipeline/data_pipeline_client.rb
strongmind-platform-sdk-3.21.6 lib/platform_sdk/data_pipeline/data_pipeline_client.rb
strongmind-platform-sdk-3.21.5 lib/platform_sdk/data_pipeline/data_pipeline_client.rb
strongmind-platform-sdk-3.21.4 lib/platform_sdk/data_pipeline/data_pipeline_client.rb
strongmind-platform-sdk-3.21.3 lib/platform_sdk/data_pipeline/data_pipeline_client.rb
strongmind-platform-sdk-3.21.2 lib/platform_sdk/data_pipeline/data_pipeline_client.rb
strongmind-platform-sdk-3.21.1 lib/platform_sdk/data_pipeline/data_pipeline_client.rb