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.21.0 lib/platform_sdk/data_pipeline/data_pipeline_client.rb
strongmind-platform-sdk-3.20.3 lib/platform_sdk/data_pipeline/data_pipeline_client.rb
strongmind-platform-sdk-3.20.2 lib/platform_sdk/data_pipeline/data_pipeline_client.rb
strongmind-platform-sdk-3.20.1 lib/platform_sdk/data_pipeline/data_pipeline_client.rb
strongmind-platform-sdk-3.20.0 lib/platform_sdk/data_pipeline/data_pipeline_client.rb
strongmind-platform-sdk-3.19.40 lib/platform_sdk/data_pipeline/data_pipeline_client.rb
strongmind-platform-sdk-3.19.39 lib/platform_sdk/data_pipeline/data_pipeline_client.rb
strongmind-platform-sdk-3.19.38 lib/platform_sdk/data_pipeline/data_pipeline_client.rb
strongmind-platform-sdk-3.19.37 lib/platform_sdk/data_pipeline/data_pipeline_client.rb
strongmind-platform-sdk-3.19.36 lib/platform_sdk/data_pipeline/data_pipeline_client.rb
strongmind-platform-sdk-3.19.35 lib/platform_sdk/data_pipeline/data_pipeline_client.rb
strongmind-platform-sdk-3.19.34 lib/platform_sdk/data_pipeline/data_pipeline_client.rb
strongmind-platform-sdk-3.19.33 lib/platform_sdk/data_pipeline/data_pipeline_client.rb
strongmind-platform-sdk-3.19.32 lib/platform_sdk/data_pipeline/data_pipeline_client.rb
strongmind-platform-sdk-3.19.31 lib/platform_sdk/data_pipeline/data_pipeline_client.rb
strongmind-platform-sdk-3.19.30 lib/platform_sdk/data_pipeline/data_pipeline_client.rb
strongmind-platform-sdk-3.19.29 lib/platform_sdk/data_pipeline/data_pipeline_client.rb
strongmind-platform-sdk-3.19.28 lib/platform_sdk/data_pipeline/data_pipeline_client.rb
strongmind-platform-sdk-3.19.27 lib/platform_sdk/data_pipeline/data_pipeline_client.rb
strongmind-platform-sdk-3.19.26 lib/platform_sdk/data_pipeline/data_pipeline_client.rb