Sha256: 66b36b297fbda242fd7169ef7d7d007a4b375423025d4cb3153e77248b51cd70

Contents?: true

Size: 1.53 KB

Versions: 12

Compression:

Stored size: 1.53 KB

Contents

# frozen_string_literal: true

require_relative "http_single_workspace"

module Seam
  module Http
    def self.new(**args)
      Http::SingleWorkspace.new(**args)
    end

    def self.from_api_key(api_key, endpoint: nil, wait_for_action_attempt: false)
      Http::SingleWorkspace.from_api_key(api_key, endpoint: endpoint, wait_for_action_attempt: wait_for_action_attempt)
    end

    def self.from_personal_access_token(personal_access_token, workspace_id, endpoint: nil, wait_for_action_attempt: false)
      Http::SingleWorkspace.from_personal_access_token(personal_access_token, workspace_id, endpoint: endpoint,
        wait_for_action_attempt: wait_for_action_attempt)
    end

    class ApiError < StandardError
      attr_reader :code, :status_code, :request_id, :data

      def initialize(error, status_code, request_id)
        super(error[:message])
        @code = error[:type]
        @status_code = status_code
        @request_id = request_id
        @data = error[:data]
      end
    end

    class UnauthorizedError < ApiError
      def initialize(request_id)
        super({type: "unauthorized", message: "Unauthorized"}, 401, request_id)
      end
    end

    class InvalidInputError < ApiError
      attr_reader :validation_errors

      def initialize(error, status_code, request_id)
        super
        @code = "invalid_input"
        @validation_errors = error["validation_errors"] || {}
      end

      def get_validation_error_messages(param_name)
        @validation_errors.dig(param_name, "_errors") || []
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

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