business-central 1.0.3 → 1.0.7

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.
Files changed (128) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +58 -15
  3. data/lib/business_central/client.rb +71 -41
  4. data/lib/business_central/exceptions.rb +19 -9
  5. data/lib/business_central/object/account.rb +4 -2
  6. data/lib/business_central/object/aged_account_payable.rb +4 -2
  7. data/lib/business_central/object/aged_account_receivable.rb +4 -2
  8. data/lib/business_central/object/argument_helper.rb +22 -0
  9. data/lib/business_central/object/attachment.rb +30 -0
  10. data/lib/business_central/object/balance_sheet.rb +4 -2
  11. data/lib/business_central/object/base.rb +90 -56
  12. data/lib/business_central/object/cash_flow_statement.rb +4 -2
  13. data/lib/business_central/object/company.rb +5 -3
  14. data/lib/business_central/object/company_information.rb +7 -5
  15. data/lib/business_central/object/country_region.rb +8 -6
  16. data/lib/business_central/object/currency.rb +8 -6
  17. data/lib/business_central/object/customer.rb +16 -9
  18. data/lib/business_central/object/customer_financial_detail.rb +3 -1
  19. data/lib/business_central/object/customer_payment.rb +8 -6
  20. data/lib/business_central/object/customer_payment_journal.rb +8 -6
  21. data/lib/business_central/object/customer_sale.rb +3 -1
  22. data/lib/business_central/object/default_dimension.rb +18 -21
  23. data/lib/business_central/object/dimension.rb +20 -0
  24. data/lib/business_central/object/dimension_line.rb +37 -0
  25. data/lib/business_central/object/dimension_value.rb +28 -0
  26. data/lib/business_central/object/employee.rb +21 -0
  27. data/lib/business_central/object/filter_query.rb +18 -0
  28. data/lib/business_central/object/general_ledger_entry.rb +13 -0
  29. data/lib/business_central/object/income_statement.rb +13 -0
  30. data/lib/business_central/object/irs1099_code.rb +16 -0
  31. data/lib/business_central/object/item.rb +17 -10
  32. data/lib/business_central/object/item_category.rb +16 -0
  33. data/lib/business_central/object/journal.rb +29 -0
  34. data/lib/business_central/object/journal_line.rb +48 -0
  35. data/lib/business_central/object/{helper.rb → object_helper.rb} +18 -10
  36. data/lib/business_central/object/payment_method.rb +16 -0
  37. data/lib/business_central/object/payment_term.rb +16 -0
  38. data/lib/business_central/object/picture.rb +53 -0
  39. data/lib/business_central/object/purchase_invoice.rb +8 -6
  40. data/lib/business_central/object/purchase_invoice_line.rb +10 -8
  41. data/lib/business_central/object/purchase_order.rb +16 -0
  42. data/lib/business_central/object/request.rb +60 -49
  43. data/lib/business_central/object/response.rb +31 -23
  44. data/lib/business_central/object/retained_earning_statement.rb +13 -0
  45. data/lib/business_central/object/sales_credit_memo.rb +20 -0
  46. data/lib/business_central/object/sales_credit_memo_line.rb +30 -0
  47. data/lib/business_central/object/sales_invoice.rb +62 -0
  48. data/lib/business_central/object/sales_invoice_line.rb +30 -0
  49. data/lib/business_central/object/sales_order.rb +20 -0
  50. data/lib/business_central/object/sales_order_line.rb +30 -0
  51. data/lib/business_central/object/sales_quote.rb +20 -0
  52. data/lib/business_central/object/sales_quote_line.rb +30 -0
  53. data/lib/business_central/object/shipment_method.rb +16 -0
  54. data/lib/business_central/object/subscription.rb +16 -0
  55. data/lib/business_central/object/tax_area.rb +16 -0
  56. data/lib/business_central/object/tax_group.rb +16 -0
  57. data/lib/business_central/object/time_registration_entry.rb +16 -0
  58. data/lib/business_central/object/trial_balance.rb +13 -0
  59. data/lib/business_central/object/units_of_measure.rb +16 -0
  60. data/lib/business_central/object/url_builder.rb +59 -0
  61. data/lib/business_central/object/url_helper.rb +44 -0
  62. data/lib/business_central/object/validation.rb +10 -7
  63. data/lib/business_central/object/vendor.rb +10 -7
  64. data/lib/business_central/object/vendor_purchase.rb +13 -0
  65. data/lib/business_central/version.rb +4 -2
  66. data/lib/business_central/web_service.rb +78 -0
  67. data/lib/business_central.rb +40 -2
  68. data/lib/core_ext/string.rb +18 -12
  69. data/test/business_central/client_test.rb +18 -11
  70. data/test/business_central/object/account_test.rb +6 -5
  71. data/test/business_central/object/aged_account_payable_test.rb +6 -5
  72. data/test/business_central/object/aged_account_receivable_test.rb +6 -5
  73. data/test/business_central/object/attachment_test.rb +117 -0
  74. data/test/business_central/object/balance_sheet_test.rb +6 -5
  75. data/test/business_central/object/base_test.rb +4 -2
  76. data/test/business_central/object/cash_flow_statement_test.rb +6 -5
  77. data/test/business_central/object/company_information_test.rb +9 -10
  78. data/test/business_central/object/company_test.rb +6 -5
  79. data/test/business_central/object/country_region_test.rb +16 -17
  80. data/test/business_central/object/currency_test.rb +17 -18
  81. data/test/business_central/object/customer_financial_detail_test.rb +8 -6
  82. data/test/business_central/object/customer_payment_journal_test.rb +14 -15
  83. data/test/business_central/object/customer_payment_test.rb +15 -16
  84. data/test/business_central/object/customer_sale_test.rb +8 -6
  85. data/test/business_central/object/customer_test.rb +59 -16
  86. data/test/business_central/object/default_dimension_test.rb +15 -16
  87. data/test/business_central/object/dimension_line_test.rb +165 -0
  88. data/test/business_central/object/dimension_test.rb +65 -0
  89. data/test/business_central/object/dimension_value_test.rb +68 -0
  90. data/test/business_central/object/employee_test.rb +141 -0
  91. data/test/business_central/object/filter_query_test.rb +36 -0
  92. data/test/business_central/object/general_ledger_entry_test.rb +82 -0
  93. data/test/business_central/object/income_statement_test.rb +82 -0
  94. data/test/business_central/object/irs1099_code_test.rb +124 -0
  95. data/test/business_central/object/item_category_test.rb +122 -0
  96. data/test/business_central/object/item_test.rb +16 -17
  97. data/test/business_central/object/journal_line_test.rb +152 -0
  98. data/test/business_central/object/journal_test.rb +144 -0
  99. data/test/business_central/object/payment_method_test.rb +134 -0
  100. data/test/business_central/object/payment_term_test.rb +134 -0
  101. data/test/business_central/object/picture_test.rb +74 -0
  102. data/test/business_central/object/purchase_invoice_line_test.rb +15 -15
  103. data/test/business_central/object/purchase_invoice_test.rb +15 -15
  104. data/test/business_central/object/request_test.rb +17 -9
  105. data/test/business_central/object/response_test.rb +14 -7
  106. data/test/business_central/object/retained_earning_statement_test.rb +52 -0
  107. data/test/business_central/object/sales_credit_memo_line_test.rb +134 -0
  108. data/test/business_central/object/sales_credit_memo_test.rb +146 -0
  109. data/test/business_central/object/sales_invoice_line_test.rb +164 -0
  110. data/test/business_central/object/sales_invoice_test.rb +156 -0
  111. data/test/business_central/object/sales_order_line_test.rb +134 -0
  112. data/test/business_central/object/sales_order_test.rb +146 -0
  113. data/test/business_central/object/sales_quote_line_test.rb +134 -0
  114. data/test/business_central/object/sales_quote_test.rb +146 -0
  115. data/test/business_central/object/shipment_method_test.rb +133 -0
  116. data/test/business_central/object/subscription_test.rb +126 -0
  117. data/test/business_central/object/tax_area_test.rb +126 -0
  118. data/test/business_central/object/tax_group_test.rb +126 -0
  119. data/test/business_central/object/time_registration_entry_test.rb +126 -0
  120. data/test/business_central/object/trial_balance_test.rb +82 -0
  121. data/test/business_central/object/units_of_measure_test.rb +126 -0
  122. data/test/business_central/object/validation_test.rb +5 -4
  123. data/test/business_central/object/vendor_purchase_test.rb +82 -0
  124. data/test/business_central/object/vendor_test.rb +16 -16
  125. data/test/business_central/web_service_test.rb +100 -0
  126. data/test/business_central_test.rb +3 -1
  127. data/test/test_helper.rb +12 -6
  128. metadata +153 -41
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bfee02464cc6b4a28c6208ced736a5d8453f917cbe8757f7e28cd6ad900721d6
4
- data.tar.gz: ca2a683c9f3440d4fa953507051021145b1690bd42152ba488eae70c451ce2ae
3
+ metadata.gz: f0f72fc6bbd65910d177852470a583d46dd0ec8972df68f3aed670cb0a2ff7f9
4
+ data.tar.gz: 42984f880fd1d2fa3b72d81ea788e3e1d60b0fec81d1f8bf89c4ed8b2a774592
5
5
  SHA512:
6
- metadata.gz: 454c708a9323072524312b21877aca84918c2bb2c611956849291446c9117a007301112333d7c3bf25b3e5ac1707a81a2bdde2d7b3cc50f561ec0d28df5a40d0
7
- data.tar.gz: 78cbb22465b21ca9f876c621986e55a9843df5b9505a6552425ae56667258aaddff9ec76e3a00f5b7f820572e3a3bf887c2d49516d8e2b203f0ef2d02bf52aaf
6
+ metadata.gz: ee5ff0ec47a550c3a2433b12ab79f6c733f3adc17a0dca4aa83393a0661cc90a0e4351743c937f523af567aef048213e60dfcec7a48c58ab94ab7f25a8a9751d
7
+ data.tar.gz: 912b7d625087bed194cd73707425089798dec3a09ab048d347842a904f170bb021f770d2826ac1398cda0be3f94f82efd406b56d5088b3bda08fa1b4b87be6c9
data/README.md CHANGED
@@ -26,6 +26,22 @@ This gem supports both authentication methods:
26
26
 
27
27
  https://docs.microsoft.com/en-us/dynamics-nav/api-reference/v1.0/endpoints-apis-for-dynamics
28
28
 
29
+ ```Ruby
30
+ require 'business_central'
31
+
32
+ client = BusinessCentral::Client.new(
33
+ username: '<username>', # Basic authentication username
34
+ password: '<password>', # Basic authentication password
35
+ url: '<url>', # URL for API defaults to https://api.businesscentral.dynamics.com/v2.0/production/api/v1.0
36
+ web_service_url: '<url>', # URL for custom web services defaults to https://api.businesscentral.dynamics.com/v2.0/production/ODataV4
37
+ application_id: '<application_id>', # Oauth2 authentication application ID
38
+ secret_key: '<application_secret_key>', # OAuth2 authentication application secret key
39
+ oauth2_login_url: '<url>', # OAuth2 authentication login URL defaults to https://login.microsoftonline.com/common
40
+ default_company_id: '<company_id>', # Default company ID used in all requests (if required)
41
+ debug: false # Output requests to console
42
+ )
43
+ ```
44
+
29
45
  ### Basic Authentication:
30
46
 
31
47
  https://docs.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/devenv-develop-connect-apps#setting-up-basic-authentication
@@ -36,26 +52,27 @@ require 'business_central'
36
52
  client = BusinessCentral::Client.new(
37
53
  username: '<username>',
38
54
  password: '<password>',
39
- url: '<url>'
55
+ url: '<url>',
56
+ default_company_id: '11111111-2222-3333-4444-555555555555'
40
57
  )
41
58
 
42
59
  # Find all vendors
43
- vendors = client.vendor(company_id: '3a502065-2a08-4c3b-9468-fb83642d3d3a').find_all
60
+ vendors = client.vendor.all
44
61
 
45
62
  # Find vendor by ID
46
- vendor = client.vendor(company_id: '3a502065-2a08-4c3b-9468-fb83642d3d3a').find_by_id('3f445b08-2ffd-4f9d-81a0-b82f0d9714c4')
63
+ vendor = client.vendor.find('3f445b08-2ffd-4f9d-81a0-b82f0d9714c4')
47
64
 
48
65
  # Query vendor by display name
49
- vendor = client.vendor(company_id: '3a502065-2a08-4c3b-9468-fb83642d3d3a').where("displayName eq 'First Up Consultants'")
66
+ vendor = client.vendor.where("displayName eq 'First Up Consultants'")
50
67
 
51
68
  # Create a new vendor
52
- vendor = client.vendor(company_id: '3a502065-2a08-4c3b-9468-fb83642d3d3a').create({ display_name: 'hello testing new vendor' })
69
+ vendor = client.vendor.create({ display_name: 'hello testing new vendor' })
53
70
 
54
71
  # Update an existing vendor by ID
55
- vendor = client.vendor(company_id: '3a502065-2a08-4c3b-9468-fb83642d3d3a').update('3f445b08-2ffd-4f9d-81a0-b82f0d9714c4', { phone_number: '1112' })
72
+ vendor = client.vendor.update('3f445b08-2ffd-4f9d-81a0-b82f0d9714c4', { phone_number: '1112' })
56
73
 
57
74
  # Delete a vendor
58
- client.vendor(company_id: '3a502065-2a08-4c3b-9468-fb83642d3d3a').destroy('f0730ada-b315-ea11-a813-000d3ad21e99')
75
+ client.vendor.destroy('f0730ada-b315-ea11-a813-000d3ad21e99')
59
76
  ```
60
77
 
61
78
  ### Oauth2 Authentication
@@ -67,10 +84,10 @@ require 'business_central'
67
84
 
68
85
  # Create client - used to connect to the API
69
86
  client = BusinessCentral::Client.new(
70
- tenant_id: '<tenant_id>',
71
87
  application_id: '<application_id>',
72
88
  secret_key: '<application_secret_key>',
73
- url: '<url>'
89
+ url: '<url>',
90
+ default_company_id: '11111111-2222-3333-4444-555555555555'
74
91
  )
75
92
 
76
93
  # Controller endpoint 1
@@ -87,22 +104,48 @@ client.authorize_from_token(
87
104
  )
88
105
 
89
106
  # Find all vendors
90
- vendors = client.vendor(company_id: '3a502065-2a08-4c3b-9468-fb83642d3d3a').find_all
107
+ vendors = client.vendor.all
91
108
 
92
109
  # Find vendor by ID
93
- vendor = client.vendor(company_id: '3a502065-2a08-4c3b-9468-fb83642d3d3a').find_by_id('3f445b08-2ffd-4f9d-81a0-b82f0d9714c4')
110
+ vendor = client.vendor.find('3f445b08-2ffd-4f9d-81a0-b82f0d9714c4')
94
111
 
95
112
  # Query vendor by display name
96
- vendor = client.vendor(company_id: '3a502065-2a08-4c3b-9468-fb83642d3d3a').where("displayName eq 'First Up Consultants'")
113
+ vendor = client.vendor.where("displayName eq 'First Up Consultants'")
97
114
 
98
115
  # Create a new vendor
99
- vendor = client.vendor(company_id: '3a502065-2a08-4c3b-9468-fb83642d3d3a').create({ display_name: 'hello testing' })
116
+ vendor = client.vendor.create({ display_name: 'hello testing' })
100
117
 
101
118
  # Update an existing vendor by ID
102
- vendor = client.vendor(company_id: '3a502065-2a08-4c3b-9468-fb83642d3d3a').update('3f445b08-2ffd-4f9d-81a0-b82f0d9714c4', { phone_number: '1112' })
119
+ vendor = client.vendor.update('3f445b08-2ffd-4f9d-81a0-b82f0d9714c4', { phone_number: '1112' })
103
120
 
104
121
  # Delete a vendor
105
- client.vendor(company_id: '3a502065-2a08-4c3b-9468-fb83642d3d3a').destroy('f0730ada-b315-ea11-a813-000d3ad21e99')
122
+ client.vendor.destroy('f0730ada-b315-ea11-a813-000d3ad21e99')
123
+ ```
124
+
125
+ ### OData Web Services
126
+
127
+ https://docs.microsoft.com/en-us/dynamics365/business-central/dev-itpro/webservices/odata-web-services
128
+
129
+ ```Ruby
130
+ require 'business_central'
131
+
132
+ client = BusinessCentral::Client.new(
133
+ username: '<username>',
134
+ password: '<password>',
135
+ web_service_url: '<url>'
136
+ )
137
+
138
+ # Query a record
139
+ company = client.web_service.object("Company('?')/Purchase_Order", 'My Company').get
140
+
141
+ # Create a record
142
+ client.web_service.object("Company('?')/Purchase_Order", 'My Company').post({})
143
+
144
+ # Update a record
145
+ client.web_service.object("Company('?')/Purchase_Order", 'My Company').patch({})
146
+
147
+ # Delete a record
148
+ client.web_service.object("Company('?')/Purchase_Order", 'My Company').delete
106
149
  ```
107
150
 
108
151
  ## Development
@@ -1,26 +1,30 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module BusinessCentral
2
4
  class Client
3
- extend BusinessCentral::Object::Helper
5
+ extend BusinessCentral::Object::ObjectHelper
4
6
 
5
- DEFAULT_URL = 'https://api.businesscentral.dynamics.com/v1.0/api/beta'.freeze
7
+ DEFAULT_LOGIN_URL = 'https://login.microsoftonline.com/common'
6
8
 
7
- DEFAULT_LOGIN_URL = 'https://login.microsoftonline.com/common'.freeze
9
+ DEFAULT_URL = 'https://api.businesscentral.dynamics.com/v2.0/production/api/v1.0'
8
10
 
9
- attr_reader :tenant_id,
10
- :username,
11
+ attr_reader :username,
11
12
  :password,
12
13
  :application_id,
13
14
  :secret_key,
14
15
  :url,
16
+ :web_service_url,
15
17
  :oauth2_login_url,
16
- :oauth2_client,
17
- :default_company_id
18
+ :oauth2_access_token,
19
+ :default_company_id,
20
+ :debug
18
21
 
19
- alias_method :access_token, :oauth2_client
22
+ alias access_token oauth2_access_token
20
23
 
21
24
  object :account
22
25
  object :aged_account_payable
23
26
  object :aged_account_receivable
27
+ object :attachment
24
28
  object :balance_sheet
25
29
  object :cash_flow_statement
26
30
  object :company
@@ -33,81 +37,107 @@ module BusinessCentral
33
37
  object :customer_payment_journal
34
38
  object :customer_sale
35
39
  object :default_dimension
36
- object :vendor
40
+ object :dimension
41
+ object :dimension_line
42
+ object :dimension_value
43
+ object :employee
44
+ object :general_ledger_entry
45
+ object :income_statement
46
+ object :irs1099_code
37
47
  object :purchase_invoice
38
48
  object :purchase_invoice_line
39
49
  object :item
50
+ object :item_category
51
+ object :journal
52
+ object :journal_line
53
+ object :payment_method
54
+ object :payment_term
55
+ object :picture
56
+ object :retained_earning_statement
57
+ object :sales_invoice
58
+ object :sales_invoice_line
59
+ object :sales_credit_memo
60
+ object :sales_credit_memo_line
61
+ object :sales_order
62
+ object :sales_order_line
63
+ object :sales_quote
64
+ object :sales_quote_line
65
+ object :shipment_method
66
+ object :subscription
67
+ object :tax_area
68
+ object :tax_group
69
+ object :time_registration_entry
70
+ object :trial_balance
71
+ object :units_of_measure
72
+ object :vendor
73
+ object :vendor_purchase
74
+ object :purchase_order
40
75
 
41
76
  def initialize(options = {})
42
77
  opts = options.dup
43
- @tenant_id = opts.delete(:tenant_id)
44
78
  @username = opts.delete(:username)
45
79
  @password = opts.delete(:password)
46
80
  @url = opts.delete(:url) || DEFAULT_URL
81
+ @web_service_url = opts.delete(:web_service_url)
47
82
  @application_id = opts.delete(:application_id)
48
83
  @secret_key = opts.delete(:secret_key)
49
84
  @oauth2_login_url = opts.delete(:oauth2_login_url) || DEFAULT_LOGIN_URL
50
85
  @default_company_id = opts.delete(:default_company_id)
86
+ @debug = opts.delete(:debug) || false
51
87
  end
52
88
 
53
89
  def authorize(params = {}, oauth_authorize_callback: '')
54
90
  params[:redirect_uri] = oauth_authorize_callback
55
91
  begin
56
92
  oauth2_client.auth_code.authorize_url(params)
57
- rescue OAuth2::Error => error
58
- handle_error(error)
93
+ rescue OAuth2::Error => e
94
+ handle_error(e)
59
95
  end
60
96
  end
61
97
 
62
98
  def request_token(code = '', oauth_token_callback: '')
63
- begin
64
- oauth2_client.auth_code.get_token(code, redirect_uri: oauth_token_callback)
65
- rescue OAuth2::Error => error
66
- handle_error(error)
67
- end
99
+ oauth2_client.auth_code.get_token(code, redirect_uri: oauth_token_callback)
100
+ rescue OAuth2::Error => e
101
+ handle_error(e)
68
102
  end
69
103
 
70
104
  def authorize_from_token(token: '', refresh_token: '', expires_at: nil, expires_in: nil)
71
- @oauth2_client = OAuth2::AccessToken.new(
105
+ @oauth2_access_token = OAuth2::AccessToken.new(
72
106
  oauth2_client,
73
107
  token,
74
108
  refresh_token: refresh_token,
75
109
  expires_at: expires_at,
76
- expires_in: expires_in,
110
+ expires_in: expires_in
77
111
  )
78
112
  end
79
113
 
80
114
  def refresh_token
81
- @oauth2_client.refresh!
115
+ @oauth2_access_token.refresh!
116
+ end
117
+
118
+ def web_service
119
+ @web_service ||= BusinessCentral::WebService.new(client: self, url: web_service_url)
82
120
  end
83
121
 
84
122
  private
85
123
 
86
124
  def oauth2_client
87
- if @oauth2_client.nil?
88
- @oauth2_client = OAuth2::Client.new(
89
- @application_id,
90
- @secret_key,
91
- {
92
- site: @oauth2_login_url,
93
- authorize_url: 'oauth2/authorize?resource=https://api.businesscentral.dynamics.com',
94
- token_url: 'oauth2/token?resource=https://api.businesscentral.dynamics.com'
95
- }
96
- )
97
- end
98
-
99
- return @oauth2_client
125
+ OAuth2::Client.new(
126
+ @application_id,
127
+ @secret_key,
128
+ site: @oauth2_login_url,
129
+ authorize_url: 'oauth2/authorize?resource=https://api.businesscentral.dynamics.com',
130
+ token_url: 'oauth2/token?resource=https://api.businesscentral.dynamics.com'
131
+ )
100
132
  end
101
133
 
102
134
  def handle_error(error)
103
- if !error.code.nil?
104
- case error.code
105
- when 'invalid_client'
106
- raise InvalidClientException.new
107
- end
108
- else
109
- raise ApiException.new(error.message)
135
+ raise ApiException, error.message if error.code.nil?
136
+
137
+ case error.code
138
+ when 'invalid_client'
139
+ raise InvalidClientException
110
140
  end
111
141
  end
112
142
  end
113
- end
143
+ end
@@ -1,5 +1,6 @@
1
- module BusinessCentral
1
+ # frozen_string_literal: true
2
2
 
3
+ module BusinessCentral
3
4
  class BusinessCentralError < StandardError; end
4
5
 
5
6
  class InvalidClientException < BusinessCentralError
@@ -13,9 +14,7 @@ module BusinessCentral
13
14
  @message = message
14
15
  end
15
16
 
16
- def message
17
- @message
18
- end
17
+ attr_reader :message
19
18
  end
20
19
 
21
20
  class CompanyNotFoundException < BusinessCentralError
@@ -30,15 +29,19 @@ module BusinessCentral
30
29
  end
31
30
  end
32
31
 
32
+ class NotFoundException < BusinessCentralError
33
+ def message
34
+ 'Not Found - The URL provided cannot be found'
35
+ end
36
+ end
37
+
33
38
  class InvalidObjectException < BusinessCentralError
34
39
  def initialize(errors)
35
40
  @errors = errors
36
41
  end
37
42
 
38
43
  def message
39
- @errors.each do |error|
40
- "#{error[:field]} - #{error[:message]}"
41
- end
44
+ @errors.each { |error| "#{error[:field]} - #{error[:message]}" }
42
45
  end
43
46
  end
44
47
 
@@ -49,7 +52,8 @@ module BusinessCentral
49
52
  end
50
53
 
51
54
  def message
52
- "#{method} method is currently not support. Allowed methods are: #{allowed_methods.join(', ')}"
55
+ methods_allowed = @allowed_methods.join(', ')
56
+ "#{@method} method is currently not support. Allowed methods are: #{methods_allowed}"
53
57
  end
54
58
  end
55
59
 
@@ -62,4 +66,10 @@ module BusinessCentral
62
66
  "Invalid argument entered - #{@message}"
63
67
  end
64
68
  end
65
- end
69
+
70
+ class InvalidObjectURLException < BusinessCentralError
71
+ def message
72
+ 'Object URL missing for request'
73
+ end
74
+ end
75
+ end
@@ -1,11 +1,13 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module BusinessCentral
2
4
  module Object
3
5
  class Account < Base
4
- OBJECT = 'accounts'.freeze
6
+ OBJECT = 'accounts'
5
7
 
6
8
  OBJECT_METHODS = [
7
9
  :get
8
10
  ].freeze
9
11
  end
10
12
  end
11
- end
13
+ end
@@ -1,11 +1,13 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module BusinessCentral
2
4
  module Object
3
5
  class AgedAccountPayable < Base
4
- OBJECT = 'agedAccountsPayable'.freeze
6
+ OBJECT = 'agedAccountsPayable'
5
7
 
6
8
  OBJECT_METHODS = [
7
9
  :get
8
10
  ].freeze
9
11
  end
10
12
  end
11
- end
13
+ end
@@ -1,11 +1,13 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module BusinessCentral
2
4
  module Object
3
5
  class AgedAccountReceivable < Base
4
- OBJECT = 'agedAccountsReceivable'.freeze
6
+ OBJECT = 'agedAccountsReceivable'
5
7
 
6
8
  OBJECT_METHODS = [
7
9
  :get
8
10
  ].freeze
9
11
  end
10
12
  end
11
- end
13
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module BusinessCentral
4
+ module Object
5
+ module ArgumentHelper
6
+ def id(argument)
7
+ return @id if instance_variable_defined?('@id') && !@id.nil?
8
+ return argument.fetch(:id, '') if !argument.nil?
9
+
10
+ nil
11
+ end
12
+
13
+ def company_id(argument)
14
+ return @client.default_company_id if !@client.default_company_id.nil?
15
+ return @company_id if instance_variable_defined?('@company_id') && !@company_id.nil?
16
+ return argument.fetch(:company_id, '') if !argument.nil?
17
+
18
+ nil
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ module BusinessCentral
4
+ module Object
5
+ class Attachment < Base
6
+ OBJECT = 'attachments'
7
+
8
+ OBJECT_METHODS = %i[
9
+ get
10
+ post
11
+ patch
12
+ delete
13
+ ].freeze
14
+
15
+ def update(parent_id:, attachment_id:, **params)
16
+ url = "#{build_url(child_path: OBJECT)}(parentId=#{parent_id},id=#{attachment_id})/content"
17
+ Request.call(:patch, @client, url, etag: '', params: {}) do |request|
18
+ request['Content-Type'] = 'application/json'
19
+ request['If-Match'] = 'application/json'
20
+ request.body = Request.convert(params)
21
+ end
22
+ end
23
+
24
+ def destroy(parent_id:, attachment_id:)
25
+ url = "#{build_url(child_path: OBJECT)}(#{parent_id},#{attachment_id})"
26
+ Request.call(:delete, @client, url, etag: '')
27
+ end
28
+ end
29
+ end
30
+ end
@@ -1,11 +1,13 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module BusinessCentral
2
4
  module Object
3
5
  class BalanceSheet < Base
4
- OBJECT = 'balanceSheet'.freeze
6
+ OBJECT = 'balanceSheet'
5
7
 
6
8
  OBJECT_METHODS = [
7
9
  :get
8
10
  ].freeze
9
11
  end
10
12
  end
11
- end
13
+ end