business-central 1.0.1 → 1.0.2

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a33078b9f42de6667181a50991b793edcc2bdedb118be70e26fdfe9224e23ba6
4
- data.tar.gz: cd67e00b86499bc25fa912a8ff662991c809f13add9f892611591e45e04453bf
3
+ metadata.gz: 918c17b06f28ef71d9866952c18674f7251b7456444660a2d6db20dccb3ed16c
4
+ data.tar.gz: 89399ed2fb0f96b3d3e680accdc3193a44d640a44e1e831650a0f810604dd0df
5
5
  SHA512:
6
- metadata.gz: 1e2616ef4f1cb78780924fe1741dcceb97ab02460b0838dccc0f94eb1fd990a4c1a8ac72e6a4a87a1189c1834557fa2efa0755f207eb6aa399d815802f663374
7
- data.tar.gz: 5d3a27c2fcfcaaabb52832382a90d74527fdb8c5c5adf4cda26c5e2be48b52a5bcda500b8733eb52406c8f3be8c958379c833a3571aca4954f8b0e51a13f627e
6
+ metadata.gz: 8d555669929150b37fdc67ce0394bdf251012cc009e851cb35f8a8bbb82c8633b60f330eb5d81d891a087e4dda8fe2bb59790a76dd65b61d4fe153b50b6b1316
7
+ data.tar.gz: bdecc5f196538bebb0e5c5f97f20574590031f0830c0e07fc5cb61d1279ef6ba3e6c2ecb2337278e167c7ff9e25ddb2246c125e49fc77bb0a2e70cb090c8e65b
@@ -18,6 +18,8 @@ require 'business_central/object/cash_flow_statement'
18
18
  require 'business_central/object/balance_sheet'
19
19
  require 'business_central/object/company'
20
20
  require 'business_central/object/company_information'
21
+ require 'business_central/object/country_region'
22
+ require 'business_central/object/currency'
21
23
  require 'business_central/object/vendor'
22
24
  require 'business_central/object/item'
23
25
  require 'business_central/object/purchase_invoice'
@@ -21,6 +21,8 @@ module BusinessCentral
21
21
  object :cash_flow_statement
22
22
  object :company
23
23
  object :company_information
24
+ object :country_region
25
+ object :currency
24
26
  object :vendor
25
27
  object :purchase_invoice
26
28
  object :purchase_invoice_line
@@ -97,7 +97,7 @@ module BusinessCentral
97
97
  url += parent_path.map { |parent| "/#{parent[:path]}(#{parent[:id]})" }.join('') if !parent_path.empty?
98
98
  url += "/#{child_path}" if !child_path.blank?
99
99
  url += "(#{child_id})" if !child_id.blank?
100
- url += "?$filter=#{filter}" if !filter.blank?
100
+ url += "?$filter=#{CGI::escape(filter)}" if !filter.blank?
101
101
  return url
102
102
  end
103
103
  end
@@ -0,0 +1,34 @@
1
+ module BusinessCentral
2
+ module Object
3
+ class CountryRegion < Base
4
+ OBJECT = 'countriesRegions'.freeze
5
+
6
+ OBJECT_VALIDATION = {
7
+ code: {
8
+ required: true
9
+ },
10
+ display_name: {
11
+ required: true,
12
+ maximum_length: 100
13
+ }
14
+ }.freeze
15
+
16
+ OBJECT_METHODS = [
17
+ :get,
18
+ :post,
19
+ :patch,
20
+ :delete
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
+ end
33
+ end
34
+ end
@@ -0,0 +1,37 @@
1
+ module BusinessCentral
2
+ module Object
3
+ class Currency < Base
4
+ OBJECT = 'currencies'.freeze
5
+
6
+ OBJECT_VALIDATION = {
7
+ code: {
8
+ required: true
9
+ },
10
+ display_name: {
11
+ required: true,
12
+ maximum_length: 100
13
+ },
14
+ symbol: {
15
+ required: true
16
+ }
17
+ }.freeze
18
+
19
+ OBJECT_METHODS = [
20
+ :get,
21
+ :post,
22
+ :patch,
23
+ :delete
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
+ end
36
+ end
37
+ end
@@ -61,7 +61,7 @@ module BusinessCentral
61
61
  if Response.unauthorized?(request.code.to_i)
62
62
  raise UnauthorizedException.new
63
63
  else
64
- if response[:error][:code].present?
64
+ if !response[:error][:code].blank?
65
65
  case response[:error][:code]
66
66
  when 'Internal_CompanyNotFound'
67
67
  raise CompanyNotFoundException.new
@@ -1,3 +1,3 @@
1
1
  module BusinessCentral
2
- VERSION = "1.0.1".freeze
2
+ VERSION = "1.0.2".freeze
3
3
  end
@@ -0,0 +1,130 @@
1
+ require "test_helper"
2
+ # rake test TEST=test/business_central/object/country_region_test.rb
3
+
4
+ class BusinessCentral::Object::CountryRegionTest < Minitest::Test
5
+ def setup
6
+ @company_id = '123456'
7
+ @client = BusinessCentral::Client.new
8
+ @country_region = @client.country_region(company_id: @company_id)
9
+ end
10
+
11
+ def test_find_all
12
+ stub_request(:get, /countriesRegions/)
13
+ .to_return(
14
+ status: 200,
15
+ body: {
16
+ 'value': [
17
+ {
18
+ id: 1,
19
+ code: 'C1',
20
+ displayName: 'country1'
21
+ }
22
+ ]
23
+ }.to_json,
24
+ )
25
+
26
+ response = @country_region.find_all
27
+ assert_equal response.first[:display_name], 'country1'
28
+ end
29
+
30
+ def test_find_by_id
31
+ test_id = '1111'
32
+ stub_request(:get, /countriesRegions\(#{test_id}\)/)
33
+ .to_return(
34
+ status: 200,
35
+ body: {
36
+ id: 2,
37
+ code: 'C2',
38
+ displayName: 'country2'
39
+ }.to_json
40
+ )
41
+
42
+ response = @country_region.find_by_id(test_id)
43
+ assert_equal response[:display_name], 'country2'
44
+ end
45
+
46
+ def test_where
47
+ test_filter = "displayName eq 'country3'"
48
+ stub_request(:get, /countriesRegions\?\$filter=#{test_filter}/)
49
+ .to_return(
50
+ status: 200,
51
+ body: {
52
+ 'value': [
53
+ {
54
+ displayName: 'country3'
55
+ }
56
+ ]
57
+ }.to_json
58
+ )
59
+
60
+ response = @country_region.where(test_filter)
61
+ assert_equal response.first[:display_name], 'country3'
62
+ end
63
+
64
+ def test_create
65
+ stub_request(:post, /countriesRegions/)
66
+ .to_return(
67
+ status: 200,
68
+ body: {
69
+ displayName: 'country4'
70
+ }.to_json
71
+ )
72
+
73
+ response = @country_region.create({
74
+ code: 'C4',
75
+ display_name: 'country4'
76
+ })
77
+ assert_equal response[:display_name], 'country4'
78
+ end
79
+
80
+
81
+ def test_update
82
+ test_id = '22222'
83
+ stub_request(:get, /countriesRegions\(#{test_id}\)/)
84
+ .to_return(
85
+ status: 200,
86
+ body: {
87
+ etag: '2222',
88
+ code: 'C5',
89
+ displayName: 'country5'
90
+ }.to_json
91
+ )
92
+
93
+ stub_request(:patch, /countriesRegions\(#{test_id}\)/)
94
+ .to_return(
95
+ status: 200,
96
+ body: {
97
+ etag: '2222',
98
+ code: 'C6',
99
+ displayName: 'country6'
100
+ }.to_json
101
+ )
102
+
103
+ response = @country_region.update(
104
+ test_id,
105
+ {
106
+ code: 'C6',
107
+ display_name: 'country6'
108
+ }
109
+ )
110
+ assert_equal response[:display_name], 'country6'
111
+ end
112
+
113
+ def test_delete
114
+ test_id = '33333'
115
+ stub_request(:get, /countriesRegions\(#{test_id}\)/)
116
+ .to_return(
117
+ status: 200,
118
+ body: {
119
+ etag: '3333',
120
+ code: 'C7',
121
+ displayName: 'country7'
122
+ }.to_json
123
+ )
124
+
125
+ stub_request(:delete, /countriesRegions\(#{test_id}\)/)
126
+ .to_return(status: 204)
127
+
128
+ assert @country_region.destroy(test_id)
129
+ end
130
+ end
@@ -0,0 +1,151 @@
1
+ require "test_helper"
2
+ # rake test TEST=test/business_central/object/currency_test.rb
3
+
4
+ class BusinessCentral::Object::CurrencyTest < Minitest::Test
5
+ def setup
6
+ @company_id = '123456'
7
+ @client = BusinessCentral::Client.new
8
+ @currency = @client.currency(company_id: @company_id)
9
+ end
10
+
11
+ def test_find_all
12
+ stub_request(:get, /currencies/)
13
+ .to_return(
14
+ status: 200,
15
+ body: {
16
+ 'value': [
17
+ {
18
+ id: 1,
19
+ code: 'C1',
20
+ displayName: 'currency1',
21
+ symbol: '$',
22
+ amountDecimalPlaces: '2:2',
23
+ amountRoundingPrecision: 0.01
24
+ }
25
+ ]
26
+ }.to_json,
27
+ )
28
+
29
+ response = @currency.find_all
30
+ assert_equal response.first[:display_name], 'currency1'
31
+ end
32
+
33
+ def test_find_by_id
34
+ test_id = '2'
35
+ stub_request(:get, /currencies\(#{test_id}\)/)
36
+ .to_return(
37
+ status: 200,
38
+ body: {
39
+ id: test_id,
40
+ code: 'C2',
41
+ displayName: 'currency2',
42
+ symbol: '$',
43
+ amountDecimalPlaces: '2:2',
44
+ amountRoundingPrecision: 0.01
45
+ }.to_json
46
+ )
47
+
48
+ response = @currency.find_by_id(test_id)
49
+ assert_equal response[:display_name], 'currency2'
50
+ end
51
+
52
+ def test_where
53
+ test_filter = "displayName eq 'country3'"
54
+ stub_request(:get, /currencies\?\$filter=#{test_filter}/)
55
+ .to_return(
56
+ status: 200,
57
+ body: {
58
+ 'value': [
59
+ {
60
+ id: 3,
61
+ code: 'C3',
62
+ displayName: 'currency3',
63
+ symbol: '$',
64
+ amountDecimalPlaces: '2:2',
65
+ amountRoundingPrecision: 0.01
66
+ }
67
+ ]
68
+ }.to_json
69
+ )
70
+
71
+ response = @currency.where(test_filter)
72
+ assert_equal response.first[:display_name], 'currency3'
73
+ end
74
+
75
+ def test_create
76
+ stub_request(:post, /currencies/)
77
+ .to_return(
78
+ status: 200,
79
+ body: {
80
+ code: 'C4',
81
+ displayName: 'currency4',
82
+ symbol: '$'
83
+ }.to_json
84
+ )
85
+
86
+ response = @currency.create({
87
+ code: 'C4',
88
+ display_name: 'currency4',
89
+ symbol: '$'
90
+ })
91
+ assert_equal response[:display_name], 'currency4'
92
+ end
93
+
94
+
95
+ def test_update
96
+ test_id = '2'
97
+ stub_request(:get, /currencies\(#{test_id}\)/)
98
+ .to_return(
99
+ status: 200,
100
+ body: {
101
+ etag: '3333',
102
+ id: test_id,
103
+ code: 'C5',
104
+ displayName: 'currency5',
105
+ symbol: '$',
106
+ amountDecimalPlaces: '2:2',
107
+ amountRoundingPrecision: 0.01
108
+ }.to_json
109
+ )
110
+
111
+ stub_request(:patch, /currencies\(#{test_id}\)/)
112
+ .to_return(
113
+ status: 200,
114
+ body: {
115
+ etag: '4444',
116
+ code: 'C6',
117
+ displayName: 'currency6',
118
+ symbol: '$'
119
+ }.to_json
120
+ )
121
+
122
+ response = @currency.update(
123
+ test_id,
124
+ {
125
+ code: 'C6',
126
+ display_name: 'currency6',
127
+ symbol: '$'
128
+ }
129
+ )
130
+ assert_equal response[:display_name], 'currency6'
131
+ end
132
+
133
+ def test_delete
134
+ test_id = '33333'
135
+ stub_request(:get, /currencies\(#{test_id}\)/)
136
+ .to_return(
137
+ status: 200,
138
+ body: {
139
+ etag: '5555',
140
+ code: 'C7',
141
+ displayName: 'currency7',
142
+ symbol: '$'
143
+ }.to_json
144
+ )
145
+
146
+ stub_request(:delete, /currencies\(#{test_id}\)/)
147
+ .to_return(status: 204)
148
+
149
+ assert @currency.destroy(test_id)
150
+ end
151
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: business-central
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jarrad Muir
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-12-10 00:00:00.000000000 Z
11
+ date: 2019-12-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -132,6 +132,8 @@ files:
132
132
  - lib/business_central/object/cash_flow_statement.rb
133
133
  - lib/business_central/object/company.rb
134
134
  - lib/business_central/object/company_information.rb
135
+ - lib/business_central/object/country_region.rb
136
+ - lib/business_central/object/currency.rb
135
137
  - lib/business_central/object/helper.rb
136
138
  - lib/business_central/object/item.rb
137
139
  - lib/business_central/object/purchase_invoice.rb
@@ -150,6 +152,8 @@ files:
150
152
  - test/business_central/object/cash_flow_statement_test.rb
151
153
  - test/business_central/object/company_information_test.rb
152
154
  - test/business_central/object/company_test.rb
155
+ - test/business_central/object/country_region_test.rb
156
+ - test/business_central/object/currency_test.rb
153
157
  - test/business_central/object/item_test.rb
154
158
  - test/business_central/object/purchase_invoice_line_test.rb
155
159
  - test/business_central/object/purchase_invoice_test.rb
@@ -194,6 +198,8 @@ test_files:
194
198
  - test/business_central/object/cash_flow_statement_test.rb
195
199
  - test/business_central/object/company_information_test.rb
196
200
  - test/business_central/object/company_test.rb
201
+ - test/business_central/object/country_region_test.rb
202
+ - test/business_central/object/currency_test.rb
197
203
  - test/business_central/object/item_test.rb
198
204
  - test/business_central/object/purchase_invoice_line_test.rb
199
205
  - test/business_central/object/purchase_invoice_test.rb