Class: Totvs::PasswordVault::Information

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
JsonParser
Defined in:
lib/totvs/password_vault/information.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from JsonParser

#parse_json

Constructor Details

#initialize(connection: nil) ⇒ Information

Returns a new instance of Information.



16
17
18
# File 'lib/totvs/password_vault/information.rb', line 16

def initialize(connection: nil)
  @connection = connection
end

Instance Attribute Details

#connectionObject



20
21
22
# File 'lib/totvs/password_vault/information.rb', line 20

def connection
  @connection ||= Connection.new
end

Instance Method Details

#destroy(id:) ⇒ Object

Parameters:

  • id (String)

    the id key to be removed

Raises:



52
53
54
55
# File 'lib/totvs/password_vault/information.rb', line 52

def destroy(id:)
  headers = { "Accept" => "application/json" }
  delete path: build_path(id), headers: headers
end

#retrieve(id:) ⇒ Hash, Array

Returns content the saved content.

Parameters:

  • id (String)

    the id key to fetch info from

Returns:

  • (Hash, Array)

    content the saved content

Raises:



27
28
29
30
31
32
33
# File 'lib/totvs/password_vault/information.rb', line 27

def retrieve(id:)
  headers = { "Accept" => "application/json" }
  response = get(path: build_path(id), headers: headers)
  response = parse_json(response.body)

  parse_json(response["info"]["conteudo"])
end

#save(id:, content:, **kwargs) ⇒ Object

Parameters:

  • id (String)

    the id key to save info

  • content (#to_json)


37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/totvs/password_vault/information.rb', line 37

def save(id:, content:, **kwargs)
  headers = {
    "Accept" => "application/json",
    "Content-Type" => "application/json"
  }

  body = {
    conteudo: content.to_json
  }.merge(kwargs)

  post path: build_path(id), body: body, headers: headers
end