Module: MyobAcumatica::Api::Currency

Defined in:
lib/myob_acumatica/api/currency.rb

Overview

Provides methods to interact with the Currency API endpoints.

Class Method Summary collapse

Class Method Details

.delete_by_id(access_token:, id:, instance_name: INSTANCE_NAME, endpoint_name: ENDPOINT_NAME, endpoint_version: ENDPOINT_VERSION, logger: nil) ⇒ nil

Deletes a currency record by its session UUID.

Examples:

Delete a currency by ID

MyobAcumatica::Api::Currency.delete_by_id(
  access_token: access_token,
  id: currency['id'],
  logger: logger
)

Parameters:

  • access_token (String)

    OAuth2 access token.

  • id (String)

    Session UUID of the currency record.

  • instance_name (String) (defaults to: INSTANCE_NAME)

    The instance name.

  • endpoint_name (String) (defaults to: ENDPOINT_NAME)

    The endpoint name.

  • endpoint_version (String) (defaults to: ENDPOINT_VERSION)

    The endpoint version.

  • logger (Logger, nil) (defaults to: nil)

    Optional logger.

Returns:

  • (nil)


26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/myob_acumatica/api/currency.rb', line 26

def delete_by_id(access_token:, id:,
                 instance_name: INSTANCE_NAME,
                 endpoint_name: ENDPOINT_NAME,
                 endpoint_version: ENDPOINT_VERSION,
                 logger: nil)
  Http.request(
    instance_name: instance_name,
    access_token: access_token,
    method: :delete,
    endpoint_name: endpoint_name,
    endpoint_version: endpoint_version,
    path: "Currency/#{id}",
    logger: logger
  )
end

.delete_by_keys(access_token:, keys:, instance_name: INSTANCE_NAME, endpoint_name: ENDPOINT_NAME, endpoint_version: ENDPOINT_VERSION, logger: nil) ⇒ nil

Deletes a currency record by composite keys.

Keys are ordered values of the record’s key fields.

Examples:

Delete a currency by keys

MyobAcumatica::Api::Currency.delete_by_keys(
  access_token: access_token,
  keys: [currency['CurrencyID']['value']],
  logger: logger
)

Parameters:

  • access_token (String)

    OAuth2 access token.

  • keys (Array<String>)

    Key values identifying the currency record.

  • instance_name (String) (defaults to: INSTANCE_NAME)

    The instance name.

  • endpoint_name (String) (defaults to: ENDPOINT_NAME)

    The endpoint name.

  • endpoint_version (String) (defaults to: ENDPOINT_VERSION)

    The endpoint version.

  • logger (Logger, nil) (defaults to: nil)

    Optional logger.

Returns:

  • (nil)


61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/myob_acumatica/api/currency.rb', line 61

def delete_by_keys(access_token:, keys:,
                   instance_name: INSTANCE_NAME,
                   endpoint_name: ENDPOINT_NAME,
                   endpoint_version: ENDPOINT_VERSION,
                   logger: nil)
  Http.request(
    instance_name: instance_name,
    access_token: access_token,
    method: :delete,
    endpoint_name: endpoint_name,
    endpoint_version: endpoint_version,
    path: "Currency/#{keys.join('/')}",
    logger: logger
  )
end

.get_ad_hoc_schema(access_token:, instance_name: INSTANCE_NAME, endpoint_name: ENDPOINT_NAME, endpoint_version: ENDPOINT_VERSION, logger: nil) ⇒ Hash

Retrieves the ad-hoc schema (custom fields) for the Currency entity.

Examples:

Retrieve ad-hoc schema

MyobAcumatica::Api::Currency.get_ad_hoc_schema(
  access_token: access_token,
  logger: logger
)

Parameters:

  • access_token (String)

    OAuth2 access token.

  • instance_name (String) (defaults to: INSTANCE_NAME)

    The instance name.

  • endpoint_name (String) (defaults to: ENDPOINT_NAME)

    The endpoint name.

  • endpoint_version (String) (defaults to: ENDPOINT_VERSION)

    The endpoint version.

  • logger (Logger, nil) (defaults to: nil)

    Optional logger.

Returns:

  • (Hash)

    Ad-hoc schema payload.



92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/myob_acumatica/api/currency.rb', line 92

def get_ad_hoc_schema(access_token:,
                      instance_name: INSTANCE_NAME,
                      endpoint_name: ENDPOINT_NAME,
                      endpoint_version: ENDPOINT_VERSION,
                      logger: nil)
  Http.request(
    instance_name: instance_name,
    access_token: access_token,
    method: :get,
    endpoint_name: endpoint_name,
    endpoint_version: endpoint_version,
    path: 'Currency/$adHocSchema',
    logger: logger
  )
end

.get_by_id(access_token:, id:, query_params: {}, instance_name: INSTANCE_NAME, endpoint_name: ENDPOINT_NAME, endpoint_version: ENDPOINT_VERSION, logger: nil) ⇒ Hash

Retrieves a currency record by its session UUID.

Examples:

Get currency by ID

MyobAcumatica::Api::Currency.get_by_id(
  access_token: access_token,
  id: currency['id'],
  logger: logger
)

Parameters:

  • access_token (String)

    OAuth2 access token.

  • id (String)

    Session UUID of the currency record.

  • query_params (Hash) (defaults to: {})

    Optional query params ($select, $expand, $filter, $custom).

  • instance_name (String) (defaults to: INSTANCE_NAME)

    The instance name.

  • endpoint_name (String) (defaults to: ENDPOINT_NAME)

    The endpoint name.

  • endpoint_version (String) (defaults to: ENDPOINT_VERSION)

    The endpoint version.

  • logger (Logger, nil) (defaults to: nil)

    Optional logger.

Returns:

  • (Hash)

    The currency record.



127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
# File 'lib/myob_acumatica/api/currency.rb', line 127

def get_by_id(access_token:, id:, query_params: {},
              instance_name: INSTANCE_NAME,
              endpoint_name: ENDPOINT_NAME,
              endpoint_version: ENDPOINT_VERSION,
              logger: nil)
  Http.request(
    instance_name: instance_name,
    access_token: access_token,
    method: :get,
    endpoint_name: endpoint_name,
    endpoint_version: endpoint_version,
    path: "Currency/#{id}",
    query_params: query_params,
    logger: logger
  )
end

.get_by_keys(access_token:, keys:, query_params: {}, instance_name: INSTANCE_NAME, endpoint_name: ENDPOINT_NAME, endpoint_version: ENDPOINT_VERSION, logger: nil) ⇒ Hash

Retrieves a currency record by composite keys.

Examples:

Get currency by keys

MyobAcumatica::Api::Currency.get_by_keys(
  access_token: access_token,
  keys: ['USD'],
  logger: logger
)

Parameters:

  • access_token (String)

    OAuth2 access token.

  • keys (Array<String>)

    Key values identifying the currency record.

  • query_params (Hash) (defaults to: {})

    Optional query params.

  • instance_name (String) (defaults to: INSTANCE_NAME)

    The instance name.

  • endpoint_name (String) (defaults to: ENDPOINT_NAME)

    The endpoint name.

  • endpoint_version (String) (defaults to: ENDPOINT_VERSION)

    The endpoint version.

  • logger (Logger, nil) (defaults to: nil)

    Optional logger.

Returns:

  • (Hash)

    The currency record.



162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
# File 'lib/myob_acumatica/api/currency.rb', line 162

def get_by_keys(access_token:, keys:, query_params: {},
                instance_name: INSTANCE_NAME,
                endpoint_name: ENDPOINT_NAME,
                endpoint_version: ENDPOINT_VERSION,
                logger: nil)
  Http.request(
    instance_name: instance_name,
    access_token: access_token,
    method: :get,
    endpoint_name: endpoint_name,
    endpoint_version: endpoint_version,
    path: "Currency/#{keys.join('/')}",
    query_params: query_params,
    logger: logger
  )
end

.get_list(access_token:, query_params: {}, instance_name: INSTANCE_NAME, endpoint_name: ENDPOINT_NAME, endpoint_version: ENDPOINT_VERSION, logger: nil) ⇒ Array<Hash>

Retrieves a list of currency records with optional filtering and paging.

Examples:

List currencies

MyobAcumatica::Api::Currency.get_list(
  access_token: access_token,
  query_params: { '$top' => 10 },
  logger: logger
)

Parameters:

  • access_token (String)

    OAuth2 access token.

  • query_params (Hash) (defaults to: {})

    Optional query params.

  • instance_name (String) (defaults to: INSTANCE_NAME)

    The instance name.

  • endpoint_name (String) (defaults to: ENDPOINT_NAME)

    The endpoint name.

  • endpoint_version (String) (defaults to: ENDPOINT_VERSION)

    The endpoint version.

  • logger (Logger, nil) (defaults to: nil)

    Optional logger.

Returns:

  • (Array<Hash>)

    List of currency records.



196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
# File 'lib/myob_acumatica/api/currency.rb', line 196

def get_list(access_token:, query_params: {},
             instance_name: INSTANCE_NAME,
             endpoint_name: ENDPOINT_NAME,
             endpoint_version: ENDPOINT_VERSION,
             logger: nil)
  Http.request(
    instance_name: instance_name,
    access_token: access_token,
    method: :get,
    endpoint_name: endpoint_name,
    endpoint_version: endpoint_version,
    path: 'Currency',
    query_params: query_params,
    logger: logger
  )
end

.invoke_action(access_token:, action_name:, entity:, parameters: {}, instance_name: INSTANCE_NAME, endpoint_name: ENDPOINT_NAME, endpoint_version: ENDPOINT_VERSION, logger: nil) ⇒ Hash?

Invokes a custom action on a currency record.

Examples:

Invoke a custom action

MyobAcumatica::Api::Currency.invoke_action(
  access_token: access_token,
  action_name: 'CustomAction',
  entity: { 'id' => currency['id'] },
  parameters: {},
  logger: logger
)

Parameters:

  • access_token (String)

    OAuth2 access token.

  • action_name (String)

    The action name to invoke.

  • entity (Hash)

    Currency entity payload.

  • parameters (Hash) (defaults to: {})

    Optional parameters for the action.

  • instance_name (String) (defaults to: INSTANCE_NAME)

    The instance name.

  • endpoint_name (String) (defaults to: ENDPOINT_NAME)

    The endpoint name.

  • endpoint_version (String) (defaults to: ENDPOINT_VERSION)

    The endpoint version.

  • logger (Logger, nil) (defaults to: nil)

    Optional logger.

Returns:

  • (Hash, nil)

    Action response or nil on 204.



234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
# File 'lib/myob_acumatica/api/currency.rb', line 234

def invoke_action(access_token:, action_name:, entity:, parameters: {},
                  instance_name: INSTANCE_NAME,
                  endpoint_name: ENDPOINT_NAME,
                  endpoint_version: ENDPOINT_VERSION,
                  logger: nil)
  Http.request(
    instance_name: instance_name,
    access_token: access_token,
    method: :post,
    endpoint_name: endpoint_name,
    endpoint_version: endpoint_version,
    path: "Currency/#{action_name}",
    body: { 'entity' => entity, 'parameters' => parameters },
    logger: logger
  )
end

.put_entity(access_token:, entity:, query_params: {}, instance_name: INSTANCE_NAME, endpoint_name: ENDPOINT_NAME, endpoint_version: ENDPOINT_VERSION, logger: nil) ⇒ Hash

Creates or updates a currency record.

Examples:

Create or update a currency

usd = MyobAcumatica::Api::Currency.put_entity(
  access_token: access_token,
  entity: { 'CurrencyID' => { 'value' => 'USD' } },
  logger: logger
)

Parameters:

  • access_token (String)

    OAuth2 access token.

  • entity (Hash)

    Currency entity payload.

  • query_params (Hash) (defaults to: {})

    Optional query params.

  • instance_name (String) (defaults to: INSTANCE_NAME)

    The instance name.

  • endpoint_name (String) (defaults to: ENDPOINT_NAME)

    The endpoint name.

  • endpoint_version (String) (defaults to: ENDPOINT_VERSION)

    The endpoint version.

  • logger (Logger, nil) (defaults to: nil)

    Optional logger.

Returns:

  • (Hash)

    The created or updated currency record.



269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
# File 'lib/myob_acumatica/api/currency.rb', line 269

def put_entity(access_token:, entity:, query_params: {},
               instance_name: INSTANCE_NAME,
               endpoint_name: ENDPOINT_NAME,
               endpoint_version: ENDPOINT_VERSION,
               logger: nil)
  Http.request(
    instance_name: instance_name,
    access_token: access_token,
    method: :put,
    endpoint_name: endpoint_name,
    endpoint_version: endpoint_version,
    path: 'Currency',
    body: entity,
    query_params: query_params,
    logger: logger
  )
end

.put_file(access_token:, keys:, file_path:, instance_name: INSTANCE_NAME, endpoint_name: ENDPOINT_NAME, endpoint_version: ENDPOINT_VERSION, logger: nil) ⇒ nil

Attaches a file to a currency record.

Examples:

Upload a file to a currency record

MyobAcumatica::Api::Currency.put_file(
  access_token: access_token,
  keys: ['USD'],
  file_path: 'examples/rate-sheet.pdf',
  logger: logger
)

Parameters:

  • access_token (String)

    OAuth2 access token.

  • keys (Array<String>)

    Key values identifying the currency record.

  • file_path (String)

    Path to the file.

  • instance_name (String) (defaults to: INSTANCE_NAME)

    The instance name.

  • endpoint_name (String) (defaults to: ENDPOINT_NAME)

    The endpoint name.

  • endpoint_version (String) (defaults to: ENDPOINT_VERSION)

    The endpoint version.

  • logger (Logger, nil) (defaults to: nil)

    Optional logger.

Returns:

  • (nil)

Raises:



306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
# File 'lib/myob_acumatica/api/currency.rb', line 306

def put_file(access_token:, keys:, file_path:,
             instance_name: INSTANCE_NAME,
             endpoint_name: ENDPOINT_NAME,
             endpoint_version: ENDPOINT_VERSION,
             logger: nil)
  entity = get_by_keys(
    access_token: access_token,
    keys: keys,
    instance_name: instance_name,
    endpoint_name: endpoint_name,
    endpoint_version: endpoint_version,
    logger: logger
  )

  put_template = entity.dig('_links', 'files:put')
  raise MyobAcumatica::Error, 'files:put link not found' unless put_template

  filename = File.basename(file_path)
  path = put_template.gsub('{filename}', filename)

  Http.request(
    instance_name: instance_name,
    access_token: access_token,
    method: :put,
    endpoint_name: endpoint_name,
    endpoint_version: endpoint_version,
    path: path,
    body: File.binread(file_path),
    content_type: 'application/octet-stream',
    logger: logger
  )
end