myob_acumatica 0.1.3 → 0.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b2f5ec6ddaf89cf216541bfa7a9fdd1a6192a784f55b01010a62a888f4847135
4
- data.tar.gz: b0e1f317f5f1b72d4606f2b8220503ef8896fbfcb64da9c5c008d28ceacde648
3
+ metadata.gz: f55ce7017ae2648ed83e6342d1067b97529db7dfac0437d45602f748e0ac402d
4
+ data.tar.gz: 3b3e9c12b1ca74f6b9214b1e97ffe8c086a16dc79af3dd475d371e127e676f2f
5
5
  SHA512:
6
- metadata.gz: 5f5694a5494e9a8452f68de3bd4e65cc0514e9b8455c9cc04b70bfd41dfc723c1f151ec4c27c1a72ec2e5c69694952a05ff88251b511c6f4ad7a8dde18513d96
7
- data.tar.gz: ae673387e1f6423664fa246d3d5c8f9309127b1233aa5da648e5e89570211f51656535e4c15b22675d9f1c682a9f452092035afb5a1b5c3f994601ff8f2a75d6
6
+ metadata.gz: 8ea6da5df7be16a1dcb9f62ad4db478683b8d60ea2c735dfd852cc510d5f84ff3437accfd1ab9747d0efa28ee97665611ff9c66fe4d8e9267a42487cbb2e5733
7
+ data.tar.gz: 5aed30d5a8da8d83f60ab217629f7327f876c87268cf86c0a4c3b1c93ef96cb6a41f6e14a6ca491e1ed09bad0d502f07cbe0a75396418795d3872aa76826e955
data/CHANGELOG.md CHANGED
@@ -1,5 +1,45 @@
1
- ## [Unreleased]
1
+ # Changelog
2
2
 
3
- ## [0.1.0] - 2025-02-05
3
+ ## [0.1.5] - 2025-08-13
4
+ ### Added
5
+ - **Currency API** support:
6
+ - `delete_by_id`
7
+ - `delete_by_keys`
8
+ - `get_ad_hoc_schema`
9
+ - `get_by_id`
10
+ - `get_by_keys`
11
+ - `get_list`
12
+ - `invoke_action`
13
+ - `put_entity`
14
+ - `put_file`
4
15
 
5
- - Initial release
16
+ ## [0.1.4] - 2025-08-13
17
+ ### Added
18
+ - **Tax API** support:
19
+ - `delete_by_id`
20
+ - `delete_by_keys`
21
+ - `get_ad_hoc_schema`
22
+ - `get_by_id`
23
+ - `get_by_keys`
24
+ - `get_list`
25
+ - `invoke_action`
26
+ - `put_entity`
27
+ - `put_file`
28
+
29
+ ## [0.1.3] - 2025-08-10
30
+ ### Added
31
+ - **Payment API** support:
32
+ - `delete_by_id`
33
+ - `delete_by_keys`
34
+ - `get_ad_hoc_schema`
35
+ - `get_by_id`
36
+ - `get_by_keys`
37
+ - `get_list`
38
+ - `put_entity`
39
+ - `put_file`
40
+ - `invoke_action`
41
+ - `capture_credit_card_payment`
42
+ - `card_operation`
43
+ - `release_payment`
44
+ - `void_card_payment`
45
+ - `void_payment`
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- myob_acumatica (0.1.2)
4
+ myob_acumatica (0.1.5)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -0,0 +1,97 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'json'
4
+ require 'logger'
5
+ require 'date'
6
+ require 'dotenv/load'
7
+ require 'myob_acumatica'
8
+
9
+ access_token = ENV['MYOB_ACUMATICA_ACCESS_TOKEN']
10
+ logger = Logger.new($stdout)
11
+
12
+ MyobAcumatica::Api::Currency.get_ad_hoc_schema(
13
+ access_token: access_token,
14
+ logger: logger
15
+ )
16
+
17
+ currency1 = MyobAcumatica::Api::Currency.put_entity(
18
+ access_token: access_token,
19
+ entity: {
20
+ 'CurrencyID' => { 'value' => 'XCU1' },
21
+ 'Description' => { 'value' => 'Example Currency 1' }
22
+ },
23
+ logger: logger
24
+ )
25
+
26
+ currency2 = MyobAcumatica::Api::Currency.put_entity(
27
+ access_token: access_token,
28
+ entity: {
29
+ 'CurrencyID' => { 'value' => 'XCU2' },
30
+ 'Description' => { 'value' => 'Example Currency 2' }
31
+ },
32
+ logger: logger
33
+ )
34
+
35
+ puts "Created XCU1 id=#{currency1['id']}"
36
+ puts "Created XCU2 id=#{currency2['id']}"
37
+
38
+ currency1 = MyobAcumatica::Api::Currency.put_entity(
39
+ access_token: access_token,
40
+ entity: {
41
+ 'id' => currency1['id'],
42
+ 'Description' => { 'value' => 'Example Currency 1 (updated)' }
43
+ },
44
+ logger: logger
45
+ )
46
+ puts 'Updated XCU1 description'
47
+
48
+ by_id = MyobAcumatica::Api::Currency.get_by_id(
49
+ access_token: access_token,
50
+ id: currency1['id'],
51
+ logger: logger
52
+ )
53
+ puts "Fetched by id: #{by_id['CurrencyID']&.dig('value')}"
54
+
55
+ by_keys = MyobAcumatica::Api::Currency.get_by_keys(
56
+ access_token: access_token,
57
+ keys: ['AMD'],
58
+ logger: logger
59
+ )
60
+ puts "Fetched by keys: #{by_keys['CurrencyID']&.dig('value')}"
61
+
62
+ list = MyobAcumatica::Api::Currency.get_list(
63
+ access_token: access_token,
64
+ query_params: { '$select' => 'CurrencyID,Description', '$top' => 5 },
65
+ logger: logger
66
+ )
67
+ puts "Listed #{list.size} currency record(s)"
68
+
69
+ # MyobAcumatica::Api::Currency.put_file(
70
+ # access_token: access_token,
71
+ # keys: ['AMD'],
72
+ # file_path: 'examples/dummy.pdf',
73
+ # logger: logger
74
+ # )
75
+ # puts 'Attached file to AMD'
76
+
77
+ # MyobAcumatica::Api::Currency.invoke_action(
78
+ # access_token: access_token,
79
+ # action_name: 'CustomAction',
80
+ # entity: { 'id' => currency1['id'] },
81
+ # logger: logger
82
+ # )
83
+ # puts 'Invoked action on XCU1'
84
+
85
+ # MyobAcumatica::Api::Currency.delete_by_keys(
86
+ # access_token: access_token,
87
+ # keys: ['XCU2'],
88
+ # logger: logger
89
+ # )
90
+ # puts 'Deleted XCU2 by keys'
91
+
92
+ MyobAcumatica::Api::Currency.delete_by_id(
93
+ access_token: access_token,
94
+ id: currency1['id'],
95
+ logger: logger
96
+ )
97
+ puts 'Deleted XCU1 by id'
data/examples/tax.rb ADDED
@@ -0,0 +1,99 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'json'
4
+ require 'logger'
5
+ require 'date'
6
+ require 'dotenv/load'
7
+ require 'myob_acumatica'
8
+
9
+ access_token = ENV['MYOB_ACUMATICA_ACCESS_TOKEN']
10
+ logger = Logger.new($stdout)
11
+
12
+ MyobAcumatica::Api::Tax.get_ad_hoc_schema(
13
+ access_token: access_token,
14
+ logger: logger
15
+ )
16
+
17
+ gst = MyobAcumatica::Api::Tax.put_entity(
18
+ access_token: access_token,
19
+ entity: {
20
+ 'TaxID' => { 'value' => 'GST' },
21
+ 'Description' => { 'value' => 'Goods and Services Tax' },
22
+ 'TaxType' => { 'value' => 'Sales' },
23
+ 'CalculateOn' => { 'value' => 'Exclusive Document-Level' },
24
+ 'TaxAgency' => { 'value' => 'ATO' },
25
+ 'TaxPayableAccount' => { 'value' => '2200' },
26
+ 'TaxPayableSubaccount' => { 'value' => '000-000' }
27
+ },
28
+ logger: logger
29
+ )
30
+
31
+ vat = MyobAcumatica::Api::Tax.put_entity(
32
+ access_token: access_token,
33
+ entity: {
34
+ 'TaxID' => { 'value' => 'VAT20' },
35
+ 'Description' => { 'value' => 'Value Added Tax 20%' },
36
+ 'TaxType' => { 'value' => 'Sales' },
37
+ 'CalculateOn' => { 'value' => 'Exclusive Document-Level' },
38
+ 'TaxAgency' => { 'value' => 'ATO' },
39
+ 'TaxPayableAccount' => { 'value' => '2200' },
40
+ 'TaxPayableSubaccount' => { 'value' => '000-000' }
41
+ },
42
+ logger: logger
43
+ )
44
+
45
+ puts "Created GST with id=#{gst['id']}"
46
+ puts "Created VAT20 with id=#{vat['id']}"
47
+
48
+ gst_by_keys = MyobAcumatica::Api::Tax.get_by_keys(
49
+ access_token: access_token,
50
+ keys: ['GST'],
51
+ logger: logger
52
+ )
53
+ puts "Fetched by keys: #{gst_by_keys['TaxID']&.dig('value')}"
54
+
55
+ gst_by_id = MyobAcumatica::Api::Tax.get_by_id(
56
+ access_token: access_token,
57
+ id: gst['id'],
58
+ logger: logger
59
+ )
60
+ puts "Fetched by id: #{gst_by_id['TaxID']&.dig('value')}"
61
+
62
+ list = MyobAcumatica::Api::Tax.get_list(
63
+ access_token: access_token,
64
+ query_params: { '$filter' => "TaxType eq 'Sales'", '$top' => 5 },
65
+ logger: logger
66
+ )
67
+ puts "Listed #{list.size} tax record(s)"
68
+
69
+ gst = MyobAcumatica::Api::Tax.put_entity(
70
+ access_token: access_token,
71
+ entity: {
72
+ 'id' => gst['id'],
73
+ 'Description' => { 'value' => 'GST (updated desc)' }
74
+ },
75
+ logger: logger
76
+ )
77
+ puts 'Updated GST description'
78
+
79
+ MyobAcumatica::Api::Tax.put_file(
80
+ access_token: access_token,
81
+ keys: ['GST'],
82
+ file_path: 'examples/dummy.pdf',
83
+ logger: logger
84
+ )
85
+ puts 'Attached file to GST'
86
+
87
+ MyobAcumatica::Api::Tax.delete_by_keys(
88
+ access_token: access_token,
89
+ keys: ['VAT20'],
90
+ logger: logger
91
+ )
92
+ puts 'Deleted VAT20 by keys'
93
+
94
+ MyobAcumatica::Api::Tax.delete_by_id(
95
+ access_token: access_token,
96
+ id: gst['id'],
97
+ logger: logger
98
+ )
99
+ puts 'Deleted GST by id'
@@ -0,0 +1,340 @@
1
+ # frozen_string_literal: true
2
+
3
+ module MyobAcumatica
4
+ module Api
5
+ # Provides methods to interact with the Currency API endpoints.
6
+ module Currency
7
+ module_function
8
+
9
+ ##
10
+ # Deletes a currency record by its session UUID.
11
+ #
12
+ # @example Delete a currency by ID
13
+ # MyobAcumatica::Api::Currency.delete_by_id(
14
+ # access_token: access_token,
15
+ # id: currency['id'],
16
+ # logger: logger
17
+ # )
18
+ #
19
+ # @param access_token [String] OAuth2 access token.
20
+ # @param id [String] Session UUID of the currency record.
21
+ # @param instance_name [String] The instance name.
22
+ # @param endpoint_name [String] The endpoint name.
23
+ # @param endpoint_version [String] The endpoint version.
24
+ # @param logger [Logger, nil] Optional logger.
25
+ # @return [nil]
26
+ def delete_by_id(access_token:, id:,
27
+ instance_name: INSTANCE_NAME,
28
+ endpoint_name: ENDPOINT_NAME,
29
+ endpoint_version: ENDPOINT_VERSION,
30
+ logger: nil)
31
+ Http.request(
32
+ instance_name: instance_name,
33
+ access_token: access_token,
34
+ method: :delete,
35
+ endpoint_name: endpoint_name,
36
+ endpoint_version: endpoint_version,
37
+ path: "Currency/#{id}",
38
+ logger: logger
39
+ )
40
+ end
41
+
42
+ ##
43
+ # Deletes a currency record by composite keys.
44
+ #
45
+ # Keys are ordered values of the record's key fields.
46
+ #
47
+ # @example Delete a currency by keys
48
+ # MyobAcumatica::Api::Currency.delete_by_keys(
49
+ # access_token: access_token,
50
+ # keys: [currency['CurrencyID']['value']],
51
+ # logger: logger
52
+ # )
53
+ #
54
+ # @param access_token [String] OAuth2 access token.
55
+ # @param keys [Array<String>] Key values identifying the currency record.
56
+ # @param instance_name [String] The instance name.
57
+ # @param endpoint_name [String] The endpoint name.
58
+ # @param endpoint_version [String] The endpoint version.
59
+ # @param logger [Logger, nil] Optional logger.
60
+ # @return [nil]
61
+ def delete_by_keys(access_token:, keys:,
62
+ instance_name: INSTANCE_NAME,
63
+ endpoint_name: ENDPOINT_NAME,
64
+ endpoint_version: ENDPOINT_VERSION,
65
+ logger: nil)
66
+ Http.request(
67
+ instance_name: instance_name,
68
+ access_token: access_token,
69
+ method: :delete,
70
+ endpoint_name: endpoint_name,
71
+ endpoint_version: endpoint_version,
72
+ path: "Currency/#{keys.join('/')}",
73
+ logger: logger
74
+ )
75
+ end
76
+
77
+ ##
78
+ # Retrieves the ad-hoc schema (custom fields) for the Currency entity.
79
+ #
80
+ # @example Retrieve ad-hoc schema
81
+ # MyobAcumatica::Api::Currency.get_ad_hoc_schema(
82
+ # access_token: access_token,
83
+ # logger: logger
84
+ # )
85
+ #
86
+ # @param access_token [String] OAuth2 access token.
87
+ # @param instance_name [String] The instance name.
88
+ # @param endpoint_name [String] The endpoint name.
89
+ # @param endpoint_version [String] The endpoint version.
90
+ # @param logger [Logger, nil] Optional logger.
91
+ # @return [Hash] Ad-hoc schema payload.
92
+ def get_ad_hoc_schema(access_token:,
93
+ instance_name: INSTANCE_NAME,
94
+ endpoint_name: ENDPOINT_NAME,
95
+ endpoint_version: ENDPOINT_VERSION,
96
+ logger: nil)
97
+ Http.request(
98
+ instance_name: instance_name,
99
+ access_token: access_token,
100
+ method: :get,
101
+ endpoint_name: endpoint_name,
102
+ endpoint_version: endpoint_version,
103
+ path: 'Currency/$adHocSchema',
104
+ logger: logger
105
+ )
106
+ end
107
+
108
+ ##
109
+ # Retrieves a currency record by its session UUID.
110
+ #
111
+ # @example Get currency by ID
112
+ # MyobAcumatica::Api::Currency.get_by_id(
113
+ # access_token: access_token,
114
+ # id: currency['id'],
115
+ # logger: logger
116
+ # )
117
+ #
118
+ # @param access_token [String] OAuth2 access token.
119
+ # @param id [String] Session UUID of the currency record.
120
+ # @param query_params [Hash] Optional query params ($select, $expand, $filter,
121
+ # $custom).
122
+ # @param instance_name [String] The instance name.
123
+ # @param endpoint_name [String] The endpoint name.
124
+ # @param endpoint_version [String] The endpoint version.
125
+ # @param logger [Logger, nil] Optional logger.
126
+ # @return [Hash] The currency record.
127
+ def get_by_id(access_token:, id:, query_params: {},
128
+ instance_name: INSTANCE_NAME,
129
+ endpoint_name: ENDPOINT_NAME,
130
+ endpoint_version: ENDPOINT_VERSION,
131
+ logger: nil)
132
+ Http.request(
133
+ instance_name: instance_name,
134
+ access_token: access_token,
135
+ method: :get,
136
+ endpoint_name: endpoint_name,
137
+ endpoint_version: endpoint_version,
138
+ path: "Currency/#{id}",
139
+ query_params: query_params,
140
+ logger: logger
141
+ )
142
+ end
143
+
144
+ ##
145
+ # Retrieves a currency record by composite keys.
146
+ #
147
+ # @example Get currency by keys
148
+ # MyobAcumatica::Api::Currency.get_by_keys(
149
+ # access_token: access_token,
150
+ # keys: ['USD'],
151
+ # logger: logger
152
+ # )
153
+ #
154
+ # @param access_token [String] OAuth2 access token.
155
+ # @param keys [Array<String>] Key values identifying the currency record.
156
+ # @param query_params [Hash] Optional query params.
157
+ # @param instance_name [String] The instance name.
158
+ # @param endpoint_name [String] The endpoint name.
159
+ # @param endpoint_version [String] The endpoint version.
160
+ # @param logger [Logger, nil] Optional logger.
161
+ # @return [Hash] The currency record.
162
+ def get_by_keys(access_token:, keys:, query_params: {},
163
+ instance_name: INSTANCE_NAME,
164
+ endpoint_name: ENDPOINT_NAME,
165
+ endpoint_version: ENDPOINT_VERSION,
166
+ logger: nil)
167
+ Http.request(
168
+ instance_name: instance_name,
169
+ access_token: access_token,
170
+ method: :get,
171
+ endpoint_name: endpoint_name,
172
+ endpoint_version: endpoint_version,
173
+ path: "Currency/#{keys.join('/')}",
174
+ query_params: query_params,
175
+ logger: logger
176
+ )
177
+ end
178
+
179
+ ##
180
+ # Retrieves a list of currency records with optional filtering and paging.
181
+ #
182
+ # @example List currencies
183
+ # MyobAcumatica::Api::Currency.get_list(
184
+ # access_token: access_token,
185
+ # query_params: { '$top' => 10 },
186
+ # logger: logger
187
+ # )
188
+ #
189
+ # @param access_token [String] OAuth2 access token.
190
+ # @param query_params [Hash] Optional query params.
191
+ # @param instance_name [String] The instance name.
192
+ # @param endpoint_name [String] The endpoint name.
193
+ # @param endpoint_version [String] The endpoint version.
194
+ # @param logger [Logger, nil] Optional logger.
195
+ # @return [Array<Hash>] List of currency records.
196
+ def get_list(access_token:, query_params: {},
197
+ instance_name: INSTANCE_NAME,
198
+ endpoint_name: ENDPOINT_NAME,
199
+ endpoint_version: ENDPOINT_VERSION,
200
+ logger: nil)
201
+ Http.request(
202
+ instance_name: instance_name,
203
+ access_token: access_token,
204
+ method: :get,
205
+ endpoint_name: endpoint_name,
206
+ endpoint_version: endpoint_version,
207
+ path: 'Currency',
208
+ query_params: query_params,
209
+ logger: logger
210
+ )
211
+ end
212
+
213
+ ##
214
+ # Invokes a custom action on a currency record.
215
+ #
216
+ # @example Invoke a custom action
217
+ # MyobAcumatica::Api::Currency.invoke_action(
218
+ # access_token: access_token,
219
+ # action_name: 'CustomAction',
220
+ # entity: { 'id' => currency['id'] },
221
+ # parameters: {},
222
+ # logger: logger
223
+ # )
224
+ #
225
+ # @param access_token [String] OAuth2 access token.
226
+ # @param action_name [String] The action name to invoke.
227
+ # @param entity [Hash] Currency entity payload.
228
+ # @param parameters [Hash] Optional parameters for the action.
229
+ # @param instance_name [String] The instance name.
230
+ # @param endpoint_name [String] The endpoint name.
231
+ # @param endpoint_version [String] The endpoint version.
232
+ # @param logger [Logger, nil] Optional logger.
233
+ # @return [Hash, nil] Action response or nil on 204.
234
+ def invoke_action(access_token:, action_name:, entity:, parameters: {},
235
+ instance_name: INSTANCE_NAME,
236
+ endpoint_name: ENDPOINT_NAME,
237
+ endpoint_version: ENDPOINT_VERSION,
238
+ logger: nil)
239
+ Http.request(
240
+ instance_name: instance_name,
241
+ access_token: access_token,
242
+ method: :post,
243
+ endpoint_name: endpoint_name,
244
+ endpoint_version: endpoint_version,
245
+ path: "Currency/#{action_name}",
246
+ body: { 'entity' => entity, 'parameters' => parameters },
247
+ logger: logger
248
+ )
249
+ end
250
+
251
+ ##
252
+ # Creates or updates a currency record.
253
+ #
254
+ # @example Create or update a currency
255
+ # usd = MyobAcumatica::Api::Currency.put_entity(
256
+ # access_token: access_token,
257
+ # entity: { 'CurrencyID' => { 'value' => 'USD' } },
258
+ # logger: logger
259
+ # )
260
+ #
261
+ # @param access_token [String] OAuth2 access token.
262
+ # @param entity [Hash] Currency entity payload.
263
+ # @param query_params [Hash] Optional query params.
264
+ # @param instance_name [String] The instance name.
265
+ # @param endpoint_name [String] The endpoint name.
266
+ # @param endpoint_version [String] The endpoint version.
267
+ # @param logger [Logger, nil] Optional logger.
268
+ # @return [Hash] The created or updated currency record.
269
+ def put_entity(access_token:, entity:, query_params: {},
270
+ instance_name: INSTANCE_NAME,
271
+ endpoint_name: ENDPOINT_NAME,
272
+ endpoint_version: ENDPOINT_VERSION,
273
+ logger: nil)
274
+ Http.request(
275
+ instance_name: instance_name,
276
+ access_token: access_token,
277
+ method: :put,
278
+ endpoint_name: endpoint_name,
279
+ endpoint_version: endpoint_version,
280
+ path: 'Currency',
281
+ body: entity,
282
+ query_params: query_params,
283
+ logger: logger
284
+ )
285
+ end
286
+
287
+ ##
288
+ # Attaches a file to a currency record.
289
+ #
290
+ # @example Upload a file to a currency record
291
+ # MyobAcumatica::Api::Currency.put_file(
292
+ # access_token: access_token,
293
+ # keys: ['USD'],
294
+ # file_path: 'examples/rate-sheet.pdf',
295
+ # logger: logger
296
+ # )
297
+ #
298
+ # @param access_token [String] OAuth2 access token.
299
+ # @param keys [Array<String>] Key values identifying the currency record.
300
+ # @param file_path [String] Path to the file.
301
+ # @param instance_name [String] The instance name.
302
+ # @param endpoint_name [String] The endpoint name.
303
+ # @param endpoint_version [String] The endpoint version.
304
+ # @param logger [Logger, nil] Optional logger.
305
+ # @return [nil]
306
+ def put_file(access_token:, keys:, file_path:,
307
+ instance_name: INSTANCE_NAME,
308
+ endpoint_name: ENDPOINT_NAME,
309
+ endpoint_version: ENDPOINT_VERSION,
310
+ logger: nil)
311
+ entity = get_by_keys(
312
+ access_token: access_token,
313
+ keys: keys,
314
+ instance_name: instance_name,
315
+ endpoint_name: endpoint_name,
316
+ endpoint_version: endpoint_version,
317
+ logger: logger
318
+ )
319
+
320
+ put_template = entity.dig('_links', 'files:put')
321
+ raise MyobAcumatica::Error, 'files:put link not found' unless put_template
322
+
323
+ filename = File.basename(file_path)
324
+ path = put_template.gsub('{filename}', filename)
325
+
326
+ Http.request(
327
+ instance_name: instance_name,
328
+ access_token: access_token,
329
+ method: :put,
330
+ endpoint_name: endpoint_name,
331
+ endpoint_version: endpoint_version,
332
+ path: path,
333
+ body: File.binread(file_path),
334
+ content_type: 'application/octet-stream',
335
+ logger: logger
336
+ )
337
+ end
338
+ end
339
+ end
340
+ end
@@ -0,0 +1,350 @@
1
+ # frozen_string_literal: true
2
+
3
+ module MyobAcumatica
4
+ module Api
5
+ # Provides methods to interact with the Tax API endpoints.
6
+ module Tax
7
+ module_function
8
+
9
+ ##
10
+ # Deletes a tax record by its session UUID.
11
+ #
12
+ # @example Delete a tax by ID
13
+ # MyobAcumatica::Api::Tax.delete_by_id(
14
+ # access_token: access_token,
15
+ # id: tax['id'],
16
+ # logger: logger
17
+ # )
18
+ #
19
+ # @param access_token [String] OAuth2 access token.
20
+ # @param id [String] Session UUID of the tax record.
21
+ # @param instance_name [String] The instance name.
22
+ # @param endpoint_name [String] The endpoint name.
23
+ # @param endpoint_version [String] The endpoint version.
24
+ # @param logger [Logger, nil] Optional logger.
25
+ # @return [nil]
26
+ def delete_by_id(access_token:, id:,
27
+ instance_name: INSTANCE_NAME,
28
+ endpoint_name: ENDPOINT_NAME,
29
+ endpoint_version: ENDPOINT_VERSION,
30
+ logger: nil)
31
+ Http.request(
32
+ instance_name: instance_name,
33
+ access_token: access_token,
34
+ method: :delete,
35
+ endpoint_name: endpoint_name,
36
+ endpoint_version: endpoint_version,
37
+ path: "Tax/#{id}",
38
+ logger: logger
39
+ )
40
+ end
41
+
42
+ ##
43
+ # Deletes a tax record by composite keys.
44
+ #
45
+ # Keys are ordered values of the record's key fields. For Tax this is
46
+ # typically the TaxID (and if applicable, other key parts defined by the
47
+ # endpoint contract).
48
+ #
49
+ # @example Delete a tax by keys
50
+ # MyobAcumatica::Api::Tax.delete_by_keys(
51
+ # access_token: access_token,
52
+ # keys: [tax['TaxID']['value']],
53
+ # logger: logger
54
+ # )
55
+ #
56
+ # @param access_token [String] OAuth2 access token.
57
+ # @param keys [Array<String>] Key values identifying the tax record.
58
+ # @param instance_name [String] The instance name.
59
+ # @param endpoint_name [String] The endpoint name.
60
+ # @param endpoint_version [String] The endpoint version.
61
+ # @param logger [Logger, nil] Optional logger.
62
+ # @return [nil]
63
+ def delete_by_keys(access_token:, keys:,
64
+ instance_name: INSTANCE_NAME,
65
+ endpoint_name: ENDPOINT_NAME,
66
+ endpoint_version: ENDPOINT_VERSION,
67
+ logger: nil)
68
+ Http.request(
69
+ instance_name: instance_name,
70
+ access_token: access_token,
71
+ method: :delete,
72
+ endpoint_name: endpoint_name,
73
+ endpoint_version: endpoint_version,
74
+ path: "Tax/#{keys.join('/')}",
75
+ logger: logger
76
+ )
77
+ end
78
+
79
+ ##
80
+ # Retrieves the ad-hoc schema (custom fields) for the Tax entity.
81
+ #
82
+ # @example Retrieve ad-hoc schema
83
+ # MyobAcumatica::Api::Tax.get_ad_hoc_schema(
84
+ # access_token: access_token,
85
+ # logger: logger
86
+ # )
87
+ #
88
+ # @param access_token [String] OAuth2 access token.
89
+ # @param instance_name [String] The instance name.
90
+ # @param endpoint_name [String] The endpoint name.
91
+ # @param endpoint_version [String] The endpoint version.
92
+ # @param logger [Logger, nil] Optional logger.
93
+ # @return [Hash] Ad-hoc schema payload.
94
+ def get_ad_hoc_schema(access_token:,
95
+ instance_name: INSTANCE_NAME,
96
+ endpoint_name: ENDPOINT_NAME,
97
+ endpoint_version: ENDPOINT_VERSION,
98
+ logger: nil)
99
+ Http.request(
100
+ instance_name: instance_name,
101
+ access_token: access_token,
102
+ method: :get,
103
+ endpoint_name: endpoint_name,
104
+ endpoint_version: endpoint_version,
105
+ path: 'Tax/$adHocSchema',
106
+ logger: logger
107
+ )
108
+ end
109
+
110
+ ##
111
+ # Retrieves a tax record by its session UUID.
112
+ #
113
+ # @example Get tax by ID
114
+ # MyobAcumatica::Api::Tax.get_by_id(
115
+ # access_token: access_token,
116
+ # id: tax['id'],
117
+ # logger: logger
118
+ # )
119
+ #
120
+ # @param access_token [String] OAuth2 access token.
121
+ # @param id [String] Session UUID of the tax record.
122
+ # @param query_params [Hash] Optional query params ($select, $expand, $filter,
123
+ # $custom).
124
+ # @param instance_name [String] The instance name.
125
+ # @param endpoint_name [String] The endpoint name.
126
+ # @param endpoint_version [String] The endpoint version.
127
+ # @param logger [Logger, nil] Optional logger.
128
+ # @return [Hash] The tax record.
129
+ def get_by_id(access_token:, id:, query_params: {},
130
+ instance_name: INSTANCE_NAME,
131
+ endpoint_name: ENDPOINT_NAME,
132
+ endpoint_version: ENDPOINT_VERSION,
133
+ logger: nil)
134
+ Http.request(
135
+ instance_name: instance_name,
136
+ access_token: access_token,
137
+ method: :get,
138
+ endpoint_name: endpoint_name,
139
+ endpoint_version: endpoint_version,
140
+ path: "Tax/#{id}",
141
+ query_params: query_params,
142
+ logger: logger
143
+ )
144
+ end
145
+
146
+ ##
147
+ # Retrieves a tax record by composite keys.
148
+ #
149
+ # @example Get tax by keys
150
+ # MyobAcumatica::Api::Tax.get_by_keys(
151
+ # access_token: access_token,
152
+ # keys: [tax_id],
153
+ # logger: logger
154
+ # )
155
+ #
156
+ # @param access_token [String] OAuth2 access token.
157
+ # @param keys [Array<String>] Key values identifying the tax record.
158
+ # @param query_params [Hash] Optional query params ($select, $expand, $filter,
159
+ # $custom).
160
+ # @param instance_name [String] The instance name.
161
+ # @param endpoint_name [String] The endpoint name.
162
+ # @param endpoint_version [String] The endpoint version.
163
+ # @param logger [Logger, nil] Optional logger.
164
+ # @return [Hash] The tax record.
165
+ def get_by_keys(access_token:, keys:, query_params: {},
166
+ instance_name: INSTANCE_NAME,
167
+ endpoint_name: ENDPOINT_NAME,
168
+ endpoint_version: ENDPOINT_VERSION,
169
+ logger: nil)
170
+ Http.request(
171
+ instance_name: instance_name,
172
+ access_token: access_token,
173
+ method: :get,
174
+ endpoint_name: endpoint_name,
175
+ endpoint_version: endpoint_version,
176
+ path: "Tax/#{keys.join('/')}",
177
+ query_params: query_params,
178
+ logger: logger
179
+ )
180
+ end
181
+
182
+ ##
183
+ # Retrieves a list of tax records with optional filtering and paging.
184
+ #
185
+ # @example List tax records with a filter
186
+ # MyobAcumatica::Api::Tax.get_list(
187
+ # access_token: access_token,
188
+ # query_params: { '$filter' => 'TaxType eq 'Sales'' },
189
+ # logger: logger
190
+ # )
191
+ #
192
+ # @param access_token [String] OAuth2 access token.
193
+ # @param query_params [Hash] Optional query params ($select, $expand, $filter,
194
+ # $custom, $skip, $top).
195
+ # @param instance_name [String] The instance name.
196
+ # @param endpoint_name [String] The endpoint name.
197
+ # @param endpoint_version [String] The endpoint version.
198
+ # @param logger [Logger, nil] Optional logger.
199
+ # @return [Array<Hash>] List of tax records.
200
+ def get_list(access_token:, query_params: {},
201
+ instance_name: INSTANCE_NAME,
202
+ endpoint_name: ENDPOINT_NAME,
203
+ endpoint_version: ENDPOINT_VERSION,
204
+ logger: nil)
205
+ Http.request(
206
+ instance_name: instance_name,
207
+ access_token: access_token,
208
+ method: :get,
209
+ endpoint_name: endpoint_name,
210
+ endpoint_version: endpoint_version,
211
+ path: 'Tax',
212
+ query_params: query_params,
213
+ logger: logger
214
+ )
215
+ end
216
+
217
+ ##
218
+ # Invokes a custom action on a tax record.
219
+ #
220
+ # @example Invoke a custom action
221
+ # MyobAcumatica::Api::Tax.invoke_action(
222
+ # access_token: access_token,
223
+ # action_name: 'Recalculate',
224
+ # entity: { 'id' => tax['id'] },
225
+ # parameters: {},
226
+ # logger: logger
227
+ # )
228
+ #
229
+ # @param access_token [String] OAuth2 access token.
230
+ # @param action_name [String] The action name to invoke.
231
+ # @param entity [Hash] Tax entity payload (e.g., { 'id' => uuid }).
232
+ # @param parameters [Hash] Optional parameters for the action.
233
+ # @param instance_name [String] The instance name.
234
+ # @param endpoint_name [String] The endpoint name.
235
+ # @param endpoint_version [String] The endpoint version.
236
+ # @param logger [Logger, nil] Optional logger.
237
+ # @return [Hash, nil] Action response or nil on 204.
238
+ def invoke_action(access_token:, action_name:, entity:, parameters: {},
239
+ instance_name: INSTANCE_NAME,
240
+ endpoint_name: ENDPOINT_NAME,
241
+ endpoint_version: ENDPOINT_VERSION,
242
+ logger: nil)
243
+ Http.request(
244
+ instance_name: instance_name,
245
+ access_token: access_token,
246
+ method: :post,
247
+ endpoint_name: endpoint_name,
248
+ endpoint_version: endpoint_version,
249
+ path: "Tax/#{action_name}",
250
+ body: { 'entity' => entity, 'parameters' => parameters },
251
+ logger: logger
252
+ )
253
+ end
254
+
255
+ ##
256
+ # Creates or updates a tax record.
257
+ #
258
+ # @example Create or update a tax
259
+ # tax = MyobAcumatica::Api::Tax.put_entity(
260
+ # access_token: access_token,
261
+ # entity: {
262
+ # 'TaxID' => { 'value' => 'GST' },
263
+ # 'Description' => { 'value' => 'Goods and Services Tax' }
264
+ # },
265
+ # logger: logger
266
+ # )
267
+ #
268
+ # @param access_token [String] OAuth2 access token.
269
+ # @param entity [Hash] Tax entity payload.
270
+ # @param query_params [Hash] Optional query params ($select, $expand, $filter,
271
+ # $custom).
272
+ # @param instance_name [String] The instance name.
273
+ # @param endpoint_name [String] The endpoint name.
274
+ # @param endpoint_version [String] The endpoint version.
275
+ # @param logger [Logger, nil] Optional logger.
276
+ # @return [Hash] The created or updated tax record.
277
+ def put_entity(access_token:, entity:, query_params: {},
278
+ instance_name: INSTANCE_NAME,
279
+ endpoint_name: ENDPOINT_NAME,
280
+ endpoint_version: ENDPOINT_VERSION,
281
+ logger: nil)
282
+ Http.request(
283
+ instance_name: instance_name,
284
+ access_token: access_token,
285
+ method: :put,
286
+ endpoint_name: endpoint_name,
287
+ endpoint_version: endpoint_version,
288
+ path: 'Tax',
289
+ body: entity,
290
+ query_params: query_params,
291
+ logger: logger
292
+ )
293
+ end
294
+
295
+ ##
296
+ # Attaches a file to a tax record. Uses the entity's files:put link to
297
+ # construct the upload path, then uploads the binary content.
298
+ #
299
+ # @example Upload a file to a tax record
300
+ # MyobAcumatica::Api::Tax.put_file(
301
+ # access_token: access_token,
302
+ # keys: [tax['TaxID']['value']],
303
+ # file_path: 'examples/rate-sheet.pdf',
304
+ # logger: logger
305
+ # )
306
+ #
307
+ # @param access_token [String] OAuth2 access token.
308
+ # @param keys [Array<String>] Key values identifying the tax record.
309
+ # @param file_path [String] Absolute or relative path to the file.
310
+ # @param instance_name [String] The instance name.
311
+ # @param endpoint_name [String] The endpoint name.
312
+ # @param endpoint_version [String] The endpoint version.
313
+ # @param logger [Logger, nil] Optional logger.
314
+ # @raise [MyobAcumatica::Error] If the files:put link is not present.
315
+ # @return [nil]
316
+ def put_file(access_token:, keys:, file_path:,
317
+ instance_name: INSTANCE_NAME,
318
+ endpoint_name: ENDPOINT_NAME,
319
+ endpoint_version: ENDPOINT_VERSION,
320
+ logger: nil)
321
+ entity = get_by_keys(
322
+ access_token: access_token,
323
+ keys: keys,
324
+ instance_name: instance_name,
325
+ endpoint_name: endpoint_name,
326
+ endpoint_version: endpoint_version,
327
+ logger: logger
328
+ )
329
+
330
+ put_template = entity.dig('_links', 'files:put')
331
+ raise MyobAcumatica::Error, 'files:put link not found' unless put_template
332
+
333
+ filename = File.basename(file_path)
334
+ path = put_template.gsub('{filename}', filename)
335
+
336
+ Http.request(
337
+ instance_name: instance_name,
338
+ access_token: access_token,
339
+ method: :put,
340
+ endpoint_name: endpoint_name,
341
+ endpoint_version: endpoint_version,
342
+ path: path,
343
+ body: File.binread(file_path),
344
+ content_type: 'application/octet-stream',
345
+ logger: logger
346
+ )
347
+ end
348
+ end
349
+ end
350
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module MyobAcumatica
4
- VERSION = '0.1.3'
4
+ VERSION = '0.1.5'
5
5
  end
@@ -28,3 +28,5 @@ require_relative 'myob_acumatica/api/http'
28
28
  require_relative 'myob_acumatica/api/customer'
29
29
  require_relative 'myob_acumatica/api/invoice'
30
30
  require_relative 'myob_acumatica/api/payment'
31
+ require_relative 'myob_acumatica/api/tax'
32
+ require_relative 'myob_acumatica/api/currency'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: myob_acumatica
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Mikulasev
@@ -153,16 +153,20 @@ files:
153
153
  - README.md
154
154
  - Rakefile
155
155
  - examples/app.rb
156
+ - examples/currency.rb
156
157
  - examples/customer.rb
157
158
  - examples/dummy.pdf
158
159
  - examples/invoice.rb
159
160
  - examples/payment.rb
161
+ - examples/tax.rb
160
162
  - lib/myob_acumatica.rb
161
163
  - lib/myob_acumatica/api.rb
164
+ - lib/myob_acumatica/api/currency.rb
162
165
  - lib/myob_acumatica/api/customer.rb
163
166
  - lib/myob_acumatica/api/http.rb
164
167
  - lib/myob_acumatica/api/invoice.rb
165
168
  - lib/myob_acumatica/api/payment.rb
169
+ - lib/myob_acumatica/api/tax.rb
166
170
  - lib/myob_acumatica/o_auth_2/http.rb
167
171
  - lib/myob_acumatica/o_auth_2/token.rb
168
172
  - lib/myob_acumatica/version.rb