myob_acumatica 0.1.0 → 0.1.2
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/.rubocop.yml +27 -0
- data/Gemfile.lock +2 -0
- data/README.md +189 -52
- data/examples/app.rb +114 -19
- data/examples/customer.rb +128 -0
- data/examples/dummy.pdf +0 -0
- data/examples/invoice.rb +121 -0
- data/lib/myob_acumatica/api/customer.rb +322 -0
- data/lib/myob_acumatica/api/http.rb +49 -0
- data/lib/myob_acumatica/api/invoice.rb +354 -0
- data/lib/myob_acumatica/api.rb +6 -0
- data/lib/myob_acumatica/o_auth_2/http.rb +26 -0
- data/lib/myob_acumatica/o_auth_2/token.rb +119 -0
- data/lib/myob_acumatica/version.rb +1 -1
- data/lib/myob_acumatica.rb +19 -4
- metadata +29 -7
- data/lib/myob_acumatica/customer.rb +0 -26
- data/lib/myob_acumatica/o_auth_2.rb +0 -59
@@ -0,0 +1,354 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module MyobAcumatica
|
4
|
+
module Api
|
5
|
+
# Provides methods to interact with the Invoice API endpoints.
|
6
|
+
module Invoice
|
7
|
+
module_function
|
8
|
+
|
9
|
+
# Deletes an invoice by ID.
|
10
|
+
# @example Delete an invoice by ID
|
11
|
+
# MyobAcumatica::Api::Invoice.delete_by_id(
|
12
|
+
# access_token: '...',
|
13
|
+
# id: '00000000-0000-4000-8000-000000000000',
|
14
|
+
# instance_name: 'example.myobadvanced.com',
|
15
|
+
# logger: Logger.new($stdout)
|
16
|
+
# )
|
17
|
+
# @param access_token [String] The OAuth2 access token.
|
18
|
+
# @param id [String] The unique ID of the invoice.
|
19
|
+
# @param instance_name [String] The instance name.
|
20
|
+
# @param endpoint_name [String] The endpoint name.
|
21
|
+
# @param endpoint_version [String] The endpoint version.
|
22
|
+
# @param logger [Logger, nil] Optional logger for logging the request process.
|
23
|
+
# @return [nil] Always nil.
|
24
|
+
def delete_by_id(access_token:, id:,
|
25
|
+
instance_name: INSTANCE_NAME,
|
26
|
+
endpoint_name: ENDPOINT_NAME,
|
27
|
+
endpoint_version: ENDPOINT_VERSION,
|
28
|
+
logger: nil)
|
29
|
+
Http.request(
|
30
|
+
instance_name: instance_name,
|
31
|
+
access_token: access_token,
|
32
|
+
method: :delete,
|
33
|
+
endpoint_name: endpoint_name,
|
34
|
+
endpoint_version: endpoint_version,
|
35
|
+
path: "Invoice/#{id}",
|
36
|
+
logger: logger
|
37
|
+
)
|
38
|
+
end
|
39
|
+
|
40
|
+
# Deletes an invoice by composite keys.
|
41
|
+
# @example Delete an invoice by keys
|
42
|
+
# MyobAcumatica::Api::Invoice.delete_by_keys(
|
43
|
+
# access_token: '...',
|
44
|
+
# keys: ['AR', 'INV000123'],
|
45
|
+
# instance_name: 'example.myobadvanced.com'
|
46
|
+
# )
|
47
|
+
# @param access_token [String] The OAuth2 access token.
|
48
|
+
# @param keys [Array<String>] An array of keys that uniquely identify the invoice.
|
49
|
+
# @param instance_name [String] The instance name.
|
50
|
+
# @param endpoint_name [String] The endpoint name.
|
51
|
+
# @param endpoint_version [String] The endpoint version.
|
52
|
+
# @param logger [Logger, nil] Optional logger for logging the request process.
|
53
|
+
# @return [nil] Always nil.
|
54
|
+
def delete_by_keys(access_token:, keys:,
|
55
|
+
instance_name: INSTANCE_NAME,
|
56
|
+
endpoint_name: ENDPOINT_NAME,
|
57
|
+
endpoint_version: ENDPOINT_VERSION,
|
58
|
+
logger: nil)
|
59
|
+
Http.request(
|
60
|
+
instance_name: instance_name,
|
61
|
+
access_token: access_token,
|
62
|
+
method: :delete,
|
63
|
+
endpoint_name: endpoint_name,
|
64
|
+
endpoint_version: endpoint_version,
|
65
|
+
path: "Invoice/#{keys.join('/')}",
|
66
|
+
logger: logger
|
67
|
+
)
|
68
|
+
end
|
69
|
+
|
70
|
+
# Retrieves the ad-hoc schema for the invoice endpoint.
|
71
|
+
# @example Retrieve the ad-hoc schema
|
72
|
+
# MyobAcumatica::Api::Invoice.get_ad_hoc_schema(
|
73
|
+
# access_token: '...',
|
74
|
+
# instance_name: 'example.myobadvanced.com'
|
75
|
+
# )
|
76
|
+
# @param access_token [String] The OAuth2 access token.
|
77
|
+
# @param instance_name [String] The instance name.
|
78
|
+
# @param endpoint_name [String] The endpoint name.
|
79
|
+
# @param endpoint_version [String] The endpoint version.
|
80
|
+
# @param logger [Logger, nil] Optional logger for logging the request process.
|
81
|
+
# @return [Hash] The ad hoc schema
|
82
|
+
def get_ad_hoc_schema(access_token:,
|
83
|
+
instance_name: INSTANCE_NAME,
|
84
|
+
endpoint_name: ENDPOINT_NAME,
|
85
|
+
endpoint_version: ENDPOINT_VERSION,
|
86
|
+
logger: nil)
|
87
|
+
Http.request(
|
88
|
+
instance_name: instance_name,
|
89
|
+
access_token: access_token,
|
90
|
+
method: :get,
|
91
|
+
endpoint_name: endpoint_name,
|
92
|
+
endpoint_version: endpoint_version,
|
93
|
+
path: 'Invoice/$adHocSchema',
|
94
|
+
logger: logger
|
95
|
+
)
|
96
|
+
end
|
97
|
+
|
98
|
+
# Retrieves an invoice by keys.
|
99
|
+
# @example Retrieve an invoice by keys
|
100
|
+
# MyobAcumatica::Api::Invoice.get_by_keys(
|
101
|
+
# access_token: '...',
|
102
|
+
# keys: ['AR', 'INV000123'],
|
103
|
+
# instance_name: 'example.myobadvanced.com'
|
104
|
+
# )
|
105
|
+
# @param access_token [String] The OAuth2 access token.
|
106
|
+
# @param keys [Array<String>] An array of keys that uniquely identify the invoice.
|
107
|
+
# @param query_params [Hash] Additional query parameters for the request.
|
108
|
+
# @param instance_name [String] The instance name.
|
109
|
+
# @param endpoint_name [String] The endpoint name.
|
110
|
+
# @param endpoint_version [String] The endpoint version.
|
111
|
+
# @param logger [Logger, nil] Optional logger for logging the request process.
|
112
|
+
# @return [Hash] The invoice.
|
113
|
+
def get_by_keys(access_token:, keys:, query_params: {},
|
114
|
+
instance_name: INSTANCE_NAME,
|
115
|
+
endpoint_name: ENDPOINT_NAME,
|
116
|
+
endpoint_version: ENDPOINT_VERSION,
|
117
|
+
logger: nil)
|
118
|
+
Http.request(
|
119
|
+
instance_name: instance_name,
|
120
|
+
access_token: access_token,
|
121
|
+
method: :get,
|
122
|
+
endpoint_name: endpoint_name,
|
123
|
+
endpoint_version: endpoint_version,
|
124
|
+
path: "Invoice/#{keys.join('/')}",
|
125
|
+
query_params: query_params,
|
126
|
+
logger: logger
|
127
|
+
)
|
128
|
+
end
|
129
|
+
|
130
|
+
# Retrieves an invoice by unique ID.
|
131
|
+
#
|
132
|
+
# @example Retrieve an invoice by ID
|
133
|
+
# MyobAcumatica::Api::Invoice.get_by_id(
|
134
|
+
# access_token: '...',
|
135
|
+
# id: 'b8c01a2d-ff7f-4f0f-bba5-abc123456789',
|
136
|
+
# )
|
137
|
+
#
|
138
|
+
# @param access_token [String] The OAuth2 access token.
|
139
|
+
# @param id [String] The unique invoice ID (UUID).
|
140
|
+
# @param query_params [Hash] Optional query parameters for the request.
|
141
|
+
# @param instance_name [String] The instance name.
|
142
|
+
# @param endpoint_name [String] The endpoint name.
|
143
|
+
# @param endpoint_version [String] The endpoint version.
|
144
|
+
# @param logger [Logger, nil] Optional logger for HTTP debugging.
|
145
|
+
# @return [Hash] The invoice with the given ID.
|
146
|
+
def get_by_id(access_token:, id:, query_params: {},
|
147
|
+
instance_name: INSTANCE_NAME,
|
148
|
+
endpoint_name: ENDPOINT_NAME,
|
149
|
+
endpoint_version: ENDPOINT_VERSION,
|
150
|
+
logger: nil)
|
151
|
+
Http.request(
|
152
|
+
instance_name: instance_name,
|
153
|
+
access_token: access_token,
|
154
|
+
method: :get,
|
155
|
+
endpoint_name: endpoint_name,
|
156
|
+
endpoint_version: endpoint_version,
|
157
|
+
path: "Invoice/#{id}",
|
158
|
+
query_params: query_params,
|
159
|
+
logger: logger
|
160
|
+
)
|
161
|
+
end
|
162
|
+
|
163
|
+
# Retrieves a list of invoices.
|
164
|
+
# @example Retrieve a list of invoices
|
165
|
+
# MyobAcumatica::Api::Invoice.get_list(
|
166
|
+
# access_token: '...',
|
167
|
+
# query_params: { '$top' => 10 },
|
168
|
+
# instance_name: 'example.myobadvanced.com'
|
169
|
+
# )
|
170
|
+
# @param access_token [String] The OAuth2 access token.
|
171
|
+
# @param query_params [Hash] Additional query parameters for the request.
|
172
|
+
# @param instance_name [String] The instance name.
|
173
|
+
# @param endpoint_name [String] The endpoint name.
|
174
|
+
# @param endpoint_version [String] The endpoint version.
|
175
|
+
# @param logger [Logger, nil] Optional logger for logging the request process.
|
176
|
+
# @return [Array<Hash>] A list of invoices.
|
177
|
+
def get_list(access_token:, query_params: {},
|
178
|
+
instance_name: INSTANCE_NAME,
|
179
|
+
endpoint_name: ENDPOINT_NAME,
|
180
|
+
endpoint_version: ENDPOINT_VERSION,
|
181
|
+
logger: nil)
|
182
|
+
Http.request(
|
183
|
+
instance_name: instance_name,
|
184
|
+
access_token: access_token,
|
185
|
+
method: :get,
|
186
|
+
endpoint_name: endpoint_name,
|
187
|
+
endpoint_version: endpoint_version,
|
188
|
+
path: 'Invoice',
|
189
|
+
query_params: query_params,
|
190
|
+
logger: logger
|
191
|
+
)
|
192
|
+
end
|
193
|
+
|
194
|
+
# Creates or updates an invoice entity.
|
195
|
+
# @example Create or update an invoice
|
196
|
+
# MyobAcumatica::Api::Invoice.put_entity(
|
197
|
+
# access_token: '...',
|
198
|
+
# entity: {
|
199
|
+
# 'CustomerID' => { 'value' => 'JOHNGOOD' },
|
200
|
+
# 'Type' => { 'value' => 'Invoice' },
|
201
|
+
# 'InvoiceNbr' => { 'value' => 'INV000123' }
|
202
|
+
# },
|
203
|
+
# instance_name: 'example.myobadvanced.com'
|
204
|
+
# )
|
205
|
+
# @param access_token [String] The OAuth2 access token.
|
206
|
+
# @param entity [Hash] The invoice entity to create or update.
|
207
|
+
# @param query_params [Hash] Additional query parameters for the request.
|
208
|
+
# @param instance_name [String] The instance name.
|
209
|
+
# @param endpoint_name [String] The endpoint name.
|
210
|
+
# @param endpoint_version [String] The endpoint version.
|
211
|
+
# @param logger [Logger, nil] Optional logger for logging the request process.
|
212
|
+
# @return [Hash] The updated or created invoice.
|
213
|
+
def put_entity(access_token:, entity:, query_params: {},
|
214
|
+
instance_name: INSTANCE_NAME,
|
215
|
+
endpoint_name: ENDPOINT_NAME,
|
216
|
+
endpoint_version: ENDPOINT_VERSION,
|
217
|
+
logger: nil)
|
218
|
+
Http.request(
|
219
|
+
instance_name: instance_name,
|
220
|
+
access_token: access_token,
|
221
|
+
method: :put,
|
222
|
+
endpoint_name: endpoint_name,
|
223
|
+
endpoint_version: endpoint_version,
|
224
|
+
path: 'Invoice',
|
225
|
+
body: entity,
|
226
|
+
query_params: query_params,
|
227
|
+
logger: logger
|
228
|
+
)
|
229
|
+
end
|
230
|
+
|
231
|
+
# Uploads a file to a specific invoice record by resolving the `files:put` link.
|
232
|
+
#
|
233
|
+
# @example Upload a PDF to an invoice
|
234
|
+
# MyobAcumatica::Api::Invoice.put_file(
|
235
|
+
# access_token: '...',
|
236
|
+
# keys: ['AR', 'INV000123'],
|
237
|
+
# file_path: 'examples/invoice.pdf',
|
238
|
+
# instance_name: 'example.myobadvanced.com'
|
239
|
+
# )
|
240
|
+
# @param access_token [String] The OAuth2 access token.
|
241
|
+
# @param keys [Array<String>] Key(s) identifying the invoice record.
|
242
|
+
# @param file_path [String] Full path to the file to be uploaded.
|
243
|
+
# @param instance_name [String] The instance name.
|
244
|
+
# @param endpoint_name [String] The endpoint name.
|
245
|
+
# @param endpoint_version [String] The endpoint version.
|
246
|
+
# @param logger [Logger, nil] Optional logger for HTTP debugging.
|
247
|
+
# @return [nil] Returns nil if successful.
|
248
|
+
# @raise [MyobAcumatica::Error] If the upload fails.
|
249
|
+
def put_file(access_token:, keys:, file_path:,
|
250
|
+
instance_name: INSTANCE_NAME,
|
251
|
+
endpoint_name: ENDPOINT_NAME,
|
252
|
+
endpoint_version: ENDPOINT_VERSION,
|
253
|
+
logger: nil)
|
254
|
+
invoice = get_by_keys(
|
255
|
+
access_token: access_token,
|
256
|
+
keys: keys,
|
257
|
+
instance_name: instance_name,
|
258
|
+
logger: logger
|
259
|
+
)
|
260
|
+
|
261
|
+
put_url_template = invoice.dig('_links', 'files:put')
|
262
|
+
raise MyobAcumatica::Error, 'files:put link not found' unless put_url_template
|
263
|
+
|
264
|
+
filename = File.basename(file_path)
|
265
|
+
path = put_url_template.gsub('{filename}', filename)
|
266
|
+
|
267
|
+
Http.request(
|
268
|
+
instance_name: instance_name,
|
269
|
+
access_token: access_token,
|
270
|
+
method: :put,
|
271
|
+
endpoint_name: endpoint_name,
|
272
|
+
endpoint_version: endpoint_version,
|
273
|
+
path: path,
|
274
|
+
body: File.binread(file_path),
|
275
|
+
content_type: 'application/octet-stream',
|
276
|
+
logger: logger
|
277
|
+
)
|
278
|
+
end
|
279
|
+
|
280
|
+
# Invokes a custom action on the Invoice entity.
|
281
|
+
#
|
282
|
+
# @example Apply a payment or custom action
|
283
|
+
# MyobAcumatica::Api::Invoice.invoke_action(
|
284
|
+
# access_token: '...',
|
285
|
+
# action_name: 'ReleaseInvoice',
|
286
|
+
# entity: { 'Type' => { 'value' => 'Invoice' }, 'InvoiceNbr' => { 'value' => 'INV000123' } },
|
287
|
+
# instance_name: 'example.myobadvanced.com'
|
288
|
+
# )
|
289
|
+
#
|
290
|
+
# @param access_token [String] The OAuth2 access token.
|
291
|
+
# @param action_name [String] The name of the action to invoke.
|
292
|
+
# @param entity [Hash] The invoice entity on which to invoke the action.
|
293
|
+
# @param parameters [Hash] Optional parameters for the action.
|
294
|
+
# @param instance_name [String] The instance name.
|
295
|
+
# @param endpoint_name [String] The endpoint name.
|
296
|
+
# @param endpoint_version [String] The endpoint version.
|
297
|
+
# @param logger [Logger, nil] Optional logger for HTTP debugging.
|
298
|
+
# @return [Hash, nil] The response from the action.
|
299
|
+
def invoke_action(access_token:, action_name:, entity:, parameters: {},
|
300
|
+
instance_name: INSTANCE_NAME,
|
301
|
+
endpoint_name: ENDPOINT_NAME,
|
302
|
+
endpoint_version: ENDPOINT_VERSION,
|
303
|
+
logger: nil)
|
304
|
+
Http.request(
|
305
|
+
instance_name: instance_name,
|
306
|
+
access_token: access_token,
|
307
|
+
method: :post,
|
308
|
+
endpoint_name: endpoint_name,
|
309
|
+
endpoint_version: endpoint_version,
|
310
|
+
path: "Invoice/#{action_name}",
|
311
|
+
body: { 'entity' => entity, 'parameters' => parameters },
|
312
|
+
logger: logger
|
313
|
+
)
|
314
|
+
end
|
315
|
+
|
316
|
+
# Releases an invoice.
|
317
|
+
#
|
318
|
+
# @example Release an invoice
|
319
|
+
# MyobAcumatica::Api::Invoice.release(
|
320
|
+
# access_token: '...',
|
321
|
+
# entity: {
|
322
|
+
# 'Type' => { 'value' => 'Invoice' },
|
323
|
+
# 'InvoiceNbr' => { 'value' => 'INV000123' }
|
324
|
+
# },
|
325
|
+
# instance_name: 'example.myobadvanced.com'
|
326
|
+
# )
|
327
|
+
#
|
328
|
+
# @param access_token [String] The OAuth2 access token.
|
329
|
+
# @param entity [Hash] The entity.
|
330
|
+
# @param parameters [Hash] The parameters.
|
331
|
+
# @param instance_name [String] The instance name.
|
332
|
+
# @param endpoint_name [String] The endpoint name.
|
333
|
+
# @param endpoint_version [String] The endpoint version.
|
334
|
+
# @param logger [Logger, nil] Optional logger for HTTP debugging.
|
335
|
+
# @return [Hash] The response from the release action.
|
336
|
+
def release(access_token:, entity:, parameters: nil,
|
337
|
+
instance_name: INSTANCE_NAME,
|
338
|
+
endpoint_name: ENDPOINT_NAME,
|
339
|
+
endpoint_version: ENDPOINT_VERSION,
|
340
|
+
logger: nil)
|
341
|
+
Http.request(
|
342
|
+
instance_name: instance_name,
|
343
|
+
access_token: access_token,
|
344
|
+
method: :post,
|
345
|
+
endpoint_name: endpoint_name,
|
346
|
+
endpoint_version: endpoint_version,
|
347
|
+
path: 'Invoice/ReleaseInvoice',
|
348
|
+
body: { 'entity' => entity, 'parameters' => parameters },
|
349
|
+
logger: logger
|
350
|
+
)
|
351
|
+
end
|
352
|
+
end
|
353
|
+
end
|
354
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module MyobAcumatica
|
4
|
+
module OAuth2
|
5
|
+
module Http
|
6
|
+
module_function
|
7
|
+
|
8
|
+
def post(uri:, body:, logger: nil)
|
9
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
10
|
+
http.use_ssl = uri.scheme == 'https'
|
11
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
12
|
+
http.set_debug_output(logger) if logger
|
13
|
+
|
14
|
+
request = Net::HTTP::Post.new(uri, 'Content-Type' => 'application/x-www-form-urlencoded')
|
15
|
+
request.set_form_data(body)
|
16
|
+
response = http.request(request)
|
17
|
+
|
18
|
+
if !response.is_a?(Net::HTTPSuccess)
|
19
|
+
raise MyobAcumatica::Error, "HTTP #{response.code}: #{response.body}"
|
20
|
+
end
|
21
|
+
|
22
|
+
JSON.parse(response.body)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,119 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module MyobAcumatica
|
4
|
+
module OAuth2
|
5
|
+
# Handles the OAuth2 flow for authenticating with MYOB Acumatica.
|
6
|
+
module Token
|
7
|
+
module_function
|
8
|
+
|
9
|
+
# Generates the OAuth2 authorization URL to initiate the login flow.
|
10
|
+
#
|
11
|
+
# @example Generate the URL to initiate the OAuth2 login
|
12
|
+
# MyobAcumatica::OAuth2::Token.authorize_url(
|
13
|
+
# redirect_uri: 'https://example.myobadvanced.com/oauth2/callback',
|
14
|
+
# instance_name: 'example.myobadvanced.com',
|
15
|
+
# client_id: 'abc123',
|
16
|
+
# scope: 'api offline_access'
|
17
|
+
# )
|
18
|
+
# # => "https://example.myobadvanced.com/identity/connect/authorize?response_type=code&client_id=abc123&redirect_uri=https%3A%2F%2Fexample.myobadvanced.com%2Foauth2%2Fcallback&scope=api+offline_access"
|
19
|
+
#
|
20
|
+
# @param redirect_uri [String] The OAuth2 redirect URI.
|
21
|
+
# @param instance_name [String] The Acumatica instance name.
|
22
|
+
# @param client_id [String] The OAuth2 client ID.
|
23
|
+
# @param scope [String] A space-delimited list of scopes.
|
24
|
+
# @return [String] The URL to redirect users for authorization.
|
25
|
+
def authorize_url(
|
26
|
+
redirect_uri: REDIRECT_URI,
|
27
|
+
instance_name: INSTANCE_NAME,
|
28
|
+
client_id: CLIENT_ID,
|
29
|
+
scope: SCOPE
|
30
|
+
)
|
31
|
+
"https://#{instance_name}/identity/connect/authorize?" \
|
32
|
+
"#{URI.encode_www_form({
|
33
|
+
response_type: 'code',
|
34
|
+
client_id: client_id,
|
35
|
+
redirect_uri: redirect_uri,
|
36
|
+
scope: scope
|
37
|
+
})}"
|
38
|
+
end
|
39
|
+
|
40
|
+
# Exchanges an authorization code for an access token.
|
41
|
+
#
|
42
|
+
# @example Exchange the code for an access token
|
43
|
+
# token = MyobAcumatica::OAuth2::Token.authorize(
|
44
|
+
# code: 'abc123',
|
45
|
+
# redirect_uri: 'http://localhost:4567/oauth2/callback'
|
46
|
+
# )
|
47
|
+
#
|
48
|
+
# @param code [String] The authorization code received from the login flow.
|
49
|
+
# @param redirect_uri [String] The OAuth2 redirect URI.
|
50
|
+
# @param instance_name [String] The Acumatica instance name.
|
51
|
+
# @param client_id [String] The OAuth2 client ID.
|
52
|
+
# @param client_secret [String] The OAuth2 client secret.
|
53
|
+
# @param logger [Logger, nil] Optional logger for debugging HTTP requests.
|
54
|
+
# @return [Hash] The token response with keys:
|
55
|
+
# - access_token [String] The bearer token.
|
56
|
+
# - token_type [String] Typically "Bearer".
|
57
|
+
# - expires_in [Integer] Number of seconds until expiration.
|
58
|
+
# - refresh_token [String] Used to obtain a new access token.
|
59
|
+
# - scope [String] Space-delimited list of granted scopes.
|
60
|
+
def authorize(
|
61
|
+
code:,
|
62
|
+
redirect_uri: REDIRECT_URI,
|
63
|
+
instance_name: INSTANCE_NAME,
|
64
|
+
client_id: CLIENT_ID,
|
65
|
+
client_secret: CLIENT_SECRET,
|
66
|
+
logger: nil
|
67
|
+
)
|
68
|
+
Http.post(
|
69
|
+
uri: URI("https://#{instance_name}/identity/connect/token"),
|
70
|
+
body: {
|
71
|
+
grant_type: 'authorization_code',
|
72
|
+
client_id: client_id,
|
73
|
+
client_secret: client_secret,
|
74
|
+
code: code,
|
75
|
+
redirect_uri: redirect_uri
|
76
|
+
},
|
77
|
+
logger: logger
|
78
|
+
)
|
79
|
+
end
|
80
|
+
|
81
|
+
# Refreshes the access token using a refresh token.
|
82
|
+
#
|
83
|
+
# @example Refresh the token
|
84
|
+
# token = MyobAcumatica::OAuth2::Token.refresh(
|
85
|
+
# refresh_token: token['refresh_token']
|
86
|
+
# )
|
87
|
+
#
|
88
|
+
# @param refresh_token [String] The previously issued refresh token.
|
89
|
+
# @param instance_name [String] The Acumatica instance name.
|
90
|
+
# @param client_id [String] The OAuth2 client ID.
|
91
|
+
# @param client_secret [String] The OAuth2 client secret.
|
92
|
+
# @param logger [Logger, nil] Optional logger for debugging HTTP requests.
|
93
|
+
# @return [Hash] The refreshed token response with keys:
|
94
|
+
# - access_token [String] The new bearer token.
|
95
|
+
# - token_type [String] Typically "Bearer".
|
96
|
+
# - expires_in [Integer] Number of seconds until expiration.
|
97
|
+
# - refresh_token [String] Used to obtain the next access token.
|
98
|
+
# - scope [String] Space-delimited list of granted scopes.
|
99
|
+
def refresh(
|
100
|
+
refresh_token:,
|
101
|
+
instance_name: INSTANCE_NAME,
|
102
|
+
client_id: CLIENT_ID,
|
103
|
+
client_secret: CLIENT_SECRET,
|
104
|
+
logger: nil
|
105
|
+
)
|
106
|
+
Http.post(
|
107
|
+
uri: URI("https://#{instance_name}/identity/connect/token"),
|
108
|
+
body: {
|
109
|
+
grant_type: 'refresh_token',
|
110
|
+
client_id: client_id,
|
111
|
+
client_secret: client_secret,
|
112
|
+
refresh_token: refresh_token
|
113
|
+
},
|
114
|
+
logger: logger
|
115
|
+
)
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
data/lib/myob_acumatica.rb
CHANGED
@@ -6,9 +6,24 @@ require 'json'
|
|
6
6
|
require 'logger'
|
7
7
|
require 'pry'
|
8
8
|
|
9
|
-
require_relative 'myob_acumatica/version'
|
10
|
-
require_relative 'myob_acumatica/o_auth_2'
|
11
|
-
require_relative 'myob_acumatica/customer'
|
12
|
-
|
13
9
|
module MyobAcumatica
|
10
|
+
class Error < StandardError; end
|
11
|
+
|
12
|
+
INSTANCE_NAME = ENV['MYOB_ACUMATICA_INSTANCE_NAME']
|
13
|
+
CLIENT_ID = ENV['MYOB_ACUMATICA_CLIENT_ID']
|
14
|
+
CLIENT_SECRET = ENV['MYOB_ACUMATICA_CLIENT_SECRET']
|
15
|
+
REDIRECT_URI = ENV['MYOB_ACUMATICA_REDIRECT_URI']
|
16
|
+
SCOPE = ENV['MYOB_ACUMATICA_SCOPE']
|
17
|
+
ENDPOINT_NAME = ENV['MYOB_ACUMATICA_ENDPOINT_NAME']
|
18
|
+
ENDPOINT_VERSION = ENV['MYOB_ACUMATICA_ENDPOINT_VERSION']
|
14
19
|
end
|
20
|
+
|
21
|
+
require_relative 'myob_acumatica/version'
|
22
|
+
|
23
|
+
require_relative 'myob_acumatica/o_auth_2/http'
|
24
|
+
require_relative 'myob_acumatica/o_auth_2/token'
|
25
|
+
|
26
|
+
require_relative 'myob_acumatica/api'
|
27
|
+
require_relative 'myob_acumatica/api/http'
|
28
|
+
require_relative 'myob_acumatica/api/customer'
|
29
|
+
require_relative 'myob_acumatica/api/invoice'
|
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.2
|
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-06-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: byebug
|
@@ -122,6 +122,20 @@ dependencies:
|
|
122
122
|
- - "~>"
|
123
123
|
- !ruby/object:Gem::Version
|
124
124
|
version: '4.1'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: yard
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - "~>"
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0.9'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - "~>"
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0.9'
|
125
139
|
description:
|
126
140
|
email:
|
127
141
|
- adammikulas@gmail.com
|
@@ -139,18 +153,26 @@ files:
|
|
139
153
|
- README.md
|
140
154
|
- Rakefile
|
141
155
|
- examples/app.rb
|
156
|
+
- examples/customer.rb
|
157
|
+
- examples/dummy.pdf
|
158
|
+
- examples/invoice.rb
|
142
159
|
- lib/myob_acumatica.rb
|
143
|
-
- lib/myob_acumatica/
|
144
|
-
- lib/myob_acumatica/
|
160
|
+
- lib/myob_acumatica/api.rb
|
161
|
+
- lib/myob_acumatica/api/customer.rb
|
162
|
+
- lib/myob_acumatica/api/http.rb
|
163
|
+
- lib/myob_acumatica/api/invoice.rb
|
164
|
+
- lib/myob_acumatica/o_auth_2/http.rb
|
165
|
+
- lib/myob_acumatica/o_auth_2/token.rb
|
145
166
|
- lib/myob_acumatica/version.rb
|
146
167
|
- sig/myob_acumatica.rbs
|
147
|
-
homepage: https://
|
168
|
+
homepage: https://github.com/fast-programmer/myob_acumatica
|
148
169
|
licenses:
|
149
170
|
- MIT
|
150
171
|
metadata:
|
151
|
-
homepage_uri: https://www.myob.com/au/erp-software/products/myob-acumatica
|
152
172
|
source_code_uri: https://github.com/fast-programmer/myob_acumatica
|
153
173
|
changelog_uri: https://github.com/fast-programmer/myob_acumatica/blob/master/CHANGELOG.md
|
174
|
+
homepage_uri: https://github.com/fast-programmer/myob_acumatica
|
175
|
+
documentation_uri: https://www.rubydoc.info/gems/myob_acumatica
|
154
176
|
post_install_message:
|
155
177
|
rdoc_options: []
|
156
178
|
require_paths:
|
@@ -169,5 +191,5 @@ requirements: []
|
|
169
191
|
rubygems_version: 3.3.27
|
170
192
|
signing_key:
|
171
193
|
specification_version: 4
|
172
|
-
summary: Ruby client for
|
194
|
+
summary: Ruby client for MYOB Acumatica
|
173
195
|
test_files: []
|
@@ -1,26 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module MyobAcumatica
|
4
|
-
module Customer
|
5
|
-
module_function
|
6
|
-
|
7
|
-
def list(instance_url:, endpoint_name:, endpoint_version:, access_token:, query_params: {}, logger: nil)
|
8
|
-
uri = URI("https://#{instance_url}/entity/#{endpoint_name}/#{endpoint_version}/Customer")
|
9
|
-
uri.query = URI.encode_www_form(query_params) unless query_params.empty?
|
10
|
-
|
11
|
-
http = Net::HTTP.new(uri.host, uri.port)
|
12
|
-
http.use_ssl = uri.scheme == 'https'
|
13
|
-
http.set_debug_output(logger) if logger
|
14
|
-
|
15
|
-
request = Net::HTTP::Get.new(uri, {
|
16
|
-
'Authorization' => "Bearer #{access_token}",
|
17
|
-
'Content-Type' => 'application/json',
|
18
|
-
'Accept' => 'application/json'
|
19
|
-
})
|
20
|
-
|
21
|
-
response = http.request(request)
|
22
|
-
|
23
|
-
JSON.parse(response.body)
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|