Class: EloquaApiService::Credential

Inherits:
Object
  • Object
show all
Defined in:
lib/eloqua_api_service/credential.rb

Constant Summary collapse

DEFAULT_SERVICE =
'infunnel_cli_default'
LABEL =
'infunnel_cli'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCredential

Returns a new instance of Credential.



9
10
11
12
13
14
# File 'lib/eloqua_api_service/credential.rb', line 9

def initialize
  @key = nil
  @options = {
    label: LABEL
  }
end

Instance Attribute Details

#keyObject (readonly)

Returns the value of attribute key.



4
5
6
# File 'lib/eloqua_api_service/credential.rb', line 4

def key
  @key
end

#optionsObject (readonly)

Returns the value of attribute options.



4
5
6
# File 'lib/eloqua_api_service/credential.rb', line 4

def options
  @options
end

Instance Method Details

#allObject



22
23
24
# File 'lib/eloqua_api_service/credential.rb', line 22

def all
  Keychain.generic_passwords.where(label: LABEL).all
end

#create(make_default: nil, options: {}) ⇒ Object



26
27
28
29
30
31
32
33
34
# File 'lib/eloqua_api_service/credential.rb', line 26

def create(make_default: nil, options: {})
  find(account: options[:account]).delete if find(account: options[:account])

  Keychain.generic_passwords.create(@options.merge(options))

  if make_default || !default
    set_default(account: options[:account])
  end
end

#defaultObject



36
37
38
39
40
41
# File 'lib/eloqua_api_service/credential.rb', line 36

def default
  default_pointer = Keychain.generic_passwords.where(service: DEFAULT_SERVICE).first
  if default_pointer
    @default ||= Keychain.generic_passwords.where(account: default_pointer.).first
  end
end

#find(account: nil) ⇒ Object



16
17
18
19
20
# File 'lib/eloqua_api_service/credential.rb', line 16

def find(account: nil)
  return default unless 

  Keychain.generic_passwords.where(account: ).first
end

#set_default(account:) ⇒ Object



43
44
45
46
47
48
49
50
51
52
# File 'lib/eloqua_api_service/credential.rb', line 43

def set_default(account:)
  default_pointer = Keychain.generic_passwords.where(service: DEFAULT_SERVICE).first
  default_pointer.delete if default_pointer

  Keychain.generic_passwords.create({
    password: '-',
    service:  DEFAULT_SERVICE,
    account:  
    })
end