Class: Bulkforce::ConnectionBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/bulkforce/connection_builder.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(host:, api_version:, **credentials) ⇒ ConnectionBuilder

Returns a new instance of ConnectionBuilder.



7
8
9
10
11
# File 'lib/bulkforce/connection_builder.rb', line 7

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

Instance Attribute Details

#api_versionObject (readonly)

Returns the value of attribute api_version.



4
5
6
# File 'lib/bulkforce/connection_builder.rb', line 4

def api_version
  @api_version
end

#credentialsObject (readonly)

Returns the value of attribute credentials.



5
6
7
# File 'lib/bulkforce/connection_builder.rb', line 5

def credentials
  @credentials
end

#hostObject (readonly)

Returns the value of attribute host.



3
4
5
# File 'lib/bulkforce/connection_builder.rb', line 3

def host
  @host
end

Instance Method Details

#buildObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/bulkforce/connection_builder.rb', line 13

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.(
      host,
      credentials.fetch(:client_id),
      credentials.fetch(:client_secret),
      credentials[:refresh_token]
    )
  else
    Bulkforce::Http.(
      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