fortnox-api 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +3 -0
  3. data/.travis.yml +1 -1
  4. data/fortnox-api.gemspec +3 -1
  5. data/lib/fortnox/api/mappers.rb +1 -0
  6. data/lib/fortnox/api/mappers/project.rb +15 -0
  7. data/lib/fortnox/api/models.rb +1 -0
  8. data/lib/fortnox/api/models/base.rb +1 -1
  9. data/lib/fortnox/api/models/customer.rb +0 -0
  10. data/lib/fortnox/api/models/project.rb +40 -0
  11. data/lib/fortnox/api/repositories.rb +1 -0
  12. data/lib/fortnox/api/repositories/base.rb +1 -1
  13. data/lib/fortnox/api/repositories/base/loaders.rb +13 -10
  14. data/lib/fortnox/api/repositories/base/savers.rb +3 -3
  15. data/lib/fortnox/api/repositories/project.rb +15 -0
  16. data/lib/fortnox/api/types.rb +2 -0
  17. data/lib/fortnox/api/types/enums.rb +3 -0
  18. data/lib/fortnox/api/version.rb +1 -1
  19. data/spec/fortnox/api/mappers/project_spec.rb +10 -0
  20. data/spec/fortnox/api/models/customer_spec.rb +1 -3
  21. data/spec/fortnox/api/models/examples/document_base.rb +2 -2
  22. data/spec/fortnox/api/models/examples/model.rb +11 -5
  23. data/spec/fortnox/api/models/invoice_spec.rb +1 -4
  24. data/spec/fortnox/api/models/order_spec.rb +0 -3
  25. data/spec/fortnox/api/models/project_spec.rb +7 -0
  26. data/spec/fortnox/api/repositories/customer_spec.rb +8 -1
  27. data/spec/fortnox/api/repositories/examples/find.rb +65 -10
  28. data/spec/fortnox/api/repositories/examples/search.rb +11 -0
  29. data/spec/fortnox/api/repositories/invoice_spec.rb +11 -1
  30. data/spec/fortnox/api/repositories/order_spec.rb +11 -1
  31. data/spec/fortnox/api/repositories/project_spec.rb +29 -0
  32. data/spec/fortnox/api/types/enums_spec.rb +1 -0
  33. data/spec/vcr_cassettes/customers/find_by_hash_failure.yml +45 -0
  34. data/spec/vcr_cassettes/customers/find_failure.yml +45 -0
  35. data/spec/vcr_cassettes/customers/multi_param_find_by_hash.yml +46 -0
  36. data/spec/vcr_cassettes/customers/search_with_special_char.yml +45 -0
  37. data/spec/vcr_cassettes/customers/single_param_find_by_hash.yml +47 -0
  38. data/spec/vcr_cassettes/invoices/find_by_hash_failure.yml +45 -0
  39. data/spec/vcr_cassettes/invoices/find_failure.yml +45 -0
  40. data/spec/vcr_cassettes/invoices/multi_param_find_by_hash.yml +46 -0
  41. data/spec/vcr_cassettes/invoices/search_with_special_char.yml +45 -0
  42. data/spec/vcr_cassettes/invoices/single_param_find_by_hash.yml +47 -0
  43. data/spec/vcr_cassettes/orders/find_by_hash_failure.yml +45 -0
  44. data/spec/vcr_cassettes/orders/find_failure.yml +45 -0
  45. data/spec/vcr_cassettes/orders/multi_param_find_by_hash.yml +46 -0
  46. data/spec/vcr_cassettes/orders/search_with_special_char.yml +45 -0
  47. data/spec/vcr_cassettes/orders/single_param_find_by_hash.yml +47 -0
  48. data/spec/vcr_cassettes/projects/all.yml +52 -0
  49. data/spec/vcr_cassettes/projects/find_by_hash_failure.yml +45 -0
  50. data/spec/vcr_cassettes/projects/find_failure.yml +45 -0
  51. data/spec/vcr_cassettes/projects/find_id_1.yml +46 -0
  52. data/spec/vcr_cassettes/projects/find_new.yml +46 -0
  53. data/spec/vcr_cassettes/projects/multi_param_find_by_hash.yml +46 -0
  54. data/spec/vcr_cassettes/projects/save_new.yml +45 -0
  55. data/spec/vcr_cassettes/projects/save_old.yml +46 -0
  56. data/spec/vcr_cassettes/projects/single_param_find_by_hash.yml +46 -0
  57. metadata +66 -6
@@ -25,6 +25,17 @@ shared_examples_for '.search' do |attribute_hash_key_name, value, matches|
25
25
  it{ is_expected.to have(matches).entries }
26
26
  end
27
27
 
28
+ context 'with special characters' do
29
+ subject do
30
+ when_performing do
31
+ VCR.use_cassette( "#{ vcr_dir }/search_with_special_char") do
32
+ repository.search( attribute_hash_key_name => 'special char å' )
33
+ end
34
+ end
35
+ end
36
+
37
+ it{ is_expected.not_to raise_error }
38
+ end
28
39
  end
29
40
  end
30
41
  end
@@ -33,7 +33,17 @@ describe Fortnox::API::Repository::Invoice, order: :defined, integration: true d
33
33
  # when running .all will continue to increase (until 100, which is max by default).
34
34
  include_examples '.all', 60
35
35
 
36
- include_examples '.find', 1
36
+ include_examples '.find', 1 do
37
+ let( :find_by_hash_failure ){ { yourreference: 'Not found' } }
38
+
39
+ let( :single_param_find_by_hash ) do
40
+ { find_hash: { yourreference: 'Gandalf the Grey' }, matches: 2 }
41
+ end
42
+ let( :multi_param_find_by_hash ) do
43
+ { find_hash: { yourreference: 'Gandalf the Grey', ourreference: 'Radagast the Brown' },
44
+ matches: 1 }
45
+ end
46
+ end
37
47
 
38
48
  include_examples '.search', :customername, 'Test', 3
39
49
 
@@ -27,7 +27,17 @@ describe Fortnox::API::Repository::Order, order: :defined, integration: true do
27
27
  # when running .all will continue to increase (until 100, which is max by default).
28
28
  include_examples '.all', 100
29
29
 
30
- include_examples '.find', 1
30
+ include_examples '.find', 1 do
31
+ let( :find_by_hash_failure ){ { ourreference: 'Not found' } }
32
+
33
+ let( :single_param_find_by_hash ) do
34
+ { find_hash: { ourreference: 'Belladonna Took' }, matches: 2 }
35
+ end
36
+ let( :multi_param_find_by_hash ) do
37
+ { find_hash: { ourreference: 'Belladonna Took', yourreference: 'Bodo Proudfoot' },
38
+ matches: 1 }
39
+ end
40
+ end
31
41
 
32
42
  include_examples '.search', :customername, 'A customer', 2
33
43
 
@@ -0,0 +1,29 @@
1
+ require 'spec_helper'
2
+ require 'fortnox/api'
3
+ require 'fortnox/api/mappers'
4
+ require 'fortnox/api/repositories/project'
5
+ require 'fortnox/api/repositories/examples/all'
6
+ require 'fortnox/api/repositories/examples/find'
7
+ require 'fortnox/api/repositories/examples/save'
8
+
9
+ describe Fortnox::API::Repository::Project, order: :defined, integration: true do
10
+ subject( :repository ){ described_class.new }
11
+
12
+ required_attributes = { description: 'Some important project' }
13
+
14
+ include_examples '.save', :comments, required_attributes
15
+
16
+ # It is not yet possible to delete Projects. Therefore, expected nr of
17
+ # Projects when running .all will continue to increase
18
+ # (until 100, which is max by default).
19
+ include_examples '.all', 8
20
+
21
+ include_examples '.find', '1' do
22
+ let( :find_by_hash_failure ){ { offset: 10000 } }
23
+ let( :single_param_find_by_hash ){ { find_hash: { limit: 1 }, matches: 1 } }
24
+
25
+ let( :multi_param_find_by_hash ) do
26
+ { find_hash: { limit: 2, offset: 2 }, matches: 2 }
27
+ end
28
+ end
29
+ end
@@ -10,4 +10,5 @@ describe Fortnox::API::Types do
10
10
  it_behaves_like 'enum', 'HouseWorkType', 'HouseWorkTypes'
11
11
  it_behaves_like 'enum', 'VATType', 'VATTypes'
12
12
  it_behaves_like 'enum', 'DefaultDeliveryType', 'DefaultDeliveryTypeValues'
13
+ it_behaves_like 'enum', 'ProjectStatusType', 'ProjectStatusTypes'
13
14
  end
@@ -0,0 +1,45 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://api.fortnox.se/3/customers/?city=Not%20Found
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ Content-Type:
11
+ - application/json
12
+ Accept:
13
+ - application/json
14
+ Client-Secret:
15
+ - 9aBA8ZgsvR
16
+ Access-Token:
17
+ - ccaef817-d5d8-4b1c-a316-54f3e55c5c54
18
+ response:
19
+ status:
20
+ code: 200
21
+ message: OK
22
+ headers:
23
+ Server:
24
+ - nginx
25
+ Date:
26
+ - Wed, 12 Jul 2017 11:31:03 GMT
27
+ Content-Type:
28
+ - application/json
29
+ Connection:
30
+ - close
31
+ Vary:
32
+ - Accept-Encoding
33
+ - Accept-Encoding
34
+ X-Rack-Responsetime:
35
+ - '88'
36
+ X-Uid:
37
+ - df511a46
38
+ X-Build:
39
+ - 401ff9d5e0
40
+ body:
41
+ encoding: UTF-8
42
+ string: '{"MetaInformation":{"@TotalResources":0,"@TotalPages":0,"@CurrentPage":1},"Customers":[]}'
43
+ http_version:
44
+ recorded_at: Wed, 12 Jul 2017 11:31:03 GMT
45
+ recorded_with: VCR 3.0.3
@@ -0,0 +1,45 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://api.fortnox.se/3/customers/123456789
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ Content-Type:
11
+ - application/json
12
+ Accept:
13
+ - application/json
14
+ Client-Secret:
15
+ - 9aBA8ZgsvR
16
+ Access-Token:
17
+ - ccaef817-d5d8-4b1c-a316-54f3e55c5c54
18
+ response:
19
+ status:
20
+ code: 404
21
+ message: Not Found
22
+ headers:
23
+ Server:
24
+ - nginx
25
+ Date:
26
+ - Wed, 12 Jul 2017 10:21:40 GMT
27
+ Content-Type:
28
+ - application/json
29
+ Connection:
30
+ - close
31
+ Vary:
32
+ - Accept-Encoding
33
+ - Accept-Encoding
34
+ X-Rack-Responsetime:
35
+ - '15'
36
+ X-Uid:
37
+ - bf005251
38
+ X-Build:
39
+ - 401ff9d5e0
40
+ body:
41
+ encoding: UTF-8
42
+ string: '{"ErrorInformation":{"Error":1,"Message":"Kan inte hitta kunden.","Code":2000433}}'
43
+ http_version:
44
+ recorded_at: Wed, 12 Jul 2017 10:21:40 GMT
45
+ recorded_with: VCR 3.0.3
@@ -0,0 +1,46 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://api.fortnox.se/3/customers/?city=New%20York&zipcode=10001
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ Content-Type:
11
+ - application/json
12
+ Accept:
13
+ - application/json
14
+ Client-Secret:
15
+ - 9aBA8ZgsvR
16
+ Access-Token:
17
+ - ccaef817-d5d8-4b1c-a316-54f3e55c5c54
18
+ response:
19
+ status:
20
+ code: 200
21
+ message: OK
22
+ headers:
23
+ Server:
24
+ - nginx
25
+ Date:
26
+ - Wed, 12 Jul 2017 12:02:22 GMT
27
+ Content-Type:
28
+ - application/json
29
+ Connection:
30
+ - close
31
+ Vary:
32
+ - Accept-Encoding
33
+ - Accept-Encoding
34
+ X-Rack-Responsetime:
35
+ - '19'
36
+ X-Uid:
37
+ - bd69c645
38
+ X-Build:
39
+ - 401ff9d5e0
40
+ body:
41
+ encoding: UTF-8
42
+ string: '{"MetaInformation":{"@TotalResources":1,"@TotalPages":1,"@CurrentPage":1},"Customers":[{"@url":"https:\/\/api.fortnox.se\/3\/customers\/2","Address1":"","Address2":"","City":"New
43
+ York","CustomerNumber":"2","Email":"","Name":"A customer","OrganisationNumber":"600102-7447","Phone":"","ZipCode":"10001"}]}'
44
+ http_version:
45
+ recorded_at: Wed, 12 Jul 2017 12:02:22 GMT
46
+ recorded_with: VCR 3.0.3
@@ -0,0 +1,45 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://api.fortnox.se/3/customers/?name=special%20char%20%C3%A5
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ Content-Type:
11
+ - application/json
12
+ Accept:
13
+ - application/json
14
+ Client-Secret:
15
+ - 9aBA8ZgsvR
16
+ Access-Token:
17
+ - ccaef817-d5d8-4b1c-a316-54f3e55c5c54
18
+ response:
19
+ status:
20
+ code: 200
21
+ message: OK
22
+ headers:
23
+ Server:
24
+ - nginx
25
+ Date:
26
+ - Fri, 16 Jun 2017 13:06:55 GMT
27
+ Content-Type:
28
+ - application/json
29
+ Connection:
30
+ - close
31
+ Vary:
32
+ - Accept-Encoding
33
+ - Accept-Encoding
34
+ X-Rack-Responsetime:
35
+ - '103'
36
+ X-Uid:
37
+ - 9e674a55
38
+ X-Build:
39
+ - 2efa532288
40
+ body:
41
+ encoding: UTF-8
42
+ string: '{"MetaInformation":{"@TotalResources":0,"@TotalPages":0,"@CurrentPage":1},"Customers":[]}'
43
+ http_version:
44
+ recorded_at: Fri, 16 Jun 2017 13:06:55 GMT
45
+ recorded_with: VCR 3.0.1
@@ -0,0 +1,47 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://api.fortnox.se/3/customers/?city=New%20York
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ Content-Type:
11
+ - application/json
12
+ Accept:
13
+ - application/json
14
+ Client-Secret:
15
+ - 9aBA8ZgsvR
16
+ Access-Token:
17
+ - ccaef817-d5d8-4b1c-a316-54f3e55c5c54
18
+ response:
19
+ status:
20
+ code: 200
21
+ message: OK
22
+ headers:
23
+ Server:
24
+ - nginx
25
+ Date:
26
+ - Wed, 12 Jul 2017 11:52:47 GMT
27
+ Content-Type:
28
+ - application/json
29
+ Connection:
30
+ - close
31
+ Vary:
32
+ - Accept-Encoding
33
+ - Accept-Encoding
34
+ X-Rack-Responsetime:
35
+ - '17'
36
+ X-Uid:
37
+ - ff8c93e9
38
+ X-Build:
39
+ - 401ff9d5e0
40
+ body:
41
+ encoding: UTF-8
42
+ string: '{"MetaInformation":{"@TotalResources":2,"@TotalPages":1,"@CurrentPage":1},"Customers":[{"@url":"https:\/\/api.fortnox.se\/3\/customers\/2","Address1":"","Address2":"","City":"New
43
+ York","CustomerNumber":"2","Email":"","Name":"A customer","OrganisationNumber":"600102-7447","Phone":"","ZipCode":""},{"@url":"https:\/\/api.fortnox.se\/3\/customers\/3","Address1":"","Address2":"","City":"New
44
+ York","CustomerNumber":"3","Email":"","Name":"Test customer","OrganisationNumber":"400101-8383","Phone":"","ZipCode":""}]}'
45
+ http_version:
46
+ recorded_at: Wed, 12 Jul 2017 11:52:47 GMT
47
+ recorded_with: VCR 3.0.3
@@ -0,0 +1,45 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://api.fortnox.se/3/invoices/?yourreference=Not%20found
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ Content-Type:
11
+ - application/json
12
+ Accept:
13
+ - application/json
14
+ Client-Secret:
15
+ - 9aBA8ZgsvR
16
+ Access-Token:
17
+ - ccaef817-d5d8-4b1c-a316-54f3e55c5c54
18
+ response:
19
+ status:
20
+ code: 200
21
+ message: OK
22
+ headers:
23
+ Server:
24
+ - nginx
25
+ Date:
26
+ - Wed, 12 Jul 2017 12:21:55 GMT
27
+ Content-Type:
28
+ - application/json
29
+ Connection:
30
+ - close
31
+ Vary:
32
+ - Accept-Encoding
33
+ - Accept-Encoding
34
+ X-Rack-Responsetime:
35
+ - '35'
36
+ X-Uid:
37
+ - 8fc6d933
38
+ X-Build:
39
+ - 401ff9d5e0
40
+ body:
41
+ encoding: UTF-8
42
+ string: '{"MetaInformation":{"@TotalResources":0,"@TotalPages":0,"@CurrentPage":1},"Invoices":[]}'
43
+ http_version:
44
+ recorded_at: Wed, 12 Jul 2017 12:21:55 GMT
45
+ recorded_with: VCR 3.0.3
@@ -0,0 +1,45 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://api.fortnox.se/3/invoices/123456789
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ Content-Type:
11
+ - application/json
12
+ Accept:
13
+ - application/json
14
+ Client-Secret:
15
+ - 9aBA8ZgsvR
16
+ Access-Token:
17
+ - ccaef817-d5d8-4b1c-a316-54f3e55c5c54
18
+ response:
19
+ status:
20
+ code: 404
21
+ message: Not Found
22
+ headers:
23
+ Server:
24
+ - nginx
25
+ Date:
26
+ - Wed, 12 Jul 2017 10:21:40 GMT
27
+ Content-Type:
28
+ - application/json
29
+ Connection:
30
+ - close
31
+ Vary:
32
+ - Accept-Encoding
33
+ - Accept-Encoding
34
+ X-Rack-Responsetime:
35
+ - '29'
36
+ X-Uid:
37
+ - 5c2c9574
38
+ X-Build:
39
+ - 401ff9d5e0
40
+ body:
41
+ encoding: UTF-8
42
+ string: '{"ErrorInformation":{"Error":1,"Message":"Kan inte hitta fakturan.","Code":2000434}}'
43
+ http_version:
44
+ recorded_at: Wed, 12 Jul 2017 10:21:40 GMT
45
+ recorded_with: VCR 3.0.3
@@ -0,0 +1,46 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://api.fortnox.se/3/invoices/?ourreference=Radagast%20the%20Brown&yourreference=Gandalf%20the%20Grey
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ Content-Type:
11
+ - application/json
12
+ Accept:
13
+ - application/json
14
+ Client-Secret:
15
+ - 9aBA8ZgsvR
16
+ Access-Token:
17
+ - ccaef817-d5d8-4b1c-a316-54f3e55c5c54
18
+ response:
19
+ status:
20
+ code: 200
21
+ message: OK
22
+ headers:
23
+ Server:
24
+ - nginx
25
+ Date:
26
+ - Wed, 12 Jul 2017 12:24:48 GMT
27
+ Content-Type:
28
+ - application/json
29
+ Connection:
30
+ - close
31
+ Vary:
32
+ - Accept-Encoding
33
+ - Accept-Encoding
34
+ X-Rack-Responsetime:
35
+ - '33'
36
+ X-Uid:
37
+ - 4a7cca37
38
+ X-Build:
39
+ - 401ff9d5e0
40
+ body:
41
+ encoding: UTF-8
42
+ string: '{"MetaInformation":{"@TotalResources":1,"@TotalPages":1,"@CurrentPage":1},"Invoices":[{"@url":"https:\/\/api.fortnox.se\/3\/invoices\/3","Balance":200,"Booked":false,"Cancelled":false,"Currency":"SEK","CurrencyRate":"1","CurrencyUnit":1,"CustomerName":"Updated
43
+ customer","CustomerNumber":"1","DocumentNumber":"3","DueDate":"2016-03-17","ExternalInvoiceReference1":"","ExternalInvoiceReference2":"","InvoiceDate":"2016-03-16","NoxFinans":false,"OCR":"331","WayOfDelivery":"","TermsOfPayment":"0","Project":"","Sent":false,"Total":200}]}'
44
+ http_version:
45
+ recorded_at: Wed, 12 Jul 2017 12:24:48 GMT
46
+ recorded_with: VCR 3.0.3