myob_acumatica 0.1.5 → 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 +4 -4
- data/CHANGELOG.md +13 -0
- data/Gemfile.lock +1 -1
- data/README.md +4 -7
- data/examples/app.rb +41 -31
- data/examples/ledger.rb +88 -0
- data/lib/myob_acumatica/api/ledger.rb +337 -0
- data/lib/myob_acumatica/version.rb +1 -1
- data/lib/myob_acumatica.rb +1 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ce19eee3aaa8648a6b035713bec45d0b194c5086b36005a7d8a2ca96890715be
|
4
|
+
data.tar.gz: a4d92210b0cc27dc599567afeea1e3e16a82a707fcbf3c5098366ef31efe9a9c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 375e4ada85b85912fbbda2d7475b5ca6519633993bea2c8a77b6b95dad5cff04f54b65611620d88c66774359fb40565ab60fed8344706b89180d73bf387c33ee
|
7
|
+
data.tar.gz: adca33c562c5c152268714889324920267a67273287548d65886d668e7d3f1c104e39bda2a155c531772b3fe9eea11b59d0255b641a21eb6459043c24d88022b
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,18 @@
|
|
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
|
+
|
3
16
|
## [0.1.5] - 2025-08-13
|
4
17
|
### Added
|
5
18
|
- **Currency API** support:
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -18,9 +18,7 @@ gem install myob_acumatica
|
|
18
18
|
|
19
19
|
## Configuration
|
20
20
|
|
21
|
-
Provide
|
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
|
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
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
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
|
|
data/examples/ledger.rb
ADDED
@@ -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,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
|
data/lib/myob_acumatica.rb
CHANGED
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
|
+
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-
|
11
|
+
date: 2025-09-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: byebug
|
@@ -157,6 +157,7 @@ files:
|
|
157
157
|
- examples/customer.rb
|
158
158
|
- examples/dummy.pdf
|
159
159
|
- examples/invoice.rb
|
160
|
+
- examples/ledger.rb
|
160
161
|
- examples/payment.rb
|
161
162
|
- examples/tax.rb
|
162
163
|
- lib/myob_acumatica.rb
|
@@ -165,6 +166,7 @@ files:
|
|
165
166
|
- lib/myob_acumatica/api/customer.rb
|
166
167
|
- lib/myob_acumatica/api/http.rb
|
167
168
|
- lib/myob_acumatica/api/invoice.rb
|
169
|
+
- lib/myob_acumatica/api/ledger.rb
|
168
170
|
- lib/myob_acumatica/api/payment.rb
|
169
171
|
- lib/myob_acumatica/api/tax.rb
|
170
172
|
- lib/myob_acumatica/o_auth_2/http.rb
|