Sha256: 349e5c67e8491363a4f6ee339ee0d6cf48d61f6524f2c6bac9bb96055eb587ef

Contents?: true

Size: 1.08 KB

Versions: 3

Compression:

Stored size: 1.08 KB

Contents

class Bulkforce
  class ConnectionBuilder
    attr_reader :host
    attr_reader :api_version
    attr_reader :credentials

    def initialize(host:, api_version:, **credentials)
      @host = host
      @api_version = api_version
      @credentials = credentials
    end

    def build
      base_options = { api_version: api_version }

      session_options = if credentials[:session_id]
        {
          session_id: credentials[:session_id],
          instance: credentials.fetch(:instance),
        }
      elsif credentials[:refresh_token]
        Bulkforce::Http.oauth_login(
          host,
          credentials.fetch(:client_id),
          credentials.fetch(:client_secret),
          credentials[:refresh_token]
        )
      else
        Bulkforce::Http.login(
          host,
          credentials.fetch(:username),
          "#{credentials.fetch(:password)}#{credentials.fetch(:security_token)}",
          api_version
        )
      end.select { |k, _|  [:session_id, :instance].include?(k) }.to_h

      Bulkforce::Connection.new(base_options.merge(session_options))
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
bulkforce-1.0.2 lib/bulkforce/connection_builder.rb
bulkforce-1.0.1 lib/bulkforce/connection_builder.rb
bulkforce-1.0.0 lib/bulkforce/connection_builder.rb