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.
Files changed (39) hide show
  1. checksums.yaml +4 -4
  2. data/lib/business_central.rb +6 -0
  3. data/lib/business_central/client.rb +16 -4
  4. data/lib/business_central/exceptions.rb +11 -1
  5. data/lib/business_central/object/account.rb +0 -10
  6. data/lib/business_central/object/aged_account_payable.rb +0 -10
  7. data/lib/business_central/object/aged_account_receivable.rb +0 -10
  8. data/lib/business_central/object/balance_sheet.rb +0 -10
  9. data/lib/business_central/object/base.rb +30 -13
  10. data/lib/business_central/object/cash_flow_statement.rb +0 -10
  11. data/lib/business_central/object/company.rb +5 -0
  12. data/lib/business_central/object/company_information.rb +0 -10
  13. data/lib/business_central/object/country_region.rb +0 -10
  14. data/lib/business_central/object/currency.rb +0 -10
  15. data/lib/business_central/object/customer.rb +27 -0
  16. data/lib/business_central/object/customer_financial_detail.rb +11 -0
  17. data/lib/business_central/object/customer_payment.rb +41 -0
  18. data/lib/business_central/object/customer_payment_journal.rb +23 -0
  19. data/lib/business_central/object/customer_sale.rb +11 -0
  20. data/lib/business_central/object/default_dimension.rb +54 -0
  21. data/lib/business_central/object/helper.rb +29 -3
  22. data/lib/business_central/object/item.rb +0 -10
  23. data/lib/business_central/object/purchase_invoice.rb +0 -10
  24. data/lib/business_central/object/purchase_invoice_line.rb +4 -10
  25. data/lib/business_central/object/request.rb +2 -2
  26. data/lib/business_central/object/vendor.rb +3 -9
  27. data/lib/business_central/version.rb +1 -1
  28. data/test/business_central/client_test.rb +37 -2
  29. data/test/business_central/object/base_test.rb +39 -0
  30. data/test/business_central/object/customer_financial_detail_test.rb +66 -0
  31. data/test/business_central/object/customer_payment_journal_test.rb +135 -0
  32. data/test/business_central/object/customer_payment_test.rb +142 -0
  33. data/test/business_central/object/customer_sale_test.rb +70 -0
  34. data/test/business_central/object/customer_test.rb +125 -0
  35. data/test/business_central/object/default_dimension_test.rb +171 -0
  36. data/test/business_central/object/request_test.rb +58 -3
  37. data/test/business_central/object/response_test.rb +24 -6
  38. data/test/test_helper.rb +6 -2
  39. metadata +36 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 918c17b06f28ef71d9866952c18674f7251b7456444660a2d6db20dccb3ed16c
4
- data.tar.gz: 89399ed2fb0f96b3d3e680accdc3193a44d640a44e1e831650a0f810604dd0df
3
+ metadata.gz: bfee02464cc6b4a28c6208ced736a5d8453f917cbe8757f7e28cd6ad900721d6
4
+ data.tar.gz: ca2a683c9f3440d4fa953507051021145b1690bd42152ba488eae70c451ce2ae
5
5
  SHA512:
6
- metadata.gz: 8d555669929150b37fdc67ce0394bdf251012cc009e851cb35f8a8bbb82c8633b60f330eb5d81d891a087e4dda8fe2bb59790a76dd65b61d4fe153b50b6b1316
7
- data.tar.gz: bdecc5f196538bebb0e5c5f97f20574590031f0830c0e07fc5cb61d1279ef6ba3e6c2ecb2337278e167c7ff9e25ddb2246c125e49fc77bb0a2e70cb090c8e65b
6
+ metadata.gz: 454c708a9323072524312b21877aca84918c2bb2c611956849291446c9117a007301112333d7c3bf25b3e5ac1707a81a2bdde2d7b3cc50f561ec0d28df5a40d0
7
+ data.tar.gz: 78cbb22465b21ca9f876c621986e55a9843df5b9505a6552425ae56667258aaddff9ec76e3a00f5b7f820572e3a3bf887c2d49516d8e2b203f0ef2d02bf52aaf
@@ -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
- :oauth2_client
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 Oauth2::Error => error
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: "https://login.windows.net/#{@tenant_id}",
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.present?
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 application setup'
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
@@ -6,16 +6,6 @@ module BusinessCentral
6
6
  OBJECT_METHODS = [
7
7
  :get
8
8
  ].freeze
9
-
10
- def initialize(client, company_id:)
11
- super(client, company_id: company_id)
12
- @parent_path = [
13
- {
14
- path: 'companies',
15
- id: company_id
16
- }
17
- ]
18
- end
19
9
  end
20
10
  end
21
11
  end
@@ -6,16 +6,6 @@ module BusinessCentral
6
6
  OBJECT_METHODS = [
7
7
  :get
8
8
  ].freeze
9
-
10
- def initialize(client, company_id:)
11
- super(client, company_id: company_id)
12
- @parent_path = [
13
- {
14
- path: 'companies',
15
- id: company_id
16
- }
17
- ]
18
- end
19
9
  end
20
10
  end
21
11
  end
@@ -6,16 +6,6 @@ module BusinessCentral
6
6
  OBJECT_METHODS = [
7
7
  :get
8
8
  ].freeze
9
-
10
- def initialize(client, company_id:)
11
- super(client, company_id: company_id)
12
- @parent_path = [
13
- {
14
- path: 'companies',
15
- id: company_id
16
- }
17
- ]
18
- end
19
9
  end
20
10
  end
21
11
  end
@@ -6,16 +6,6 @@ module BusinessCentral
6
6
  OBJECT_METHODS = [
7
7
  :get
8
8
  ].freeze
9
-
10
- def initialize(client, company_id:)
11
- super(client, company_id: company_id)
12
- @parent_path = [
13
- {
14
- path: 'companies',
15
- id: company_id
16
- }
17
- ]
18
- end
19
9
  end
20
10
  end
21
11
  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
- :errors
6
+ :path
7
+
8
+ attr_writer :id, :company_id
9
9
 
10
10
  def initialize(client, args = {})
11
11
  @client = client
12
- @company_id = args[:company_id] if !args.nil?
13
- @parent_path = []
14
- @path = ''
15
- @errors = []
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, params).valid?
56
- Request.patch(@client, build_url(parent_path: @parent_path, child_path: object_name, child_id: id), object[:etag], params)
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
@@ -6,16 +6,6 @@ module BusinessCentral
6
6
  OBJECT_METHODS = [
7
7
  :get
8
8
  ].freeze
9
-
10
- def initialize(client, company_id:)
11
- super(client, company_id: company_id)
12
- @parent_path = [
13
- {
14
- path: 'companies',
15
- id: company_id
16
- }
17
- ]
18
- end
19
9
  end
20
10
  end
21
11
  end
@@ -6,6 +6,11 @@ module BusinessCentral
6
6
  OBJECT_METHODS = [
7
7
  :get
8
8
  ].freeze
9
+
10
+ def initialize(client, args)
11
+ super(client)
12
+ @parent_path = []
13
+ end
9
14
  end
10
15
  end
11
16
  end
@@ -7,16 +7,6 @@ module BusinessCentral
7
7
  :get,
8
8
  :patch
9
9
  ].freeze
10
-
11
- def initialize(client, company_id:)
12
- super(client, company_id: company_id)
13
- @parent_path = [
14
- {
15
- path: 'companies',
16
- id: company_id
17
- }
18
- ]
19
- end
20
10
  end
21
11
  end
22
12
  end
@@ -19,16 +19,6 @@ module BusinessCentral
19
19
  :patch,
20
20
  :delete
21
21
  ].freeze
22
-
23
- def initialize(client, company_id:)
24
- super(client, company_id: company_id)
25
- @parent_path = [
26
- {
27
- path: 'companies',
28
- id: company_id
29
- }
30
- ]
31
- end
32
22
  end
33
23
  end
34
24
  end
@@ -22,16 +22,6 @@ module BusinessCentral
22
22
  :patch,
23
23
  :delete
24
24
  ].freeze
25
-
26
- def initialize(client, company_id:)
27
- super(client, company_id: company_id)
28
- @parent_path = [
29
- {
30
- path: 'companies',
31
- id: company_id
32
- }
33
- ]
34
- end
35
25
  end
36
26
  end
37
27
  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,11 @@
1
+ module BusinessCentral
2
+ module Object
3
+ class CustomerFinancialDetail < Base
4
+ OBJECT = 'customerFinancialDetails'.freeze
5
+
6
+ OBJECT_METHODS = [
7
+ :get
8
+ ].freeze
9
+ end
10
+ end
11
+ 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