Class: StarkBank::DictKey

Inherits:
Utils::Resource show all
Defined in:
lib/dict_key/dict_key.rb

Overview

# DictKey object

DictKey represents a PIX key registered in Bacen’s DICT system.

## Parameters (required):

  • id [string]: DictKey object unique id and PIX key itself. ex: ‘[email protected]’, ‘722.461.430-04’, ‘20.018.183/0001-80’, ‘+5511988887777’, ‘b6295ee1-f054-47d1-9e90-ee57b74f60d9’

## Attributes (return-only):

  • type [string, default nil]: DICT key type. ex: ‘email’, ‘cpf’, ‘cnpj’, ‘phone’ or ‘evp’

  • name [string, default nil]: account owner full name. ex: ‘Tony Stark’

  • tax_id [string, default nil]: key owner tax ID (CNPJ or masked CPF). ex: ‘*.345.678-’ or ‘20.018.183/0001-80’

  • owner_type [string, default nil]: DICT key owner type. ex ‘naturalPerson’ or ‘legalPerson’

  • ispb [string, default nil]: bank ISPB associated with the DICT key. ex: ‘20018183’

  • branch_code [string, default nil]: bank account branch code associated with the DICT key. ex: ‘9585’

  • account_number [string, default nil]: bank account number associated with the DICT key. ex: ‘9828282578010513’

  • account_type [string, default nil]: bank account type associated with the DICT key. ex: ‘checking’, ‘saving’ e ‘salary’

  • status [string, default nil]: current DICT key status. ex: ‘created’, ‘registered’, ‘canceled’ or ‘failed’

  • account_created [DateTime or string, default nil]: creation datetime of the bank account associated with the DICT key. ex: ‘2020-11-05T14:55:08.812665+00:00’

  • owned [DateTime or string, default nil]: datetime since when the current owner hold this DICT key. ex : ‘2020-11-05T14:55:08.812665+00:00’

  • created [DateTime or string, default nil]: creation datetime for the DICT key. ex: ‘2020-03-10 10:30:00.000’

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Utils::Resource

#inspect, #to_s

Constructor Details

#initialize(id:, type:, name:, tax_id:, owner_type:, ispb:, branch_code:, account_number:, account_type:, status:, account_created:, owned:, created:) ⇒ DictKey

Returns a new instance of DictKey.



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/dict_key/dict_key.rb', line 30

def initialize(
  id:, type:, name:, tax_id:, owner_type:, ispb:, branch_code:, account_number:, account_type:,
  status:, account_created:, owned:, created:
)
  super(id)
  @type = type
  @name = name
  @tax_id = tax_id
  @owner_type = owner_type
  @ispb = ispb
  @branch_code = branch_code
  @account_number = 
  @account_type = 
  @status = status
  @account_created = StarkBank::Utils::Checks.check_datetime()
  @owned = StarkBank::Utils::Checks.check_datetime(owned)
  @created = StarkBank::Utils::Checks.check_datetime(created)
end

Instance Attribute Details

#account_createdObject (readonly)

Returns the value of attribute account_created.



29
30
31
# File 'lib/dict_key/dict_key.rb', line 29

def 
  @account_created
end

#account_numberObject (readonly)

Returns the value of attribute account_number.



29
30
31
# File 'lib/dict_key/dict_key.rb', line 29

def 
  @account_number
end

#account_typeObject (readonly)

Returns the value of attribute account_type.



29
30
31
# File 'lib/dict_key/dict_key.rb', line 29

def 
  @account_type
end

#branch_codeObject (readonly)

Returns the value of attribute branch_code.



29
30
31
# File 'lib/dict_key/dict_key.rb', line 29

def branch_code
  @branch_code
end

#createdObject (readonly)

Returns the value of attribute created.



29
30
31
# File 'lib/dict_key/dict_key.rb', line 29

def created
  @created
end

#idObject (readonly)

Returns the value of attribute id.



29
30
31
# File 'lib/dict_key/dict_key.rb', line 29

def id
  @id
end

#ispbObject (readonly)

Returns the value of attribute ispb.



29
30
31
# File 'lib/dict_key/dict_key.rb', line 29

def ispb
  @ispb
end

#nameObject (readonly)

Returns the value of attribute name.



29
30
31
# File 'lib/dict_key/dict_key.rb', line 29

def name
  @name
end

#ownedObject (readonly)

Returns the value of attribute owned.



29
30
31
# File 'lib/dict_key/dict_key.rb', line 29

def owned
  @owned
end

#owner_typeObject (readonly)

Returns the value of attribute owner_type.



29
30
31
# File 'lib/dict_key/dict_key.rb', line 29

def owner_type
  @owner_type
end

#statusObject (readonly)

Returns the value of attribute status.



29
30
31
# File 'lib/dict_key/dict_key.rb', line 29

def status
  @status
end

#tax_idObject (readonly)

Returns the value of attribute tax_id.



29
30
31
# File 'lib/dict_key/dict_key.rb', line 29

def tax_id
  @tax_id
end

#typeObject (readonly)

Returns the value of attribute type.



29
30
31
# File 'lib/dict_key/dict_key.rb', line 29

def type
  @type
end

Class Method Details

.get(id, user: nil) ⇒ Object

# Retrieve a specific DictKey

Receive a single DictKey object by passing its id

## Parameters (required):

  • id [string]: DictKey object unique id and PIX key itself. ex: ‘[email protected]’, ‘722.461.430-04’, ‘20.018.183/0001-80’, ‘+5511988887777’, ‘b6295ee1-f054-47d1-9e90-ee57b74f60d9’

## Parameters (optional):

  • user [Organization/Project object]: Organization or Project object. Not necessary if StarkBank.user was set before function call

## Return:

  • DictKey object with updated attributes



61
62
63
# File 'lib/dict_key/dict_key.rb', line 61

def self.get(id, user: nil)
  StarkBank::Utils::Rest.get_id(id: id, user: user, **resource)
end

.query(limit: nil, type: nil, after: nil, before: nil, ids: nil, status: nil, user: nil) ⇒ Object

# Retrieve DitcKeys

Receive a generator of DitcKey objects previously created in the Stark Bank API

## Parameters (optional):

  • limit [integer, default nil]: maximum number of objects to be retrieved. Unlimited if nil. ex: 35

  • type [string, default nil]: DictKey type. ex: ‘cpf’, ‘cnpj’, ‘phone’, ‘email’ or ‘evp’

  • after [Date , DateTime, Time or string, default nil] date filter for objects created only after specified date. ex: Date.new(2020, 3, 10)

  • before [Date, DateTime, Time or string, default nil] date filter for objects created only before specified date. ex: Date.new(2020, 3, 10)

  • ids [list of strings, default nil]: list of ids to filter retrieved objects. ex: [‘5656565656565656’, ‘4545454545454545’]

  • status [string, default nil]: filter for status of retrieved objects. ex: ‘canceled’, ‘registered’

  • user [Organization/Project object]: Organization or Project object. Not necessary if Starkbank.user was set before function call

## Return:

  • generator of DitcKey objects with updated attributes



80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/dict_key/dict_key.rb', line 80

def self.query(limit: nil, type: nil, after: nil, before: nil, ids: nil, status: nil, user: nil)
  after = StarkBank::Utils::Checks.check_date(after)
  before = StarkBank::Utils::Checks.check_date(before)
  StarkBank::Utils::Rest.get_list(
    limit: limit,
    type: type,
    after: after,
    before: before,
    ids: ids,
    status: status,
    user: user,
    **resource
  )
end

.resourceObject



95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/dict_key/dict_key.rb', line 95

def self.resource
  {
    resource_name: 'DictKey',
    resource_maker: proc { |json|
      DictKey.new(
        id: json['id'],
        account_type: json['account_type'],
        name: json['name'],
        tax_id: json['tax_id'],
        owner_type: json['owner_type'],
        ispb: json['ispb'],
        branch_code: json['branch_code'],
        account_number: json['account_number'],
        type: json['type'],
        status: json['status'],
        account_created: json['account_created'],
        owned: json['owned'],
        created: json['created']
      )
    }
  }
end