business-central 1.0.0 → 1.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +58 -15
- data/lib/business_central.rb +52 -2
- data/lib/business_central/client.rb +87 -39
- data/lib/business_central/exceptions.rb +30 -10
- data/lib/business_central/object/account.rb +4 -2
- data/lib/business_central/object/aged_account_payable.rb +13 -0
- data/lib/business_central/object/aged_account_receivable.rb +13 -0
- data/lib/business_central/object/argument_helper.rb +22 -0
- data/lib/business_central/object/attachment.rb +30 -0
- data/lib/business_central/object/balance_sheet.rb +13 -0
- data/lib/business_central/object/base.rb +100 -49
- data/lib/business_central/object/cash_flow_statement.rb +13 -0
- data/lib/business_central/object/company.rb +9 -2
- data/lib/business_central/object/company_information.rb +14 -0
- data/lib/business_central/object/country_region.rb +26 -0
- data/lib/business_central/object/currency.rb +29 -0
- data/lib/business_central/object/customer.rb +34 -0
- data/lib/business_central/object/customer_financial_detail.rb +13 -0
- data/lib/business_central/object/customer_payment.rb +43 -0
- data/lib/business_central/object/customer_payment_journal.rb +25 -0
- data/lib/business_central/object/customer_sale.rb +13 -0
- data/lib/business_central/object/default_dimension.rb +51 -0
- data/lib/business_central/object/dimension.rb +20 -0
- data/lib/business_central/object/dimension_line.rb +37 -0
- data/lib/business_central/object/dimension_value.rb +28 -0
- data/lib/business_central/object/employee.rb +21 -0
- data/lib/business_central/object/filter_query.rb +18 -0
- data/lib/business_central/object/general_ledger_entry.rb +13 -0
- data/lib/business_central/object/income_statement.rb +13 -0
- data/lib/business_central/object/irs1099_code.rb +16 -0
- data/lib/business_central/object/item.rb +16 -19
- data/lib/business_central/object/item_category.rb +16 -0
- data/lib/business_central/object/journal.rb +29 -0
- data/lib/business_central/object/journal_line.rb +48 -0
- data/lib/business_central/object/object_helper.rb +49 -0
- data/lib/business_central/object/payment_method.rb +16 -0
- data/lib/business_central/object/payment_term.rb +16 -0
- data/lib/business_central/object/picture.rb +53 -0
- data/lib/business_central/object/purchase_invoice.rb +8 -16
- data/lib/business_central/object/purchase_invoice_line.rb +14 -18
- data/lib/business_central/object/request.rb +61 -50
- data/lib/business_central/object/response.rb +28 -22
- data/lib/business_central/object/retained_earning_statement.rb +13 -0
- data/lib/business_central/object/sales_credit_memo.rb +20 -0
- data/lib/business_central/object/sales_credit_memo_line.rb +30 -0
- data/lib/business_central/object/sales_invoice.rb +62 -0
- data/lib/business_central/object/sales_invoice_line.rb +30 -0
- data/lib/business_central/object/sales_order.rb +20 -0
- data/lib/business_central/object/sales_order_line.rb +30 -0
- data/lib/business_central/object/sales_quote.rb +20 -0
- data/lib/business_central/object/sales_quote_line.rb +30 -0
- data/lib/business_central/object/shipment_method.rb +16 -0
- data/lib/business_central/object/subscription.rb +16 -0
- data/lib/business_central/object/tax_area.rb +16 -0
- data/lib/business_central/object/tax_group.rb +16 -0
- data/lib/business_central/object/time_registration_entry.rb +16 -0
- data/lib/business_central/object/trial_balance.rb +13 -0
- data/lib/business_central/object/units_of_measure.rb +16 -0
- data/lib/business_central/object/url_builder.rb +59 -0
- data/lib/business_central/object/url_helper.rb +32 -0
- data/lib/business_central/object/validation.rb +11 -8
- data/lib/business_central/object/vendor.rb +12 -15
- data/lib/business_central/object/vendor_purchase.rb +13 -0
- data/lib/business_central/version.rb +4 -2
- data/lib/business_central/web_service.rb +78 -0
- data/lib/core_ext/string.rb +18 -12
- data/test/business_central/client_test.rb +49 -7
- data/test/business_central/object/account_test.rb +24 -5
- data/test/business_central/object/aged_account_payable_test.rb +61 -0
- data/test/business_central/object/aged_account_receivable_test.rb +61 -0
- data/test/business_central/object/attachment_test.rb +117 -0
- data/test/business_central/object/balance_sheet_test.rb +61 -0
- data/test/business_central/object/base_test.rb +41 -0
- data/test/business_central/object/cash_flow_statement_test.rb +61 -0
- data/test/business_central/object/company_information_test.rb +81 -0
- data/test/business_central/object/company_test.rb +24 -11
- data/test/business_central/object/country_region_test.rb +129 -0
- data/test/business_central/object/currency_test.rb +150 -0
- data/test/business_central/object/customer_financial_detail_test.rb +68 -0
- data/test/business_central/object/customer_payment_journal_test.rb +134 -0
- data/test/business_central/object/customer_payment_test.rb +141 -0
- data/test/business_central/object/customer_sale_test.rb +72 -0
- data/test/business_central/object/customer_test.rb +168 -0
- data/test/business_central/object/default_dimension_test.rb +170 -0
- data/test/business_central/object/dimension_line_test.rb +165 -0
- data/test/business_central/object/dimension_test.rb +65 -0
- data/test/business_central/object/dimension_value_test.rb +68 -0
- data/test/business_central/object/employee_test.rb +141 -0
- data/test/business_central/object/filter_query_test.rb +36 -0
- data/test/business_central/object/general_ledger_entry_test.rb +82 -0
- data/test/business_central/object/income_statement_test.rb +82 -0
- data/test/business_central/object/irs1099_code_test.rb +124 -0
- data/test/business_central/object/item_category_test.rb +122 -0
- data/test/business_central/object/item_test.rb +16 -23
- data/test/business_central/object/journal_line_test.rb +152 -0
- data/test/business_central/object/journal_test.rb +144 -0
- data/test/business_central/object/payment_method_test.rb +134 -0
- data/test/business_central/object/payment_term_test.rb +134 -0
- data/test/business_central/object/picture_test.rb +74 -0
- data/test/business_central/object/purchase_invoice_line_test.rb +15 -21
- data/test/business_central/object/purchase_invoice_test.rb +15 -21
- data/test/business_central/object/request_test.rb +75 -18
- data/test/business_central/object/response_test.rb +29 -9
- data/test/business_central/object/retained_earning_statement_test.rb +52 -0
- data/test/business_central/object/sales_credit_memo_line_test.rb +134 -0
- data/test/business_central/object/sales_credit_memo_test.rb +146 -0
- data/test/business_central/object/sales_invoice_line_test.rb +164 -0
- data/test/business_central/object/sales_invoice_test.rb +156 -0
- data/test/business_central/object/sales_order_line_test.rb +134 -0
- data/test/business_central/object/sales_order_test.rb +146 -0
- data/test/business_central/object/sales_quote_line_test.rb +134 -0
- data/test/business_central/object/sales_quote_test.rb +146 -0
- data/test/business_central/object/shipment_method_test.rb +133 -0
- data/test/business_central/object/subscription_test.rb +126 -0
- data/test/business_central/object/tax_area_test.rb +126 -0
- data/test/business_central/object/tax_group_test.rb +126 -0
- data/test/business_central/object/time_registration_entry_test.rb +126 -0
- data/test/business_central/object/trial_balance_test.rb +82 -0
- data/test/business_central/object/units_of_measure_test.rb +126 -0
- data/test/business_central/object/validation_test.rb +5 -4
- data/test/business_central/object/vendor_purchase_test.rb +82 -0
- data/test/business_central/object/vendor_test.rb +16 -22
- data/test/business_central/web_service_test.rb +95 -0
- data/test/business_central_test.rb +3 -1
- data/test/test_helper.rb +16 -6
- metadata +199 -33
- data/lib/business_central/object/helper.rb +0 -15
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: eb391f19d6cbf2649ddbe7eb0cf937d2657c140de32d6f6a8c1f92483a353f57
|
4
|
+
data.tar.gz: c9ad222424c8b46bd9cdc4e282e5b583b2e795d1e1917c942b7da259e8380c92
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3413af99b793f31b5913c726dd7fc3f5c48328f39321809b35da46f62100a12b529996eadfd3191d1581c52a718d749fa7eb2b808eb3f063f7a2e9c05975967e
|
7
|
+
data.tar.gz: 5e96d79316386187618b362f3ea365f2f510b50622a50f2436ec45feaa32d435e839fcbf4ac20b8c7bb8dc8b33e98a5a7295b2d9beeac7257bd4f1d5e6a4aca5
|
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
|
60
|
+
vendors = client.vendor.all
|
44
61
|
|
45
62
|
# Find vendor by ID
|
46
|
-
vendor = client.vendor
|
63
|
+
vendor = client.vendor.find('3f445b08-2ffd-4f9d-81a0-b82f0d9714c4')
|
47
64
|
|
48
65
|
# Query vendor by display name
|
49
|
-
vendor = client.vendor
|
66
|
+
vendor = client.vendor.where("displayName eq 'First Up Consultants'")
|
50
67
|
|
51
68
|
# Create a new vendor
|
52
|
-
vendor = client.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
|
72
|
+
vendor = client.vendor.update('3f445b08-2ffd-4f9d-81a0-b82f0d9714c4', { phone_number: '1112' })
|
56
73
|
|
57
74
|
# Delete a vendor
|
58
|
-
client.vendor
|
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
|
107
|
+
vendors = client.vendor.all
|
91
108
|
|
92
109
|
# Find vendor by ID
|
93
|
-
vendor = client.vendor
|
110
|
+
vendor = client.vendor.find('3f445b08-2ffd-4f9d-81a0-b82f0d9714c4')
|
94
111
|
|
95
112
|
# Query vendor by display name
|
96
|
-
vendor = client.vendor
|
113
|
+
vendor = client.vendor.where("displayName eq 'First Up Consultants'")
|
97
114
|
|
98
115
|
# Create a new vendor
|
99
|
-
vendor = client.vendor
|
116
|
+
vendor = client.vendor.create({ display_name: 'hello testing' })
|
100
117
|
|
101
118
|
# Update an existing vendor by ID
|
102
|
-
vendor = client.vendor
|
119
|
+
vendor = client.vendor.update('3f445b08-2ffd-4f9d-81a0-b82f0d9714c4', { phone_number: '1112' })
|
103
120
|
|
104
121
|
# Delete a vendor
|
105
|
-
client.vendor
|
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
|
data/lib/business_central.rb
CHANGED
@@ -5,18 +5,68 @@ require 'json'
|
|
5
5
|
|
6
6
|
require 'core_ext/string'
|
7
7
|
|
8
|
-
require 'business_central/object/
|
8
|
+
require 'business_central/object/argument_helper'
|
9
|
+
require 'business_central/object/url_helper'
|
10
|
+
require 'business_central/object/object_helper'
|
11
|
+
|
9
12
|
require 'business_central/object/base'
|
10
13
|
require 'business_central/object/validation'
|
11
14
|
require 'business_central/object/response'
|
12
15
|
require 'business_central/object/request'
|
16
|
+
require 'business_central/object/filter_query'
|
17
|
+
require 'business_central/object/url_builder'
|
13
18
|
|
14
19
|
require 'business_central/object/account'
|
20
|
+
require 'business_central/object/aged_account_payable'
|
21
|
+
require 'business_central/object/aged_account_receivable'
|
22
|
+
require 'business_central/object/attachment'
|
23
|
+
require 'business_central/object/cash_flow_statement'
|
24
|
+
require 'business_central/object/balance_sheet'
|
15
25
|
require 'business_central/object/company'
|
16
|
-
require 'business_central/object/
|
26
|
+
require 'business_central/object/company_information'
|
27
|
+
require 'business_central/object/country_region'
|
28
|
+
require 'business_central/object/currency'
|
29
|
+
require 'business_central/object/customer'
|
30
|
+
require 'business_central/object/customer_financial_detail'
|
31
|
+
require 'business_central/object/customer_payment'
|
32
|
+
require 'business_central/object/customer_payment_journal'
|
33
|
+
require 'business_central/object/customer_sale'
|
34
|
+
require 'business_central/object/default_dimension'
|
35
|
+
require 'business_central/object/dimension'
|
36
|
+
require 'business_central/object/dimension_line'
|
37
|
+
require 'business_central/object/dimension_value'
|
38
|
+
require 'business_central/object/employee'
|
39
|
+
require 'business_central/object/general_ledger_entry'
|
40
|
+
require 'business_central/object/income_statement'
|
41
|
+
require 'business_central/object/irs1099_code'
|
17
42
|
require 'business_central/object/item'
|
43
|
+
require 'business_central/object/item_category'
|
44
|
+
require 'business_central/object/journal'
|
45
|
+
require 'business_central/object/journal_line'
|
46
|
+
require 'business_central/object/payment_method'
|
47
|
+
require 'business_central/object/payment_term'
|
48
|
+
require 'business_central/object/picture'
|
18
49
|
require 'business_central/object/purchase_invoice'
|
19
50
|
require 'business_central/object/purchase_invoice_line'
|
51
|
+
require 'business_central/object/retained_earning_statement'
|
52
|
+
require 'business_central/object/sales_invoice'
|
53
|
+
require 'business_central/object/sales_invoice_line'
|
54
|
+
require 'business_central/object/sales_credit_memo'
|
55
|
+
require 'business_central/object/sales_credit_memo_line'
|
56
|
+
require 'business_central/object/sales_order'
|
57
|
+
require 'business_central/object/sales_order_line'
|
58
|
+
require 'business_central/object/sales_quote'
|
59
|
+
require 'business_central/object/sales_quote_line'
|
60
|
+
require 'business_central/object/shipment_method'
|
61
|
+
require 'business_central/object/subscription'
|
62
|
+
require 'business_central/object/tax_area'
|
63
|
+
require 'business_central/object/tax_group'
|
64
|
+
require 'business_central/object/time_registration_entry'
|
65
|
+
require 'business_central/object/trial_balance'
|
66
|
+
require 'business_central/object/units_of_measure'
|
67
|
+
require 'business_central/object/vendor'
|
68
|
+
require 'business_central/object/vendor_purchase'
|
20
69
|
|
21
70
|
require 'business_central/exceptions'
|
22
71
|
require 'business_central/client'
|
72
|
+
require 'business_central/web_service'
|
@@ -1,94 +1,142 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module BusinessCentral
|
2
4
|
class Client
|
3
|
-
extend BusinessCentral::Object::
|
5
|
+
extend BusinessCentral::Object::ObjectHelper
|
6
|
+
|
7
|
+
DEFAULT_LOGIN_URL = 'https://login.microsoftonline.com/common'
|
4
8
|
|
5
|
-
DEFAULT_URL = 'https://api.businesscentral.dynamics.com/
|
9
|
+
DEFAULT_URL = 'https://api.businesscentral.dynamics.com/v2.0/production/api/v1.0'
|
6
10
|
|
7
|
-
attr_reader :
|
8
|
-
:username,
|
11
|
+
attr_reader :username,
|
9
12
|
:password,
|
10
13
|
:application_id,
|
11
14
|
:secret_key,
|
12
15
|
:url,
|
13
|
-
:
|
16
|
+
:web_service_url,
|
17
|
+
:oauth2_login_url,
|
18
|
+
:oauth2_access_token,
|
19
|
+
:default_company_id,
|
20
|
+
:debug
|
14
21
|
|
15
|
-
|
22
|
+
alias access_token oauth2_access_token
|
16
23
|
|
17
24
|
object :account
|
25
|
+
object :aged_account_payable
|
26
|
+
object :aged_account_receivable
|
27
|
+
object :attachment
|
28
|
+
object :balance_sheet
|
29
|
+
object :cash_flow_statement
|
18
30
|
object :company
|
19
|
-
object :
|
31
|
+
object :company_information
|
32
|
+
object :country_region
|
33
|
+
object :currency
|
34
|
+
object :customer
|
35
|
+
object :customer_financial_detail
|
36
|
+
object :customer_payment
|
37
|
+
object :customer_payment_journal
|
38
|
+
object :customer_sale
|
39
|
+
object :default_dimension
|
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
|
20
47
|
object :purchase_invoice
|
21
48
|
object :purchase_invoice_line
|
22
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
|
23
74
|
|
24
75
|
def initialize(options = {})
|
25
76
|
opts = options.dup
|
26
|
-
@tenant_id = opts.delete(:tenant_id)
|
27
77
|
@username = opts.delete(:username)
|
28
78
|
@password = opts.delete(:password)
|
29
79
|
@url = opts.delete(:url) || DEFAULT_URL
|
80
|
+
@web_service_url = opts.delete(:web_service_url)
|
30
81
|
@application_id = opts.delete(:application_id)
|
31
82
|
@secret_key = opts.delete(:secret_key)
|
83
|
+
@oauth2_login_url = opts.delete(:oauth2_login_url) || DEFAULT_LOGIN_URL
|
84
|
+
@default_company_id = opts.delete(:default_company_id)
|
85
|
+
@debug = opts.delete(:debug) || false
|
32
86
|
end
|
33
87
|
|
34
88
|
def authorize(params = {}, oauth_authorize_callback: '')
|
35
89
|
params[:redirect_uri] = oauth_authorize_callback
|
36
90
|
begin
|
37
91
|
oauth2_client.auth_code.authorize_url(params)
|
38
|
-
rescue
|
39
|
-
handle_error(
|
92
|
+
rescue OAuth2::Error => e
|
93
|
+
handle_error(e)
|
40
94
|
end
|
41
95
|
end
|
42
96
|
|
43
97
|
def request_token(code = '', oauth_token_callback: '')
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
handle_error(error)
|
48
|
-
end
|
98
|
+
oauth2_client.auth_code.get_token(code, redirect_uri: oauth_token_callback)
|
99
|
+
rescue OAuth2::Error => e
|
100
|
+
handle_error(e)
|
49
101
|
end
|
50
102
|
|
51
103
|
def authorize_from_token(token: '', refresh_token: '', expires_at: nil, expires_in: nil)
|
52
|
-
@
|
104
|
+
@oauth2_access_token = OAuth2::AccessToken.new(
|
53
105
|
oauth2_client,
|
54
106
|
token,
|
55
107
|
refresh_token: refresh_token,
|
56
108
|
expires_at: expires_at,
|
57
|
-
expires_in: expires_in
|
109
|
+
expires_in: expires_in
|
58
110
|
)
|
59
111
|
end
|
60
112
|
|
61
113
|
def refresh_token
|
62
|
-
@
|
114
|
+
@oauth2_access_token.refresh!
|
115
|
+
end
|
116
|
+
|
117
|
+
def web_service
|
118
|
+
@web_service ||= BusinessCentral::WebService.new(client: self, url: web_service_url)
|
63
119
|
end
|
64
120
|
|
65
121
|
private
|
66
122
|
|
67
123
|
def oauth2_client
|
68
|
-
|
69
|
-
@
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
token_url: 'oauth2/token?resource=https://api.businesscentral.dynamics.com'
|
76
|
-
}
|
77
|
-
)
|
78
|
-
end
|
79
|
-
|
80
|
-
return @oauth2_client
|
124
|
+
OAuth2::Client.new(
|
125
|
+
@application_id,
|
126
|
+
@secret_key,
|
127
|
+
site: @oauth2_login_url,
|
128
|
+
authorize_url: 'oauth2/authorize?resource=https://api.businesscentral.dynamics.com',
|
129
|
+
token_url: 'oauth2/token?resource=https://api.businesscentral.dynamics.com'
|
130
|
+
)
|
81
131
|
end
|
82
132
|
|
83
133
|
def handle_error(error)
|
84
|
-
if error.code.
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
else
|
90
|
-
raise ApiException.new(error.message)
|
134
|
+
raise ApiException, error.message if error.code.nil?
|
135
|
+
|
136
|
+
case error.code
|
137
|
+
when 'invalid_client'
|
138
|
+
raise InvalidClientException
|
91
139
|
end
|
92
140
|
end
|
93
141
|
end
|
94
|
-
end
|
142
|
+
end
|
@@ -1,10 +1,11 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
+
module BusinessCentral
|
3
4
|
class BusinessCentralError < StandardError; end
|
4
5
|
|
5
6
|
class InvalidClientException < BusinessCentralError
|
6
7
|
def message
|
7
|
-
'Invalid
|
8
|
+
'Invalid client setup'
|
8
9
|
end
|
9
10
|
end
|
10
11
|
|
@@ -13,9 +14,7 @@ module BusinessCentral
|
|
13
14
|
@message = message
|
14
15
|
end
|
15
16
|
|
16
|
-
|
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
|
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,24 @@ module BusinessCentral
|
|
49
52
|
end
|
50
53
|
|
51
54
|
def message
|
52
|
-
|
55
|
+
methods_allowed = @allowed_methods.join(', ')
|
56
|
+
"#{@method} method is currently not support. Allowed methods are: #{methods_allowed}"
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
class InvalidArgumentException < BusinessCentralError
|
61
|
+
def initialize(message)
|
62
|
+
@message = message
|
63
|
+
end
|
64
|
+
|
65
|
+
def message
|
66
|
+
"Invalid argument entered - #{@message}"
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
class InvalidObjectURLException < BusinessCentralError
|
71
|
+
def message
|
72
|
+
'Object URL missing for request'
|
53
73
|
end
|
54
74
|
end
|
55
|
-
end
|
75
|
+
end
|