myob_acumatica 0.1.4 → 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: e15a5861adfeb95df2fd9ba27fdcabdd38ddd7256e06114f4f24307c3f094429
4
- data.tar.gz: b30cb9b7080780e7017572c24e886785c8ea6c7b136ac770396f36dada9f55b6
3
+ metadata.gz: f55ce7017ae2648ed83e6342d1067b97529db7dfac0437d45602f748e0ac402d
4
+ data.tar.gz: 3b3e9c12b1ca74f6b9214b1e97ffe8c086a16dc79af3dd475d371e127e676f2f
5
5
  SHA512:
6
- metadata.gz: 8d505819ddac73957aa98a108f1f4a7d2ae9d8f21b9b0f5faa7f026fb61e2e52c16e45cdf8f04eab7e2d4b69f6c9b45d920a800060c5b896d997c00978e89bcc
7
- data.tar.gz: 9d558ce25b14bc005aebe2c4693d3ca2c9e1192d36a1f6aaf4ff984d8e640a4590b453ea75276acd8a47eb28fcd5f46200d354319353e535886ba77249443257
6
+ metadata.gz: 8ea6da5df7be16a1dcb9f62ad4db478683b8d60ea2c735dfd852cc510d5f84ff3437accfd1ab9747d0efa28ee97665611ff9c66fe4d8e9267a42487cbb2e5733
7
+ data.tar.gz: 5aed30d5a8da8d83f60ab217629f7327f876c87268cf86c0a4c3b1c93ef96cb6a41f6e14a6ca491e1ed09bad0d502f07cbe0a75396418795d3872aa76826e955
data/CHANGELOG.md CHANGED
@@ -1,5 +1,18 @@
1
1
  # Changelog
2
2
 
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`
15
+
3
16
  ## [0.1.4] - 2025-08-13
4
17
  ### Added
5
18
  - **Tax API** support:
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- myob_acumatica (0.1.4)
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'
@@ -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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module MyobAcumatica
4
- VERSION = '0.1.4'
4
+ VERSION = '0.1.5'
5
5
  end
@@ -29,3 +29,4 @@ require_relative 'myob_acumatica/api/customer'
29
29
  require_relative 'myob_acumatica/api/invoice'
30
30
  require_relative 'myob_acumatica/api/payment'
31
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.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Mikulasev
@@ -153,6 +153,7 @@ 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
@@ -160,6 +161,7 @@ files:
160
161
  - examples/tax.rb
161
162
  - lib/myob_acumatica.rb
162
163
  - lib/myob_acumatica/api.rb
164
+ - lib/myob_acumatica/api/currency.rb
163
165
  - lib/myob_acumatica/api/customer.rb
164
166
  - lib/myob_acumatica/api/http.rb
165
167
  - lib/myob_acumatica/api/invoice.rb