fortnox-api 0.1.0 → 0.2.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/.codeclimate.yml +3 -2
- data/.env.test +3 -0
- data/.rubocop.yml +32 -23
- data/.travis.yml +3 -2
- data/Guardfile +2 -2
- data/LICENSE.txt +165 -22
- data/README.md +56 -37
- data/fortnox-api.gemspec +9 -6
- data/lib/fortnox/api.rb +18 -2
- data/lib/fortnox/api/base.rb +5 -3
- data/lib/fortnox/api/environment_validation.rb +51 -6
- data/lib/fortnox/api/mappers.rb +49 -0
- data/lib/fortnox/api/mappers/base.rb +47 -0
- data/lib/fortnox/api/mappers/base/from_json.rb +78 -0
- data/lib/fortnox/api/mappers/base/to_json.rb +65 -0
- data/lib/fortnox/api/mappers/customer.rb +27 -0
- data/lib/fortnox/api/mappers/default_delivery_types.rb +13 -0
- data/lib/fortnox/api/mappers/default_templates.rb +15 -0
- data/lib/fortnox/api/mappers/edi_information.rb +22 -0
- data/lib/fortnox/api/mappers/email_information.rb +18 -0
- data/lib/fortnox/api/mappers/invoice.rb +27 -0
- data/lib/fortnox/api/mappers/invoice_row.rb +20 -0
- data/lib/fortnox/api/mappers/order.rb +23 -0
- data/lib/fortnox/api/mappers/order_row.rb +16 -0
- data/lib/fortnox/api/models.rb +2 -0
- data/lib/fortnox/api/models/base.rb +56 -13
- data/lib/fortnox/api/models/customer.rb +112 -101
- data/lib/fortnox/api/models/document_base.rb +189 -0
- data/lib/fortnox/api/models/invoice.rb +29 -195
- data/lib/fortnox/api/models/label.rb +17 -0
- data/lib/fortnox/api/models/order.rb +27 -0
- data/lib/fortnox/api/repositories.rb +2 -0
- data/lib/fortnox/api/repositories/base.rb +4 -5
- data/lib/fortnox/api/repositories/base/loaders.rb +22 -14
- data/lib/fortnox/api/repositories/base/savers.rb +30 -16
- data/lib/fortnox/api/repositories/customer.rb +3 -25
- data/lib/fortnox/api/repositories/invoice.rb +3 -22
- data/lib/fortnox/api/repositories/order.rb +16 -0
- data/lib/fortnox/api/request_handling.rb +3 -3
- data/lib/fortnox/api/types.rb +44 -0
- data/lib/fortnox/api/types/default_delivery_types.rb +20 -0
- data/lib/fortnox/api/types/default_templates.rb +23 -0
- data/lib/fortnox/api/types/defaulted.rb +11 -0
- data/lib/fortnox/api/types/document_row.rb +65 -0
- data/lib/fortnox/api/types/edi_information.rb +29 -0
- data/lib/fortnox/api/types/email_information.rb +26 -0
- data/lib/fortnox/api/types/enums.rb +75 -0
- data/lib/fortnox/api/types/invoice_row.rb +19 -0
- data/lib/fortnox/api/types/model.rb +40 -0
- data/lib/fortnox/api/types/nullable.rb +21 -0
- data/lib/fortnox/api/types/order_row.rb +16 -0
- data/lib/fortnox/api/types/required.rb +13 -0
- data/lib/fortnox/api/types/sized.rb +25 -0
- data/lib/fortnox/api/version.rb +1 -1
- data/spec/fortnox/api/base_spec.rb +85 -14
- data/spec/fortnox/api/mappers/base/from_json_spec.rb +70 -0
- data/spec/fortnox/api/mappers/base/to_json_spec.rb +76 -0
- data/spec/fortnox/api/mappers/base_spec.rb +156 -0
- data/spec/fortnox/api/mappers/contexts/json_conversion.rb +56 -0
- data/spec/fortnox/api/mappers/customer_spec.rb +25 -0
- data/spec/fortnox/api/mappers/default_delivery_types_spec.rb +12 -0
- data/spec/fortnox/api/mappers/edi_information_spec.rb +21 -0
- data/spec/fortnox/api/mappers/email_information_spec.rb +17 -0
- data/spec/fortnox/api/mappers/examples/mapper.rb +26 -0
- data/spec/fortnox/api/mappers/invoice_row_spec.rb +19 -0
- data/spec/fortnox/api/mappers/invoice_spec.rb +24 -0
- data/spec/fortnox/api/mappers/order_row_spec.rb +14 -0
- data/spec/fortnox/api/mappers/order_spec.rb +20 -0
- data/spec/fortnox/api/models/base_spec.rb +44 -22
- data/spec/fortnox/api/models/customer_spec.rb +9 -0
- data/spec/fortnox/api/models/examples/document_base.rb +13 -0
- data/spec/fortnox/api/models/examples/model.rb +13 -0
- data/spec/fortnox/api/models/invoice_spec.rb +7 -31
- data/spec/fortnox/api/models/order_spec.rb +13 -0
- data/spec/fortnox/api/repositories/customer_spec.rb +20 -76
- data/spec/fortnox/api/repositories/examples/all.rb +17 -0
- data/spec/fortnox/api/repositories/examples/find.rb +25 -0
- data/spec/fortnox/api/repositories/examples/only.rb +42 -0
- data/spec/fortnox/api/repositories/examples/save.rb +69 -0
- data/spec/fortnox/api/repositories/examples/save_with_nested_model.rb +32 -0
- data/spec/fortnox/api/repositories/examples/save_with_specially_named_attribute.rb +27 -0
- data/spec/fortnox/api/repositories/examples/search.rb +31 -0
- data/spec/fortnox/api/repositories/invoice_spec.rb +36 -5
- data/spec/fortnox/api/repositories/order_spec.rb +35 -0
- data/spec/fortnox/api/types/account_number_spec.rb +28 -0
- data/spec/fortnox/api/types/default_delivery_types_spec.rb +10 -0
- data/spec/fortnox/api/types/edi_information_spec.rb +13 -0
- data/spec/fortnox/api/types/email_information_spec.rb +13 -0
- data/spec/fortnox/api/types/email_spec.rb +29 -0
- data/spec/fortnox/api/types/enums_spec.rb +13 -0
- data/spec/fortnox/api/types/examples/document_row.rb +15 -0
- data/spec/fortnox/api/types/examples/enum.rb +48 -0
- data/spec/fortnox/api/types/examples/types.rb +9 -0
- data/spec/fortnox/api/types/house_work_types_spec.rb +60 -0
- data/spec/fortnox/api/types/invoice_row_spec.rb +9 -0
- data/spec/fortnox/api/types/model_spec.rb +56 -0
- data/spec/fortnox/api/types/nullable_spec.rb +57 -0
- data/spec/fortnox/api/types/order_row_spec.rb +13 -0
- data/spec/fortnox/api/types/required_spec.rb +42 -0
- data/spec/fortnox/api/types/sized_spec.rb +74 -0
- data/spec/fortnox/api_spec.rb +16 -15
- data/spec/spec_helper.rb +19 -9
- data/spec/support/helpers/dummy_class_helper.rb +19 -0
- data/spec/support/helpers/environment_helper.rb +7 -0
- data/spec/support/helpers/repository_helper.rb +8 -0
- data/spec/support/helpers/when_performing_helper.rb +5 -0
- data/spec/support/matchers.rb +1 -1
- data/spec/support/matchers/type.rb +17 -0
- data/spec/support/matchers/type/attribute_matcher.rb +39 -0
- data/spec/support/matchers/type/enum_matcher.rb +21 -0
- data/spec/support/matchers/type/have_account_number_matcher.rb +21 -0
- data/spec/support/matchers/type/have_country_code_matcher.rb +13 -0
- data/spec/support/matchers/type/have_currency_matcher.rb +7 -0
- data/spec/support/matchers/type/have_customer_type_matcher.rb +13 -0
- data/spec/support/matchers/type/have_default_delivery_type_matcher.rb +7 -0
- data/spec/support/matchers/type/have_discount_type_matcher.rb +7 -0
- data/spec/support/matchers/type/have_email_matcher.rb +22 -0
- data/spec/support/matchers/type/have_house_work_type_matcher.rb +7 -0
- data/spec/support/matchers/type/have_nullable_date_matcher.rb +58 -0
- data/spec/support/matchers/type/have_nullable_matcher.rb +52 -0
- data/spec/support/matchers/type/have_nullable_string_matcher.rb +49 -0
- data/spec/support/matchers/type/have_sized_float_matcher.rb +8 -0
- data/spec/support/matchers/type/have_sized_integer_matcher.rb +8 -0
- data/spec/support/matchers/type/have_sized_string_matcher.rb +35 -0
- data/spec/support/matchers/type/have_vat_type_matcher.rb +7 -0
- data/spec/support/matchers/type/numeric_matcher.rb +50 -0
- data/spec/support/matchers/type/require_attribute_matcher.rb +69 -0
- data/spec/support/matchers/type/type_matcher.rb +38 -0
- data/spec/vcr_cassettes/customers/all.yml +119 -9
- data/spec/vcr_cassettes/customers/find_id_1.yml +8 -9
- data/spec/vcr_cassettes/customers/find_new.yml +46 -0
- data/spec/vcr_cassettes/customers/save_new.yml +9 -11
- data/spec/vcr_cassettes/customers/save_old.yml +9 -12
- data/spec/vcr_cassettes/customers/save_with_specially_named_attribute.yml +45 -0
- data/spec/vcr_cassettes/customers/search_by_name.yml +66 -0
- data/spec/vcr_cassettes/customers/search_miss.yml +45 -0
- data/spec/vcr_cassettes/invoices/all.yml +104 -0
- data/spec/vcr_cassettes/invoices/filter_hit.yml +46 -0
- data/spec/vcr_cassettes/invoices/filter_invalid.yml +42 -0
- data/spec/vcr_cassettes/invoices/find_id_1.yml +47 -0
- data/spec/vcr_cassettes/invoices/find_new.yml +49 -0
- data/spec/vcr_cassettes/invoices/save_new.yml +48 -0
- data/spec/vcr_cassettes/invoices/save_old.yml +49 -0
- data/spec/vcr_cassettes/invoices/save_with_nested_model.yml +47 -0
- data/spec/vcr_cassettes/invoices/save_with_specially_named_attribute.yml +47 -0
- data/spec/vcr_cassettes/invoices/search_by_name.yml +48 -0
- data/spec/vcr_cassettes/invoices/search_miss.yml +45 -0
- data/spec/vcr_cassettes/orders/all.yml +144 -0
- data/spec/vcr_cassettes/orders/filter_hit.yml +48 -0
- data/spec/vcr_cassettes/orders/filter_invalid.yml +42 -0
- data/spec/vcr_cassettes/orders/find_id_1.yml +48 -0
- data/spec/vcr_cassettes/orders/find_new.yml +49 -0
- data/spec/vcr_cassettes/orders/house_work_type_babysitting.yml +47 -0
- data/spec/vcr_cassettes/orders/house_work_type_cleaning.yml +47 -0
- data/spec/vcr_cassettes/orders/house_work_type_construction.yml +47 -0
- data/spec/vcr_cassettes/orders/house_work_type_cooking.yml +43 -0
- data/spec/vcr_cassettes/orders/house_work_type_electricity.yml +47 -0
- data/spec/vcr_cassettes/orders/house_work_type_gardening.yml +47 -0
- data/spec/vcr_cassettes/orders/house_work_type_glassmetalwork.yml +47 -0
- data/spec/vcr_cassettes/orders/house_work_type_grounddrainagework.yml +47 -0
- data/spec/vcr_cassettes/orders/house_work_type_hvac.yml +47 -0
- data/spec/vcr_cassettes/orders/house_work_type_masonry.yml +47 -0
- data/spec/vcr_cassettes/orders/house_work_type_othercare.yml +47 -0
- data/spec/vcr_cassettes/orders/house_work_type_othercosts.yml +47 -0
- data/spec/vcr_cassettes/orders/house_work_type_paintingwallpapering.yml +47 -0
- data/spec/vcr_cassettes/orders/house_work_type_snowplowing.yml +47 -0
- data/spec/vcr_cassettes/orders/house_work_type_textileclothing.yml +47 -0
- data/spec/vcr_cassettes/orders/house_work_type_tutoring.yml +43 -0
- data/spec/vcr_cassettes/orders/save_new.yml +48 -0
- data/spec/vcr_cassettes/orders/save_old.yml +49 -0
- data/spec/vcr_cassettes/orders/save_with_nested_model.yml +47 -0
- data/spec/vcr_cassettes/orders/search_by_name.yml +47 -0
- data/spec/vcr_cassettes/orders/search_miss.yml +45 -0
- metadata +301 -71
- data/lib/fortnox/api/models/attributes/country_code.rb +0 -17
- data/lib/fortnox/api/models/attributes/currency.rb +0 -17
- data/lib/fortnox/api/models/edi_information.rb +0 -28
- data/lib/fortnox/api/models/email_information.rb +0 -25
- data/lib/fortnox/api/models/row.rb +0 -82
- data/lib/fortnox/api/repositories/base/json_convertion.rb +0 -68
- data/lib/fortnox/api/repositories/base/options.rb +0 -33
- data/lib/fortnox/api/validators.rb +0 -1
- data/lib/fortnox/api/validators/attributes/country_code.rb +0 -42
- data/lib/fortnox/api/validators/attributes/currency.rb +0 -38
- data/lib/fortnox/api/validators/base.rb +0 -70
- data/lib/fortnox/api/validators/constant.rb +0 -21
- data/lib/fortnox/api/validators/customer.rb +0 -29
- data/lib/fortnox/api/validators/edi_information.rb +0 -11
- data/lib/fortnox/api/validators/email_information.rb +0 -19
- data/lib/fortnox/api/validators/invoice.rb +0 -33
- data/lib/fortnox/api/validators/row.rb +0 -22
- data/spec/fortnox/api/models/attributes/country_code_spec.rb +0 -23
- data/spec/fortnox/api/models/attributes/currency_spec.rb +0 -23
- data/spec/fortnox/api/models/attributes/dummy_model_context.rb +0 -9
- data/spec/fortnox/api/models/row_spec.rb +0 -13
- data/spec/fortnox/api/repositories/context.rb +0 -10
- data/spec/fortnox/api/repositories/examples.rb +0 -16
- data/spec/fortnox/api/validators/attributes/country_code_spec.rb +0 -9
- data/spec/fortnox/api/validators/attributes/currency_spec.rb +0 -9
- data/spec/fortnox/api/validators/attributes/examples_for_validate.rb +0 -29
- data/spec/fortnox/api/validators/base_spec.rb +0 -61
- data/spec/fortnox/api/validators/constant_spec.rb +0 -12
- data/spec/fortnox/api/validators/context.rb +0 -102
- data/spec/fortnox/api/validators/customer_spec.rb +0 -31
- data/spec/fortnox/api/validators/edi_information_spec.rb +0 -18
- data/spec/fortnox/api/validators/email_information_spec.rb +0 -26
- data/spec/fortnox/api/validators/invoice_spec.rb +0 -36
- data/spec/fortnox/api/validators/row_spec.rb +0 -27
- data/spec/fortnox/api/validators/validator_examples.rb +0 -20
- data/spec/support/matchers/models.rb +0 -27
- data/spec/support/matchers/validators.rb +0 -36
@@ -0,0 +1,13 @@
|
|
1
|
+
require "fortnox/api/mappers/base"
|
2
|
+
|
3
|
+
module Fortnox
|
4
|
+
module API
|
5
|
+
module Mapper
|
6
|
+
class DefaultDeliveryTypes < Fortnox::API::Mapper::Base
|
7
|
+
KEY_MAP = {}.freeze
|
8
|
+
end
|
9
|
+
|
10
|
+
Registry.register( DefaultDeliveryTypes.canonical_name_sym, DefaultDeliveryTypes )
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require "fortnox/api/mappers/base"
|
2
|
+
|
3
|
+
module Fortnox
|
4
|
+
module API
|
5
|
+
module Mapper
|
6
|
+
class DefaultTemplates < Fortnox::API::Mapper::Base
|
7
|
+
|
8
|
+
KEY_MAP = {}.freeze
|
9
|
+
JSON_ENTITY_WRAPPER = JSON_COLLECTION_WRAPPER = 'DefaultTemplates'.freeze
|
10
|
+
end
|
11
|
+
|
12
|
+
Registry.register( DefaultTemplates.canonical_name_sym, DefaultTemplates )
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require "fortnox/api/mappers/base"
|
2
|
+
|
3
|
+
module Fortnox
|
4
|
+
module API
|
5
|
+
module Mapper
|
6
|
+
class EDIInformation < Fortnox::API::Mapper::Base
|
7
|
+
|
8
|
+
KEY_MAP = {
|
9
|
+
edi_global_location_number: 'EDIGlobalLocationNumber',
|
10
|
+
edi_global_location_number_delivery: 'EDIGlobalLocationNumberDelivery',
|
11
|
+
edi_invoice_extra1: 'EDIInvoiceExtra1',
|
12
|
+
edi_invoice_extra2: 'EDIInvoiceExtra2',
|
13
|
+
edi_our_electronic_reference: 'EDIOurElectronicReference',
|
14
|
+
edi_your_electronic_reference: 'EDIYourElectronicReference'
|
15
|
+
}.freeze
|
16
|
+
JSON_ENTITY_WRAPPER = JSON_COLLECTION_WRAPPER = 'EDIInformation'.freeze
|
17
|
+
end
|
18
|
+
|
19
|
+
Registry.register( EDIInformation.canonical_name_sym, EDIInformation )
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require "fortnox/api/mappers/base"
|
2
|
+
|
3
|
+
module Fortnox
|
4
|
+
module API
|
5
|
+
module Mapper
|
6
|
+
class EmailInformation < Fortnox::API::Mapper::Base
|
7
|
+
|
8
|
+
KEY_MAP = {
|
9
|
+
email_address_bcc: 'EmailAddressBCC',
|
10
|
+
email_address_cc: 'EmailAddressCC'
|
11
|
+
}.freeze
|
12
|
+
JSON_ENTITY_WRAPPER = JSON_COLLECTION_WRAPPER = 'EmailInformation'.freeze
|
13
|
+
end
|
14
|
+
|
15
|
+
Registry.register( EmailInformation.canonical_name_sym, EmailInformation )
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require "fortnox/api/mappers/base"
|
2
|
+
require "fortnox/api/mappers/edi_information"
|
3
|
+
require "fortnox/api/mappers/email_information"
|
4
|
+
require "fortnox/api/mappers/invoice_row"
|
5
|
+
|
6
|
+
module Fortnox
|
7
|
+
module API
|
8
|
+
module Mapper
|
9
|
+
class Invoice < Fortnox::API::Mapper::Base
|
10
|
+
|
11
|
+
KEY_MAP = {
|
12
|
+
administration_fee_vat: 'AdministrationFeeVAT',
|
13
|
+
edi_information: 'EDIInformation',
|
14
|
+
eu_quarterly_report: 'EUQuarterlyReport',
|
15
|
+
freight_vat: 'FreightVAT',
|
16
|
+
ocr: 'OCR',
|
17
|
+
total_vat: 'TotalVAT',
|
18
|
+
vat_included: 'VATIncluded'
|
19
|
+
}.freeze
|
20
|
+
JSON_ENTITY_WRAPPER = 'Invoice'.freeze
|
21
|
+
JSON_COLLECTION_WRAPPER = 'Invoices'.freeze
|
22
|
+
end
|
23
|
+
|
24
|
+
Registry.register( Invoice.canonical_name_sym, Invoice )
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require "fortnox/api/mappers/base"
|
2
|
+
|
3
|
+
module Fortnox
|
4
|
+
module API
|
5
|
+
module Mapper
|
6
|
+
class InvoiceRow < Fortnox::API::Mapper::Base
|
7
|
+
KEY_MAP = {
|
8
|
+
vat: 'VAT',
|
9
|
+
price_excluding_vat: 'PriceExcludingVAT',
|
10
|
+
total_excluding_vat: 'TotalExcludingVAT'
|
11
|
+
}.freeze
|
12
|
+
JSON_ENTITY_WRAPPER = 'InvoiceRow'.freeze
|
13
|
+
JSON_COLLECTION_WRAPPER = 'InvoiceRows'.freeze
|
14
|
+
end
|
15
|
+
|
16
|
+
Registry.register( InvoiceRow.canonical_name_sym, InvoiceRow )
|
17
|
+
Registry.register( :invoicerows, InvoiceRow )
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require "fortnox/api/mappers/base"
|
2
|
+
require "fortnox/api/mappers/edi_information"
|
3
|
+
require "fortnox/api/mappers/email_information"
|
4
|
+
require "fortnox/api/mappers/order_row"
|
5
|
+
|
6
|
+
module Fortnox
|
7
|
+
module API
|
8
|
+
module Mapper
|
9
|
+
class Order < Fortnox::API::Mapper::Base
|
10
|
+
KEY_MAP = {
|
11
|
+
administration_fee_vat: 'AdministrationFeeVAT',
|
12
|
+
freight_vat: 'FreightVAT',
|
13
|
+
total_vat: 'TotalVAT',
|
14
|
+
vat_included: 'VATIncluded'
|
15
|
+
}.freeze
|
16
|
+
JSON_ENTITY_WRAPPER = 'Order'.freeze
|
17
|
+
JSON_COLLECTION_WRAPPER = 'Orders'.freeze
|
18
|
+
end
|
19
|
+
|
20
|
+
Registry.register( Order.canonical_name_sym, Order )
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require "fortnox/api/mappers/base"
|
2
|
+
|
3
|
+
module Fortnox
|
4
|
+
module API
|
5
|
+
module Mapper
|
6
|
+
class OrderRow < Fortnox::API::Mapper::Base
|
7
|
+
KEY_MAP = { vat: 'VAT' }.freeze
|
8
|
+
JSON_ENTITY_WRAPPER = 'OrderRow'.freeze
|
9
|
+
JSON_COLLECTION_WRAPPER = 'OrderRows'.freeze
|
10
|
+
end
|
11
|
+
|
12
|
+
Registry.register( OrderRow.canonical_name_sym, OrderRow )
|
13
|
+
Registry.register( :orderrows, OrderRow )
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
data/lib/fortnox/api/models.rb
CHANGED
@@ -1,33 +1,37 @@
|
|
1
|
-
require "
|
1
|
+
require "fortnox/api/types"
|
2
2
|
require "ice_nine"
|
3
3
|
|
4
4
|
module Fortnox
|
5
5
|
module API
|
6
6
|
module Model
|
7
|
-
class Base
|
7
|
+
class Base < Fortnox::API::Types::Model
|
8
8
|
|
9
|
-
#
|
10
|
-
include Virtus.model
|
9
|
+
# TODO(jonas): Restructure this class a bit, it is not very readable.
|
11
10
|
|
12
|
-
attr_accessor :unsaved
|
11
|
+
attr_accessor :unsaved, :parent
|
13
12
|
|
14
13
|
def self.attribute( name, *args )
|
15
|
-
define_method( "#{name}?" ) do
|
14
|
+
define_method( "#{ name }?" ) do
|
16
15
|
!send( name ).nil?
|
17
16
|
end
|
18
17
|
|
19
18
|
super
|
20
19
|
end
|
21
20
|
|
22
|
-
def
|
23
|
-
|
24
|
-
|
25
|
-
|
21
|
+
def self.new( hash )
|
22
|
+
begin
|
23
|
+
obj = preserve_meta_properties( hash ) do
|
24
|
+
super( hash )
|
25
|
+
end
|
26
|
+
rescue Dry::Struct::Error => e
|
27
|
+
raise Fortnox::API::AttributeError.new e
|
28
|
+
end
|
26
29
|
|
27
|
-
|
30
|
+
IceNine.deep_freeze( obj )
|
31
|
+
end
|
28
32
|
|
29
|
-
|
30
|
-
|
33
|
+
def unique_id
|
34
|
+
send( self.class::UNIQUE_ID )
|
31
35
|
end
|
32
36
|
|
33
37
|
def update( hash )
|
@@ -38,6 +42,7 @@ module Fortnox
|
|
38
42
|
|
39
43
|
new_hash = new_attributes.delete_if{ |_, value| value.nil? }
|
40
44
|
new_hash[:new] = @new
|
45
|
+
new_hash[:parent] = self
|
41
46
|
self.class.new( new_hash )
|
42
47
|
end
|
43
48
|
|
@@ -55,6 +60,44 @@ module Fortnox
|
|
55
60
|
@saved
|
56
61
|
end
|
57
62
|
|
63
|
+
def parent?
|
64
|
+
not @parent.nil?
|
65
|
+
end
|
66
|
+
|
67
|
+
def parent
|
68
|
+
@parent || self.class.new( self.class::STUB.dup )
|
69
|
+
end
|
70
|
+
|
71
|
+
def to_hash( recursive = false )
|
72
|
+
return super() if recursive
|
73
|
+
|
74
|
+
self.class.schema.keys.each_with_object({}) do |key, result|
|
75
|
+
result[key] = self[key]
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
private_class_method
|
80
|
+
|
81
|
+
# dry-types filter anything that isn't specified as an attribute on the
|
82
|
+
# class that is being instansiated. This wrapper preserves the meta
|
83
|
+
# properties we need to track object state during that initilisation and
|
84
|
+
# sets them on the object after dry-types is done with it.
|
85
|
+
def self.preserve_meta_properties( hash )
|
86
|
+
is_unsaved = hash.delete( :unsaved ){ true }
|
87
|
+
is_new = hash.delete( :new ){ true }
|
88
|
+
parent = hash.delete( :parent ){ nil }
|
89
|
+
|
90
|
+
obj = yield
|
91
|
+
|
92
|
+
# TODO: remove new, unsaved, saved
|
93
|
+
obj.instance_variable_set( :@unsaved, is_unsaved )
|
94
|
+
obj.instance_variable_set( :@saved, !is_unsaved )
|
95
|
+
obj.instance_variable_set( :@new, is_new )
|
96
|
+
obj.instance_variable_set( :@parent, parent )
|
97
|
+
|
98
|
+
return obj
|
99
|
+
end
|
100
|
+
|
58
101
|
private
|
59
102
|
|
60
103
|
def private_attributes
|
@@ -1,12 +1,14 @@
|
|
1
|
+
require "fortnox/api/types"
|
1
2
|
require "fortnox/api/models/base"
|
2
|
-
require "fortnox/api/models/attributes/country_code"
|
3
|
-
require "fortnox/api/models/attributes/currency"
|
4
3
|
|
5
4
|
module Fortnox
|
6
5
|
module API
|
7
6
|
module Model
|
8
7
|
class Customer < Fortnox::API::Model::Base
|
9
8
|
|
9
|
+
UNIQUE_ID = :customer_number
|
10
|
+
STUB = { name: '' }.freeze
|
11
|
+
|
10
12
|
# searchable_attributes(
|
11
13
|
# :city, :customer_number, :email, :name, :organisation_number,
|
12
14
|
# :phone1, :zip_code
|
@@ -25,173 +27,182 @@ module Fortnox
|
|
25
27
|
# )
|
26
28
|
|
27
29
|
#Url Direct URL to the record
|
28
|
-
attribute :url, String
|
30
|
+
attribute :url, Fortnox::API::Types::Nullable::String.with( read_only: true )
|
29
31
|
|
30
|
-
#Address1 First address of the customer
|
31
|
-
attribute :address1, String
|
32
|
+
#Address1 First address of the customer. 1024 characters
|
33
|
+
attribute :address1, Fortnox::API::Types::Sized::String[ 1024 ]
|
32
34
|
|
33
|
-
#Address2 Second address of the customer
|
34
|
-
attribute :address2, String
|
35
|
+
#Address2 Second address of the customer. 1024 characters
|
36
|
+
attribute :address2, Fortnox::API::Types::Sized::String[ 1024 ]
|
35
37
|
|
36
|
-
#City City of the customer
|
37
|
-
attribute :city, String
|
38
|
+
#City City of the customer. 1024 characters
|
39
|
+
attribute :city, Fortnox::API::Types::Sized::String[ 1024 ]
|
38
40
|
|
39
|
-
#Country Country of the customer
|
40
|
-
attribute :country, String
|
41
|
+
#Country Country of the customer. Read-only.
|
42
|
+
attribute :country, Fortnox::API::Types::Nullable::String.with( read_only: true )
|
41
43
|
|
42
|
-
#Comments Comments
|
43
|
-
attribute :comments, String
|
44
|
+
#Comments Comments. 1024 characters.
|
45
|
+
attribute :comments, Fortnox::API::Types::Sized::String[ 1024 ]
|
44
46
|
|
45
47
|
#Currency Currency of the customer, 3 letters
|
46
|
-
|
48
|
+
attribute :currency, Fortnox::API::Types::Currency
|
47
49
|
|
48
50
|
#CostCenter Cost center of the customer, Cost center in Fortnox
|
49
|
-
attribute :cost_center, String
|
51
|
+
attribute :cost_center, Fortnox::API::Types::Nullable::String
|
50
52
|
|
51
53
|
#CountryCode Country code of the customer, 2 letters
|
52
|
-
|
54
|
+
attribute :country_code, Fortnox::API::Types::CountryCode
|
55
|
+
|
56
|
+
#CustomerNumber Customer number. 1024 characters
|
57
|
+
attribute :customer_number, Fortnox::API::Types::Sized::String[ 1024 ]
|
58
|
+
|
59
|
+
#DefaultDeliveryTypes The properties for this object is listed in the table for “Default Delivery Types”.
|
60
|
+
attribute :default_delivery_types, Types::DefaultDeliveryTypes
|
53
61
|
|
54
|
-
#
|
55
|
-
attribute :
|
62
|
+
#The properties for this object is listed in the table for “Default Templates”.
|
63
|
+
attribute :default_templates, Types::DefaultTemplates
|
56
64
|
|
57
|
-
#DeliveryAddress1 First delivery address of the customer
|
58
|
-
attribute :delivery_address1, String
|
65
|
+
#DeliveryAddress1 First delivery address of the customer. 1024 characters
|
66
|
+
attribute :delivery_address1, Fortnox::API::Types::Sized::String[ 1024 ]
|
59
67
|
|
60
|
-
#DeliveryAddress2 Second delivery address of the customer
|
61
|
-
attribute :delivery_address2, String
|
68
|
+
#DeliveryAddress2 Second delivery address of the customer. 1024 characters
|
69
|
+
attribute :delivery_address2, Fortnox::API::Types::Sized::String[ 1024 ]
|
62
70
|
|
63
|
-
#DeliveryCity Delivery city of the customer
|
64
|
-
attribute :delivery_city, String
|
71
|
+
#DeliveryCity Delivery city of the customer. 1024 characters
|
72
|
+
attribute :delivery_city, Fortnox::API::Types::Sized::String[ 1024 ]
|
65
73
|
|
66
|
-
#DeliveryCountry Delivery country of the customer
|
67
|
-
attribute :delivery_country, String
|
74
|
+
#DeliveryCountry Delivery country of the customer. Read-only.
|
75
|
+
attribute :delivery_country, Fortnox::API::Types::Nullable::String.with( read_only: true )
|
68
76
|
|
69
|
-
#DeliveryCountryCode Delivery country code of the customer
|
70
|
-
attribute :delivery_country_code,
|
77
|
+
#DeliveryCountryCode Delivery country code of the customer, 2 letters
|
78
|
+
attribute :delivery_country_code, Fortnox::API::Types::CountryCode
|
71
79
|
|
72
|
-
#DeliveryFax Delivery fax number of the customer
|
73
|
-
attribute :delivery_fax, String
|
80
|
+
#DeliveryFax Delivery fax number of the customer. 1024 characters
|
81
|
+
attribute :delivery_fax, Fortnox::API::Types::Sized::String[ 1024 ]
|
74
82
|
|
75
|
-
#DeliveryName Delivery name of the customer
|
76
|
-
attribute :delivery_name, String
|
83
|
+
#DeliveryName Delivery name of the customer. 1024 characters
|
84
|
+
attribute :delivery_name, Fortnox::API::Types::Sized::String[ 1024 ]
|
77
85
|
|
78
|
-
#DeliveryPhone1 First delivery phone number of the customer
|
79
|
-
attribute :delivery_phone1, String
|
86
|
+
#DeliveryPhone1 First delivery phone number of the customer. 1024 characters
|
87
|
+
attribute :delivery_phone1, Fortnox::API::Types::Sized::String[ 1024 ]
|
80
88
|
|
81
|
-
#DeliveryPhone2 Second delivery phone number of the customer
|
82
|
-
attribute :delivery_phone2, String
|
89
|
+
#DeliveryPhone2 Second delivery phone number of the customer. 1024 characters
|
90
|
+
attribute :delivery_phone2, Fortnox::API::Types::Sized::String[ 1024 ]
|
83
91
|
|
84
|
-
#DeliveryZipCode Delivery zip code of the customer
|
85
|
-
attribute :delivery_zip_code, String
|
92
|
+
#DeliveryZipCode Delivery zip code of the customer. 1024 characters.
|
93
|
+
attribute :delivery_zip_code, Fortnox::API::Types::Sized::String[ 1024 ]
|
86
94
|
|
87
|
-
#Email Email address of the customer
|
88
|
-
attribute :email,
|
95
|
+
#Email Email address of the customer. 1024 characters
|
96
|
+
attribute :email, Types::Email
|
89
97
|
|
90
|
-
#EmailInvoice Invoice email address of the customer
|
91
|
-
attribute :email_invoice,
|
98
|
+
#EmailInvoice Invoice email address of the customer. 1024 characters
|
99
|
+
attribute :email_invoice, Types::Email
|
92
100
|
|
93
|
-
#EmailInvoiceBCC Invoice BCC email address of the customer
|
94
|
-
attribute :email_invoice_bcc,
|
101
|
+
#EmailInvoiceBCC Invoice BCC email address of the customer. 1024 characters
|
102
|
+
attribute :email_invoice_bcc, Types::Email
|
95
103
|
|
96
|
-
#EmailInvoiceCC Invoice CC email address of the customer
|
97
|
-
attribute :email_invoice_cc,
|
104
|
+
#EmailInvoiceCC Invoice CC email address of the customer. 1024 characters
|
105
|
+
attribute :email_invoice_cc, Types::Email
|
98
106
|
|
99
|
-
#EmailOffer Offer email address of the customer
|
100
|
-
attribute :email_offer,
|
107
|
+
#EmailOffer Offer email address of the customer. 1024 characters
|
108
|
+
attribute :email_offer, Types::Email
|
101
109
|
|
102
|
-
#EmailOfferBCC Offer BCC email address of the customer
|
103
|
-
attribute :email_offer_bcc,
|
110
|
+
#EmailOfferBCC Offer BCC email address of the customer. 1024 characters
|
111
|
+
attribute :email_offer_bcc, Types::Email
|
104
112
|
|
105
|
-
#EmailOfferCC Offer CC email address of the customer
|
106
|
-
attribute :email_offer_cc,
|
113
|
+
#EmailOfferCC Offer CC email address of the customer. 1024 characters
|
114
|
+
attribute :email_offer_cc, Types::Email
|
107
115
|
|
108
|
-
#EmailOrder Order email address of the customer
|
109
|
-
attribute :email_order,
|
116
|
+
#EmailOrder Order email address of the customer. 1024 characters
|
117
|
+
attribute :email_order, Types::Email
|
110
118
|
|
111
|
-
#EmailOrderBCC Order BCC email address of the customer
|
112
|
-
attribute :email_order_bcc,
|
119
|
+
#EmailOrderBCC Order BCC email address of the customer. 1024 characters
|
120
|
+
attribute :email_order_bcc, Types::Email
|
113
121
|
|
114
|
-
#EmailOrderCC Order CC email address of the customer
|
115
|
-
attribute :email_order_cc,
|
122
|
+
#EmailOrderCC Order CC email address of the customer. 1024 characters
|
123
|
+
attribute :email_order_cc, Types::Email
|
116
124
|
|
117
|
-
#Fax Fax number of the customer
|
118
|
-
attribute :fax, String
|
125
|
+
#Fax Fax number of the customer. 1024 characters
|
126
|
+
attribute :fax, Fortnox::API::Types::Sized::String[ 1024 ]
|
119
127
|
|
120
|
-
#InvoiceAdministrationFee Invoice administration fee of the customer
|
121
|
-
attribute :invoice_administration_fee,
|
128
|
+
#InvoiceAdministrationFee Invoice administration fee of the customer, 12 digits (incl. decimals).
|
129
|
+
attribute :invoice_administration_fee,
|
130
|
+
Fortnox::API::Types::Sized::Float[ 0.0, 99_999_999_999.9 ]
|
122
131
|
|
123
|
-
#InvoiceDiscount Invoice discount of the customer
|
124
|
-
attribute :invoice_discount, Float
|
132
|
+
#InvoiceDiscount Invoice discount of the customer, 12 digits (incl. decimals)
|
133
|
+
attribute :invoice_discount, Fortnox::API::Types::Sized::Float[ 0.0, 99_999_999_999.9 ]
|
125
134
|
|
126
|
-
#InvoiceFreight Invoice freight fee of the customer
|
127
|
-
attribute :invoice_freight, Float
|
135
|
+
#InvoiceFreight Invoice freight fee of the customer, 12 digits (incl. decimals)
|
136
|
+
attribute :invoice_freight, Fortnox::API::Types::Sized::Float[ 0.0, 99_999_999_999.9 ]
|
128
137
|
|
129
|
-
#InvoiceRemark Invoice remark of the customer
|
130
|
-
attribute :invoice_remark, String
|
138
|
+
#InvoiceRemark Invoice remark of the customer. 1024 characters
|
139
|
+
attribute :invoice_remark, Fortnox::API::Types::Sized::String[ 1024 ]
|
131
140
|
|
132
|
-
#Name Name of the customer
|
133
|
-
attribute :name, String
|
141
|
+
#Name Name of the customer, 1024 characters
|
142
|
+
attribute :name, Fortnox::API::Types::Sized::String[ 1024 ].with( required: true )
|
134
143
|
|
135
|
-
#OrganisationNumber Organisation number of the customer
|
136
|
-
attribute :organisation_number, String
|
144
|
+
#OrganisationNumber Organisation number of the customer. 30 characters
|
145
|
+
attribute :organisation_number, Fortnox::API::Types::Sized::String[ 30 ]
|
137
146
|
|
138
|
-
#OurReference Our reference of the customer
|
139
|
-
attribute :our_reference, String
|
147
|
+
#OurReference Our reference of the customer. 50 characters
|
148
|
+
attribute :our_reference, Fortnox::API::Types::Sized::String[ 50 ]
|
140
149
|
|
141
|
-
#Phone1 First phone number of the customer
|
142
|
-
attribute :phone1, String
|
150
|
+
#Phone1 First phone number of the customer. 1024 characters
|
151
|
+
attribute :phone1, Fortnox::API::Types::Sized::String[ 1024 ]
|
143
152
|
|
144
|
-
#Phone2 Second phone number of the customer
|
145
|
-
attribute :phone2, String
|
153
|
+
#Phone2 Second phone number of the customer. 1024 characters
|
154
|
+
attribute :phone2, Fortnox::API::Types::Sized::String[ 1024 ]
|
146
155
|
|
147
156
|
#PriceList Price list of the customer, Price list in Fortnox
|
148
|
-
attribute :price_list, String
|
157
|
+
attribute :price_list, Fortnox::API::Types::Nullable::String
|
149
158
|
|
150
159
|
#Project Project of the customer, Project in Fortnox
|
151
|
-
attribute :project,
|
160
|
+
attribute :project, Fortnox::API::Types::Nullable::String
|
152
161
|
|
153
162
|
#SalesAccount Sales account of the customer, 4 digits
|
154
|
-
attribute :sales_account,
|
163
|
+
attribute :sales_account, Fortnox::API::Types::AccountNumber
|
155
164
|
|
156
165
|
#ShowPriceVATIncluded Show prices with VAT included or not
|
157
|
-
attribute :show_price_vat_included, Boolean
|
166
|
+
attribute :show_price_vat_included, Fortnox::API::Types::Nullable::Boolean
|
158
167
|
|
159
168
|
#TermsOfDeliveryCode Terms of delivery code of the customer
|
160
|
-
attribute :terms_of_delivery, String
|
169
|
+
attribute :terms_of_delivery, Fortnox::API::Types::Nullable::String
|
161
170
|
|
162
171
|
#TermsOfPaymentCode Terms of payment code of the customer
|
163
|
-
attribute :terms_of_payment, String
|
172
|
+
attribute :terms_of_payment, Fortnox::API::Types::Nullable::String
|
164
173
|
|
165
174
|
#Type Customer type, PRIVATE / COMPANY
|
166
|
-
attribute :type,
|
175
|
+
attribute :type, Fortnox::API::Types::CustomerType
|
167
176
|
|
168
177
|
#VATNumber VAT number of the customer
|
169
|
-
attribute :vat_number, String
|
178
|
+
attribute :vat_number, Fortnox::API::Types::Nullable::String
|
170
179
|
|
171
180
|
#VATType VAT type of the customer, SEVAT / SEREVERSEDVAT / EUREVERSEDVAT / EUVAT / EXPORT
|
172
|
-
attribute :vat_type,
|
181
|
+
attribute :vat_type, Fortnox::API::Types::VATType
|
173
182
|
|
174
|
-
#VisitAddress Visit address of the customer
|
175
|
-
attribute :visiting_address, String
|
183
|
+
#VisitAddress Visit address of the customer. 128 characters
|
184
|
+
attribute :visiting_address, Fortnox::API::Types::Sized::String[ 128 ]
|
176
185
|
|
177
|
-
#VisitCity Visit city of the customer
|
178
|
-
attribute :visiting_city, String
|
186
|
+
#VisitCity Visit city of the customer. 128 characters
|
187
|
+
attribute :visiting_city, Fortnox::API::Types::Sized::String[ 128 ]
|
179
188
|
|
180
|
-
#VisitCountry Visit country of the customer
|
181
|
-
attribute :visiting_country, String
|
189
|
+
#VisitCountry Visit country of the customer, read-only
|
190
|
+
attribute :visiting_country, Fortnox::API::Types::Nullable::String.with( read_only: true )
|
182
191
|
|
183
|
-
#
|
184
|
-
attribute :
|
192
|
+
#VisitingCountryCode Code of the visiting country for the customer, 2 letters
|
193
|
+
attribute :visiting_country_code, Fortnox::API::Types::CountryCode
|
185
194
|
|
186
|
-
#
|
187
|
-
attribute :
|
195
|
+
#VisitZipCode Visit zip code of the customer. 10 characters
|
196
|
+
attribute :visiting_zip_code, Fortnox::API::Types::Sized::String[ 10 ]
|
188
197
|
|
189
|
-
#
|
190
|
-
attribute :
|
198
|
+
#WayOfDeliveryCode Way of delivery code of the customer
|
199
|
+
attribute :way_of_delivery, Fortnox::API::Types::Nullable::String
|
191
200
|
|
192
|
-
#
|
193
|
-
attribute :
|
201
|
+
#YourReference Your reference of the customer. 50 characters
|
202
|
+
attribute :your_reference, Fortnox::API::Types::Sized::String[ 50 ]
|
194
203
|
|
204
|
+
#ZipCode Zip code of the customer. 10 characters
|
205
|
+
attribute :zip_code, Fortnox::API::Types::Sized::String[ 10 ]
|
195
206
|
end
|
196
207
|
end
|
197
208
|
end
|