myob_acumatica 0.1.2 → 0.1.4

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.
@@ -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.2'
4
+ VERSION = '0.1.4'
5
5
  end
@@ -27,3 +27,5 @@ require_relative 'myob_acumatica/api'
27
27
  require_relative 'myob_acumatica/api/http'
28
28
  require_relative 'myob_acumatica/api/customer'
29
29
  require_relative 'myob_acumatica/api/invoice'
30
+ require_relative 'myob_acumatica/api/payment'
31
+ require_relative 'myob_acumatica/api/tax'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: myob_acumatica
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Mikulasev
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2025-06-06 00:00:00.000000000 Z
11
+ date: 2025-08-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: byebug
@@ -156,11 +156,15 @@ files:
156
156
  - examples/customer.rb
157
157
  - examples/dummy.pdf
158
158
  - examples/invoice.rb
159
+ - examples/payment.rb
160
+ - examples/tax.rb
159
161
  - lib/myob_acumatica.rb
160
162
  - lib/myob_acumatica/api.rb
161
163
  - lib/myob_acumatica/api/customer.rb
162
164
  - lib/myob_acumatica/api/http.rb
163
165
  - lib/myob_acumatica/api/invoice.rb
166
+ - lib/myob_acumatica/api/payment.rb
167
+ - lib/myob_acumatica/api/tax.rb
164
168
  - lib/myob_acumatica/o_auth_2/http.rb
165
169
  - lib/myob_acumatica/o_auth_2/token.rb
166
170
  - lib/myob_acumatica/version.rb