fortnox-api 0.5.2 → 0.6.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/.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,64 +1,63 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Fortnox
|
2
4
|
module API
|
3
5
|
module Types
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
#AccountNumber Account number. 4 digits
|
8
|
-
attribute :account_number, Types::AccountNumber
|
6
|
+
class DocumentRow < Fortnox::API::Types::Model
|
7
|
+
# AccountNumber Account number. 4 digits
|
8
|
+
attribute :account_number, Types::AccountNumber
|
9
9
|
|
10
|
-
|
11
|
-
|
10
|
+
# ArticleNumber Article number. 50 characters
|
11
|
+
attribute :article_number, Types::Sized::String[50]
|
12
12
|
|
13
|
-
|
14
|
-
|
13
|
+
# ContributionPercent Contribution Percent.
|
14
|
+
attribute :contribution_percent, Types::Nullable::Float.with(private: true)
|
15
15
|
|
16
|
-
|
17
|
-
|
16
|
+
# ContributionValue Contribution Value.
|
17
|
+
attribute :contribution_value, Types::Nullable::Float.with(private: true)
|
18
18
|
|
19
|
-
|
20
|
-
|
19
|
+
# CostCenter Code of the cost center for the row.
|
20
|
+
attribute :cost_center, Types::Nullable::String
|
21
21
|
|
22
|
-
|
23
|
-
|
22
|
+
# DeliveredQuantity Delivered quantity. 14 digits
|
23
|
+
attribute :delivered_quantity, Types::Sized::Float[0.0, 9_999_999_999_999.9]
|
24
24
|
|
25
|
-
|
26
|
-
|
25
|
+
# Description Description Row description. 50 characters
|
26
|
+
attribute :description, Types::Sized::String[50]
|
27
27
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
28
|
+
# Discount amount. 12 digits (for amount) / 5 digits (for percent)
|
29
|
+
# TODO(hannes): Verify that we can send in more than 5 digits through
|
30
|
+
# the actual API for DiscountType PERCENT. This cannot be done until
|
31
|
+
# we fix issue #62...
|
32
|
+
attribute :discount, Types::Sized::Float[0.0, 99_999_999_999.9]
|
33
33
|
|
34
|
-
|
35
|
-
|
34
|
+
# DiscountType The type of discount used for the row.
|
35
|
+
attribute :discount_type, Types::DiscountType
|
36
36
|
|
37
|
-
|
38
|
-
|
37
|
+
# HouseWork If the row is housework
|
38
|
+
attribute :housework, Types::Nullable::Boolean
|
39
39
|
|
40
|
-
|
41
|
-
|
40
|
+
# HouseWorkHoursToReport Hours to be reported if the quantity of the row should not be used as hours.
|
41
|
+
# 5 digits
|
42
|
+
attribute :housework_hours_to_report, Types::Sized::Integer[0, 99_999]
|
42
43
|
|
43
|
-
|
44
|
-
|
44
|
+
# HouseWorkType The type of housework.
|
45
|
+
attribute :housework_type, Types::HouseworkType
|
45
46
|
|
46
|
-
|
47
|
-
|
47
|
+
# Price Price per unit. 12 digits
|
48
|
+
attribute :price, Types::Sized::Float[0.0, 99_999_999_999.9]
|
48
49
|
|
49
|
-
|
50
|
-
|
50
|
+
# Project Code of the project for the row.
|
51
|
+
attribute :project, Types::Nullable::String
|
51
52
|
|
52
|
-
|
53
|
-
|
53
|
+
# Total Total amount for the row.
|
54
|
+
attribute :total, Types::Nullable::Float.with(private: true)
|
54
55
|
|
55
|
-
|
56
|
-
|
56
|
+
# Unit Code of the unit for the row.
|
57
|
+
attribute :unit, Types::Nullable::String
|
57
58
|
|
58
|
-
|
59
|
-
|
60
|
-
end
|
61
|
-
end
|
59
|
+
# VAT VAT percentage of the row.
|
60
|
+
attribute :vat, Types::Nullable::Integer
|
62
61
|
end
|
63
62
|
end
|
64
63
|
end
|
@@ -1,27 +1,29 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'fortnox/api/types'
|
2
4
|
|
3
5
|
module Fortnox
|
4
6
|
module API
|
5
7
|
module Types
|
6
8
|
class EDIInformation < Types::Model
|
7
9
|
STUB = {}.freeze
|
8
|
-
|
9
|
-
#EDIGlobalLocationNumber Invoice address GLN for EDI
|
10
|
+
|
11
|
+
# EDIGlobalLocationNumber Invoice address GLN for EDI
|
10
12
|
attribute :edi_global_location_number, Types::Nullable::String
|
11
13
|
|
12
|
-
#EDIGlobalLocationNumberDelivery Delivery address GLN for EDI
|
14
|
+
# EDIGlobalLocationNumberDelivery Delivery address GLN for EDI
|
13
15
|
attribute :edi_global_location_number_delivery, Types::Nullable::String
|
14
16
|
|
15
|
-
#EDIInvoiceExtra1 Extra EDI Information
|
17
|
+
# EDIInvoiceExtra1 Extra EDI Information
|
16
18
|
attribute :edi_invoice_extra1, Types::Nullable::String
|
17
19
|
|
18
|
-
#EDIInvoiceExtra2 Extra EDI Information
|
20
|
+
# EDIInvoiceExtra2 Extra EDI Information
|
19
21
|
attribute :edi_invoice_extra2, Types::Nullable::String
|
20
22
|
|
21
|
-
#EDIOurElectronicReference Our electronic reference for EDI
|
23
|
+
# EDIOurElectronicReference Our electronic reference for EDI
|
22
24
|
attribute :edi_our_electronic_reference, Types::Nullable::String
|
23
25
|
|
24
|
-
#EDIYourElectronicReference Your electronic reference for EDI
|
26
|
+
# EDIYourElectronicReference Your electronic reference for EDI
|
25
27
|
attribute :edi_your_electronic_reference, Types::Nullable::String
|
26
28
|
end
|
27
29
|
end
|
@@ -1,4 +1,6 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'fortnox/api/types'
|
2
4
|
|
3
5
|
module Fortnox
|
4
6
|
module API
|
@@ -6,20 +8,20 @@ module Fortnox
|
|
6
8
|
class EmailInformation < Types::Model
|
7
9
|
STUB = {}.freeze
|
8
10
|
|
9
|
-
#EmailAddressTo Customer e-mail address. Must be a valid e-mail address. 1024 characters
|
11
|
+
# EmailAddressTo Customer e-mail address. Must be a valid e-mail address. 1024 characters
|
10
12
|
attribute :email_address_to, Types::Email
|
11
13
|
|
12
|
-
#EmailAddressCC Customer e-mail address
|
14
|
+
# EmailAddressCC Customer e-mail address, Carbon copy. Must be a valid e-mail address. 1024 characters
|
13
15
|
attribute :email_address_cc, Types::Email
|
14
16
|
|
15
|
-
#EmailAddressBCC Customer e-mail address
|
17
|
+
# EmailAddressBCC Customer e-mail address, Blind carbon copy. Must be a valid e-mail address. 1024 characters
|
16
18
|
attribute :email_address_bcc, Types::Email
|
17
19
|
|
18
|
-
#EmailSubject Subject of the e-mail, 100 characters.
|
19
|
-
attribute :email_subject, Types::Sized::String[
|
20
|
+
# EmailSubject Subject of the e-mail, 100 characters.
|
21
|
+
attribute :email_subject, Types::Sized::String[100]
|
20
22
|
|
21
|
-
#EmailBody Body of the e-mail, 20000 characters.
|
22
|
-
attribute :email_body, Types::Sized::String[
|
23
|
+
# EmailBody Body of the e-mail, 20000 characters.
|
24
|
+
attribute :email_body, Types::Sized::String[20_000]
|
23
25
|
end
|
24
26
|
end
|
25
27
|
end
|
@@ -1,69 +1,82 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Fortnox
|
2
4
|
module API
|
3
5
|
module Types
|
4
|
-
|
5
6
|
module EnumConstructors
|
6
|
-
def self.sized(
|
7
|
-
|
7
|
+
def self.sized(size)
|
8
|
+
lambda do |value|
|
9
|
+
return nil if value == ''
|
10
|
+
value.to_s.upcase[0...size] unless value.nil?
|
11
|
+
end
|
8
12
|
end
|
9
13
|
|
10
14
|
def self.default
|
11
|
-
|
15
|
+
lambda do |value|
|
16
|
+
return nil if value == ''
|
17
|
+
value.to_s.upcase unless value.nil?
|
18
|
+
end
|
12
19
|
end
|
13
20
|
end
|
14
21
|
|
15
22
|
ArticleTypes = Types::Strict::String.enum(
|
16
|
-
'SERVICE','STOCK'
|
23
|
+
'SERVICE', 'STOCK'
|
17
24
|
)
|
18
25
|
DiscountTypes = Types::Strict::String.enum(
|
19
|
-
'AMOUNT','PERCENT'
|
26
|
+
'AMOUNT', 'PERCENT'
|
20
27
|
)
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
28
|
+
CURRENT_HOUSEWORK_TYPES = %w[
|
29
|
+
CONSTRUCTION ELECTRICITY GLASSMETALWORK GROUNDDRAINAGEWORK
|
30
|
+
MASONRY PAINTINGWALLPAPERING HVAC MAJORAPPLIANCEREPAIR
|
31
|
+
MOVINGSERVICES ITSERVICES CLEANING TEXTILECLOTHING
|
32
|
+
SNOWPLOWING GARDENING BABYSITTING OTHERCARE OTHERCOSTS
|
26
33
|
].freeze
|
27
|
-
|
28
|
-
|
29
|
-
*(
|
34
|
+
LEGACY_HOUSEWORK_TYPES = %w[COOKING TUTORING].freeze
|
35
|
+
HouseworkTypes = Types::Strict::String.enum(
|
36
|
+
*(CURRENT_HOUSEWORK_TYPES + LEGACY_HOUSEWORK_TYPES)
|
30
37
|
)
|
31
38
|
CountryCodes = Types::Strict::String.enum(
|
32
|
-
'AF','AX','AL','DZ','AS','AD','AO','AI','AQ','AG','AR','AM',
|
33
|
-
'AT','AZ','BS','BH','BD','BB','BY','BE','BZ','BJ',
|
34
|
-
'
|
35
|
-
'
|
36
|
-
'
|
37
|
-
'
|
38
|
-
'
|
39
|
-
'
|
40
|
-
'
|
41
|
-
'
|
42
|
-
'
|
43
|
-
'
|
44
|
-
'
|
45
|
-
'
|
46
|
-
'
|
47
|
-
'
|
48
|
-
'
|
49
|
-
'
|
39
|
+
'AF', 'AX', 'AL', 'DZ', 'AS', 'AD', 'AO', 'AI', 'AQ', 'AG', 'AR', 'AM',
|
40
|
+
'AW', 'AU', 'AT', 'AZ', 'BS', 'BH', 'BD', 'BB', 'BY', 'BE', 'BZ', 'BJ',
|
41
|
+
'BM', 'BT', 'BO', 'BQ', 'BA', 'BW', 'BV', 'BR', 'IO', 'BN', 'BG', 'BF',
|
42
|
+
'BI', 'CV', 'KH', 'CM', 'CA', 'KY', 'CF', 'TD', 'CL', 'CN', 'CX', 'CC',
|
43
|
+
'CO', 'KM', 'CG', 'CD', 'CK', 'CR', 'CI', 'HR', 'CU', 'CW', 'CY', 'CZ',
|
44
|
+
'DK', 'DJ', 'DM', 'DO', 'EC', 'EG', 'SV', 'GQ', 'ER', 'EE', 'ET', 'FK',
|
45
|
+
'FO', 'FJ', 'FI', 'FR', 'GF', 'PF', 'TF', 'GA', 'GM', 'GE', 'DE', 'GH',
|
46
|
+
'GI', 'GR', 'GL', 'GD', 'GP', 'GU', 'GT', 'GG', 'GN', 'GW', 'GY', 'HT',
|
47
|
+
'HM', 'VA', 'HN', 'HK', 'HU', 'IS', 'IN', 'ID', 'IR', 'IQ', 'IE', 'IM',
|
48
|
+
'IL', 'IT', 'JM', 'JP', 'JE', 'JO', 'KZ', 'KE', 'KI', 'KP', 'KR', 'KW',
|
49
|
+
'KG', 'LA', 'LV', 'LB', 'LS', 'LR', 'LY', 'LI', 'LT', 'LU', 'MO', 'MK',
|
50
|
+
'MG', 'MW', 'MY', 'MV', 'ML', 'MT', 'MH', 'MQ', 'MR', 'MU', 'YT', 'MX',
|
51
|
+
'FM', 'MD', 'MC', 'MN', 'ME', 'MS', 'MA', 'MZ', 'MM', 'NA', 'NR', 'NP',
|
52
|
+
'NL', 'NC', 'NZ', 'NI', 'NE', 'NG', 'NU', 'NF', 'MP', 'NO', 'OM', 'PK',
|
53
|
+
'PW', 'PS', 'PA', 'PG', 'PY', 'PE', 'PH', 'PN', 'PL', 'PT', 'PR', 'QA',
|
54
|
+
'RE', 'RO', 'RU', 'RW', 'BL', 'SH', 'KN', 'LC', 'MF', 'PM', 'VC', 'WS',
|
55
|
+
'SM', 'ST', 'SA', 'SN', 'RS', 'SC', 'SL', 'SG', 'SX', 'SK', 'SI', 'SB',
|
56
|
+
'SO', 'ZA', 'GS', 'SS', 'ES', 'LK', 'SD', 'SR', 'SJ', 'SZ', 'SE', 'CH',
|
57
|
+
'SY', 'TW', 'TJ', 'TZ', 'TH', 'TL', 'TG', 'TK', 'TO', 'TT', 'TN', 'TR',
|
58
|
+
'TM', 'TC', 'TV', 'UG', 'UA', 'AE', 'GB', 'US', 'UM', 'UY', 'UZ', 'VU',
|
59
|
+
'VE', 'VN', 'VG', 'VI', 'WF', 'EH', 'YE', 'ZM', 'ZW'
|
50
60
|
)
|
51
61
|
Currencies = Types::Strict::String.enum(
|
52
|
-
'AED','AFN','ALL','AMD','ANG','AOA','ARS','AUD','AWG','AZN',
|
53
|
-
'BDT','BGN','BHD','BIF','BMD','BND','BOB','BOV',
|
54
|
-
'
|
55
|
-
'
|
56
|
-
'
|
57
|
-
'
|
58
|
-
'
|
59
|
-
'
|
60
|
-
'
|
61
|
-
'
|
62
|
-
'
|
63
|
-
'
|
64
|
-
'
|
65
|
-
'
|
66
|
-
'
|
62
|
+
'AED', 'AFN', 'ALL', 'AMD', 'ANG', 'AOA', 'ARS', 'AUD', 'AWG', 'AZN',
|
63
|
+
'BAM', 'BBD', 'BDT', 'BGN', 'BHD', 'BIF', 'BMD', 'BND', 'BOB', 'BOV',
|
64
|
+
'BRL', 'BSD', 'BTN', 'BWP', 'BYR', 'BZD', 'CAD', 'CDF', 'CHE', 'CHF',
|
65
|
+
'CHW', 'CLF', 'CLP', 'CNY', 'COP', 'COU', 'CRC', 'CUP', 'CVE', 'CZK',
|
66
|
+
'DJF', 'DKK', 'DOP', 'DZD', 'EGP', 'ERN', 'ETB', 'EUR', 'FJD', 'FKP',
|
67
|
+
'GBP', 'GEL', 'GHS', 'GIP', 'GMD', 'GNF', 'GTQ', 'GYD', 'HKD', 'HNL',
|
68
|
+
'HRK', 'HTG', 'HUF', 'IDR', 'ILS', 'INR', 'IQD', 'IRR', 'ISK', 'JMD',
|
69
|
+
'JOD', 'JPY', 'KES', 'KGS', 'KHR', 'KUR', 'KMF', 'KPW', 'KRW', 'KWD',
|
70
|
+
'KYD', 'KZT', 'LAK', 'LBP', 'LKR', 'LRD', 'LSL', 'LYD', 'MAD', 'MDL',
|
71
|
+
'MGA', 'MKD', 'MMK', 'MNT', 'MOP', 'MRO', 'MUR', 'MVR', 'MWK', 'MXN',
|
72
|
+
'MXV', 'MYR', 'MZN', 'NAD', 'NGN', 'NIO', 'NOK', 'NPR', 'NZD', 'OMR',
|
73
|
+
'PAB', 'PEN', 'PGK', 'PHP', 'PKR', 'PLN', 'PYG', 'QAR', 'RON', 'RSD',
|
74
|
+
'RUB', 'RWF', 'SAR', 'SBD', 'SCR', 'SDG', 'SEK', 'SGD', 'SHP', 'SLL',
|
75
|
+
'SOS', 'SRD', 'SSP', 'STD', 'SYP', 'SZL', 'THB', 'TJS', 'TMM', 'TND',
|
76
|
+
'TOP', 'TRY', 'TTD', 'TWD', 'TZS', 'UAH', 'UGX', 'USD', 'USN', 'USS',
|
77
|
+
'UYU', 'UZS', 'VEF', 'VND', 'VUV', 'WST', 'XAF', 'XAG', 'XAU', 'XBA',
|
78
|
+
'XBB', 'XBC', 'XBD', 'XCD', 'XDR', 'XFU', 'XOF', 'XPD', 'XPF', 'XPT',
|
79
|
+
'XTS', 'XXX', 'YER', 'ZAR', 'ZMK', 'ZWD'
|
67
80
|
)
|
68
81
|
CustomerTypes = Types::Strict::String.enum(
|
69
82
|
'PRIVATE', 'COMPANY'
|
@@ -1,18 +1,18 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'fortnox/api/types/document_row'
|
2
4
|
|
3
5
|
module Fortnox
|
4
6
|
module API
|
5
7
|
module Types
|
6
|
-
class InvoiceRow <
|
8
|
+
class InvoiceRow < DocumentRow
|
7
9
|
STUB = {}.freeze
|
8
|
-
|
9
|
-
DocumentRow.ify self
|
10
10
|
|
11
|
-
#PriceExcludingVAT Price per unit excluding VAT.
|
12
|
-
attribute :price_excluding_vat, Types::Nullable::Float.with(
|
11
|
+
# PriceExcludingVAT Price per unit excluding VAT.
|
12
|
+
attribute :price_excluding_vat, Types::Nullable::Float.with(private: true)
|
13
13
|
|
14
|
-
#TotalExcludingVAT Total amount for the row excluding VAT.
|
15
|
-
attribute :total_excluding_vat, Types::Nullable::Float.with(
|
14
|
+
# TotalExcludingVAT Total amount for the row excluding VAT.
|
15
|
+
attribute :total_excluding_vat, Types::Nullable::Float.with(private: true)
|
16
16
|
end
|
17
17
|
end
|
18
18
|
end
|
@@ -1,21 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Fortnox
|
2
4
|
module API
|
3
5
|
module Types
|
4
6
|
class Model < Dry::Struct
|
5
7
|
constructor_type(:schema)
|
6
8
|
|
7
|
-
def initialize(
|
8
|
-
if (missing_key = first_missing_required_key(
|
9
|
-
|
9
|
+
def initialize(input_attributes)
|
10
|
+
if (missing_key = first_missing_required_key(input_attributes))
|
11
|
+
error_message = "Missing attribute #{missing_key.inspect} in attributes: #{input_attributes}"
|
12
|
+
raise Fortnox::API::MissingAttributeError, error_message
|
10
13
|
end
|
11
14
|
|
12
15
|
super
|
13
16
|
end
|
14
17
|
|
15
|
-
|
18
|
+
def self.is?(*_args) end
|
19
|
+
|
20
|
+
private
|
16
21
|
|
17
|
-
def missing_keys(
|
18
|
-
non_nil_attributes = attributes.
|
22
|
+
def missing_keys(attributes)
|
23
|
+
non_nil_attributes = attributes.reject { |_, value| value.nil? }
|
19
24
|
|
20
25
|
attribute_keys = non_nil_attributes.keys
|
21
26
|
schema_keys = self.class.schema.keys
|
@@ -23,14 +28,13 @@ module Fortnox
|
|
23
28
|
schema_keys - attribute_keys
|
24
29
|
end
|
25
30
|
|
26
|
-
def first_missing_required_key(
|
27
|
-
missing_keys(
|
28
|
-
attribute = self.class.schema[
|
31
|
+
def first_missing_required_key(attributes)
|
32
|
+
missing_keys(attributes).find do |name|
|
33
|
+
attribute = self.class.schema[name]
|
29
34
|
attribute.respond_to?(:options) && attribute.options[:required]
|
30
35
|
end
|
31
36
|
end
|
32
37
|
end
|
33
|
-
|
34
38
|
end
|
35
39
|
end
|
36
40
|
end
|
@@ -1,21 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'date'
|
2
4
|
|
3
5
|
module Fortnox
|
4
6
|
module API
|
5
7
|
module Types
|
6
|
-
|
7
8
|
module Nullable
|
8
|
-
String = Types::Strict::String.optional.constructor{ |value| value.to_s unless value.nil? }
|
9
|
-
Float = Types::Strict::Float.optional.constructor{ |value| value.to_f unless value.nil? }
|
10
|
-
Integer = Types::Strict::Int.optional.constructor{ |value| value.to_i unless value.nil? }
|
11
|
-
Boolean = Types::Bool.optional.constructor{ |value| THE_TRUTH.fetch(
|
9
|
+
String = Types::Strict::String.optional.constructor { |value| value.to_s unless value.nil? }
|
10
|
+
Float = Types::Strict::Float.optional.constructor { |value| value.to_f unless value.nil? }
|
11
|
+
Integer = Types::Strict::Int.optional.constructor { |value| value.to_i unless value.nil? }
|
12
|
+
Boolean = Types::Bool.optional.constructor { |value| THE_TRUTH.fetch(value) { false } }
|
12
13
|
# TODO: Improve parsing!
|
13
14
|
# In case date parsing fails, ArgumentError is thrown. Currently, it is rescued in Repository::Loaders.find.
|
14
15
|
# That method assumes that the exception is due to invalid argument to the find method, which is not the case
|
15
16
|
# if it is raised from here!
|
16
|
-
Date = Types::Date.optional.constructor{ |value| ::Date.parse(
|
17
|
+
Date = Types::Date.optional.constructor { |value| ::Date.parse(value.to_s) unless value.nil? || value == '' }
|
17
18
|
end
|
18
|
-
|
19
19
|
end
|
20
20
|
end
|
21
21
|
end
|
@@ -1,14 +1,14 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'fortnox/api/types/document_row'
|
2
4
|
|
3
5
|
module Fortnox
|
4
6
|
module API
|
5
7
|
module Types
|
6
|
-
class OrderRow <
|
8
|
+
class OrderRow < DocumentRow
|
7
9
|
STUB = { ordered_quantity: 0 }.freeze
|
8
10
|
|
9
|
-
|
10
|
-
|
11
|
-
#OrderedQuantity Ordered quantity
|
11
|
+
# OrderedQuantity Ordered quantity
|
12
12
|
attribute :ordered_quantity, Types::Required::Float
|
13
13
|
end
|
14
14
|
end
|