Module: STP::Account

Defined in:
lib/stp/account.rb

Class Method Summary collapse

Class Method Details

.create(account) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
# File 'lib/stp/account.rb', line 3

def self.create()
  .signature = Crypto::Commons.rsa_seal(STP.private_key, STP.private_key_password, .original_chain)
  connection = Faraday.new(url: "#{STP.api_uri}/cuentaModule/fisica")
  response = connection.put do |req|
    req.url ''
    req.headers['Content-Type'] = 'application/json'
    req.body = .to_json
  end
  puts response.body if STP.verbose
  hash = JSON.parse(response.body)
  raise STP::Errors::AccountAlreadyExists.new(hash['id'], hash['descripcion']) if hash['id'] == 1 && hash['descripcion'] == 'Cuenta Duplicada'
  raise STP::Errors::STPError.new(hash['id'], hash['descripcion']) unless hash['id'] == 0
end

.delete(account) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/stp/account.rb', line 17

def self.delete()
  .signature = Crypto::Commons.rsa_seal(STP.private_key, STP.private_key_password, .original_chain)
  connection = Faraday.new(url: "#{STP.api_uri}/cuentaModule/fisica")
  response = connection.delete do |req|
    req.url ''
    req.headers['Content-Type'] = 'application/json'
    req.body = .to_json
  end
  puts response.body if STP.verbose
  hash = JSON.parse(response.body)
  raise STP::Errors::STPError.new(hash['id'], hash['descripcion']) unless hash['id'] == 0
end