myob_acumatica 0.1.4 → 0.1.6

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: ce19eee3aaa8648a6b035713bec45d0b194c5086b36005a7d8a2ca96890715be
4
+ data.tar.gz: a4d92210b0cc27dc599567afeea1e3e16a82a707fcbf3c5098366ef31efe9a9c
5
5
  SHA512:
6
- metadata.gz: 8d505819ddac73957aa98a108f1f4a7d2ae9d8f21b9b0f5faa7f026fb61e2e52c16e45cdf8f04eab7e2d4b69f6c9b45d920a800060c5b896d997c00978e89bcc
7
- data.tar.gz: 9d558ce25b14bc005aebe2c4693d3ca2c9e1192d36a1f6aaf4ff984d8e640a4590b453ea75276acd8a47eb28fcd5f46200d354319353e535886ba77249443257
6
+ metadata.gz: 375e4ada85b85912fbbda2d7475b5ca6519633993bea2c8a77b6b95dad5cff04f54b65611620d88c66774359fb40565ab60fed8344706b89180d73bf387c33ee
7
+ data.tar.gz: adca33c562c5c152268714889324920267a67273287548d65886d668e7d3f1c104e39bda2a155c531772b3fe9eea11b59d0255b641a21eb6459043c24d88022b
data/CHANGELOG.md CHANGED
@@ -1,5 +1,31 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.1.6] - 2025-09-17
4
+ ### Added
5
+ - **Ledger 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
+ - `put_entity`
13
+ - `put_file`
14
+ - `invoke_action`
15
+
16
+ ## [0.1.5] - 2025-08-13
17
+ ### Added
18
+ - **Currency 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
+
3
29
  ## [0.1.4] - 2025-08-13
4
30
  ### Added
5
31
  - **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.6)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -18,9 +18,7 @@ gem install myob_acumatica
18
18
 
19
19
  ## Configuration
20
20
 
21
- Provide configuration via **environment variables** and **explicitly per call**.
22
-
23
- **Note**: explicit parameters always override environment variables.
21
+ Provide via **environment variables** or **explicit arguments**.
24
22
 
25
23
  ### Environment variables
26
24
 
@@ -41,7 +39,7 @@ MyobAcumatica::Api::Customer.get_list(
41
39
  )
42
40
  ```
43
41
 
44
- ### Explicit parameters
42
+ ### Explicit arguments
45
43
 
46
44
  ```ruby
47
45
  MyobAcumatica::Api::Customer.get_list(
@@ -53,6 +51,8 @@ MyobAcumatica::Api::Customer.get_list(
53
51
  )
54
52
  ```
55
53
 
54
+ **Note**: explicit arguments override environment variables.
55
+
56
56
  ## Authorization
57
57
 
58
58
  Allow a client application to obtain an access token on behalf of a user, using an authorization code granted by the user after consent.
@@ -296,9 +296,6 @@ MyobAcumatica::Api::Customer.get_list(access_token: token["access_token"])
296
296
  Bug reports and pull requests are welcome at:
297
297
  https://github.com/fast-programmer/myob_acumatica
298
298
 
299
- Please follow the code of conduct:
300
- https://github.com/fast-programmer/myob_acumatica/blob/master/CODE_OF_CONDUCT.md
301
-
302
299
  ## License
303
300
 
304
301
  MIT — see the LICENSE
data/examples/app.rb CHANGED
@@ -41,6 +41,7 @@ module MyobAcumaticIntegration
41
41
  access_token: response['access_token'],
42
42
  endpoint_name: ENV['MYOB_ACUMATICA_ENDPOINT_NAME'],
43
43
  endpoint_version: ENV['MYOB_ACUMATICA_ENDPOINT_VERSION'],
44
+ query_params: { '$top' => 100, '$skip' => 0 },
44
45
  logger: Logger.new($stdout)
45
46
  )
46
47
 
@@ -96,40 +97,49 @@ module MyobAcumaticIntegration
96
97
  # end
97
98
 
98
99
  get '/customers' do
99
- page_size = 1
100
- skip = 0
101
-
102
- customer_enum = Enumerator.new do |yielder|
103
- customers = MyobAcumatica::Api::Customer.get_list(
104
- instance_name: ENV['MYOB_ACUMATICA_INSTANCE_NAME'],
105
- access_token: params['access_token'],
106
- query_params: {
107
- '$top' => page_size,
108
- '$skip' => skip
109
- }
110
- )
111
-
112
- while customers.size == page_size
113
- yielder << customers
114
- skip += page_size
115
-
116
- customers = MyobAcumatica::Api::Customer.get_list(
117
- instance_name: ENV['MYOB_ACUMATICA_INSTANCE_NAME'],
118
- access_token: params['access_token'],
119
- query_params: {
120
- '$top' => page_size,
121
- '$skip' => skip
122
- }
123
- )
124
- end
125
-
126
- yielder << customers if customers.any?
127
- end
128
-
129
- customers = customer_enum.flat_map(&:itself)
100
+ # page_size = 1
101
+ # skip = 0
102
+
103
+ # customer_enum = Enumerator.new do |yielder|
104
+ # customers = MyobAcumatica::Api::Customer.get_list(
105
+ # instance_name: ENV['MYOB_ACUMATICA_INSTANCE_NAME'],
106
+ # access_token: params['access_token'],
107
+ # query_params: {
108
+ # '$top' => page_size,
109
+ # '$skip' => skip
110
+ # }
111
+ # )
112
+
113
+ # while customers.size == page_size
114
+ # yielder << customers
115
+ # skip += page_size
116
+
117
+ # customers = MyobAcumatica::Api::Customer.get_list(
118
+ # instance_name: ENV['MYOB_ACUMATICA_INSTANCE_NAME'],
119
+ # access_token: params['access_token'],
120
+ # query_params: {
121
+ # '$top' => page_size,
122
+ # '$skip' => skip
123
+ # }
124
+ # )
125
+ # end
126
+
127
+ # yielder << customers if customers.any?
130
128
 
131
129
  content_type :json
132
130
 
131
+ customers = MyobAcumatica::Api::Customer.get_list(
132
+ instance_name: ENV['MYOB_ACUMATICA_INSTANCE_NAME'],
133
+ access_token: params['access_token'],
134
+ endpoint_name: ENV['MYOB_ACUMATICA_ENDPOINT_NAME'],
135
+ endpoint_version: ENV['MYOB_ACUMATICA_ENDPOINT_VERSION'],
136
+ query_params: {
137
+ '$top' => 100,
138
+ '$skip' => 0
139
+ },
140
+ logger: Logger.new($stdout)
141
+ )
142
+
133
143
  { customers: customers }.to_json
134
144
  end
135
145
 
@@ -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,88 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'json'
4
+ require 'logger'
5
+ require 'dotenv/load'
6
+
7
+ require 'myob_acumatica'
8
+
9
+ access_token = ENV['MYOB_ACUMATICA_ACCESS_TOKEN']
10
+ logger = Logger.new($stdout)
11
+
12
+ MyobAcumatica::Api::Ledger.get_ad_hoc_schema(
13
+ access_token: access_token,
14
+ logger: logger
15
+ )
16
+
17
+ ledger1 = MyobAcumatica::Api::Ledger.put_entity(
18
+ access_token: access_token,
19
+ entity: {
20
+ 'LedgerID' => { 'value' => 'LEDGER-ACTUAL' },
21
+ 'Description' => { 'value' => 'Actuals Ledger' },
22
+ 'Active' => { 'value' => true }
23
+ },
24
+ logger: logger
25
+ )
26
+
27
+ ledger1 = MyobAcumatica::Api::Ledger.put_entity(
28
+ access_token: access_token,
29
+ entity: {
30
+ 'LedgerID' => { 'value' => ledger1['LedgerID']['value'] },
31
+ 'Description' => { 'value' => 'Actuals Ledger (Updated)' }
32
+ },
33
+ logger: logger
34
+ )
35
+
36
+ ledger1 = MyobAcumatica::Api::Ledger.get_by_keys(
37
+ access_token: access_token,
38
+ keys: [ledger1['LedgerID']['value']],
39
+ logger: logger
40
+ )
41
+
42
+ MyobAcumatica::Api::Ledger.put_file(
43
+ access_token: access_token,
44
+ keys: [ledger1['LedgerID']['value']],
45
+ file_path: 'examples/dummy.pdf',
46
+ logger: logger
47
+ )
48
+
49
+ MyobAcumatica::Api::Ledger.get_by_id(
50
+ access_token: access_token,
51
+ id: ledger1['id'],
52
+ logger: logger
53
+ )
54
+
55
+ MyobAcumatica::Api::Ledger.get_list(
56
+ access_token: access_token,
57
+ logger: logger
58
+ )
59
+
60
+ MyobAcumatica::Api::Ledger.delete_by_id(
61
+ access_token: access_token,
62
+ id: ledger1['id'],
63
+ logger: logger
64
+ )
65
+
66
+ ledger2 = MyobAcumatica::Api::Ledger.put_entity(
67
+ access_token: access_token,
68
+ entity: {
69
+ 'LedgerID' => { 'value' => 'LEDGER-BUDGET' },
70
+ 'Description' => { 'value' => 'Budget Ledger' },
71
+ 'Active' => { 'value' => false }
72
+ },
73
+ logger: logger
74
+ )
75
+
76
+ MyobAcumatica::Api::Ledger.delete_by_keys(
77
+ access_token: access_token,
78
+ keys: [ledger2['LedgerID']['value']],
79
+ logger: logger
80
+ )
81
+
82
+ # MyobAcumatica::Api::Ledger.invoke_action(
83
+ # access_token: access_token,
84
+ # action_name: 'RebuildBalances',
85
+ # entity: { 'LedgerID' => { 'value' => 'LEDGER-ACTUAL' } },
86
+ # parameters: { 'FromPeriod' => { 'value' => '2024-01' } },
87
+ # logger: logger
88
+ # )
@@ -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,337 @@
1
+ # frozen_string_literal: true
2
+
3
+ module MyobAcumatica
4
+ module Api
5
+ # Provides methods to interact with the Ledger API endpoints.
6
+ #
7
+ # All methods follow the same conventions as other entities in this gem:
8
+ # - Paths, query params, and headers are set via Http.request
9
+ # - Keys are joined with "/" when addressing composite primary keys
10
+ # - Binary uploads use 'application/octet-stream'
11
+ module Ledger
12
+ module_function
13
+
14
+ # Deletes a ledger by session identifier (GUID).
15
+ #
16
+ # @example Delete a ledger by ID
17
+ # MyobAcumatica::Api::Ledger.delete_by_id(
18
+ # access_token: '...',
19
+ # id: '00000000-0000-4000-8000-000000000000',
20
+ # logger: Logger.new($stdout)
21
+ # )
22
+ #
23
+ # @param access_token [String] The OAuth2 access token.
24
+ # @param id [String] The session GUID of the record.
25
+ # @param instance_name [String] The instance name.
26
+ # @param endpoint_name [String] The endpoint name.
27
+ # @param endpoint_version [String] The endpoint version.
28
+ # @param logger [Logger, nil] Optional logger.
29
+ # @return [nil] Always nil.
30
+ def delete_by_id(access_token:, id:,
31
+ instance_name: INSTANCE_NAME,
32
+ endpoint_name: ENDPOINT_NAME,
33
+ endpoint_version: ENDPOINT_VERSION,
34
+ logger: nil)
35
+ Http.request(
36
+ instance_name: instance_name,
37
+ access_token: access_token,
38
+ method: :delete,
39
+ endpoint_name: endpoint_name,
40
+ endpoint_version: endpoint_version,
41
+ path: "Ledger/#{id}",
42
+ logger: logger
43
+ )
44
+ end
45
+
46
+ # Deletes a ledger by composite keys.
47
+ #
48
+ # @example Delete a ledger by keys
49
+ # MyobAcumatica::Api::Ledger.delete_by_keys(
50
+ # access_token: '...',
51
+ # keys: ['LEDGER-ACTUAL'],
52
+ # logger: Logger.new($stdout)
53
+ # )
54
+ #
55
+ # @param access_token [String] The OAuth2 access token.
56
+ # @param keys [Array<String>] The key values identifying the record.
57
+ # @param instance_name [String] The instance name.
58
+ # @param endpoint_name [String] The endpoint name.
59
+ # @param endpoint_version [String] The endpoint version.
60
+ # @param logger [Logger, nil] Optional logger.
61
+ # @return [nil] Always nil.
62
+ def delete_by_keys(access_token:, keys:,
63
+ instance_name: INSTANCE_NAME,
64
+ endpoint_name: ENDPOINT_NAME,
65
+ endpoint_version: ENDPOINT_VERSION,
66
+ logger: nil)
67
+ Http.request(
68
+ instance_name: instance_name,
69
+ access_token: access_token,
70
+ method: :delete,
71
+ endpoint_name: endpoint_name,
72
+ endpoint_version: endpoint_version,
73
+ path: "Ledger/#{keys.join('/')}",
74
+ logger: logger
75
+ )
76
+ end
77
+
78
+ # Retrieves the ad-hoc schema (custom fields) for Ledger.
79
+ #
80
+ # @example Retrieve the ad-hoc schema
81
+ # MyobAcumatica::Api::Ledger.get_ad_hoc_schema(
82
+ # access_token: '...',
83
+ # logger: Logger.new($stdout)
84
+ # )
85
+ #
86
+ # @param access_token [String] The 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] The ad-hoc schema document.
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: 'Ledger/$adHocSchema',
104
+ logger: logger
105
+ )
106
+ end
107
+
108
+ # Retrieves a ledger by session identifier (GUID).
109
+ #
110
+ # @example Retrieve a ledger by ID
111
+ # MyobAcumatica::Api::Ledger.get_by_id(
112
+ # access_token: '...',
113
+ # id: '00000000-0000-4000-8000-000000000000',
114
+ # logger: Logger.new($stdout)
115
+ # )
116
+ #
117
+ # @param access_token [String] The OAuth2 access token.
118
+ # @param id [String] The session GUID of the record.
119
+ # @param query_params [Hash] Optional query params ($select, $filter, etc.).
120
+ # @param instance_name [String] The instance name.
121
+ # @param endpoint_name [String] The endpoint name.
122
+ # @param endpoint_version [String] The endpoint version.
123
+ # @param logger [Logger, nil] Optional logger.
124
+ # @return [Hash] The ledger record.
125
+ def get_by_id(access_token:, id:, query_params: {},
126
+ instance_name: INSTANCE_NAME,
127
+ endpoint_name: ENDPOINT_NAME,
128
+ endpoint_version: ENDPOINT_VERSION,
129
+ logger: nil)
130
+ Http.request(
131
+ instance_name: instance_name,
132
+ access_token: access_token,
133
+ method: :get,
134
+ endpoint_name: endpoint_name,
135
+ endpoint_version: endpoint_version,
136
+ path: "Ledger/#{id}",
137
+ query_params: query_params,
138
+ logger: logger
139
+ )
140
+ end
141
+
142
+ # Retrieves a ledger by its key values.
143
+ #
144
+ # @example Retrieve a ledger by keys
145
+ # MyobAcumatica::Api::Ledger.get_by_keys(
146
+ # access_token: '...',
147
+ # keys: ['LEDGER-ACTUAL'],
148
+ # logger: Logger.new($stdout)
149
+ # )
150
+ #
151
+ # @param access_token [String] The OAuth2 access token.
152
+ # @param keys [Array<String>] The key values identifying the record.
153
+ # @param query_params [Hash] Optional query params ($select, $filter, etc.).
154
+ # @param instance_name [String] The instance name.
155
+ # @param endpoint_name [String] The endpoint name.
156
+ # @param endpoint_version [String] The endpoint version.
157
+ # @param logger [Logger, nil] Optional logger.
158
+ # @return [Hash] The ledger record.
159
+ def get_by_keys(access_token:, keys:, query_params: {},
160
+ instance_name: INSTANCE_NAME,
161
+ endpoint_name: ENDPOINT_NAME,
162
+ endpoint_version: ENDPOINT_VERSION,
163
+ logger: nil)
164
+ Http.request(
165
+ instance_name: instance_name,
166
+ access_token: access_token,
167
+ method: :get,
168
+ endpoint_name: endpoint_name,
169
+ endpoint_version: endpoint_version,
170
+ path: "Ledger/#{keys.join('/')}",
171
+ query_params: query_params,
172
+ logger: logger
173
+ )
174
+ end
175
+
176
+ # Retrieves a list of ledgers matching optional filters.
177
+ #
178
+ # @example Retrieve a list of ledgers
179
+ # MyobAcumatica::Api::Ledger.get_list(
180
+ # access_token: '...',
181
+ # query_params: { '$top' => 10 },
182
+ # logger: Logger.new($stdout)
183
+ # )
184
+ #
185
+ # @param access_token [String] The OAuth2 access token.
186
+ # @param query_params [Hash] Optional query params ($select, $top, etc.).
187
+ # @param instance_name [String] The instance name.
188
+ # @param endpoint_name [String] The endpoint name.
189
+ # @param endpoint_version [String] The endpoint version.
190
+ # @param logger [Logger, nil] Optional logger.
191
+ # @return [Array<Hash>] A list of ledger records.
192
+ def get_list(access_token:, query_params: {},
193
+ instance_name: INSTANCE_NAME,
194
+ endpoint_name: ENDPOINT_NAME,
195
+ endpoint_version: ENDPOINT_VERSION,
196
+ logger: nil)
197
+ Http.request(
198
+ instance_name: instance_name,
199
+ access_token: access_token,
200
+ method: :get,
201
+ endpoint_name: endpoint_name,
202
+ endpoint_version: endpoint_version,
203
+ path: 'Ledger',
204
+ query_params: query_params,
205
+ logger: logger
206
+ )
207
+ end
208
+
209
+ # Creates or updates a ledger record.
210
+ #
211
+ # @example Upsert a ledger
212
+ # MyobAcumatica::Api::Ledger.put_entity(
213
+ # access_token: '...',
214
+ # entity: {
215
+ # 'LedgerID' => { 'value' => 'LEDGER-ACTUAL' },
216
+ # 'Description' => { 'value' => 'Actuals' }
217
+ # },
218
+ # logger: Logger.new($stdout)
219
+ # )
220
+ #
221
+ # @param access_token [String] The OAuth2 access token.
222
+ # @param entity [Hash] The ledger entity payload.
223
+ # @param query_params [Hash] Optional query params ($select, $custom, etc.).
224
+ # @param instance_name [String] The instance name.
225
+ # @param endpoint_name [String] The endpoint name.
226
+ # @param endpoint_version [String] The endpoint version.
227
+ # @param logger [Logger, nil] Optional logger.
228
+ # @return [Hash] The created or updated record.
229
+ def put_entity(access_token:, entity:, query_params: {},
230
+ instance_name: INSTANCE_NAME,
231
+ endpoint_name: ENDPOINT_NAME,
232
+ endpoint_version: ENDPOINT_VERSION,
233
+ logger: nil)
234
+ Http.request(
235
+ instance_name: instance_name,
236
+ access_token: access_token,
237
+ method: :put,
238
+ endpoint_name: endpoint_name,
239
+ endpoint_version: endpoint_version,
240
+ path: 'Ledger',
241
+ body: entity,
242
+ query_params: query_params,
243
+ logger: logger
244
+ )
245
+ end
246
+
247
+ # Attaches a file to a specific ledger record by resolving the 'files:put' link.
248
+ #
249
+ # @example Upload a PDF to a ledger record
250
+ # MyobAcumatica::Api::Ledger.put_file(
251
+ # access_token: '...',
252
+ # keys: ['LEDGER-ACTUAL'],
253
+ # file_path: 'examples/sample.pdf',
254
+ # logger: Logger.new($stdout)
255
+ # )
256
+ #
257
+ # @param access_token [String] The OAuth2 access token.
258
+ # @param keys [Array<String>] Key(s) identifying the record.
259
+ # @param file_path [String] Full path to the file to upload.
260
+ # @param instance_name [String] The instance name.
261
+ # @param endpoint_name [String] The endpoint name.
262
+ # @param endpoint_version [String] The endpoint version.
263
+ # @param logger [Logger, nil] Optional logger.
264
+ # @return [nil] Returns nil if successful.
265
+ # @raise [MyobAcumatica::Error] If the upload link is missing or request fails.
266
+ def put_file(access_token:, keys:, file_path:,
267
+ instance_name: INSTANCE_NAME,
268
+ endpoint_name: ENDPOINT_NAME,
269
+ endpoint_version: ENDPOINT_VERSION,
270
+ logger: nil)
271
+ ledger = get_by_keys(
272
+ access_token: access_token,
273
+ instance_name: instance_name,
274
+ keys: keys,
275
+ logger: logger
276
+ )
277
+
278
+ put_url_template = ledger.dig('_links', 'files:put')
279
+ raise MyobAcumatica::Error, 'files:put link not found' unless put_url_template
280
+
281
+ filename = File.basename(file_path)
282
+ path = put_url_template.gsub('{filename}', filename)
283
+
284
+ Http.request(
285
+ instance_name: instance_name,
286
+ access_token: access_token,
287
+ method: :put,
288
+ endpoint_name: endpoint_name,
289
+ endpoint_version: endpoint_version,
290
+ path: path,
291
+ body: File.binread(file_path),
292
+ content_type: 'application/octet-stream',
293
+ logger: logger
294
+ )
295
+ end
296
+
297
+ # Invokes a custom action on the Ledger entity.
298
+ #
299
+ # The API may respond with 202 (accepted, in progress) or 204 (completed).
300
+ #
301
+ # @example Invoke a custom action
302
+ # MyobAcumatica::Api::Ledger.invoke_action(
303
+ # access_token: '...',
304
+ # action_name: 'RebuildBalances',
305
+ # entity: { 'LedgerID' => { 'value' => 'LEDGER-ACTUAL' } },
306
+ # parameters: { 'FromPeriod' => { 'value' => '2024-01' } },
307
+ # logger: Logger.new($stdout)
308
+ # )
309
+ #
310
+ # @param access_token [String] The OAuth2 access token.
311
+ # @param action_name [String] The action name (e.g., 'RebuildBalances').
312
+ # @param entity [Hash] The entity on which to invoke the action.
313
+ # @param parameters [Hash] Optional parameters for the action.
314
+ # @param instance_name [String] The instance name.
315
+ # @param endpoint_name [String] The endpoint name.
316
+ # @param endpoint_version [String] The endpoint version.
317
+ # @param logger [Logger, nil] Optional logger.
318
+ # @return [Hash, nil] The action response, if any.
319
+ def invoke_action(access_token:, action_name:, entity:, parameters: {},
320
+ instance_name: INSTANCE_NAME,
321
+ endpoint_name: ENDPOINT_NAME,
322
+ endpoint_version: ENDPOINT_VERSION,
323
+ logger: nil)
324
+ Http.request(
325
+ instance_name: instance_name,
326
+ access_token: access_token,
327
+ method: :post,
328
+ endpoint_name: endpoint_name,
329
+ endpoint_version: endpoint_version,
330
+ path: "Ledger/#{action_name}",
331
+ body: { 'entity' => entity, 'parameters' => parameters },
332
+ logger: logger
333
+ )
334
+ end
335
+ end
336
+ end
337
+ 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.6'
5
5
  end
@@ -29,3 +29,5 @@ 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'
33
+ require_relative 'myob_acumatica/api/ledger'
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.4
4
+ version: 0.1.6
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-08-13 00:00:00.000000000 Z
11
+ date: 2025-09-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: byebug
@@ -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
160
+ - examples/ledger.rb
159
161
  - examples/payment.rb
160
162
  - examples/tax.rb
161
163
  - lib/myob_acumatica.rb
162
164
  - lib/myob_acumatica/api.rb
165
+ - lib/myob_acumatica/api/currency.rb
163
166
  - lib/myob_acumatica/api/customer.rb
164
167
  - lib/myob_acumatica/api/http.rb
165
168
  - lib/myob_acumatica/api/invoice.rb
169
+ - lib/myob_acumatica/api/ledger.rb
166
170
  - lib/myob_acumatica/api/payment.rb
167
171
  - lib/myob_acumatica/api/tax.rb
168
172
  - lib/myob_acumatica/o_auth_2/http.rb