Class: StarkBank::BoletoHolmes

Inherits:
Utils::Resource show all
Defined in:
lib/boleto_holmes/boleto_holmes.rb,
lib/boleto_holmes/log.rb

Overview

# BoletoHolmes object

When you initialize a BoletoHolmes, 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 list of created objects.

## Parameters (required):

  • boleto_id [string]: investigated boleto entity ID. ex: ‘5656565656565656’

## Parameters (optional):

  • tags [list of strings]: list of strings for tagging

## Attributes (return-only):

  • id [string, default nil]: unique id returned when holmes is created. ex: ‘5656565656565656’

  • status [string, default nil]: current holmes status. ex: ‘solving’ or ‘solved’

  • result [string, default nil]: result of boleto status investigation. ex: ‘paid’ or ‘cancelled’

  • created [DateTime, default nil]: creation datetime for the Boleto. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)

  • updated [DateTime, default nil]: latest update datetime for the holmes. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)

Defined Under Namespace

Classes: Log

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Utils::Resource

#inspect, #to_s

Constructor Details

#initialize(boleto_id:, tags: nil, id: nil, status: nil, result: nil, created: nil, updated: nil) ⇒ BoletoHolmes

Returns a new instance of BoletoHolmes.



28
29
30
31
32
33
34
35
36
37
38
# File 'lib/boleto_holmes/boleto_holmes.rb', line 28

def initialize(
  boleto_id:, tags: nil, id: nil, status: nil, result: nil, created: nil, updated: nil
)
  super(id)
  @boleto_id = boleto_id
  @tags = tags
  @status = status
  @result = result
  @created = StarkBank::Utils::Checks.check_datetime(created)
  @updated = StarkBank::Utils::Checks.check_datetime(updated)
end

Instance Attribute Details

#boleto_idObject (readonly)

Returns the value of attribute boleto_id.



27
28
29
# File 'lib/boleto_holmes/boleto_holmes.rb', line 27

def boleto_id
  @boleto_id
end

#createdObject (readonly)

Returns the value of attribute created.



27
28
29
# File 'lib/boleto_holmes/boleto_holmes.rb', line 27

def created
  @created
end

#idObject (readonly)

Returns the value of attribute id.



27
28
29
# File 'lib/boleto_holmes/boleto_holmes.rb', line 27

def id
  @id
end

#resultObject (readonly)

Returns the value of attribute result.



27
28
29
# File 'lib/boleto_holmes/boleto_holmes.rb', line 27

def result
  @result
end

#statusObject (readonly)

Returns the value of attribute status.



27
28
29
# File 'lib/boleto_holmes/boleto_holmes.rb', line 27

def status
  @status
end

#tagsObject (readonly)

Returns the value of attribute tags.



27
28
29
# File 'lib/boleto_holmes/boleto_holmes.rb', line 27

def tags
  @tags
end

#updatedObject (readonly)

Returns the value of attribute updated.



27
28
29
# File 'lib/boleto_holmes/boleto_holmes.rb', line 27

def updated
  @updated
end

Class Method Details

.create(holmes, user: nil) ⇒ Object

# Create BoletoHolmes

Send a list of BoletoHolmes objects for creation in the Stark Bank API

## Parameters (required):

  • holmes [list of BoletoHolmes objects]: list of BoletoHolmes objects to be created in the API

## Parameters (optional):

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

## Return:

  • list of BoletoHolmes objects with updated attributes



52
53
54
# File 'lib/boleto_holmes/boleto_holmes.rb', line 52

def self.create(holmes, user: nil)
  StarkBank::Utils::Rest.post(entities: holmes, user: user, **resource)
end

.get(id, user: nil) ⇒ Object

# Retrieve a specific BoletoHolmes

Receive a single BoletoHolmes object previously created by the Stark Bank API by passing its id

## Parameters (required):

  • id [string]: object unique id. ex: ‘5656565656565656’

## Parameters (optional):

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

## Return:

  • BoletoHolmes object with updated attributes



68
69
70
# File 'lib/boleto_holmes/boleto_holmes.rb', line 68

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

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

# Retrieve BoletoHolmes

Receive a generator of BoletoHolmes 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 , 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)

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

  • tags [list of strings, default nil]: tags to filter retrieved objects. ex: [‘tony’, ‘stark’]

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

  • boleto_id [string, default nil]: filter for holmes that investigate a specific boleto by its ID. ex: ‘5656565656565656’

  • user [Project object, default nil]: Project object. Not necessary if StarkBank.user was set before function call

## Return:

  • generator of BoletoHolmes objects with updated attributes



88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/boleto_holmes/boleto_holmes.rb', line 88

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

.resourceObject



104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'lib/boleto_holmes/boleto_holmes.rb', line 104

def self.resource
  {
    resource_name: 'BoletoHolmes',
    resource_maker: proc { |json|
      BoletoHolmes.new(
        boleto_id: json['boleto_id'],
        tags: json['tags'],
        id: json['id'],
        status: json['status'],
        result: json['result'],
        created: json['created'],
        updated: json['updated']
      )
    }
  }
end