Class: StarkBank::CorporateHolder
- Inherits:
-
StarkCore::Utils::Resource
- Object
- StarkCore::Utils::Resource
- StarkBank::CorporateHolder
- Defined in:
- lib/corporate_holder/corporateholder.rb,
lib/corporate_holder/log.rb,
lib/corporate_holder/permission.rb
Overview
# CorporateHolder object
The CorporateHolder describes a card holder that may group several cards.
When you initialize a CorporateHolder, the entity will not be automatically created in the Stark Bank API. The ‘create’ function sends the objects to the Stark Bank API and returns the created object.
## Parameters (required):
-
name [string]: card holder name. ex: “Tony Stark”
## Parameters (optional):
-
center_id [string, default nil]: target cost center ID. ex: “5656565656565656”
-
permissions [list of Permission objects, default nil]: list of Permission object representing access granted to an user for a particular cardholder.
-
rules [list of CorporateRule objects, default nil]: [EXPANDABLE] list of holder spending rules.
-
tags [list of strings, default nil]: list of strings for tagging. ex: [‘travel’, ‘food’]
## Attributes (return-only):
-
id [string]: unique id returned when CorporateHolder is created. ex: ‘5656565656565656’
-
status [string]: current CorporateHolder status. ex: ‘active’, ‘blocked’, ‘canceled’
-
updated [DateTime]: latest update datetime for the CorporateHolder. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
-
created [DateTime]: creation datetime for the log. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
Defined Under Namespace
Classes: Log, Permission
Instance Attribute Summary collapse
-
#center_id ⇒ Object
readonly
Returns the value of attribute center_id.
-
#created ⇒ Object
readonly
Returns the value of attribute created.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#permissions ⇒ Object
readonly
Returns the value of attribute permissions.
-
#rules ⇒ Object
readonly
Returns the value of attribute rules.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
-
#tags ⇒ Object
readonly
Returns the value of attribute tags.
-
#updated ⇒ Object
readonly
Returns the value of attribute updated.
Class Method Summary collapse
-
.cancel(id, user: nil) ⇒ Object
# Cancel a CorporateHolder entity.
-
.create(holders:, expand: nil, user: nil) ⇒ Object
# Create CorporateHolders.
-
.get(id, expand: nil, user: nil) ⇒ Object
# Retrieve a specific CorporateHolder.
-
.page(cursor: nil, limit: nil, ids: nil, after: nil, before: nil, status: nil, tags: nil, expand: nil, user: nil) ⇒ Object
# Retrieve paged CorporateHolders.
-
.query(limit: nil, ids: nil, after: nil, before: nil, status: nil, tags: nil, expand: nil, user: nil) ⇒ Object
# Retrieve CorporateHolders.
- .resource ⇒ Object
-
.update(id, center_id: nil, permissions: nil, status: nil, name: nil, tags: nil, rules: nil, user: nil) ⇒ Object
# Update CorporateHolder entity.
Instance Method Summary collapse
-
#initialize(name:, center_id: nil, permissions: nil, rules: nil, tags: nil, id: nil, status: nil, updated: nil, created: nil) ⇒ CorporateHolder
constructor
A new instance of CorporateHolder.
Constructor Details
#initialize(name:, center_id: nil, permissions: nil, rules: nil, tags: nil, id: nil, status: nil, updated: nil, created: nil) ⇒ CorporateHolder
Returns a new instance of CorporateHolder.
31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/corporate_holder/corporateholder.rb', line 31 def initialize( name:, center_id: nil, permissions: nil, rules: nil, tags: nil, id: nil, status: nil, updated: nil, created: nil ) super(id) @name = name @center_id = center_id @permissions = Permission.() @rules = StarkBank::CorporateRule.parse_rules(rules) @tags = @status = status @created = StarkCore::Utils::Checks.check_datetime(created) @updated = StarkCore::Utils::Checks.check_datetime(updated) end |
Instance Attribute Details
#center_id ⇒ Object (readonly)
Returns the value of attribute center_id.
30 31 32 |
# File 'lib/corporate_holder/corporateholder.rb', line 30 def center_id @center_id end |
#created ⇒ Object (readonly)
Returns the value of attribute created.
30 31 32 |
# File 'lib/corporate_holder/corporateholder.rb', line 30 def created @created end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
30 31 32 |
# File 'lib/corporate_holder/corporateholder.rb', line 30 def id @id end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
30 31 32 |
# File 'lib/corporate_holder/corporateholder.rb', line 30 def name @name end |
#permissions ⇒ Object (readonly)
Returns the value of attribute permissions.
30 31 32 |
# File 'lib/corporate_holder/corporateholder.rb', line 30 def @permissions end |
#rules ⇒ Object (readonly)
Returns the value of attribute rules.
30 31 32 |
# File 'lib/corporate_holder/corporateholder.rb', line 30 def rules @rules end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
30 31 32 |
# File 'lib/corporate_holder/corporateholder.rb', line 30 def status @status end |
#tags ⇒ Object (readonly)
Returns the value of attribute tags.
30 31 32 |
# File 'lib/corporate_holder/corporateholder.rb', line 30 def @tags end |
#updated ⇒ Object (readonly)
Returns the value of attribute updated.
30 31 32 |
# File 'lib/corporate_holder/corporateholder.rb', line 30 def updated @updated end |
Class Method Details
.cancel(id, user: nil) ⇒ Object
# Cancel a CorporateHolder entity
Cancel a CorporateHolder entity previously created in the Stark Bank API
## Parameters (required):
-
id [string]: CorporateHolder unique id. ex: ‘5656565656565656’
## Parameters (optional):
-
user [Organization/Project object, default nil]: Organization or Project object. Not necessary if StarkBank.user was set before function call
## Return:
-
canceled CorporateHolder object
192 193 194 |
# File 'lib/corporate_holder/corporateholder.rb', line 192 def self.cancel(id, user: nil) StarkBank::Utils::Rest.delete_id(id: id, user: user, **resource) end |
.create(holders:, expand: nil, user: nil) ⇒ Object
# Create CorporateHolders
Send a list of CorporateHolder objects for creation in the Stark Bank API
## Parameters (required):
-
holders [list of CorporateHolder objects]: list of CorporateHolder objects to be created in the API
## Parameters (optional):
-
expand [list of strings, default nil]: fields to expand information. Options: [‘rules’]
-
user [Organization/Project object, default nil]: Organization or Project object. Not necessary if StarkBank.user was set before function call
## Return:
-
list of CorporateHolder objects with updated attributes
58 59 60 |
# File 'lib/corporate_holder/corporateholder.rb', line 58 def self.create(holders:, expand: nil, user: nil) StarkBank::Utils::Rest.post(entities: holders, expand: , user: user, **resource) end |
.get(id, expand: nil, user: nil) ⇒ Object
# Retrieve a specific CorporateHolder
Receive a single CorporateHolder object previously created in the Stark Bank API by its id
## Parameters (required):
-
id [string]: object unique id. ex: ‘5656565656565656’
## Parameters (optional):
-
expand [list of strings, default nil]: fields to expand information. ex: [‘rules’]
-
user [Organization/Project object, default nil]: Organization or Project object. Not necessary if starkbank.user was set before function call
## Return:
-
CorporateHolder object with updated attributes
75 76 77 |
# File 'lib/corporate_holder/corporateholder.rb', line 75 def self.get(id, expand: nil, user: nil) StarkBank::Utils::Rest.get_id(id: id, expand: , user: user, **resource) end |
.page(cursor: nil, limit: nil, ids: nil, after: nil, before: nil, status: nil, tags: nil, expand: nil, user: nil) ⇒ Object
# Retrieve paged CorporateHolders
Receive a list of up to 100 CorporateHolders objects previously created in the Stark Bank API and the cursor to the next page. Use this function instead of query if you want to manually page your logs.
## Parameters (optional):
-
cursor [string, default nil]: cursor returned on the previous page function call.
-
limit [integer, default 100]: maximum number of objects to be retrieved. Max = 100. ex: 35
-
after [Date or string, default nil]: date filter for objects created only after specified date. ex: Date.new(2020, 3, 10)
-
before [Date or string, default nil]: date filter for objects created only before specified date. ex: Date.new(2020, 3, 10)
-
status [list of strings, default nil]: filter for status of retrieved objects. ex: [‘active’, ‘blocked’, ‘canceled’]
-
tags [list of strings, default nil]: tags to filter retrieved objects. ex: [‘tony’, ‘stark’]
-
expand [string, default nil]: fields to expand information. ex: [‘rules’]
-
ids [list of strings, default nil]: list of ids to filter retrieved objects. ex: [‘5656565656565656’, ‘4545454545454545’]
-
user [Organization/Project object, default nil]: Organization or Project object. Not necessary if starkbank.user was set before function call
## Return:
-
list of CorporateHolders objects with updated attributes
-
cursor to retrieve the next page of CorporateHolders objects
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 |
# File 'lib/corporate_holder/corporateholder.rb', line 130 def self.page(cursor: nil, limit: nil, ids: nil, after: nil, before: nil, status: nil, tags: nil, expand: nil, user: nil) after = StarkCore::Utils::Checks.check_date(after) before = StarkCore::Utils::Checks.check_date(before) StarkBank::Utils::Rest.get_page( cursor: cursor, limit: limit, ids: ids, after: after, before: before, status: status, tags: , expand: , user: user, **resource ) end |
.query(limit: nil, ids: nil, after: nil, before: nil, status: nil, tags: nil, expand: nil, user: nil) ⇒ Object
# Retrieve CorporateHolders
Receive a generator of CorporateHolder 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
-
after [Date or string, default nil]: date filter for objects created only after specified date. ex: Date.new(2020, 3, 10)
-
before [Date or string, default nil]: date filter for objects created only before specified date. ex: Date.new(2020, 3, 10)
-
status [list of strings, default nil]: filter for status of retrieved objects. ex: [‘active’, ‘blocked’, ‘canceled’]
-
tags [list of strings, default nil]: tags to filter retrieved objects. ex: [‘tony’, ‘stark’]
-
expand [string, default nil]: fields to expand information. ex: [‘rules’]
-
ids [list of strings, default nil]: list of ids to filter retrieved objects. ex: [‘5656565656565656’, ‘4545454545454545’]
-
user [Organization/Project object, default nil]: Organization or Project object. Not necessary if starkbank.user was set before function call
## Return:
-
generator of CorporateHolders objects with updated attributes
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/corporate_holder/corporateholder.rb', line 95 def self.query(limit: nil, ids: nil, after: nil, before: nil, status: nil, tags: nil, expand: nil, user: nil) after = StarkCore::Utils::Checks.check_date(after) before = StarkCore::Utils::Checks.check_date(before) StarkBank::Utils::Rest.get_stream( limit: limit, ids: ids, after: after, before: before, status: status, tags: , expand: , user: user, **resource ) end |
.resource ⇒ Object
196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 |
# File 'lib/corporate_holder/corporateholder.rb', line 196 def self.resource { resource_name: 'CorporateHolder', resource_maker: proc { |json| CorporateHolder.new( id: json['id'], name: json['name'], center_id: json['center_id'], permissions: json['permissions'], rules: json['rules'], tags: json['tags'], status: json['status'], updated: json['updated'], created: json['created'] ) } } end |
.update(id, center_id: nil, permissions: nil, status: nil, name: nil, tags: nil, rules: nil, user: nil) ⇒ Object
# Update CorporateHolder entity
Update a CorporateHolder by passing id.
## Parameters (required):
-
id [string]: CorporateHolder id. ex: ‘5656565656565656’
## Parameters (optional):
-
center_id [string, default nil]: target cost center ID. ex: “5656565656565656”
-
permissions [list of Permission object, default nil]: list of Permission object representing access granted to an user for a particular cardholder.
-
status [string, default nil]: You may block the CorporateHolder by passing ‘blocked’ in the status
-
name [string, default nil]: card holder name.
-
tags [list of strings, default nil]: list of strings for tagging
-
rules [list of CorporateRule objects, default nil]: list of objects that represent the holder’s spending rules.
-
user [Organization/Project object, default nil]: Organization or Project object. Not necessary if starkbank.user was set before function call
## Return:
-
target CorporateHolder with updated attributes
166 167 168 169 170 171 172 173 174 175 176 177 178 |
# File 'lib/corporate_holder/corporateholder.rb', line 166 def self.update(id, center_id: nil, permissions: nil, status: nil, name: nil, tags: nil, rules: nil, user: nil) StarkBank::Utils::Rest.patch_id( id: id, center_id: center_id, permissions: , status: status, name: name, tags: , rules: rules, user: user, **resource ) end |