fortnox-api 0.4.0 → 0.5.0
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 +4 -4
- data/README.md +31 -29
- data/bin/console +8 -0
- data/fortnox-api.gemspec +1 -3
- data/lib/fortnox/api.rb +49 -14
- data/lib/fortnox/api/circular_queue.rb +33 -0
- data/lib/fortnox/api/mappers.rb +1 -1
- data/lib/fortnox/api/mappers/base.rb +3 -0
- data/lib/fortnox/api/models/article.rb +25 -25
- data/lib/fortnox/api/models/customer.rb +47 -47
- data/lib/fortnox/api/models/document_base.rb +4 -4
- data/lib/fortnox/api/repositories/article.rb +3 -4
- data/lib/fortnox/api/repositories/base.rb +77 -5
- data/lib/fortnox/api/repositories/base/savers.rb +2 -2
- data/lib/fortnox/api/repositories/customer.rb +3 -4
- data/lib/fortnox/api/repositories/invoice.rb +3 -4
- data/lib/fortnox/api/repositories/order.rb +3 -4
- data/lib/fortnox/api/repositories/project.rb +3 -3
- data/lib/fortnox/api/types/document_row.rb +3 -3
- data/lib/fortnox/api/types/model.rb +2 -6
- data/lib/fortnox/api/version.rb +1 -1
- data/spec/fortnox/api/mappers/base_spec.rb +6 -0
- data/spec/fortnox/api/repositories/article_spec.rb +4 -0
- data/spec/fortnox/api/repositories/base_spec.rb +348 -0
- data/spec/fortnox/api/repositories/customer_spec.rb +4 -0
- data/spec/fortnox/api/repositories/invoice_spec.rb +4 -0
- data/spec/fortnox/api/repositories/order_spec.rb +4 -0
- data/spec/fortnox/api/repositories/project_spec.rb +4 -0
- data/spec/fortnox/api/types/examples/document_row.rb +2 -2
- data/spec/fortnox/api/types/house_work_types_spec.rb +4 -0
- data/spec/fortnox/api_spec.rb +161 -31
- data/spec/spec_helper.rb +7 -2
- data/spec/support/helpers/configuration_helper.rb +10 -0
- metadata +10 -27
- data/lib/fortnox/api/base.rb +0 -47
- data/lib/fortnox/api/class_methods.rb +0 -30
- data/lib/fortnox/api/environment_validation.rb +0 -78
- data/spec/fortnox/api/base_spec.rb +0 -167
- data/spec/support/helpers/environment_helper.rb +0 -7
@@ -9,6 +9,10 @@ require 'fortnox/api/repositories/examples/save_with_specially_named_attribute'
|
|
9
9
|
require 'fortnox/api/repositories/examples/search'
|
10
10
|
|
11
11
|
describe Fortnox::API::Repository::Customer, order: :defined, integration: true do
|
12
|
+
include Helpers::Configuration
|
13
|
+
|
14
|
+
before{ set_api_test_configuration }
|
15
|
+
|
12
16
|
subject(:repository){ described_class.new }
|
13
17
|
|
14
18
|
include_examples '.save', :name
|
@@ -11,6 +11,10 @@ require 'fortnox/api/repositories/examples/save_with_specially_named_attribute'
|
|
11
11
|
require 'fortnox/api/repositories/examples/only'
|
12
12
|
|
13
13
|
describe Fortnox::API::Repository::Invoice, order: :defined, integration: true do
|
14
|
+
include Helpers::Configuration
|
15
|
+
|
16
|
+
before{ set_api_test_configuration }
|
17
|
+
|
14
18
|
subject(:repository){ described_class.new }
|
15
19
|
|
16
20
|
required_hash = { customer_number: '1' }
|
@@ -10,6 +10,10 @@ require 'fortnox/api/repositories/examples/save_with_nested_model'
|
|
10
10
|
require 'fortnox/api/repositories/examples/search'
|
11
11
|
|
12
12
|
describe Fortnox::API::Repository::Order, order: :defined, integration: true do
|
13
|
+
include Helpers::Configuration
|
14
|
+
|
15
|
+
before{ set_api_test_configuration }
|
16
|
+
|
13
17
|
subject(:repository){ described_class.new }
|
14
18
|
|
15
19
|
required_hash = { customer_number: '1' }
|
@@ -7,6 +7,10 @@ require 'fortnox/api/repositories/examples/find'
|
|
7
7
|
require 'fortnox/api/repositories/examples/save'
|
8
8
|
|
9
9
|
describe Fortnox::API::Repository::Project, order: :defined, integration: true do
|
10
|
+
include Helpers::Configuration
|
11
|
+
|
12
|
+
before{ set_api_test_configuration }
|
13
|
+
|
10
14
|
subject( :repository ){ described_class.new }
|
11
15
|
|
12
16
|
include_examples '.save',
|
@@ -4,8 +4,8 @@ shared_examples_for 'DocumentRow' do |valid_hash|
|
|
4
4
|
it{ is_expected.to have_sized_string( :article_number, 50, valid_hash ) }
|
5
5
|
it{ is_expected.to have_sized_string( :description, 50, valid_hash ) }
|
6
6
|
|
7
|
-
it{ is_expected.to have_sized_float( :delivered_quantity, 0.0, 9_999_999_999_999.
|
8
|
-
it{ is_expected.to have_sized_float( :price, 0.0, 99_999_999_999.
|
7
|
+
it{ is_expected.to have_sized_float( :delivered_quantity, 0.0, 9_999_999_999_999.9, valid_hash ) }
|
8
|
+
it{ is_expected.to have_sized_float( :price, 0.0, 99_999_999_999.9, valid_hash ) }
|
9
9
|
|
10
10
|
it{ is_expected.to have_discount_type( :discount_type, valid_hash ) }
|
11
11
|
|
@@ -7,6 +7,10 @@ require 'fortnox/api/types/order_row'
|
|
7
7
|
|
8
8
|
# rubocop:disable RSpec/DescribeClass
|
9
9
|
describe 'HouseWorkTypes', integration: true do
|
10
|
+
include Helpers::Configuration
|
11
|
+
|
12
|
+
before{ set_api_test_configuration }
|
13
|
+
|
10
14
|
let(:repository){ Fortnox::API::Repository::Order.new }
|
11
15
|
let(:valid_model) do
|
12
16
|
Fortnox::API::Model::Order.new(customer_number: '1', order_rows: [order_row])
|
data/spec/fortnox/api_spec.rb
CHANGED
@@ -2,36 +2,166 @@ require 'spec_helper'
|
|
2
2
|
require 'fortnox/api'
|
3
3
|
|
4
4
|
describe Fortnox::API do
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
5
|
+
before do
|
6
|
+
module Fortnox
|
7
|
+
module API
|
8
|
+
class TestBase
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
describe 'configuration defaults' do
|
15
|
+
subject(:config_value){ described_class.config[config_key] }
|
16
|
+
|
17
|
+
before{ Fortnox::API::TestBase.new }
|
18
|
+
|
19
|
+
describe 'base_url' do
|
20
|
+
let( :config_key ){ :base_url }
|
21
|
+
|
22
|
+
it{ is_expected.to eql 'https://api.fortnox.se/3/' }
|
23
|
+
end
|
24
|
+
|
25
|
+
describe 'client_secret' do
|
26
|
+
let( :config_key ){ :client_secret }
|
27
|
+
|
28
|
+
it{ is_expected.to be_nil }
|
29
|
+
end
|
30
|
+
|
31
|
+
describe 'access_token' do
|
32
|
+
let( :config_key ){ :access_token }
|
33
|
+
|
34
|
+
it{ is_expected.to be_nil }
|
35
|
+
end
|
36
|
+
|
37
|
+
describe 'access_tokens' do
|
38
|
+
let( :config_key ){ :access_tokens }
|
39
|
+
|
40
|
+
it{ is_expected.to be_nil }
|
41
|
+
end
|
42
|
+
|
43
|
+
describe 'token_store' do
|
44
|
+
let( :config_key ){ :token_store }
|
45
|
+
|
46
|
+
it{ is_expected.to eql( {} ) }
|
47
|
+
end
|
48
|
+
|
49
|
+
describe 'debugging' do
|
50
|
+
let( :config_key ){ :debugging }
|
51
|
+
|
52
|
+
it{ is_expected.to be false }
|
53
|
+
end
|
54
|
+
|
55
|
+
describe 'logger' do
|
56
|
+
let( :config_key ){ :logger }
|
57
|
+
|
58
|
+
it{ is_expected.to be_a Logger }
|
59
|
+
|
60
|
+
describe 'level' do
|
61
|
+
subject{ config_value.level }
|
62
|
+
|
63
|
+
it{ is_expected.to be Logger::WARN }
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
describe 'access_token' do
|
69
|
+
context 'when set to a String' do
|
70
|
+
subject{ described_class.config.access_token }
|
71
|
+
|
72
|
+
before{ described_class.configure{ |config| config.access_token = value } }
|
73
|
+
let( :value ){ '12345' }
|
74
|
+
|
75
|
+
it{ is_expected.to eql value }
|
76
|
+
end
|
77
|
+
|
78
|
+
shared_examples_for 'invalid argument' do
|
79
|
+
subject{ ->{ described_class.configure{ |config| config.access_token = value } } }
|
80
|
+
|
81
|
+
it{ is_expected.to raise_error(ArgumentError, /expected a String/) }
|
82
|
+
end
|
83
|
+
|
84
|
+
context 'when set to a Hash' do
|
85
|
+
include_examples 'invalid argument' do
|
86
|
+
let( :value ){ { a: '123' } }
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
context 'when set to an Array' do
|
91
|
+
include_examples 'invalid argument' do
|
92
|
+
let( :value ){ ['123', '456'] }
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
describe 'access_tokens' do
|
98
|
+
context 'when set to a String' do
|
99
|
+
subject{ ->{ described_class.configure{ |config| config.access_tokens = '12345' } } }
|
100
|
+
|
101
|
+
it{ is_expected.to raise_error(ArgumentError, /expected a Hash or an Array/) }
|
102
|
+
end
|
103
|
+
|
104
|
+
shared_examples_for 'valid argument' do
|
105
|
+
subject{ described_class.configure{ |config| config.access_tokens = value } }
|
106
|
+
|
107
|
+
it{ is_expected.to eql( value ) }
|
108
|
+
end
|
109
|
+
|
110
|
+
context 'when set to a Hash' do
|
111
|
+
include_examples 'valid argument' do
|
112
|
+
let( :value ){ { a: '123', b: '456' } }
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
context 'when set to an Array' do
|
117
|
+
include_examples 'valid argument' do
|
118
|
+
let( :value ){ ['123', '456'] }
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
describe 'token_store' do
|
124
|
+
subject{ described_class.config[:token_store] }
|
125
|
+
|
126
|
+
context 'when access_token set' do
|
127
|
+
before{ described_class.configure{ |config| config.access_token = access_token } }
|
128
|
+
let( :access_token ){ '12345' }
|
129
|
+
|
130
|
+
it{ is_expected.to eql(default: access_token) }
|
131
|
+
end
|
132
|
+
|
133
|
+
context 'when access_tokens is' do
|
134
|
+
before{ described_class.configure{ |config| config.access_tokens = access_tokens } }
|
135
|
+
|
136
|
+
describe 'a Hash' do
|
137
|
+
let( :access_tokens ){ { a: '123', b: '456' } }
|
138
|
+
|
139
|
+
it{ is_expected.to eql( access_tokens ) }
|
140
|
+
end
|
141
|
+
|
142
|
+
describe 'an Array' do
|
143
|
+
let( :access_tokens ){ ['123', '456'] }
|
144
|
+
|
145
|
+
it{ is_expected.to eql( default: access_tokens ) }
|
146
|
+
end
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
describe 'readers for' do
|
151
|
+
describe 'debugging' do
|
152
|
+
subject{ described_class.debugging }
|
153
|
+
|
154
|
+
it 'is available' do
|
155
|
+
is_expected.to be false
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
159
|
+
describe 'logger' do
|
160
|
+
subject{ described_class.logger }
|
161
|
+
|
162
|
+
it 'is available' do
|
163
|
+
is_expected.to be_a Logger
|
164
|
+
end
|
165
|
+
end
|
36
166
|
end
|
37
167
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -7,10 +7,8 @@ require "codeclimate-test-reporter"
|
|
7
7
|
require 'support/matchers'
|
8
8
|
require 'support/helpers'
|
9
9
|
require 'support/vcr_setup'
|
10
|
-
require 'dotenv'
|
11
10
|
|
12
11
|
CodeClimate::TestReporter.start
|
13
|
-
Dotenv.load('.env.test')
|
14
12
|
|
15
13
|
RSpec.configure do |config|
|
16
14
|
config.run_all_when_everything_filtered = true
|
@@ -38,4 +36,11 @@ RSpec.configure do |config|
|
|
38
36
|
config.after do
|
39
37
|
Object.send(:remove_const, Test.remove_constants.name)
|
40
38
|
end
|
39
|
+
|
40
|
+
# Reset configuration after each test run
|
41
|
+
config.after do
|
42
|
+
Fortnox::API::DEFAULT_CONFIGURATION.each do |key, value|
|
43
|
+
Fortnox::API.config.send("#{ key }=", value)
|
44
|
+
end
|
45
|
+
end
|
41
46
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fortnox-api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jonas Schubert Erlandsson
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2017-
|
13
|
+
date: 2017-12-18 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: httparty
|
@@ -26,20 +26,6 @@ dependencies:
|
|
26
26
|
- - "~>"
|
27
27
|
- !ruby/object:Gem::Version
|
28
28
|
version: 0.14.0
|
29
|
-
- !ruby/object:Gem::Dependency
|
30
|
-
name: dotenv
|
31
|
-
requirement: !ruby/object:Gem::Requirement
|
32
|
-
requirements:
|
33
|
-
- - "~>"
|
34
|
-
- !ruby/object:Gem::Version
|
35
|
-
version: '2.0'
|
36
|
-
type: :runtime
|
37
|
-
prerelease: false
|
38
|
-
version_requirements: !ruby/object:Gem::Requirement
|
39
|
-
requirements:
|
40
|
-
- - "~>"
|
41
|
-
- !ruby/object:Gem::Version
|
42
|
-
version: '2.0'
|
43
29
|
- !ruby/object:Gem::Dependency
|
44
30
|
name: dry-struct
|
45
31
|
requirement: !ruby/object:Gem::Requirement
|
@@ -243,7 +229,8 @@ description: This gem uses the HTTParty library to abstract away the REST calls.
|
|
243
229
|
method.
|
244
230
|
email:
|
245
231
|
- jonas.schubert.erlandsson@my-codeworks.com
|
246
|
-
executables:
|
232
|
+
executables:
|
233
|
+
- console
|
247
234
|
extensions: []
|
248
235
|
extra_rdoc_files: []
|
249
236
|
files:
|
@@ -259,15 +246,14 @@ files:
|
|
259
246
|
- LICENSE.txt
|
260
247
|
- README.md
|
261
248
|
- Rakefile
|
249
|
+
- bin/console
|
262
250
|
- docs/account.rb
|
263
251
|
- docs/extraction_script.js
|
264
252
|
- docs/generation_script.rb
|
265
253
|
- docs/json/account.json
|
266
254
|
- fortnox-api.gemspec
|
267
255
|
- lib/fortnox/api.rb
|
268
|
-
- lib/fortnox/api/
|
269
|
-
- lib/fortnox/api/class_methods.rb
|
270
|
-
- lib/fortnox/api/environment_validation.rb
|
256
|
+
- lib/fortnox/api/circular_queue.rb
|
271
257
|
- lib/fortnox/api/mappers.rb
|
272
258
|
- lib/fortnox/api/mappers/article.rb
|
273
259
|
- lib/fortnox/api/mappers/base.rb
|
@@ -317,7 +303,6 @@ files:
|
|
317
303
|
- lib/fortnox/api/types/required.rb
|
318
304
|
- lib/fortnox/api/types/sized.rb
|
319
305
|
- lib/fortnox/api/version.rb
|
320
|
-
- spec/fortnox/api/base_spec.rb
|
321
306
|
- spec/fortnox/api/mappers/article_spec.rb
|
322
307
|
- spec/fortnox/api/mappers/base/from_json_spec.rb
|
323
308
|
- spec/fortnox/api/mappers/base/to_json_spec.rb
|
@@ -342,6 +327,7 @@ files:
|
|
342
327
|
- spec/fortnox/api/models/order_spec.rb
|
343
328
|
- spec/fortnox/api/models/project_spec.rb
|
344
329
|
- spec/fortnox/api/repositories/article_spec.rb
|
330
|
+
- spec/fortnox/api/repositories/base_spec.rb
|
345
331
|
- spec/fortnox/api/repositories/customer_spec.rb
|
346
332
|
- spec/fortnox/api/repositories/examples/all.rb
|
347
333
|
- spec/fortnox/api/repositories/examples/find.rb
|
@@ -372,8 +358,8 @@ files:
|
|
372
358
|
- spec/fortnox/api_spec.rb
|
373
359
|
- spec/spec_helper.rb
|
374
360
|
- spec/support/helpers.rb
|
361
|
+
- spec/support/helpers/configuration_helper.rb
|
375
362
|
- spec/support/helpers/dummy_class_helper.rb
|
376
|
-
- spec/support/helpers/environment_helper.rb
|
377
363
|
- spec/support/helpers/repository_helper.rb
|
378
364
|
- spec/support/helpers/when_performing_helper.rb
|
379
365
|
- spec/support/matchers.rb
|
@@ -494,9 +480,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
494
480
|
- - ">"
|
495
481
|
- !ruby/object:Gem::Version
|
496
482
|
version: '2.2'
|
497
|
-
- - "<"
|
498
|
-
- !ruby/object:Gem::Version
|
499
|
-
version: '2.4'
|
500
483
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
501
484
|
requirements:
|
502
485
|
- - ">="
|
@@ -509,7 +492,6 @@ signing_key:
|
|
509
492
|
specification_version: 4
|
510
493
|
summary: Gem to use Fortnox REST API in Ruby.
|
511
494
|
test_files:
|
512
|
-
- spec/fortnox/api/base_spec.rb
|
513
495
|
- spec/fortnox/api/mappers/article_spec.rb
|
514
496
|
- spec/fortnox/api/mappers/base/from_json_spec.rb
|
515
497
|
- spec/fortnox/api/mappers/base/to_json_spec.rb
|
@@ -534,6 +516,7 @@ test_files:
|
|
534
516
|
- spec/fortnox/api/models/order_spec.rb
|
535
517
|
- spec/fortnox/api/models/project_spec.rb
|
536
518
|
- spec/fortnox/api/repositories/article_spec.rb
|
519
|
+
- spec/fortnox/api/repositories/base_spec.rb
|
537
520
|
- spec/fortnox/api/repositories/customer_spec.rb
|
538
521
|
- spec/fortnox/api/repositories/examples/all.rb
|
539
522
|
- spec/fortnox/api/repositories/examples/find.rb
|
@@ -564,8 +547,8 @@ test_files:
|
|
564
547
|
- spec/fortnox/api_spec.rb
|
565
548
|
- spec/spec_helper.rb
|
566
549
|
- spec/support/helpers.rb
|
550
|
+
- spec/support/helpers/configuration_helper.rb
|
567
551
|
- spec/support/helpers/dummy_class_helper.rb
|
568
|
-
- spec/support/helpers/environment_helper.rb
|
569
552
|
- spec/support/helpers/repository_helper.rb
|
570
553
|
- spec/support/helpers/when_performing_helper.rb
|
571
554
|
- spec/support/matchers.rb
|
data/lib/fortnox/api/base.rb
DELETED
@@ -1,47 +0,0 @@
|
|
1
|
-
require 'fortnox/api/class_methods'
|
2
|
-
require 'fortnox/api/environment_validation'
|
3
|
-
require 'fortnox/api/request_handling'
|
4
|
-
require 'httparty'
|
5
|
-
|
6
|
-
module Fortnox
|
7
|
-
module API
|
8
|
-
class Base
|
9
|
-
|
10
|
-
include HTTParty
|
11
|
-
extend Fortnox::API::ClassMethods
|
12
|
-
include Fortnox::API::EnvironmentValidation
|
13
|
-
include Fortnox::API::RequestHandling
|
14
|
-
|
15
|
-
HTTParty::Parser::SupportedFormats[ "text/html" ] = :json
|
16
|
-
|
17
|
-
DEFAULT_HEADERS = {
|
18
|
-
'Content-Type' => 'application/json',
|
19
|
-
'Accept' => 'application/json',
|
20
|
-
}.freeze
|
21
|
-
|
22
|
-
HTTP_METHODS = [ :get, :put, :post, :delete ].freeze
|
23
|
-
|
24
|
-
attr_accessor :headers
|
25
|
-
|
26
|
-
def initialize
|
27
|
-
self.class.base_uri( get_base_url )
|
28
|
-
|
29
|
-
self.headers = DEFAULT_HEADERS.merge({
|
30
|
-
'Client-Secret' => get_client_secret,
|
31
|
-
})
|
32
|
-
|
33
|
-
check_access_tokens!
|
34
|
-
end
|
35
|
-
|
36
|
-
HTTP_METHODS.each do |method|
|
37
|
-
define_method method do |*args|
|
38
|
-
self.headers['Access-Token'] = get_access_token
|
39
|
-
execute do |remote|
|
40
|
-
remote.send( method, *args )
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|