starkinfra 0.1.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (72) hide show
  1. checksums.yaml +4 -4
  2. data/lib/brcodepreview/brcodepreview.rb +125 -0
  3. data/lib/cardmethod/cardmethod.rb +56 -0
  4. data/lib/creditholmes/creditholmes.rb +160 -0
  5. data/lib/creditnote/creditnote.rb +51 -355
  6. data/lib/creditnote/invoice/description.rb +51 -0
  7. data/lib/creditnote/invoice/discount.rb +49 -0
  8. data/lib/creditnote/invoice/invoice.rb +124 -0
  9. data/lib/creditnote/log.rb +18 -19
  10. data/lib/creditnote/transfer.rb +90 -0
  11. data/lib/creditpreview/creditnotepreview.rb +85 -0
  12. data/lib/creditpreview/creditpreview.rb +77 -0
  13. data/lib/creditsigner/creditsigner.rb +57 -0
  14. data/lib/dynamicbrcode/dynamicbrcode.rb +350 -0
  15. data/lib/event/attempt.rb +5 -4
  16. data/lib/event/event.rb +11 -11
  17. data/lib/individualdocument/individualdocument.rb +165 -0
  18. data/lib/individualdocument/log.rb +125 -0
  19. data/lib/individualidentity/individualidentity.rb +193 -0
  20. data/lib/individualidentity/log.rb +124 -0
  21. data/lib/issuingbalance/issuingbalance.rb +4 -4
  22. data/lib/issuingcard/issuingcard.rb +35 -33
  23. data/lib/issuingcard/log.rb +21 -21
  24. data/lib/issuingdesign/issuingdesign.rb +138 -0
  25. data/lib/issuingembossingkit/issuingembossingkit.rb +121 -0
  26. data/lib/issuingembossingrequest/issuingembossingrequest.rb +210 -0
  27. data/lib/issuingembossingrequest/log.rb +128 -0
  28. data/lib/issuingholder/issuingholder.rb +21 -15
  29. data/lib/issuingholder/log.rb +19 -19
  30. data/lib/issuinginvoice/issuinginvoice.rb +29 -14
  31. data/lib/issuinginvoice/log.rb +18 -18
  32. data/lib/{issuingbin/issuingbin.rb → issuingproduct/issuingproduct.rb} +27 -30
  33. data/lib/issuingpurchase/issuingpurchase.rb +111 -31
  34. data/lib/issuingpurchase/log.rb +16 -16
  35. data/lib/issuingrestock/issuingrestock.rb +162 -0
  36. data/lib/issuingrestock/log.rb +127 -0
  37. data/lib/issuingrule/issuingrule.rb +64 -18
  38. data/lib/issuingstock/issuingstock.rb +138 -0
  39. data/lib/issuingstock/log.rb +130 -0
  40. data/lib/issuingtransaction/issuingtransaction.rb +12 -13
  41. data/lib/issuingwithdrawal/issuingwithdrawal.rb +12 -11
  42. data/lib/merchantcategory/merchantcategory.rb +63 -0
  43. data/lib/merchantcountry/merchantcountry.rb +59 -0
  44. data/lib/pixbalance/pixbalance.rb +5 -5
  45. data/lib/pixchargeback/log.rb +15 -15
  46. data/lib/pixchargeback/pixchargeback.rb +32 -20
  47. data/lib/pixclaim/log.rb +21 -24
  48. data/lib/pixclaim/pixclaim.rb +44 -34
  49. data/lib/pixdirector/pixdirector.rb +9 -11
  50. data/lib/pixdomain/certificate.rb +1 -1
  51. data/lib/pixdomain/pixdomain.rb +5 -5
  52. data/lib/pixinfraction/log.rb +20 -20
  53. data/lib/pixinfraction/pixinfraction.rb +23 -15
  54. data/lib/pixkey/log.rb +23 -23
  55. data/lib/pixkey/pixkey.rb +14 -12
  56. data/lib/pixrequest/log.rb +24 -20
  57. data/lib/pixrequest/pixrequest.rb +54 -21
  58. data/lib/pixreversal/log.rb +3 -3
  59. data/lib/pixreversal/pixreversal.rb +48 -21
  60. data/lib/pixstatement/pixstatement.rb +13 -8
  61. data/lib/starkinfra.rb +40 -15
  62. data/lib/staticbrcode/staticbrcode.rb +170 -0
  63. data/lib/user/project.rb +1 -1
  64. data/lib/utils/api.rb +1 -0
  65. data/lib/utils/bacenid.rb +1 -1
  66. data/lib/utils/parse.rb +7 -3
  67. data/lib/utils/request.rb +1 -1
  68. data/lib/utils/resource.rb +1 -1
  69. data/lib/utils/sub_resource.rb +21 -22
  70. data/lib/webhook/webhook.rb +11 -11
  71. metadata +29 -4
  72. data/lib/issuingauthorization/issuingauthorization.rb +0 -141
@@ -0,0 +1,127 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative('IssuingRestock')
4
+ require_relative('../utils/rest')
5
+ require_relative('../utils/checks')
6
+ require_relative('../utils/resource')
7
+
8
+ module StarkInfra
9
+ class IssuingRestock
10
+ # # IssuingRestock::Log object
11
+ #
12
+ # Every time an IssuingRestock entity is updated, a corresponding IssuingRestock::Log is generated for the entity. This log
13
+ # is never generated by the user, but it can be retrieved to check additional information on the IssuingRestock.
14
+ #
15
+ # ## Attributes (return-only):
16
+ # - id [string]: unique id returned when the log is created. ex: '5656565656565656'
17
+ # - restock [IssuingRestock]: IssuingRestock entity to which the log refers to.
18
+ # - type [string]: type of the IssuingRestock event which triggered the log creation. ex: "created", "processing", "confirmed"
19
+ # - created [DateTime]: creation datetime for the log. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
20
+ class Log < StarkInfra::Utils::Resource
21
+ attr_reader :id, :restock, :type, :created
22
+ def initialize(id: nil, restock: nil, type: nil, created: nil)
23
+ super(id)
24
+ @restock = restock
25
+ @type = type
26
+ @created = StarkInfra::Utils::Checks.check_datetime(created)
27
+ end
28
+
29
+ # # Retrieve a specific IssuingRestock::Log
30
+ #
31
+ # Receive a single IssuingRestock::Log object previously created by the Stark Infra API by passing its id
32
+ #
33
+ # ## Parameters (required):
34
+ # - id [string]: object unique id. ex: '5656565656565656'
35
+ #
36
+ # ## Parameters (optional):
37
+ # - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if StarkInfra.user was set before function call
38
+ #
39
+ # ## Return:
40
+ # - IssuingRestock::Log object with updated attributes
41
+ def self.get(id, user: nil)
42
+ StarkInfra::Utils::Rest.get_id(id: id, user: user, **resource)
43
+ end
44
+
45
+ # # Retrieve IssuingRestock::Logs
46
+ #
47
+ # Receive a generator of IssuingRestock::Log objects previously created in the Stark Infra API
48
+ #
49
+ # ## Parameters (optional):
50
+ # - limit [integer, default nil]: maximum number of objects to be retrieved. Unlimited if nil. ex: 35
51
+ # - after [Date or string, default nil]: date filter for objects created only after specified date. ex: Date.new(2020, 3, 10)
52
+ # - before [Date or string, default nil]: date filter for objects created only before specified date. ex: Date.new(2020, 3, 10)
53
+ # - types [list of strings, default nil]: filter for log event types. ex: ["created", "processing", "confirmed"]
54
+ # - restock_ids [list of strings, default nil]: list of IssuingRestock ids to filter logs. ex: ['5656565656565656', '4545454545454545']
55
+ # - ids [list of strings, default nil]: list of ids to filter retrieved objects. ex: ['5656565656565656', '4545454545454545']
56
+ # - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if starkinfra.user was set before function call
57
+ #
58
+ # ## Return:
59
+ # - generator of IssuingRestock::Log objects with updated attributes
60
+ def self.query(
61
+ limit: nil, after: nil, before: nil, types: nil, restock_ids: nil, ids: nil, user: nil
62
+ )
63
+ after = StarkInfra::Utils::Checks.check_date(after)
64
+ before = StarkInfra::Utils::Checks.check_date(before)
65
+ StarkInfra::Utils::Rest.get_stream(
66
+ limit: limit,
67
+ after: after,
68
+ before: before,
69
+ types: types,
70
+ restock_ids: restock_ids,
71
+ ids: ids,
72
+ user: user,
73
+ **resource
74
+ )
75
+ end
76
+
77
+ # # Retrieve paged IssuingRestock::Logs
78
+ #
79
+ # Receive a list of up to 100 IssuingRestock::Log objects previously created in the Stark Infra API and the cursor to the next page.
80
+ # Use this function instead of query if you want to manually page your logs.
81
+ #
82
+ # ## Parameters (optional):
83
+ # - cursor [string, default nil]: cursor returned on the previous page function call
84
+ # - limit [integer, default 100]: maximum number of objects to be retrieved. Max = 100. ex: 35
85
+ # - after [Date or string, default nil]: date filter for objects created only after specified date. ex: Date.new(2020, 3, 10)
86
+ # - before [Date or string, default nil]: date filter for objects created only before specified date. ex: Date.new(2020, 3, 10)
87
+ # - types [list of strings, default nil]: filter for log event types. ex: ["created", "processing", "confirmed"]
88
+ # - restock_ids [list of strings, default nil]: list of IssuingRestock ids to filter logs. ex: ['5656565656565656', '4545454545454545']
89
+ # - ids [list of strings, default nil]: list of ids to filter retrieved objects. ex: ['5656565656565656', '4545454545454545']
90
+ # - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if starkinfra.user was set before function call
91
+ #
92
+ # ## Return:
93
+ # - list of IssuingRestock::Log objects with updated attributes
94
+ # - Cursor to retrieve the next page of Log objects
95
+ def self.page(cursor: nil, limit: nil, after: nil, before: nil, types: nil, restock_ids: nil, ids: nil, user: nil)
96
+ after = StarkInfra::Utils::Checks.check_date(after)
97
+ before = StarkInfra::Utils::Checks.check_date(before)
98
+ StarkInfra::Utils::Rest.get_page(
99
+ cursor: cursor,
100
+ limit: limit,
101
+ after: after,
102
+ before: before,
103
+ types: types,
104
+ restock_ids: restock_ids,
105
+ ids: ids,
106
+ user: user,
107
+ **resource
108
+ )
109
+ end
110
+
111
+ def self.resource
112
+ request_maker = StarkInfra::IssuingRestock.resource[:resource_maker]
113
+ {
114
+ resource_name: 'IssuingRestockLog',
115
+ resource_maker: proc { |json|
116
+ Log.new(
117
+ id: json['id'],
118
+ restock: StarkInfra::Utils::API.from_api_json(request_maker, json['restock']),
119
+ type: json['type'],
120
+ created: json['created']
121
+ )
122
+ }
123
+ }
124
+ end
125
+ end
126
+ end
127
+ end
@@ -1,8 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative('../utils/resource')
4
3
  require_relative('../utils/rest')
5
4
  require_relative('../utils/checks')
5
+ require_relative('../utils/resource')
6
6
 
7
7
  module StarkInfra
8
8
  # # IssuingRule object
@@ -12,33 +12,79 @@ module StarkInfra
12
12
  # ## Parameters (required):
13
13
  # - name [string]: rule name. ex: 'Travel' or 'Food'
14
14
  # - amount [integer]: maximum amount that can be spent in the informed interval. ex: 200000 (= R$ 2000.00)
15
+ #
15
16
  # ## Parameters (optional):
16
- # - id [string, default nil]: unique id returned when Rule is created. ex: '5656565656565656'
17
+ # - id [string, default nil]: unique id returned when an IssuingRule is created, used to update a specific IssuingRule. ex: '5656565656565656'
17
18
  # - interval [string, default 'lifetime']: interval after which the rule amount counter will be reset to 0. ex: 'instant', 'day', 'week', 'month', 'year' or 'lifetime'
18
19
  # - currency_code [string, default 'BRL']: code of the currency that the rule amount refers to. ex: 'BRL' or 'USD'
19
- # - categories [list of strings, default []]: merchant categories accepted by the rule. ex: ['eatingPlacesRestaurants', 'travelAgenciesTourOperators']
20
- # - countries [list of strings, default []]: countries accepted by the rule. ex: ['BRA', 'USA']
21
- # - methods [list of strings, default []]: card purchase methods accepted by the rule. ex: ['chip', 'token', 'server', 'manual', 'magstripe', 'contactless']
20
+ # - categories [list of MerchantCategories, default nil]: merchant categories accepted by the rule. ex: [MerchantCategory(code='fastFoodRestaurants')]
21
+ # - countries [list of MerchantCountries, default nil]: countries accepted by the rule. ex: [MerchantCountry(code='BRA')]
22
+ # - methods [list of CardMethods, default nil]: card purchase methods accepted by the rule. ex: [CardMethod(code='magstripe')]
23
+ #
22
24
  # ## Attributes (expanded return-only):
23
25
  # - counter_amount [integer]: current rule spent amount. ex: 1000
24
26
  # - currency_symbol [string]: currency symbol. ex: 'R$'
25
27
  # - currency_name [string]: currency name. ex: 'Brazilian Real'
26
28
  class IssuingRule < StarkInfra::Utils::Resource
27
- attr_reader :name, :interval, :amount, :currency_code, :counter_amount, :currency_name, :currency_symbol, :categories, :countries, :methods
28
- def initialize(name:, amount:, id: nil, interval: nil, currency_code: nil, counter_amount: nil, currency_name: nil,
29
- currency_symbol: nil, categories: nil, countries: nil, methods: nil
29
+ attr_reader :name, :interval, :amount, :currency_code, :counter_amount, :currency_name, :currency_symbol,
30
+ :categories, :countries, :methods
31
+ def initialize(
32
+ name:, amount:, id: nil, interval: nil, currency_code: nil, categories: nil, countries: nil, methods: nil,
33
+ counter_amount: nil, currency_symbol: nil, currency_name: nil
30
34
  )
31
35
  super(id)
32
36
  @name = name
33
- @interval = interval
34
37
  @amount = amount
38
+ @interval = interval
35
39
  @currency_code = currency_code
40
+ @categories = IssuingRule.parse_categories(categories)
41
+ @countries = IssuingRule.parse_categories(countries)
42
+ @methods = IssuingRule.parse_categories(methods)
36
43
  @counter_amount = counter_amount
37
- @currency_name = currency_name
38
44
  @currency_symbol = currency_symbol
39
- @categories = categories
40
- @countries = countries
41
- @methods = methods
45
+ @currency_name = currency_name
46
+ end
47
+
48
+ def self.parse_categories(categories)
49
+ resource_maker = StarkInfra::MerchantCategory.resource[:resource_maker]
50
+ return categories if categories.nil?
51
+
52
+ parsed_categories = []
53
+ categories.each do |category|
54
+ unless category.is_a? MerchantCategory
55
+ category = StarkInfra::Utils::API.from_api_json(resource_maker, category)
56
+ end
57
+ parsed_categories << category
58
+ end
59
+ parsed_categories
60
+ end
61
+
62
+ def self.parse_countries(countries)
63
+ resource_maker = StarkInfra::MerchantCountry.resource[:resource_maker]
64
+ return countries if countries.nil?
65
+
66
+ parsed_countries = []
67
+ countries.each do |country|
68
+ unless country.is_a? MerchantCountry
69
+ country = StarkInfra::Utils::API.from_api_json(resource_maker, country)
70
+ end
71
+ parsed_countries << country
72
+ end
73
+ parsed_countries
74
+ end
75
+
76
+ def self.parse_methods(methods)
77
+ resource_maker = StarkInfra::CardMethod.resource[:resource_maker]
78
+ return methods if methods.nil?
79
+
80
+ parsed_methods = []
81
+ methods.each do |method|
82
+ unless method.is_a? CardMethod
83
+ method = StarkInfra::Utils::API.from_api_json(resource_maker, method)
84
+ end
85
+ parsed_methods << method
86
+ end
87
+ parsed_methods
42
88
  end
43
89
 
44
90
  def self.parse_rules(rules)
@@ -61,15 +107,15 @@ module StarkInfra
61
107
  resource_maker: proc { |json|
62
108
  IssuingRule.new(
63
109
  name: json['name'],
64
- interval: json['interval'],
65
110
  amount: json['amount'],
111
+ interval: json['interval'],
66
112
  currency_code: json['currency_code'],
67
- counter_amount: json['counter_amount'],
68
- currency_name: json['currency_name'],
69
- currency_symbol: json['currency_symbol'],
70
113
  categories: json['categories'],
71
114
  countries: json['countries'],
72
- methods: json['methods']
115
+ methods: json['methods'],
116
+ counter_amount: json['counter_amount'],
117
+ currency_symbol: json['currency_symbol'],
118
+ currency_name: json['currency_name']
73
119
  )
74
120
  }
75
121
  }
@@ -0,0 +1,138 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative('../utils/rest')
4
+ require_relative('../utils/checks')
5
+ require_relative('../utils/resource')
6
+
7
+ module StarkInfra
8
+ # # IssuingStock object
9
+ #
10
+ # The IssuingStock object represents the current stock of a certain IssuingDesign linked to an Embosser available to your workspace.
11
+ #
12
+ # ## Attributes (return-only):
13
+ # - id [string]: unique id returned when IssuingStock is created. ex: "5656565656565656"
14
+ # - balance [integer]: [EXPANDABLE] current stock balance. ex: 1000
15
+ # - design_id [string]: IssuingDesign unique id. ex: "5656565656565656"
16
+ # - embosser_id [string]: Embosser unique id. ex: "5656565656565656"
17
+ # - updated [DateTime]: latest update datetime for the IssuingStock. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
18
+ # - created [DateTime]: creation datetime for the IssuingStock. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
19
+ class IssuingStock < StarkInfra::Utils::Resource
20
+ attr_reader :id, :balance, :design_id, :embosser_id, :updated, :created
21
+ def initialize(
22
+ id: nil, balance: nil, design_id: nil, embosser_id: nil, updated: nil, created: nil
23
+ )
24
+ super(id)
25
+ @balance = balance
26
+ @design_id = design_id
27
+ @embosser_id = embosser_id
28
+ @updated = StarkInfra::Utils::Checks.check_datetime(updated)
29
+ @created = StarkInfra::Utils::Checks.check_datetime(created)
30
+ end
31
+
32
+ # # Retrieve a specific IssuingStock
33
+ #
34
+ # Receive a single IssuingStock object previously created in the Stark Infra API by its id
35
+ #
36
+ # ## Parameters (required):
37
+ # - id [string]: object unique id. ex: '5656565656565656'
38
+ #
39
+ # ## Parameters (optional):
40
+ # - expand [list of strings, default nil]: fields to expand information. ex: ['balance']
41
+ # - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if StarkInfra.user was set before function call
42
+ #
43
+ # ## Return:
44
+ # - IssuingStock object with updated attributes
45
+ def self.get(id, expand: nil, user: nil)
46
+ StarkInfra::Utils::Rest.get_id(id: id, expand: expand, user: user, **resource)
47
+ end
48
+
49
+ # # Retrieve IssuingStocks
50
+ #
51
+ # Receive a generator of IssuingStocks objects previously created in the Stark Infra API
52
+ #
53
+ # ## Parameters (optional):
54
+ # - limit [integer, default nil]: maximum number of objects to be retrieved. Unlimited if nil. ex: 35
55
+ # - after [Date or string, default nil]: date filter for objects created only after specified date. ex: Date.new(2020, 3, 10)
56
+ # - before [Date or string, default nil]: date filter for objects created only before specified date. ex: Date.new(2020, 3, 10)
57
+ # - design_ids [list of strings, default nil]: IssuingDesign unique ids. ex: ["5656565656565656", "4545454545454545"]
58
+ # - embosser_ids [list of strings, default nil]: Embosser unique ids. ex: ["5656565656565656", "4545454545454545"]
59
+ # - ids [list of strings, default nil]: list of ids to filter retrieved objects. ex: ["5656565656565656", "4545454545454545"]
60
+ # - expand [list of strings, default []]: fields to expand information. ex: ["balance"]
61
+ # - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if StarkInfra.user was set before function call
62
+ #
63
+ # ## Return:
64
+ # - generator of IssuingStocks objects with updated attributes
65
+ def self.query(
66
+ limit: nil, after: nil, before: nil, design_ids: nil, embosser_ids: nil, ids: nil, expand: nil, user: nil
67
+ )
68
+ after = StarkInfra::Utils::Checks.check_date(after)
69
+ before = StarkInfra::Utils::Checks.check_date(before)
70
+ StarkInfra::Utils::Rest.get_stream(
71
+ limit: limit,
72
+ after: after,
73
+ before: before,
74
+ design_ids: design_ids,
75
+ embosser_ids: embosser_ids,
76
+ ids: ids,
77
+ expand: expand,
78
+ user: user,
79
+ **resource
80
+ )
81
+ end
82
+
83
+ # # Retrieve paged IssuingStocks
84
+ #
85
+ # Receive a list of up to 100 IssuingStock objects previously created in the Stark Infra API and the cursor to the next page.
86
+ # Use this function instead of query if you want to manually page your requests.
87
+ #
88
+ # ## Parameters (optional):
89
+ # - cursor [string, default nil]: cursor returned on the previous page function call.
90
+ # - limit [integer, default 100]: maximum number of objects to be retrieved. Max = 100. ex: 35
91
+ # - after [Date or string, default nil]: date filter for objects created only after specified date. ex: Date.new(2020, 3, 10)
92
+ # - before [Date or string, default nil]: date filter for objects created only before specified date. ex: Date.new(2020, 3, 10)
93
+ # - design_ids [list of strings, default nil]: IssuingDesign unique ids. ex: ["5656565656565656", "4545454545454545"]
94
+ # - embosser_ids [list of strings, default nil]: Embosser unique ids. ex: ["5656565656565656", "4545454545454545"]
95
+ # - ids [list of strings, default nil]: list of ids to filter retrieved objects. ex: ["5656565656565656", "4545454545454545"]
96
+ # - expand [list of strings, default []]: fields to expand information. ex: ["balance"]
97
+ # - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if StarkInfra.user was set before function call
98
+ #
99
+ # ## Return:
100
+ # - list of IssuingStocks objects with updated attributes
101
+ # - cursor to retrieve the next page of IssuingStocks objects
102
+ def self.page(
103
+ cursor: nil, limit: nil, after: nil, before: nil, design_ids: nil, embosser_ids: nil,
104
+ ids: nil, expand: nil, user: nil
105
+ )
106
+ after = StarkInfra::Utils::Checks.check_date(after)
107
+ before = StarkInfra::Utils::Checks.check_date(before)
108
+ StarkInfra::Utils::Rest.get_page(
109
+ cursor: cursor,
110
+ limit: limit,
111
+ after: after,
112
+ before: before,
113
+ design_ids: design_ids,
114
+ embosser_ids: embosser_ids,
115
+ ids: ids,
116
+ expand: expand,
117
+ user: user,
118
+ **resource
119
+ )
120
+ end
121
+
122
+ def self.resource
123
+ {
124
+ resource_name: 'IssuingStock',
125
+ resource_maker: proc { |json|
126
+ IssuingStock.new(
127
+ id: json['id'],
128
+ balance: json['balance'],
129
+ design_id: json['design_id'],
130
+ embosser_id: json['embosser_id'],
131
+ updated: json['updated'],
132
+ created: json['created']
133
+ )
134
+ }
135
+ }
136
+ end
137
+ end
138
+ end
@@ -0,0 +1,130 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative('IssuingStock')
4
+ require_relative('../utils/rest')
5
+ require_relative('../utils/checks')
6
+ require_relative('../utils/resource')
7
+
8
+ module StarkInfra
9
+ class IssuingStock
10
+ # # IssuingStock::Log object
11
+ #
12
+ # Every time an IssuingStock entity is updated, a corresponding IssuingStock::Log is generated for the entity. This log
13
+ # is never generated by the user, but it can be retrieved to check additional information on the IssuingStock.
14
+ #
15
+ # ## Attributes (return-only):
16
+ # - id [string]: unique id returned when the log is created. ex: '5656565656565656'
17
+ # - stock [IssuingStock]: IssuingStock entity to which the log refers to.
18
+ # - type [string]: type of the IssuingStock event which triggered the log creation. ex: "created", "spent", "restocked", "lost"
19
+ # - count [integer]: shift in stock balance. ex: 10
20
+ # - created [DateTime]: creation datetime for the log. ex: DateTime.new(2020, 3, 10, 10, 30, 0, 0)
21
+ class Log < StarkInfra::Utils::Resource
22
+ attr_reader :id, :stock, :type, :count, :created
23
+ def initialize(id: nil, stock: nil, type: nil, count: nil, created: nil)
24
+ super(id)
25
+ @stock = stock
26
+ @type = type
27
+ @count = count
28
+ @created = StarkInfra::Utils::Checks.check_datetime(created)
29
+ end
30
+
31
+ # # Retrieve a specific IssuingStock::Log
32
+ #
33
+ # Receive a single IssuingStock::Log object previously created by the Stark Infra API by passing its id
34
+ #
35
+ # ## Parameters (required):
36
+ # - id [string]: object unique id. ex: '5656565656565656'
37
+ #
38
+ # ## Parameters (optional):
39
+ # - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if StarkInfra.user was set before function call
40
+ #
41
+ # ## Return:
42
+ # - IssuingStock::Log object with updated attributes
43
+ def self.get(id, user: nil)
44
+ StarkInfra::Utils::Rest.get_id(id: id, user: user, **resource)
45
+ end
46
+
47
+ # # Retrieve IssuingStock::Logs
48
+ #
49
+ # Receive a generator of IssuingStock::Log objects previously created in the Stark Infra API
50
+ #
51
+ # ## Parameters (optional):
52
+ # - limit [integer, default nil]: maximum number of objects to be retrieved. Unlimited if nil. ex: 35
53
+ # - after [Date or string, default nil]: date filter for objects created only after specified date. ex: Date.new(2020, 3, 10)
54
+ # - before [Date or string, default nil]: date filter for objects created only before specified date. ex: Date.new(2020, 3, 10)
55
+ # - types [list of strings, default nil]: filter for log event types. ex: ["created", "spent", "restocked", "lost"]
56
+ # - stock_ids [list of strings, default nil]: list of IssuingStock ids to filter logs. ex: ['5656565656565656', '4545454545454545']
57
+ # - ids [list of strings, default nil]: list of ids to filter retrieved objects. ex: ['5656565656565656', '4545454545454545']
58
+ # - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if starkinfra.user was set before function call
59
+ #
60
+ # ## Return:
61
+ # - generator of IssuingStock::Log objects with updated attributes
62
+ def self.query(limit: nil, after: nil, before: nil, types: nil, stock_ids: nil, ids: nil, user: nil)
63
+ after = StarkInfra::Utils::Checks.check_date(after)
64
+ before = StarkInfra::Utils::Checks.check_date(before)
65
+ StarkInfra::Utils::Rest.get_stream(
66
+ limit: limit,
67
+ after: after,
68
+ before: before,
69
+ types: types,
70
+ stock_ids: stock_ids,
71
+ ids: ids,
72
+ user: user,
73
+ **resource
74
+ )
75
+ end
76
+
77
+ # # Retrieve paged IssuingStock::Logs
78
+ #
79
+ # Receive a list of up to 100 IssuingStock::Log objects previously created in the Stark Infra API and the cursor to the next page.
80
+ # Use this function instead of query if you want to manually page your logs.
81
+ #
82
+ # ## Parameters (optional):
83
+ # - cursor [string, default nil]: cursor returned on the previous page function call
84
+ # - limit [integer, default 100]: maximum number of objects to be retrieved. Max = 100. ex: 35
85
+ # - after [Date or string, default nil]: date filter for objects created only after specified date. ex: Date.new(2020, 3, 10)
86
+ # - before [Date or string, default nil]: date filter for objects created only before specified date. ex: Date.new(2020, 3, 10)
87
+ # - types [list of strings, default nil]: filter for log event types. ex: ["created", "spent", "restocked", "lost"]
88
+ # - stock_ids [list of strings, default nil]: list of IssuingStock ids to filter logs. ex: ['5656565656565656', '4545454545454545']
89
+ # - ids [list of strings, default nil]: list of ids to filter retrieved objects. ex: ['5656565656565656', '4545454545454545']
90
+ # - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if starkinfra.user was set before function call
91
+ #
92
+ # ## Return:
93
+ # - list of IssuingStock::Log objects with updated attributes
94
+ # - Cursor to retrieve the next page of Log objects
95
+ def self.page(
96
+ cursor: nil, limit: nil, after: nil, before: nil, types: nil, stock_ids: nil, ids: nil, user: nil
97
+ )
98
+ after = StarkInfra::Utils::Checks.check_date(after)
99
+ before = StarkInfra::Utils::Checks.check_date(before)
100
+ StarkInfra::Utils::Rest.get_page(
101
+ cursor: cursor,
102
+ limit: limit,
103
+ after: after,
104
+ before: before,
105
+ types: types,
106
+ stock_ids: stock_ids,
107
+ ids: ids,
108
+ user: user,
109
+ **resource
110
+ )
111
+ end
112
+
113
+ def self.resource
114
+ request_maker = StarkInfra::IssuingStock.resource[:resource_maker]
115
+ {
116
+ resource_name: 'IssuingStockLog',
117
+ resource_maker: proc { |json|
118
+ Log.new(
119
+ id: json['id'],
120
+ stock: StarkInfra::Utils::API.from_api_json(request_maker, json['stock']),
121
+ type: json['type'],
122
+ count: json['count'],
123
+ created: json['created']
124
+ )
125
+ }
126
+ }
127
+ end
128
+ end
129
+ end
130
+ end
@@ -1,8 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative('../utils/resource')
4
3
  require_relative('../utils/rest')
5
4
  require_relative('../utils/checks')
5
+ require_relative('../utils/resource')
6
6
 
7
7
  module StarkInfra
8
8
  # # IssuingTransaction object
@@ -20,9 +20,7 @@ module StarkInfra
20
20
  class IssuingTransaction < StarkInfra::Utils::Resource
21
21
  attr_reader :id, :amount, :balance, :description, :source, :tags, :created
22
22
 
23
- def initialize(
24
- id: nil, amount: nil, balance: nil, description: nil, source: nil, tags: nil, created: nil
25
- )
23
+ def initialize(id: nil, amount: nil, balance: nil, description: nil, source: nil, tags: nil, created: nil)
26
24
  super(id)
27
25
  @amount = amount
28
26
  @balance = balance
@@ -54,11 +52,11 @@ module StarkInfra
54
52
  #
55
53
  # ## Parameters (optional):
56
54
  # - tags [list of strings, default nil]: tags to filter retrieved objects. ex: ['tony', 'stark']
57
- # - external_ids [list of strings, default []]: external IDs. ex: ['5656565656565656', '4545454545454545']
58
- # - after [Date or string, default nil] date filter for objects created only after specified date. ex: Date.new(2020, 3, 10)
59
- # - before [Date or string, default nil] date filter for objects created only before specified date. ex: Date.new(2020, 3, 10)
55
+ # - external_ids [list of strings, default nil]: external IDs. ex: ['5656565656565656', '4545454545454545']
56
+ # - after [Date or string, default nil]: date filter for objects created only after specified date. ex: Date.new(2020, 3, 10)
57
+ # - before [Date or string, default nil]: date filter for objects created only before specified date. ex: Date.new(2020, 3, 10)
60
58
  # - status [string, default nil]: filter for status of retrieved objects. ex: 'approved', 'canceled', 'denied', 'confirmed' or 'voided'
61
- # - ids [list of strings, default [], default nil]: purchase IDs
59
+ # - ids [list of strings, default nil]: purchase IDs
62
60
  # - limit [integer, default nil]: maximum number of objects to be retrieved. Unlimited if nil. ex: 35
63
61
  # - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if starkinfra.user was set before function call
64
62
  #
@@ -82,17 +80,18 @@ module StarkInfra
82
80
 
83
81
  # # Retrieve paged IssuingTransactions
84
82
  #
85
- # Receive a list of IssuingTransaction objects previously created in the Stark Infra API and the cursor to the next page.
83
+ # Receive a list of up to 100 IssuingTransaction objects previously created in the Stark Infra API and the cursor to the next page.
84
+ # Use this function instead of query if you want to manually page your requests.
86
85
  #
87
86
  # ## Parameters (optional):
88
87
  # - cursor [string, default nil]: cursor returned on the previous page function call.
88
+ # - limit [integer, default 100]: maximum number of objects to be retrieved. Max = 100. ex: 35
89
+ # - after [Date or string, default nil]: date filter for objects created only after specified date. ex: Date.new(2020, 3, 10)
90
+ # - before [Date or string, default nil]: date filter for objects created only before specified date. ex: Date.new(2020, 3, 10)
89
91
  # - tags [list of strings, default nil]: tags to filter retrieved objects. ex: ['tony', 'stark']
90
- # - external_ids [list of strings, default nil: external IDs. ex: ['5656565656565656', '4545454545454545']
91
- # - after [Date or string, default nil] date filter for objects created only after specified date. ex: Date.new(2020, 3, 10)
92
- # - before [Date or string, default nil] date filter for objects created only before specified date. ex: Date.new(2020, 3, 10)
92
+ # - external_ids [list of strings, default nil]: external IDs. ex: ['5656565656565656', '4545454545454545']
93
93
  # - status [string, default nil]: filter for status of retrieved objects. ex: 'approved', 'canceled', 'denied', 'confirmed' or 'voided'
94
94
  # - ids [list of strings, default nil]: purchase IDs
95
- # - limit [integer, default 100]: maximum number of objects to be retrieved. Max = 100. ex: 35
96
95
  # - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if starkinfra.user was set before function call
97
96
  #
98
97
  # ## Return:
@@ -1,8 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative('../utils/resource')
4
3
  require_relative('../utils/rest')
5
4
  require_relative('../utils/checks')
5
+ require_relative('../utils/resource')
6
6
 
7
7
  module StarkInfra
8
8
  # # IssuingWithdrawal object
@@ -15,7 +15,7 @@ module StarkInfra
15
15
  # - description [string]: IssuingWithdrawal description. ex: 'sending money back'
16
16
  #
17
17
  # ## Parameters (optional):
18
- # - tags [list of strings, default []]: list of strings for tagging. ex: ['tony', 'stark']
18
+ # - tags [list of strings, default nil]: list of strings for tagging. ex: ['tony', 'stark']
19
19
  #
20
20
  # ## Attributes (return-only):
21
21
  # - id [string]: unique id returned when IssuingWithdrawal is created. ex: '5656565656565656'
@@ -36,8 +36,8 @@ module StarkInfra
36
36
  @tags = tags
37
37
  @transaction_id = transaction_id
38
38
  @issuing_transaction_id = issuing_transaction_id
39
- @created = StarkInfra::Utils::Checks.check_datetime(created)
40
39
  @updated = StarkInfra::Utils::Checks.check_datetime(updated)
40
+ @created = StarkInfra::Utils::Checks.check_datetime(created)
41
41
  end
42
42
 
43
43
  # # Create an IssuingWithdrawal
@@ -78,10 +78,10 @@ module StarkInfra
78
78
  #
79
79
  # ## Parameters (optional):
80
80
  # - limit [integer, default nil]: maximum number of objects to be retrieved. Unlimited if nil. ex: 35
81
- # - external_ids [list of strings, default []]: external IDs. ex: ['5656565656565656', '4545454545454545']
82
- # - after [Date or string, default nil] date filter for objects created only after specified date. ex: Date.new(2020, 3, 10)
83
- # - before [Date or string, default nil] date filter for objects created only before specified date. ex: Date.new(2020, 3, 10)
81
+ # - after [Date or string, default nil]: date filter for objects created only after specified date. ex: Date.new(2020, 3, 10)
82
+ # - before [Date or string, default nil]: date filter for objects created only before specified date. ex: Date.new(2020, 3, 10)
84
83
  # - tags [list of strings, default nil]: tags to filter retrieved objects. ex: ['tony', 'stark']
84
+ # - external_ids [list of strings, default nil]: external IDs. ex: ['5656565656565656', '4545454545454545']
85
85
  # - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if starkinfra.user was set before function call
86
86
  #
87
87
  # ## Return:
@@ -102,15 +102,16 @@ module StarkInfra
102
102
 
103
103
  # # Retrieve paged IssuingWithdrawals
104
104
  #
105
- # Receive a list of IssuingWithdrawals objects previously created in the Stark Infra API and the cursor to the next page.
105
+ # Receive a list of up to 100 IssuingWithdrawal objects previously created in the Stark Infra API and the cursor to the next page.
106
+ # Use this function instead of query if you want to manually page your requests.
106
107
  #
107
108
  # ## Parameters (optional):
108
109
  # - cursor [string, default nil]: cursor returned on the previous page function call.
109
110
  # - limit [integer, default 100]: maximum number of objects to be retrieved. Max = 100. ex: 35
110
- # - external_ids [list of strings, default []]: external IDs. ex: ['5656565656565656', '4545454545454545']
111
- # - after [Date or string, default nil] date filter for objects created only after specified date. ex: Date.new(2020, 3, 10)
112
- # - before [Date or string, default nil] date filter for objects created only before specified date. ex: Date.new(2020, 3, 10)
111
+ # - after [Date or string, default nil]: date filter for objects created only after specified date. ex: Date.new(2020, 3, 10)
112
+ # - before [Date or string, default nil]: date filter for objects created only before specified date. ex: Date.new(2020, 3, 10)
113
113
  # - tags [list of strings, default nil]: tags to filter retrieved objects. ex: ['tony', 'stark']
114
+ # - external_ids [list of strings, default nil]: external IDs. ex: ['5656565656565656', '4545454545454545']
114
115
  # - user [Organization/Project object, default nil]: Organization or Project object. Not necessary if starkinfra.user was set before function call
115
116
  #
116
117
  # ## Return:
@@ -136,11 +137,11 @@ module StarkInfra
136
137
  resource_name: 'IssuingWithdrawal',
137
138
  resource_maker: proc { |json|
138
139
  IssuingWithdrawal.new(
140
+ id: json['id'],
139
141
  amount: json['amount'],
140
142
  external_id: json['external_id'],
141
143
  description: json['description'],
142
144
  tags: json['tags'],
143
- id: json['id'],
144
145
  transaction_id: json['transaction_id'],
145
146
  issuing_transaction_id: json['issuing_transaction_id'],
146
147
  updated: json['updated'],