Class: Salesforce::Einstein::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/salesforce/einstein/base.rb

Direct Known Subclasses

V2::LanguageClient, V2::VisionClient

Constant Summary collapse

BASE_URI =
'https://api.einstein.ai/v2'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cert: nil, private_key: nil, password: nil, email:, timeout: 3600) ⇒ Base

Returns a new instance of Base.



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/salesforce/einstein/base.rb', line 15

def initialize(cert: nil, private_key: nil, password: nil, email:, timeout: 3600)
  if cert.nil? && private_key.nil?
    raise ArgumentError, 'At least one parameter must be specified: cert or private_key'
  end

  if cert
    cert_contents = File.read(File.expand_path(cert))
    pkcs12 = OpenSSL::PKCS12.new(cert_contents, password)
    @private_key = pkcs12.key
  else
    private_key_contents = File.read(File.expand_path(private_key))
    @private_key = OpenSSL::PKey::RSA.new(private_key_contents, password)
  end
  @email = email
  @boundary = SecureRandom.hex(10)
  @timeout = 3600
end

Instance Attribute Details

#access_tokenObject

Returns the value of attribute access_token.



13
14
15
# File 'lib/salesforce/einstein/base.rb', line 13

def access_token
  @access_token
end

#boundaryObject

Returns the value of attribute boundary.



13
14
15
# File 'lib/salesforce/einstein/base.rb', line 13

def boundary
  @boundary
end

#emailObject

Returns the value of attribute email.



13
14
15
# File 'lib/salesforce/einstein/base.rb', line 13

def email
  @email
end

#private_keyObject

Returns the value of attribute private_key.



13
14
15
# File 'lib/salesforce/einstein/base.rb', line 13

def private_key
  @private_key
end

#timeoutObject

Returns the value of attribute timeout.



13
14
15
# File 'lib/salesforce/einstein/base.rb', line 13

def timeout
  @timeout
end

Instance Method Details

#delete_reflesh_token(token) ⇒ Object



42
43
44
# File 'lib/salesforce/einstein/base.rb', line 42

def delete_reflesh_token(token)
  delete "/oauth2/token/#{token}"
end

#get_api_usageObject



38
39
40
# File 'lib/salesforce/einstein/base.rb', line 38

def get_api_usage
  get '/apiusage'
end