fortnox-api 0.5.2 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +3 -0
- data/.rubocop.yml +9 -1104
- data/.travis.yml +22 -2
- data/Gemfile +3 -1
- data/Guardfile +4 -2
- data/README.md +2 -2
- data/Rakefile +3 -1
- data/bin/console +17 -3
- data/fortnox-api.gemspec +32 -27
- data/lib/fortnox/api.rb +17 -16
- data/lib/fortnox/api/circular_queue.rb +13 -7
- data/lib/fortnox/api/mappers.rb +29 -25
- data/lib/fortnox/api/mappers/article.rb +7 -6
- data/lib/fortnox/api/mappers/base.rb +18 -16
- data/lib/fortnox/api/mappers/base/from_json.rb +37 -30
- data/lib/fortnox/api/mappers/base/to_json.rb +39 -37
- data/lib/fortnox/api/mappers/customer.rb +7 -7
- data/lib/fortnox/api/mappers/default_delivery_types.rb +4 -2
- data/lib/fortnox/api/mappers/default_templates.rb +5 -4
- data/lib/fortnox/api/mappers/edi_information.rb +5 -4
- data/lib/fortnox/api/mappers/email_information.rb +5 -4
- data/lib/fortnox/api/mappers/invoice.rb +10 -8
- data/lib/fortnox/api/mappers/invoice_row.rb +12 -7
- data/lib/fortnox/api/mappers/order.rb +10 -7
- data/lib/fortnox/api/mappers/order_row.rb +13 -6
- data/lib/fortnox/api/mappers/project.rb +6 -4
- data/lib/fortnox/api/mappers/terms_of_payments.rb +17 -0
- data/lib/fortnox/api/mappers/unit.rb +17 -0
- data/lib/fortnox/api/models.rb +9 -5
- data/lib/fortnox/api/models/article.rb +68 -67
- data/lib/fortnox/api/models/base.rb +52 -36
- data/lib/fortnox/api/models/customer.rb +95 -94
- data/lib/fortnox/api/models/document.rb +186 -0
- data/lib/fortnox/api/models/invoice.rb +44 -44
- data/lib/fortnox/api/models/label.rb +5 -3
- data/lib/fortnox/api/models/order.rb +8 -8
- data/lib/fortnox/api/models/project.rb +10 -8
- data/lib/fortnox/api/models/terms_of_payments.rb +28 -0
- data/lib/fortnox/api/models/unit.rb +24 -0
- data/lib/fortnox/api/repositories.rb +9 -5
- data/lib/fortnox/api/repositories/article.rb +6 -4
- data/lib/fortnox/api/repositories/base.rb +49 -46
- data/lib/fortnox/api/repositories/base/loaders.rb +32 -36
- data/lib/fortnox/api/repositories/base/savers.rb +23 -21
- data/lib/fortnox/api/repositories/customer.rb +6 -4
- data/lib/fortnox/api/repositories/invoice.rb +6 -4
- data/lib/fortnox/api/repositories/order.rb +6 -4
- data/lib/fortnox/api/repositories/project.rb +6 -4
- data/lib/fortnox/api/repositories/terms_of_payments.rb +17 -0
- data/lib/fortnox/api/repositories/unit.rb +17 -0
- data/lib/fortnox/api/request_handling.rb +12 -12
- data/lib/fortnox/api/types.rb +62 -11
- data/lib/fortnox/api/types/default_delivery_types.rb +5 -3
- data/lib/fortnox/api/types/default_templates.rb +3 -1
- data/lib/fortnox/api/types/defaulted.rb +2 -2
- data/lib/fortnox/api/types/document_row.rb +41 -42
- data/lib/fortnox/api/types/edi_information.rb +10 -8
- data/lib/fortnox/api/types/email_information.rb +10 -8
- data/lib/fortnox/api/types/enums.rb +60 -47
- data/lib/fortnox/api/types/invoice_row.rb +8 -8
- data/lib/fortnox/api/types/model.rb +14 -10
- data/lib/fortnox/api/types/nullable.rb +7 -7
- data/lib/fortnox/api/types/order_row.rb +5 -5
- data/lib/fortnox/api/types/required.rb +5 -5
- data/lib/fortnox/api/types/sized.rb +14 -6
- data/lib/fortnox/api/version.rb +3 -1
- data/spec/fortnox/api/mappers/article_spec.rb +3 -1
- data/spec/fortnox/api/mappers/base/from_json_spec.rb +15 -13
- data/spec/fortnox/api/mappers/base/to_json_spec.rb +4 -3
- data/spec/fortnox/api/mappers/base_spec.rb +40 -35
- data/spec/fortnox/api/mappers/contexts/json_conversion.rb +12 -11
- data/spec/fortnox/api/mappers/customer_spec.rb +3 -1
- data/spec/fortnox/api/mappers/default_delivery_types_spec.rb +3 -1
- data/spec/fortnox/api/mappers/edi_information_spec.rb +4 -2
- data/spec/fortnox/api/mappers/email_information_spec.rb +4 -2
- data/spec/fortnox/api/mappers/examples/mapper.rb +17 -9
- data/spec/fortnox/api/mappers/invoice_row_spec.rb +8 -3
- data/spec/fortnox/api/mappers/invoice_spec.rb +4 -1
- data/spec/fortnox/api/mappers/order_row_spec.rb +9 -2
- data/spec/fortnox/api/mappers/order_spec.rb +4 -1
- data/spec/fortnox/api/mappers/project_spec.rb +3 -1
- data/spec/fortnox/api/mappers/terms_of_payments_spec.rb +16 -0
- data/spec/fortnox/api/mappers/unit_spec.rb +57 -0
- data/spec/fortnox/api/models/article_spec.rb +2 -0
- data/spec/fortnox/api/models/base_spec.rb +46 -38
- data/spec/fortnox/api/models/customer_spec.rb +2 -0
- data/spec/fortnox/api/models/examples/document_base.rb +5 -3
- data/spec/fortnox/api/models/examples/model.rb +12 -9
- data/spec/fortnox/api/models/invoice_spec.rb +2 -0
- data/spec/fortnox/api/models/order_spec.rb +2 -0
- data/spec/fortnox/api/models/project_spec.rb +2 -0
- data/spec/fortnox/api/models/terms_of_payments_spec.rb +9 -0
- data/spec/fortnox/api/models/unit_spec.rb +31 -0
- data/spec/fortnox/api/repositories/article_spec.rb +7 -5
- data/spec/fortnox/api/repositories/base_spec.rb +121 -100
- data/spec/fortnox/api/repositories/customer_spec.rb +7 -5
- data/spec/fortnox/api/repositories/examples/all.rb +5 -4
- data/spec/fortnox/api/repositories/examples/find.rb +50 -41
- data/spec/fortnox/api/repositories/examples/only.rb +14 -13
- data/spec/fortnox/api/repositories/examples/save.rb +23 -29
- data/spec/fortnox/api/repositories/examples/save_with_nested_model.rb +11 -11
- data/spec/fortnox/api/repositories/examples/save_with_specially_named_attribute.rb +11 -10
- data/spec/fortnox/api/repositories/examples/search.rb +15 -15
- data/spec/fortnox/api/repositories/invoice_spec.rb +8 -6
- data/spec/fortnox/api/repositories/order_spec.rb +8 -6
- data/spec/fortnox/api/repositories/project_spec.rb +7 -5
- data/spec/fortnox/api/repositories/terms_of_payments_spec.rb +30 -0
- data/spec/fortnox/api/repositories/unit_spec.rb +34 -0
- data/spec/fortnox/api/types/account_number_spec.rb +12 -9
- data/spec/fortnox/api/types/default_delivery_types_spec.rb +6 -4
- data/spec/fortnox/api/types/edi_information_spec.rb +9 -7
- data/spec/fortnox/api/types/email_information_spec.rb +8 -6
- data/spec/fortnox/api/types/email_spec.rb +27 -14
- data/spec/fortnox/api/types/enums_spec.rb +3 -1
- data/spec/fortnox/api/types/examples/document_row.rb +10 -8
- data/spec/fortnox/api/types/examples/enum.rb +29 -22
- data/spec/fortnox/api/types/examples/types.rb +8 -4
- data/spec/fortnox/api/types/housework_types_spec.rb +68 -0
- data/spec/fortnox/api/types/invoice_row_spec.rb +3 -1
- data/spec/fortnox/api/types/model_spec.rb +12 -9
- data/spec/fortnox/api/types/nullable_spec.rb +8 -6
- data/spec/fortnox/api/types/order_row_spec.rb +4 -2
- data/spec/fortnox/api/types/required_spec.rb +4 -2
- data/spec/fortnox/api/types/sized_spec.rb +18 -16
- data/spec/fortnox/api_spec.rb +45 -43
- data/spec/spec_helper.rb +9 -6
- data/spec/support/helpers.rb +3 -1
- data/spec/support/helpers/configuration_helper.rb +2 -0
- data/spec/support/helpers/dummy_class_helper.rb +7 -8
- data/spec/support/helpers/repository_helper.rb +2 -0
- data/spec/support/helpers/when_performing_helper.rb +3 -1
- data/spec/support/matchers.rb +2 -0
- data/spec/support/matchers/type.rb +3 -1
- data/spec/support/matchers/type/attribute_matcher.rb +15 -14
- data/spec/support/matchers/type/enum_matcher.rb +9 -7
- data/spec/support/matchers/type/have_account_number_matcher.rb +11 -9
- data/spec/support/matchers/type/have_country_code_matcher.rb +6 -4
- data/spec/support/matchers/type/have_currency_matcher.rb +4 -2
- data/spec/support/matchers/type/have_customer_type_matcher.rb +6 -4
- data/spec/support/matchers/type/have_default_delivery_type_matcher.rb +4 -2
- data/spec/support/matchers/type/have_discount_type_matcher.rb +4 -2
- data/spec/support/matchers/type/have_email_matcher.rb +11 -9
- data/spec/support/matchers/type/have_housework_type_matcher.rb +9 -0
- data/spec/support/matchers/type/have_nullable_date_matcher.rb +29 -29
- data/spec/support/matchers/type/have_nullable_matcher.rb +23 -21
- data/spec/support/matchers/type/have_nullable_string_matcher.rb +30 -32
- data/spec/support/matchers/type/have_sized_float_matcher.rb +4 -2
- data/spec/support/matchers/type/have_sized_integer_matcher.rb +4 -2
- data/spec/support/matchers/type/have_sized_string_matcher.rb +16 -15
- data/spec/support/matchers/type/have_vat_type_matcher.rb +4 -2
- data/spec/support/matchers/type/numeric_matcher.rb +25 -23
- data/spec/support/matchers/type/require_attribute_matcher.rb +36 -37
- data/spec/support/matchers/type/type_matcher.rb +18 -16
- data/spec/support/vcr_setup.rb +2 -0
- data/spec/vcr_cassettes/orders/{house_work_type_babysitting.yml → housework_type_babysitting.yml} +9 -10
- data/spec/vcr_cassettes/orders/{house_work_type_cleaning.yml → housework_type_cleaning.yml} +9 -10
- data/spec/vcr_cassettes/orders/{house_work_type_construction.yml → housework_type_construction.yml} +9 -10
- data/spec/vcr_cassettes/orders/{house_work_type_cooking.yml → housework_type_cooking.yml} +7 -7
- data/spec/vcr_cassettes/orders/{house_work_type_electricity.yml → housework_type_electricity.yml} +9 -10
- data/spec/vcr_cassettes/orders/{house_work_type_gardening.yml → housework_type_gardening.yml} +9 -10
- data/spec/vcr_cassettes/orders/{house_work_type_glassmetalwork.yml → housework_type_glassmetalwork.yml} +9 -10
- data/spec/vcr_cassettes/orders/{house_work_type_grounddrainagework.yml → housework_type_grounddrainagework.yml} +9 -10
- data/spec/vcr_cassettes/orders/{house_work_type_hvac.yml → housework_type_hvac.yml} +9 -10
- data/spec/vcr_cassettes/orders/{house_work_type_masonry.yml → housework_type_masonry.yml} +9 -10
- data/spec/vcr_cassettes/orders/{house_work_type_othercare.yml → housework_type_othercare.yml} +9 -10
- data/spec/vcr_cassettes/orders/{house_work_type_othercosts.yml → housework_type_othercosts.yml} +9 -10
- data/spec/vcr_cassettes/orders/{house_work_type_paintingwallpapering.yml → housework_type_paintingwallpapering.yml} +9 -10
- data/spec/vcr_cassettes/orders/{house_work_type_snowplowing.yml → housework_type_snowplowing.yml} +9 -10
- data/spec/vcr_cassettes/orders/{house_work_type_textileclothing.yml → housework_type_textileclothing.yml} +9 -10
- data/spec/vcr_cassettes/orders/{house_work_type_tutoring.yml → housework_type_tutoring.yml} +7 -7
- data/spec/vcr_cassettes/termsofpayments/all.yml +51 -0
- data/spec/vcr_cassettes/termsofpayments/find_failure.yml +45 -0
- data/spec/vcr_cassettes/termsofpayments/find_id_1.yml +46 -0
- data/spec/vcr_cassettes/termsofpayments/find_new.yml +46 -0
- data/spec/vcr_cassettes/termsofpayments/save_new.yml +45 -0
- data/spec/vcr_cassettes/termsofpayments/save_old.yml +46 -0
- data/spec/vcr_cassettes/units/all.yml +48 -0
- data/spec/vcr_cassettes/units/find_failure.yml +45 -0
- data/spec/vcr_cassettes/units/find_id_1.yml +46 -0
- data/spec/vcr_cassettes/units/find_new.yml +48 -0
- data/spec/vcr_cassettes/units/save_new.yml +47 -0
- data/spec/vcr_cassettes/units/save_old.yml +48 -0
- data/spec/vcr_cassettes/units/save_with_specially_named_attribute.yml +47 -0
- metadata +127 -88
- data/docs/account.rb +0 -59
- data/docs/extraction_script.js +0 -23
- data/docs/generation_script.rb +0 -43
- data/docs/json/account.json +0 -77
- data/lib/fortnox/api/models/document_base.rb +0 -189
- data/spec/fortnox/api/types/house_work_types_spec.rb +0 -64
- data/spec/support/matchers/type/have_house_work_type_matcher.rb +0 -7
@@ -1,67 +1,63 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'cgi'
|
2
4
|
|
3
5
|
module Fortnox
|
4
6
|
module API
|
5
7
|
module Repository
|
6
8
|
module Loaders
|
7
|
-
|
8
|
-
|
9
|
-
response_hash
|
10
|
-
instantiate_collection_response( response_hash )
|
9
|
+
def all
|
10
|
+
response_hash = get(self.class::URI)
|
11
|
+
instantiate_collection_response(response_hash)
|
11
12
|
end
|
12
13
|
|
13
|
-
def only(
|
14
|
-
response_hash = get(
|
15
|
-
instantiate_collection_response(
|
14
|
+
def only(filter)
|
15
|
+
response_hash = get("#{self.class::URI}?filter=#{filter}")
|
16
|
+
instantiate_collection_response(response_hash)
|
16
17
|
end
|
17
18
|
|
18
|
-
def search(
|
19
|
+
def search(hash)
|
19
20
|
attribute, value = hash.first
|
20
|
-
uri_encoded_value =
|
21
|
-
uri = "#{
|
22
|
-
response_hash = get(
|
23
|
-
instantiate_collection_response(
|
21
|
+
uri_encoded_value = CGI.escape(value)
|
22
|
+
uri = "#{self.class::URI}?#{attribute}=#{uri_encoded_value}"
|
23
|
+
response_hash = get(uri)
|
24
|
+
instantiate_collection_response(response_hash)
|
24
25
|
end
|
25
26
|
|
26
|
-
def find(
|
27
|
-
return find_all_by(
|
28
|
-
|
29
|
-
id = Integer( id_or_hash )
|
30
|
-
find_one_by( id )
|
27
|
+
def find(id_or_hash)
|
28
|
+
return find_all_by(id_or_hash) if id_or_hash.is_a? Hash
|
31
29
|
|
32
|
-
|
33
|
-
raise ArgumentError, "find only accepts a number or hash as argument"
|
30
|
+
find_one_by(id_or_hash)
|
34
31
|
end
|
35
32
|
|
36
|
-
def find_one_by(
|
37
|
-
response_hash = get(
|
38
|
-
instantiate(
|
33
|
+
def find_one_by(id)
|
34
|
+
response_hash = get("#{self.class::URI}#{id}")
|
35
|
+
instantiate(@mapper.wrapped_json_hash_to_entity_hash(response_hash))
|
39
36
|
end
|
40
37
|
|
41
|
-
def find_all_by(
|
42
|
-
response_hash = get(
|
43
|
-
instantiate_collection_response(
|
38
|
+
def find_all_by(hash)
|
39
|
+
response_hash = get("#{self.class::URI}?#{to_query(hash)}")
|
40
|
+
instantiate_collection_response(response_hash)
|
44
41
|
end
|
45
42
|
|
46
|
-
def to_query(
|
43
|
+
def to_query(hash)
|
47
44
|
hash.collect do |key, value|
|
48
|
-
escape(
|
45
|
+
escape(key, value)
|
49
46
|
end.sort * '&'
|
50
47
|
end
|
51
48
|
|
52
|
-
def escape(
|
53
|
-
"#{
|
49
|
+
def escape(key, value)
|
50
|
+
"#{CGI.escape(key.to_s)}=#{CGI.escape(value.to_s)}"
|
54
51
|
end
|
55
52
|
|
56
53
|
private
|
57
54
|
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
end
|
55
|
+
def instantiate_collection_response(response_hash)
|
56
|
+
entities_hash = @mapper.wrapped_json_collection_to_entities_hash(response_hash)
|
57
|
+
entities_hash.map do |entity_hash|
|
58
|
+
instantiate(entity_hash)
|
63
59
|
end
|
64
|
-
|
60
|
+
end
|
65
61
|
end
|
66
62
|
end
|
67
63
|
end
|
@@ -1,46 +1,48 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Fortnox
|
2
4
|
module API
|
3
5
|
module Repository
|
4
6
|
module Savers
|
5
|
-
|
6
|
-
def save( entity )
|
7
|
+
def save(entity)
|
7
8
|
return true if entity.saved?
|
8
9
|
|
9
|
-
return save_new(
|
10
|
-
update_existing(
|
10
|
+
return save_new(entity) if entity.new?
|
11
|
+
update_existing(entity)
|
11
12
|
end
|
12
13
|
|
13
|
-
|
14
|
-
|
15
|
-
|
14
|
+
private
|
15
|
+
|
16
|
+
def execute_save(entity)
|
17
|
+
body = get_changes_on(entity).to_json
|
16
18
|
result = yield body
|
17
|
-
instantiate_saved(
|
19
|
+
instantiate_saved(result)
|
18
20
|
end
|
19
21
|
|
20
|
-
def save_new(
|
21
|
-
execute_save(
|
22
|
-
post(
|
22
|
+
def save_new(entity)
|
23
|
+
execute_save(entity) do |body|
|
24
|
+
post(self.class::URI, body: body)
|
23
25
|
end
|
24
26
|
end
|
25
27
|
|
26
|
-
def update_existing(
|
27
|
-
execute_save(
|
28
|
-
put(
|
28
|
+
def update_existing(entity)
|
29
|
+
execute_save(entity) do |body|
|
30
|
+
put(get_update_url_for(entity), body: body)
|
29
31
|
end
|
30
32
|
end
|
31
33
|
|
32
|
-
def get_changes_on(
|
33
|
-
hash = @mapper.entity_to_hash(
|
34
|
-
parent_hash = @mapper.entity_to_hash(
|
34
|
+
def get_changes_on(entity)
|
35
|
+
hash = @mapper.entity_to_hash(entity, @keys_filtered_on_save)
|
36
|
+
parent_hash = @mapper.entity_to_hash(entity.parent, @keys_filtered_on_save)
|
35
37
|
|
36
|
-
@mapper.wrap_entity_json_hash(
|
38
|
+
@mapper.wrap_entity_json_hash(@mapper.diff(hash, parent_hash))
|
37
39
|
end
|
38
40
|
|
39
|
-
def get_update_url_for(
|
40
|
-
"#{
|
41
|
+
def get_update_url_for(entity)
|
42
|
+
"#{self.class::URI}#{entity.unique_id}"
|
41
43
|
end
|
42
44
|
|
43
|
-
def instantiate_saved(
|
45
|
+
def instantiate_saved(wrapped_json_hash)
|
44
46
|
instantiate(
|
45
47
|
@mapper.wrapped_json_hash_to_entity_hash(
|
46
48
|
wrapped_json_hash
|
@@ -1,6 +1,8 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'fortnox/api/repositories/base'
|
4
|
+
require 'fortnox/api/models/customer'
|
5
|
+
require 'fortnox/api/mappers/customer'
|
4
6
|
|
5
7
|
module Fortnox
|
6
8
|
module API
|
@@ -8,7 +10,7 @@ module Fortnox
|
|
8
10
|
class Customer < Base
|
9
11
|
MODEL = Model::Customer
|
10
12
|
MAPPER = Mapper::Customer
|
11
|
-
URI = '/customers/'
|
13
|
+
URI = '/customers/'
|
12
14
|
end
|
13
15
|
end
|
14
16
|
end
|
@@ -1,6 +1,8 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'fortnox/api/repositories/base'
|
4
|
+
require 'fortnox/api/models/invoice'
|
5
|
+
require 'fortnox/api/mappers/invoice'
|
4
6
|
|
5
7
|
module Fortnox
|
6
8
|
module API
|
@@ -8,7 +10,7 @@ module Fortnox
|
|
8
10
|
class Invoice < Base
|
9
11
|
MODEL = Model::Invoice
|
10
12
|
MAPPER = Mapper::Invoice
|
11
|
-
URI = '/invoices/'
|
13
|
+
URI = '/invoices/'
|
12
14
|
end
|
13
15
|
end
|
14
16
|
end
|
@@ -1,6 +1,8 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'fortnox/api/repositories/base'
|
4
|
+
require 'fortnox/api/models/order'
|
5
|
+
require 'fortnox/api/mappers/order'
|
4
6
|
|
5
7
|
module Fortnox
|
6
8
|
module API
|
@@ -8,7 +10,7 @@ module Fortnox
|
|
8
10
|
class Order < Base
|
9
11
|
MODEL = Model::Order
|
10
12
|
MAPPER = Mapper::Order
|
11
|
-
URI = '/orders/'
|
13
|
+
URI = '/orders/'
|
12
14
|
end
|
13
15
|
end
|
14
16
|
end
|
@@ -1,6 +1,8 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'fortnox/api/repositories/base'
|
4
|
+
require 'fortnox/api/models/project'
|
5
|
+
require 'fortnox/api/mappers/project'
|
4
6
|
|
5
7
|
module Fortnox
|
6
8
|
module API
|
@@ -8,7 +10,7 @@ module Fortnox
|
|
8
10
|
class Project < Base
|
9
11
|
MODEL = Model::Project
|
10
12
|
MAPPER = Mapper::Project
|
11
|
-
URI = '/projects/'
|
13
|
+
URI = '/projects/'
|
12
14
|
end
|
13
15
|
end
|
14
16
|
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'fortnox/api/repositories/base'
|
4
|
+
require 'fortnox/api/models/terms_of_payments'
|
5
|
+
require 'fortnox/api/mappers/terms_of_payments'
|
6
|
+
|
7
|
+
module Fortnox
|
8
|
+
module API
|
9
|
+
module Repository
|
10
|
+
class TermsOfPayments < Base
|
11
|
+
MODEL = Model::TermsOfPayments
|
12
|
+
MAPPER = Mapper::TermsOfPayments
|
13
|
+
URI = '/termsofpayments/'
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'fortnox/api/repositories/base'
|
4
|
+
require 'fortnox/api/models/unit'
|
5
|
+
require 'fortnox/api/mappers/unit'
|
6
|
+
|
7
|
+
module Fortnox
|
8
|
+
module API
|
9
|
+
module Repository
|
10
|
+
class Unit < Fortnox::API::Repository::Base
|
11
|
+
MODEL = Fortnox::API::Model::Unit
|
12
|
+
MAPPER = Fortnox::API::Mapper::Unit
|
13
|
+
URI = '/units/'
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -1,35 +1,35 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Fortnox
|
2
4
|
module API
|
3
5
|
module RequestHandling
|
4
|
-
|
5
6
|
private
|
6
7
|
|
7
|
-
def raise_api_error(
|
8
|
-
message = (
|
8
|
+
def raise_api_error(error, response)
|
9
|
+
message = (error['message'] || error['Message'] || 'Okänt fel')
|
9
10
|
|
10
|
-
message += "\n\n#{
|
11
|
+
message += "\n\n#{response.request.inspect}" if Fortnox::API.debugging
|
11
12
|
|
12
13
|
raise Fortnox::API::RemoteServerError, message
|
13
14
|
end
|
14
15
|
|
15
|
-
def validate_response(
|
16
|
+
def validate_response(response)
|
16
17
|
return if response.code == 200
|
17
18
|
|
18
|
-
api_error = response.parsed_response[
|
19
|
-
raise_api_error(
|
19
|
+
api_error = response.parsed_response['ErrorInformation']
|
20
|
+
raise_api_error(api_error, response) if api_error
|
20
21
|
end
|
21
22
|
|
22
|
-
def validate_and_parse(
|
23
|
-
validate_response(
|
23
|
+
def validate_and_parse(response)
|
24
|
+
validate_response(response)
|
24
25
|
response.parsed_response
|
25
26
|
end
|
26
27
|
|
27
28
|
def execute
|
28
|
-
self.class.set_headers(
|
29
|
-
response = yield(
|
29
|
+
self.class.set_headers(@headers)
|
30
|
+
response = yield(self.class)
|
30
31
|
validate_and_parse response
|
31
32
|
end
|
32
|
-
|
33
33
|
end
|
34
34
|
end
|
35
35
|
end
|
data/lib/fortnox/api/types.rb
CHANGED
@@ -1,6 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'dry-struct'
|
2
4
|
require 'dry-types'
|
3
5
|
|
6
|
+
module Dry
|
7
|
+
module Types
|
8
|
+
module Options
|
9
|
+
def is(*option_names)
|
10
|
+
new_options = option_names.each_with_object({}) do |name, hash|
|
11
|
+
hash[name] = true
|
12
|
+
end
|
13
|
+
with(new_options)
|
14
|
+
end
|
15
|
+
|
16
|
+
def is?(option_name)
|
17
|
+
@options[option_name]
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
4
23
|
module Fortnox
|
5
24
|
module API
|
6
25
|
module Types
|
@@ -16,25 +35,57 @@ module Fortnox
|
|
16
35
|
|
17
36
|
require 'fortnox/api/types/sized'
|
18
37
|
|
19
|
-
AccountNumber = Strict::Int
|
38
|
+
AccountNumber = Strict::Int
|
39
|
+
.constrained(gteq: 0, lteq: 9999)
|
40
|
+
.optional
|
20
41
|
|
21
|
-
ArticleType = Strict::String
|
42
|
+
ArticleType = Strict::String
|
43
|
+
.constrained(included_in: ArticleTypes.values)
|
44
|
+
.optional
|
45
|
+
.constructor(EnumConstructors.default)
|
22
46
|
|
23
|
-
CountryCode = Strict::String
|
24
|
-
|
25
|
-
|
47
|
+
CountryCode = Strict::String
|
48
|
+
.constrained(included_in: CountryCodes.values)
|
49
|
+
.optional
|
50
|
+
.constructor(EnumConstructors.sized(2))
|
51
|
+
Currency = Strict::String
|
52
|
+
.constrained(included_in: Currencies.values)
|
53
|
+
.optional
|
54
|
+
.constructor(EnumConstructors.sized(3))
|
55
|
+
CustomerType = Strict::String
|
56
|
+
.constrained(included_in: CustomerTypes.values)
|
57
|
+
.optional
|
58
|
+
.constructor(EnumConstructors.default)
|
26
59
|
|
27
|
-
DiscountType = Strict::String
|
60
|
+
DiscountType = Strict::String
|
61
|
+
.constrained(included_in: DiscountTypes.values)
|
62
|
+
.optional
|
63
|
+
.constructor(EnumConstructors.default)
|
28
64
|
|
29
|
-
Email = Strict::String
|
65
|
+
Email = Strict::String
|
66
|
+
.constrained(max_size: 1024, format: /^$|\A[\w+-_.]+@[\w+-_.]+\.[a-z]+\z/i)
|
67
|
+
.optional
|
68
|
+
.constructor { |v| v.to_s.downcase unless v.nil? }
|
30
69
|
|
31
|
-
|
70
|
+
HouseworkType = Strict::String
|
71
|
+
.constrained(included_in: HouseworkTypes.values)
|
72
|
+
.optional
|
73
|
+
.constructor(EnumConstructors.default)
|
32
74
|
|
33
|
-
VATType = Strict::String
|
75
|
+
VATType = Strict::String
|
76
|
+
.constrained(included_in: VATTypes.values)
|
77
|
+
.optional
|
78
|
+
.constructor(EnumConstructors.default)
|
34
79
|
|
35
|
-
DefaultDeliveryType = Strict::String
|
80
|
+
DefaultDeliveryType = Strict::String
|
81
|
+
.constrained(included_in: DefaultDeliveryTypeValues.values)
|
82
|
+
.optional
|
83
|
+
.constructor(EnumConstructors.default)
|
36
84
|
|
37
|
-
ProjectStatusType = Strict::String
|
85
|
+
ProjectStatusType = Strict::String
|
86
|
+
.constrained(included_in: ProjectStatusTypes.values)
|
87
|
+
.optional
|
88
|
+
.constructor(EnumConstructors.default)
|
38
89
|
|
39
90
|
require 'fortnox/api/types/model'
|
40
91
|
require 'fortnox/api/types/default_delivery_types'
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'fortnox/api/types'
|
2
4
|
|
3
5
|
module Fortnox
|
@@ -6,13 +8,13 @@ module Fortnox
|
|
6
8
|
class DefaultDeliveryTypes < Types::Model
|
7
9
|
STUB = {}.freeze
|
8
10
|
|
9
|
-
#Default delivery type for invoices. Can be PRINT EMAIL or PRINTSERVICE.
|
11
|
+
# Default delivery type for invoices. Can be PRINT EMAIL or PRINTSERVICE.
|
10
12
|
attribute :invoice, Types::DefaultDeliveryType
|
11
13
|
|
12
|
-
#Default delivery type for orders. Can be PRINT EMAIL or PRINTSERVICE.
|
14
|
+
# Default delivery type for orders. Can be PRINT EMAIL or PRINTSERVICE.
|
13
15
|
attribute :order, Types::DefaultDeliveryType
|
14
16
|
|
15
|
-
#Default delivery type for offers. Can be PRINT EMAIL or PRINTSERVICE.
|
17
|
+
# Default delivery type for offers. Can be PRINT EMAIL or PRINTSERVICE.
|
16
18
|
attribute :offer, Types::DefaultDeliveryType
|
17
19
|
end
|
18
20
|
end
|