Sha256: 24df354d86a5eb8d25d3ed572252c4cf96150d4e769be34e44f36a5ee8219401

Contents?: true

Size: 1.82 KB

Versions: 12

Compression:

Stored size: 1.82 KB

Contents

# frozen_string_literal: true

require_relative "default_endpoint"

module Seam
  module Http
    module Options
      def self.get_endpoint(endpoint = nil)
        endpoint || get_endpoint_from_env || Seam::DEFAULT_ENDPOINT
      end

      def self.get_endpoint_from_env
        seam_api_url = ENV["SEAM_API_URL"]
        seam_endpoint = ENV["SEAM_ENDPOINT"]

        if seam_api_url
          warn "\033[93mUsing the SEAM_API_URL environment variable is deprecated. Support will be removed in a later major version. Use SEAM_ENDPOINT instead.\033[0m"
        end

        if seam_api_url && seam_endpoint
          warn "\033[93mDetected both the SEAM_API_URL and SEAM_ENDPOINT environment variables. Using SEAM_ENDPOINT.\033[0m"
        end

        seam_endpoint || seam_api_url
      end

      class SeamInvalidOptionsError < StandardError
        def initialize(message)
          super("Seam received invalid options: #{message}")
        end
      end

      def self.seam_http_options_with_api_key?(api_key: nil, personal_access_token: nil)
        return false if api_key.nil?

        if personal_access_token
          raise SeamInvalidOptionsError.new(
            "The personal_access_token option cannot be used with the api_key option"
          )
        end

        true
      end

      def self.seam_http_options_with_personal_access_token?(personal_access_token: nil, api_key: nil, workspace_id: nil)
        return false if personal_access_token.nil?

        if api_key
          raise SeamInvalidOptionsError.new(
            "The api_key option cannot be used with the personal_access_token option"
          )
        end

        if workspace_id.nil?
          raise SeamInvalidOptionsError.new(
            "Must pass a workspace_id when using a personal_access_token"
          )
        end

        true
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
seam-2.3.0 lib/seam/options.rb
seam-2.2.0 lib/seam/options.rb
seam-2.1.0 lib/seam/options.rb
seam-2.0.1 lib/seam/options.rb
seam-2.0.0 lib/seam/options.rb
seam-2.0.0rc0 lib/seam/options.rb
seam-2.0.0b5 lib/seam/options.rb
seam-2.0.0b4 lib/seam/options.rb
seam-2.0.0b3 lib/seam/options.rb
seam-2.0.0b2 lib/seam/options.rb
seam-2.0.0b1 lib/seam/options.rb
seam-2.0.0b0 lib/seam/options.rb