business-central 1.0.2 → 1.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/business_central.rb +6 -0
- data/lib/business_central/client.rb +16 -4
- data/lib/business_central/exceptions.rb +11 -1
- data/lib/business_central/object/account.rb +0 -10
- data/lib/business_central/object/aged_account_payable.rb +0 -10
- data/lib/business_central/object/aged_account_receivable.rb +0 -10
- data/lib/business_central/object/balance_sheet.rb +0 -10
- data/lib/business_central/object/base.rb +30 -13
- data/lib/business_central/object/cash_flow_statement.rb +0 -10
- data/lib/business_central/object/company.rb +5 -0
- data/lib/business_central/object/company_information.rb +0 -10
- data/lib/business_central/object/country_region.rb +0 -10
- data/lib/business_central/object/currency.rb +0 -10
- data/lib/business_central/object/customer.rb +27 -0
- data/lib/business_central/object/customer_financial_detail.rb +11 -0
- data/lib/business_central/object/customer_payment.rb +41 -0
- data/lib/business_central/object/customer_payment_journal.rb +23 -0
- data/lib/business_central/object/customer_sale.rb +11 -0
- data/lib/business_central/object/default_dimension.rb +54 -0
- data/lib/business_central/object/helper.rb +29 -3
- data/lib/business_central/object/item.rb +0 -10
- data/lib/business_central/object/purchase_invoice.rb +0 -10
- data/lib/business_central/object/purchase_invoice_line.rb +4 -10
- data/lib/business_central/object/request.rb +2 -2
- data/lib/business_central/object/vendor.rb +3 -9
- data/lib/business_central/version.rb +1 -1
- data/test/business_central/client_test.rb +37 -2
- data/test/business_central/object/base_test.rb +39 -0
- data/test/business_central/object/customer_financial_detail_test.rb +66 -0
- data/test/business_central/object/customer_payment_journal_test.rb +135 -0
- data/test/business_central/object/customer_payment_test.rb +142 -0
- data/test/business_central/object/customer_sale_test.rb +70 -0
- data/test/business_central/object/customer_test.rb +125 -0
- data/test/business_central/object/default_dimension_test.rb +171 -0
- data/test/business_central/object/request_test.rb +58 -3
- data/test/business_central/object/response_test.rb +24 -6
- data/test/test_helper.rb +6 -2
- metadata +36 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bfee02464cc6b4a28c6208ced736a5d8453f917cbe8757f7e28cd6ad900721d6
|
4
|
+
data.tar.gz: ca2a683c9f3440d4fa953507051021145b1690bd42152ba488eae70c451ce2ae
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 454c708a9323072524312b21877aca84918c2bb2c611956849291446c9117a007301112333d7c3bf25b3e5ac1707a81a2bdde2d7b3cc50f561ec0d28df5a40d0
|
7
|
+
data.tar.gz: 78cbb22465b21ca9f876c621986e55a9843df5b9505a6552425ae56667258aaddff9ec76e3a00f5b7f820572e3a3bf887c2d49516d8e2b203f0ef2d02bf52aaf
|
data/lib/business_central.rb
CHANGED
@@ -20,6 +20,12 @@ require 'business_central/object/company'
|
|
20
20
|
require 'business_central/object/company_information'
|
21
21
|
require 'business_central/object/country_region'
|
22
22
|
require 'business_central/object/currency'
|
23
|
+
require 'business_central/object/customer'
|
24
|
+
require 'business_central/object/customer_financial_detail'
|
25
|
+
require 'business_central/object/customer_payment'
|
26
|
+
require 'business_central/object/customer_payment_journal'
|
27
|
+
require 'business_central/object/customer_sale'
|
28
|
+
require 'business_central/object/default_dimension'
|
23
29
|
require 'business_central/object/vendor'
|
24
30
|
require 'business_central/object/item'
|
25
31
|
require 'business_central/object/purchase_invoice'
|
@@ -4,13 +4,17 @@ module BusinessCentral
|
|
4
4
|
|
5
5
|
DEFAULT_URL = 'https://api.businesscentral.dynamics.com/v1.0/api/beta'.freeze
|
6
6
|
|
7
|
+
DEFAULT_LOGIN_URL = 'https://login.microsoftonline.com/common'.freeze
|
8
|
+
|
7
9
|
attr_reader :tenant_id,
|
8
10
|
:username,
|
9
11
|
:password,
|
10
12
|
:application_id,
|
11
13
|
:secret_key,
|
12
14
|
:url,
|
13
|
-
:
|
15
|
+
:oauth2_login_url,
|
16
|
+
:oauth2_client,
|
17
|
+
:default_company_id
|
14
18
|
|
15
19
|
alias_method :access_token, :oauth2_client
|
16
20
|
|
@@ -23,6 +27,12 @@ module BusinessCentral
|
|
23
27
|
object :company_information
|
24
28
|
object :country_region
|
25
29
|
object :currency
|
30
|
+
object :customer
|
31
|
+
object :customer_financial_detail
|
32
|
+
object :customer_payment
|
33
|
+
object :customer_payment_journal
|
34
|
+
object :customer_sale
|
35
|
+
object :default_dimension
|
26
36
|
object :vendor
|
27
37
|
object :purchase_invoice
|
28
38
|
object :purchase_invoice_line
|
@@ -36,13 +46,15 @@ module BusinessCentral
|
|
36
46
|
@url = opts.delete(:url) || DEFAULT_URL
|
37
47
|
@application_id = opts.delete(:application_id)
|
38
48
|
@secret_key = opts.delete(:secret_key)
|
49
|
+
@oauth2_login_url = opts.delete(:oauth2_login_url) || DEFAULT_LOGIN_URL
|
50
|
+
@default_company_id = opts.delete(:default_company_id)
|
39
51
|
end
|
40
52
|
|
41
53
|
def authorize(params = {}, oauth_authorize_callback: '')
|
42
54
|
params[:redirect_uri] = oauth_authorize_callback
|
43
55
|
begin
|
44
56
|
oauth2_client.auth_code.authorize_url(params)
|
45
|
-
rescue
|
57
|
+
rescue OAuth2::Error => error
|
46
58
|
handle_error(error)
|
47
59
|
end
|
48
60
|
end
|
@@ -77,7 +89,7 @@ module BusinessCentral
|
|
77
89
|
@application_id,
|
78
90
|
@secret_key,
|
79
91
|
{
|
80
|
-
site:
|
92
|
+
site: @oauth2_login_url,
|
81
93
|
authorize_url: 'oauth2/authorize?resource=https://api.businesscentral.dynamics.com',
|
82
94
|
token_url: 'oauth2/token?resource=https://api.businesscentral.dynamics.com'
|
83
95
|
}
|
@@ -88,7 +100,7 @@ module BusinessCentral
|
|
88
100
|
end
|
89
101
|
|
90
102
|
def handle_error(error)
|
91
|
-
if error.code.
|
103
|
+
if !error.code.nil?
|
92
104
|
case error.code
|
93
105
|
when 'invalid_client'
|
94
106
|
raise InvalidClientException.new
|
@@ -4,7 +4,7 @@ module BusinessCentral
|
|
4
4
|
|
5
5
|
class InvalidClientException < BusinessCentralError
|
6
6
|
def message
|
7
|
-
'Invalid
|
7
|
+
'Invalid client setup'
|
8
8
|
end
|
9
9
|
end
|
10
10
|
|
@@ -52,4 +52,14 @@ module BusinessCentral
|
|
52
52
|
"#{method} method is currently not support. Allowed methods are: #{allowed_methods.join(', ')}"
|
53
53
|
end
|
54
54
|
end
|
55
|
+
|
56
|
+
class InvalidArgumentException < BusinessCentralError
|
57
|
+
def initialize(message)
|
58
|
+
@message = message
|
59
|
+
end
|
60
|
+
|
61
|
+
def message
|
62
|
+
"Invalid argument entered - #{@message}"
|
63
|
+
end
|
64
|
+
end
|
55
65
|
end
|
@@ -2,17 +2,34 @@ module BusinessCentral
|
|
2
2
|
module Object
|
3
3
|
class Base
|
4
4
|
attr_reader :client,
|
5
|
-
:company_id,
|
6
5
|
:parent_path,
|
7
|
-
:path
|
8
|
-
|
6
|
+
:path
|
7
|
+
|
8
|
+
attr_writer :id, :company_id
|
9
9
|
|
10
10
|
def initialize(client, args = {})
|
11
11
|
@client = client
|
12
|
-
@
|
13
|
-
@
|
14
|
-
@
|
15
|
-
|
12
|
+
@id = id(args)
|
13
|
+
@company_id = company_id(args)
|
14
|
+
@parent_path = @company_id.nil? ? [] : [
|
15
|
+
{
|
16
|
+
path: 'companies',
|
17
|
+
id: @company_id
|
18
|
+
}
|
19
|
+
]
|
20
|
+
end
|
21
|
+
|
22
|
+
def id(argument)
|
23
|
+
return @id if !@id.nil?
|
24
|
+
return argument.fetch(:id, '') if !argument.nil?
|
25
|
+
return nil
|
26
|
+
end
|
27
|
+
|
28
|
+
def company_id(argument)
|
29
|
+
return @client.default_company_id if !@client.default_company_id.nil?
|
30
|
+
return @company_id if !@company_id.nil?
|
31
|
+
return argument.fetch(:company_id, '') if !argument.nil?
|
32
|
+
return nil
|
16
33
|
end
|
17
34
|
|
18
35
|
def find_all
|
@@ -51,9 +68,9 @@ module BusinessCentral
|
|
51
68
|
|
52
69
|
def update(id, params = {})
|
53
70
|
if method_supported?(:patch)
|
54
|
-
object = find_by_id(id)
|
55
|
-
if Validation.new(object_validation,
|
56
|
-
Request.patch(@client, build_url(parent_path: @parent_path, child_path: object_name, child_id: id), object[:etag],
|
71
|
+
object = find_by_id(id).merge(params)
|
72
|
+
if Validation.new(object_validation, object).valid?
|
73
|
+
Request.patch(@client, build_url(parent_path: @parent_path, child_path: object_name, child_id: id), object[:etag], object)
|
57
74
|
end
|
58
75
|
else
|
59
76
|
raise BusinessCentral::NoSupportedMethod.new(:patch, object_methods)
|
@@ -95,9 +112,9 @@ module BusinessCentral
|
|
95
112
|
def url_builder(parent_path = [], child_path = '', child_id = '', filter = '')
|
96
113
|
url = @client.url
|
97
114
|
url += parent_path.map { |parent| "/#{parent[:path]}(#{parent[:id]})" }.join('') if !parent_path.empty?
|
98
|
-
url += "/#{child_path}" if !child_path.blank?
|
99
|
-
url += "(#{child_id})" if !child_id.blank?
|
100
|
-
url += "?$filter=#{CGI::escape(filter)}" if !filter.blank?
|
115
|
+
url += "/#{child_path}" if !child_path.to_s.blank?
|
116
|
+
url += "(#{child_id})" if !child_id.to_s.blank?
|
117
|
+
url += "?$filter=#{CGI::escape(filter)}" if !filter.to_s.blank?
|
101
118
|
return url
|
102
119
|
end
|
103
120
|
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module BusinessCentral
|
2
|
+
module Object
|
3
|
+
class Customer < Base
|
4
|
+
OBJECT = 'customers'.freeze
|
5
|
+
|
6
|
+
OBJECT_VALIDATION = {
|
7
|
+
display_name: {
|
8
|
+
required: true,
|
9
|
+
maximum_length: 100
|
10
|
+
},
|
11
|
+
type: {
|
12
|
+
inclusion_of: [
|
13
|
+
'Company',
|
14
|
+
'Person'
|
15
|
+
]
|
16
|
+
}
|
17
|
+
}.freeze
|
18
|
+
|
19
|
+
OBJECT_METHODS = [
|
20
|
+
:get,
|
21
|
+
:post,
|
22
|
+
:patch,
|
23
|
+
:delete
|
24
|
+
].freeze
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module BusinessCentral
|
2
|
+
module Object
|
3
|
+
class CustomerPayment < Base
|
4
|
+
OBJECT = 'customerPayments'.freeze
|
5
|
+
|
6
|
+
OBJECT_VALIDATION = {
|
7
|
+
customer_number: {
|
8
|
+
maximum_length: 20
|
9
|
+
},
|
10
|
+
contact_id: {
|
11
|
+
maximum_length: 250
|
12
|
+
},
|
13
|
+
posting_date: {
|
14
|
+
date: true
|
15
|
+
},
|
16
|
+
document_number: {
|
17
|
+
maximum_length: 20
|
18
|
+
},
|
19
|
+
external_document_number: {
|
20
|
+
maximum_length: 20
|
21
|
+
},
|
22
|
+
applies_to_invoice_number: {
|
23
|
+
maximum_length: 20
|
24
|
+
},
|
25
|
+
description: {
|
26
|
+
maximum_length: 50
|
27
|
+
},
|
28
|
+
comment: {
|
29
|
+
maximum_length: 250
|
30
|
+
}
|
31
|
+
}.freeze
|
32
|
+
|
33
|
+
OBJECT_METHODS = [
|
34
|
+
:get,
|
35
|
+
:post,
|
36
|
+
:patch,
|
37
|
+
:delete
|
38
|
+
].freeze
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module BusinessCentral
|
2
|
+
module Object
|
3
|
+
class CustomerPaymentJournal < Base
|
4
|
+
OBJECT = 'customerPaymentJournals'.freeze
|
5
|
+
|
6
|
+
OBJECT_VALIDATION = {
|
7
|
+
code: {
|
8
|
+
maximum_length: 10
|
9
|
+
},
|
10
|
+
display_name: {
|
11
|
+
maximum_length: 50
|
12
|
+
}
|
13
|
+
}.freeze
|
14
|
+
|
15
|
+
OBJECT_METHODS = [
|
16
|
+
:get,
|
17
|
+
:post,
|
18
|
+
:patch,
|
19
|
+
:delete
|
20
|
+
].freeze
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|