fortnox-api 0.9.2 → 1.0.0.rc2
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/CHANGELOG.md +120 -95
- data/{LICENSE.txt → LICENSE.md} +0 -0
- data/README.md +245 -248
- data/bin/fortnox-setup +211 -0
- data/bin/fortnox-update-env +38 -0
- data/fortnox.gemspec +29 -0
- data/lib/fortnox/auth/thread_local.rb +28 -0
- data/lib/fortnox/collection.rb +23 -0
- data/lib/fortnox/mappers/country_code.rb +34 -0
- data/lib/fortnox/mappers/date.rb +21 -0
- data/lib/fortnox/mappers/document_row.rb +12 -0
- data/lib/fortnox/mappers/edi_information.rb +15 -0
- data/lib/fortnox/mappers/email_information.rb +11 -0
- data/lib/fortnox/mappers/invoice_row.rb +14 -0
- data/lib/fortnox/mappers/label_references.rb +24 -0
- data/lib/fortnox/mappers/order_row.rb +9 -0
- data/lib/fortnox/mappers/struct.rb +71 -0
- data/lib/fortnox/mappers/struct_array.rb +31 -0
- data/lib/fortnox/resource.rb +131 -0
- data/lib/fortnox/resources/article.rb +160 -0
- data/lib/fortnox/resources/customer.rb +209 -0
- data/lib/fortnox/resources/document.rb +202 -0
- data/lib/fortnox/resources/invoice.rb +92 -0
- data/lib/fortnox/resources/label.rb +15 -0
- data/lib/fortnox/resources/order.rb +38 -0
- data/lib/fortnox/resources/project.rb +41 -0
- data/lib/fortnox/resources/terms_of_payment.rb +23 -0
- data/lib/fortnox/resources/unit.rb +26 -0
- data/lib/fortnox/struct.rb +24 -0
- data/lib/fortnox/structs/default_delivery_types.rb +16 -0
- data/lib/fortnox/structs/default_templates.rb +19 -0
- data/lib/fortnox/structs/document_row.rb +62 -0
- data/lib/fortnox/structs/edi_information.rb +25 -0
- data/lib/fortnox/structs/email_information.rb +22 -0
- data/lib/fortnox/structs/invoice_row.rb +13 -0
- data/lib/fortnox/structs/order_row.rb +10 -0
- data/lib/fortnox/types.rb +129 -0
- data/lib/fortnox/{api/version.rb → version.rb} +1 -3
- data/lib/fortnox.rb +111 -0
- metadata +55 -580
- data/.codeclimate.yml +0 -20
- data/.env.template +0 -7
- data/.env.test +0 -11
- data/.gitignore +0 -20
- data/.rspec +0 -2
- data/.rubocop.yml +0 -41
- data/.tool-versions +0 -1
- data/.travis.yml +0 -32
- data/CLAUDE.md +0 -79
- data/CONTRIBUTE.md +0 -38
- data/DEVELOPER_README.md +0 -69
- data/Gemfile +0 -6
- data/Guardfile +0 -16
- data/Rakefile +0 -140
- data/bin/console +0 -22
- data/bin/fortnox +0 -285
- data/bin/get_tokens +0 -79
- data/bin/renew_tokens +0 -28
- data/docs/gotchas.md +0 -146
- data/fortnox-api.gemspec +0 -50
- data/lib/fortnox/api/mappers/article.rb +0 -23
- data/lib/fortnox/api/mappers/base/canonical_name_sym.rb +0 -21
- data/lib/fortnox/api/mappers/base/from_json.rb +0 -91
- data/lib/fortnox/api/mappers/base/to_json.rb +0 -66
- data/lib/fortnox/api/mappers/base.rb +0 -30
- data/lib/fortnox/api/mappers/customer.rb +0 -27
- data/lib/fortnox/api/mappers/default_delivery_types.rb +0 -15
- data/lib/fortnox/api/mappers/default_templates.rb +0 -16
- data/lib/fortnox/api/mappers/edi_information.rb +0 -23
- data/lib/fortnox/api/mappers/email_information.rb +0 -19
- data/lib/fortnox/api/mappers/invoice.rb +0 -29
- data/lib/fortnox/api/mappers/invoice_row.rb +0 -25
- data/lib/fortnox/api/mappers/order.rb +0 -26
- data/lib/fortnox/api/mappers/order_row.rb +0 -23
- data/lib/fortnox/api/mappers/project.rb +0 -17
- data/lib/fortnox/api/mappers/terms_of_payment.rb +0 -17
- data/lib/fortnox/api/mappers/unit.rb +0 -17
- data/lib/fortnox/api/mappers/value/array.rb +0 -18
- data/lib/fortnox/api/mappers/value/country_string.rb +0 -24
- data/lib/fortnox/api/mappers/value/date.rb +0 -11
- data/lib/fortnox/api/mappers/value/hash.rb +0 -16
- data/lib/fortnox/api/mappers/value/identity.rb +0 -18
- data/lib/fortnox/api/mappers.rb +0 -21
- data/lib/fortnox/api/models/article.rb +0 -134
- data/lib/fortnox/api/models/base.rb +0 -128
- data/lib/fortnox/api/models/customer.rb +0 -210
- data/lib/fortnox/api/models/document.rb +0 -189
- data/lib/fortnox/api/models/invoice.rb +0 -87
- data/lib/fortnox/api/models/label.rb +0 -19
- data/lib/fortnox/api/models/order.rb +0 -27
- data/lib/fortnox/api/models/project.rb +0 -42
- data/lib/fortnox/api/models/terms_of_payment.rb +0 -28
- data/lib/fortnox/api/models/unit.rb +0 -24
- data/lib/fortnox/api/models.rb +0 -9
- data/lib/fortnox/api/repositories/article.rb +0 -17
- data/lib/fortnox/api/repositories/authentication.rb +0 -61
- data/lib/fortnox/api/repositories/base/loaders.rb +0 -64
- data/lib/fortnox/api/repositories/base/savers.rb +0 -57
- data/lib/fortnox/api/repositories/base.rb +0 -93
- data/lib/fortnox/api/repositories/customer.rb +0 -17
- data/lib/fortnox/api/repositories/invoice.rb +0 -17
- data/lib/fortnox/api/repositories/order.rb +0 -17
- data/lib/fortnox/api/repositories/project.rb +0 -17
- data/lib/fortnox/api/repositories/terms_of_payment.rb +0 -17
- data/lib/fortnox/api/repositories/unit.rb +0 -17
- data/lib/fortnox/api/repositories.rb +0 -10
- data/lib/fortnox/api/request_handling.rb +0 -46
- data/lib/fortnox/api/types/default_delivery_types.rb +0 -20
- data/lib/fortnox/api/types/default_templates.rb +0 -23
- data/lib/fortnox/api/types/defaulted.rb +0 -11
- data/lib/fortnox/api/types/document_row.rb +0 -64
- data/lib/fortnox/api/types/edi_information.rb +0 -29
- data/lib/fortnox/api/types/email_information.rb +0 -26
- data/lib/fortnox/api/types/enums.rb +0 -116
- data/lib/fortnox/api/types/invoice_row.rb +0 -19
- data/lib/fortnox/api/types/model.rb +0 -37
- data/lib/fortnox/api/types/nullable.rb +0 -25
- data/lib/fortnox/api/types/order_row.rb +0 -16
- data/lib/fortnox/api/types/required.rb +0 -13
- data/lib/fortnox/api/types/shim/country_string.rb +0 -10
- data/lib/fortnox/api/types/sized.rb +0 -33
- data/lib/fortnox/api/types.rb +0 -144
- data/lib/fortnox/api.rb +0 -62
- data/spec/fortnox/api/mappers/article_spec.rb +0 -17
- data/spec/fortnox/api/mappers/base/canonical_name_sym_spec.rb +0 -36
- data/spec/fortnox/api/mappers/base/from_json_spec.rb +0 -70
- data/spec/fortnox/api/mappers/base/to_json_spec.rb +0 -68
- data/spec/fortnox/api/mappers/base_spec.rb +0 -154
- data/spec/fortnox/api/mappers/contexts/json_conversion.rb +0 -62
- data/spec/fortnox/api/mappers/customer_spec.rb +0 -27
- data/spec/fortnox/api/mappers/default_delivery_types_spec.rb +0 -14
- data/spec/fortnox/api/mappers/edi_information_spec.rb +0 -23
- data/spec/fortnox/api/mappers/email_information_spec.rb +0 -19
- data/spec/fortnox/api/mappers/examples/mapper.rb +0 -34
- data/spec/fortnox/api/mappers/invoice_row_spec.rb +0 -24
- data/spec/fortnox/api/mappers/invoice_spec.rb +0 -27
- data/spec/fortnox/api/mappers/order_row_spec.rb +0 -21
- data/spec/fortnox/api/mappers/order_spec.rb +0 -23
- data/spec/fortnox/api/mappers/project_spec.rb +0 -12
- data/spec/fortnox/api/mappers/terms_of_payment_spec.rb +0 -16
- data/spec/fortnox/api/mappers/unit_spec.rb +0 -56
- data/spec/fortnox/api/models/article_spec.rb +0 -9
- data/spec/fortnox/api/models/base_spec.rb +0 -117
- data/spec/fortnox/api/models/customer_spec.rb +0 -9
- data/spec/fortnox/api/models/examples/document_base.rb +0 -15
- data/spec/fortnox/api/models/examples/model.rb +0 -22
- data/spec/fortnox/api/models/invoice_spec.rb +0 -11
- data/spec/fortnox/api/models/order_spec.rb +0 -12
- data/spec/fortnox/api/models/project_spec.rb +0 -9
- data/spec/fortnox/api/models/terms_of_payment_spec.rb +0 -9
- data/spec/fortnox/api/models/unit_spec.rb +0 -33
- data/spec/fortnox/api/repositories/article_spec.rb +0 -80
- data/spec/fortnox/api/repositories/authentication_spec.rb +0 -103
- data/spec/fortnox/api/repositories/base_spec.rb +0 -168
- data/spec/fortnox/api/repositories/customer_spec.rb +0 -119
- data/spec/fortnox/api/repositories/examples/all.rb +0 -17
- data/spec/fortnox/api/repositories/examples/find.rb +0 -84
- data/spec/fortnox/api/repositories/examples/only.rb +0 -34
- data/spec/fortnox/api/repositories/examples/save.rb +0 -76
- data/spec/fortnox/api/repositories/examples/save_with_nested_model.rb +0 -28
- data/spec/fortnox/api/repositories/examples/save_with_specially_named_attribute.rb +0 -26
- data/spec/fortnox/api/repositories/examples/search.rb +0 -39
- data/spec/fortnox/api/repositories/invoice_spec.rb +0 -297
- data/spec/fortnox/api/repositories/order_spec.rb +0 -53
- data/spec/fortnox/api/repositories/project_spec.rb +0 -36
- data/spec/fortnox/api/repositories/terms_of_payment_spec.rb +0 -34
- data/spec/fortnox/api/repositories/unit_spec.rb +0 -39
- data/spec/fortnox/api/types/account_number_spec.rb +0 -35
- data/spec/fortnox/api/types/country_code_spec.rb +0 -42
- data/spec/fortnox/api/types/country_spec.rb +0 -67
- data/spec/fortnox/api/types/default_delivery_types_spec.rb +0 -12
- data/spec/fortnox/api/types/edi_information_spec.rb +0 -15
- data/spec/fortnox/api/types/email_information_spec.rb +0 -15
- data/spec/fortnox/api/types/email_spec.rb +0 -56
- data/spec/fortnox/api/types/enums_spec.rb +0 -17
- data/spec/fortnox/api/types/examples/document_row.rb +0 -25
- data/spec/fortnox/api/types/examples/enum.rb +0 -55
- data/spec/fortnox/api/types/examples/types.rb +0 -11
- data/spec/fortnox/api/types/housework_types_spec.rb +0 -149
- data/spec/fortnox/api/types/invoice_row_spec.rb +0 -11
- data/spec/fortnox/api/types/model_spec.rb +0 -69
- data/spec/fortnox/api/types/nullable_spec.rb +0 -79
- data/spec/fortnox/api/types/order_row_spec.rb +0 -15
- data/spec/fortnox/api/types/required_spec.rb +0 -36
- data/spec/fortnox/api/types/sales_account_spec.rb +0 -57
- data/spec/fortnox/api/types/sized_spec.rb +0 -76
- data/spec/fortnox/api_spec.rb +0 -66
- data/spec/spec_helper.rb +0 -35
- data/spec/support/helpers/configuration_helper.rb +0 -39
- data/spec/support/helpers/repository_helper.rb +0 -10
- data/spec/support/helpers.rb +0 -3
- data/spec/support/matchers/type/attribute_matcher.rb +0 -40
- data/spec/support/matchers/type/enum_matcher.rb +0 -23
- data/spec/support/matchers/type/have_account_number_matcher.rb +0 -23
- data/spec/support/matchers/type/have_currency_matcher.rb +0 -9
- data/spec/support/matchers/type/have_customer_type_matcher.rb +0 -15
- data/spec/support/matchers/type/have_default_delivery_type_matcher.rb +0 -9
- data/spec/support/matchers/type/have_discount_type_matcher.rb +0 -9
- data/spec/support/matchers/type/have_email_matcher.rb +0 -24
- data/spec/support/matchers/type/have_housework_type_matcher.rb +0 -9
- data/spec/support/matchers/type/have_nullable_date_matcher.rb +0 -60
- data/spec/support/matchers/type/have_nullable_matcher.rb +0 -54
- data/spec/support/matchers/type/have_nullable_string_matcher.rb +0 -47
- data/spec/support/matchers/type/have_sized_float_matcher.rb +0 -10
- data/spec/support/matchers/type/have_sized_integer_matcher.rb +0 -10
- data/spec/support/matchers/type/have_sized_string_matcher.rb +0 -36
- data/spec/support/matchers/type/have_vat_type_matcher.rb +0 -9
- data/spec/support/matchers/type/numeric_matcher.rb +0 -52
- data/spec/support/matchers/type/require_attribute_matcher.rb +0 -68
- data/spec/support/matchers/type/type_matcher.rb +0 -40
- data/spec/support/matchers/type.rb +0 -19
- data/spec/support/matchers.rb +0 -3
- data/spec/support/vcr_setup.rb +0 -25
- data/spec/vcr_cassettes/articles/all.yml +0 -67
- data/spec/vcr_cassettes/articles/find_by_hash_failure.yml +0 -62
- data/spec/vcr_cassettes/articles/find_failure.yml +0 -62
- data/spec/vcr_cassettes/articles/find_id_1.yml +0 -63
- data/spec/vcr_cassettes/articles/find_new.yml +0 -63
- data/spec/vcr_cassettes/articles/limits/quantity_in_stock_min_value.yml +0 -63
- data/spec/vcr_cassettes/articles/limits/quantity_in_stock_rounding_positive_value.yml +0 -63
- data/spec/vcr_cassettes/articles/multi_param_find_by_hash.yml +0 -62
- data/spec/vcr_cassettes/articles/save_new.yml +0 -63
- data/spec/vcr_cassettes/articles/save_old.yml +0 -63
- data/spec/vcr_cassettes/articles/save_with_specially_named_attribute.yml +0 -63
- data/spec/vcr_cassettes/articles/search_by_name.yml +0 -65
- data/spec/vcr_cassettes/articles/search_miss.yml +0 -62
- data/spec/vcr_cassettes/articles/search_with_special_char.yml +0 -62
- data/spec/vcr_cassettes/articles/single_param_find_by_hash.yml +0 -62
- data/spec/vcr_cassettes/authentication/expired_token.yml +0 -54
- data/spec/vcr_cassettes/authentication/invalid_authorization.yml +0 -57
- data/spec/vcr_cassettes/authentication/invalid_refresh_token.yml +0 -58
- data/spec/vcr_cassettes/authentication/valid_request.yml +0 -63
- data/spec/vcr_cassettes/customers/all.yml +0 -69
- data/spec/vcr_cassettes/customers/find_by_hash_failure.yml +0 -62
- data/spec/vcr_cassettes/customers/find_failure.yml +0 -62
- data/spec/vcr_cassettes/customers/find_id_1.yml +0 -64
- data/spec/vcr_cassettes/customers/find_new.yml +0 -63
- data/spec/vcr_cassettes/customers/find_with_sales_account.yml +0 -63
- data/spec/vcr_cassettes/customers/multi_param_find_by_hash.yml +0 -63
- data/spec/vcr_cassettes/customers/save_new.yml +0 -63
- data/spec/vcr_cassettes/customers/save_new_with_country_code_SE.yml +0 -64
- data/spec/vcr_cassettes/customers/save_new_with_idn_email.yml +0 -67
- data/spec/vcr_cassettes/customers/save_new_with_sales_account.yml +0 -63
- data/spec/vcr_cassettes/customers/save_old.yml +0 -63
- data/spec/vcr_cassettes/customers/save_with_specially_named_attribute.yml +0 -63
- data/spec/vcr_cassettes/customers/search_by_name.yml +0 -64
- data/spec/vcr_cassettes/customers/search_miss.yml +0 -62
- data/spec/vcr_cassettes/customers/search_with_special_char.yml +0 -62
- data/spec/vcr_cassettes/customers/single_param_find_by_hash.yml +0 -64
- data/spec/vcr_cassettes/invoices/all.yml +0 -96
- data/spec/vcr_cassettes/invoices/filter_hit.yml +0 -64
- data/spec/vcr_cassettes/invoices/filter_invalid.yml +0 -60
- data/spec/vcr_cassettes/invoices/find_by_hash_failure.yml +0 -62
- data/spec/vcr_cassettes/invoices/find_failure.yml +0 -62
- data/spec/vcr_cassettes/invoices/find_id_1.yml +0 -65
- data/spec/vcr_cassettes/invoices/find_new.yml +0 -65
- data/spec/vcr_cassettes/invoices/multi_param_find_by_hash.yml +0 -63
- data/spec/vcr_cassettes/invoices/row_delivered_quantity_decimals.yml +0 -65
- data/spec/vcr_cassettes/invoices/row_delivered_quantity_decimals_round_up.yml +0 -65
- data/spec/vcr_cassettes/invoices/row_description_limit.yml +0 -65
- data/spec/vcr_cassettes/invoices/row_price_limit.yml +0 -65
- data/spec/vcr_cassettes/invoices/row_price_limit_round_up.yml +0 -65
- data/spec/vcr_cassettes/invoices/save_new.yml +0 -65
- data/spec/vcr_cassettes/invoices/save_new_with_comments.yml +0 -65
- data/spec/vcr_cassettes/invoices/save_new_with_country.yml +0 -65
- data/spec/vcr_cassettes/invoices/save_new_with_country_GB.yml +0 -66
- data/spec/vcr_cassettes/invoices/save_new_with_country_Norge.yml +0 -65
- data/spec/vcr_cassettes/invoices/save_new_with_country_Norway.yml +0 -65
- data/spec/vcr_cassettes/invoices/save_new_with_country_Sverige.yml +0 -65
- data/spec/vcr_cassettes/invoices/save_new_with_country_VA.yml +0 -66
- data/spec/vcr_cassettes/invoices/save_new_with_country_VI.yml +0 -66
- data/spec/vcr_cassettes/invoices/save_new_with_country_empty_string.yml +0 -65
- data/spec/vcr_cassettes/invoices/save_new_with_country_nil.yml +0 -65
- data/spec/vcr_cassettes/invoices/save_new_with_unsaved_parent.yml +0 -65
- data/spec/vcr_cassettes/invoices/save_old.yml +0 -65
- data/spec/vcr_cassettes/invoices/save_old_with_empty_comments.yml +0 -65
- data/spec/vcr_cassettes/invoices/save_old_with_empty_country.yml +0 -65
- data/spec/vcr_cassettes/invoices/save_old_with_nil_comments.yml +0 -65
- data/spec/vcr_cassettes/invoices/save_old_with_nil_country.yml +0 -65
- data/spec/vcr_cassettes/invoices/save_with_nested_model.yml +0 -65
- data/spec/vcr_cassettes/invoices/save_with_specially_named_attribute.yml +0 -65
- data/spec/vcr_cassettes/invoices/search_by_name.yml +0 -63
- data/spec/vcr_cassettes/invoices/search_miss.yml +0 -62
- data/spec/vcr_cassettes/invoices/search_with_special_char.yml +0 -62
- data/spec/vcr_cassettes/invoices/single_param_find_by_hash.yml +0 -64
- data/spec/vcr_cassettes/orders/all.yml +0 -69
- data/spec/vcr_cassettes/orders/filter_hit.yml +0 -64
- data/spec/vcr_cassettes/orders/filter_invalid.yml +0 -60
- data/spec/vcr_cassettes/orders/find_by_hash_failure.yml +0 -62
- data/spec/vcr_cassettes/orders/find_failure.yml +0 -62
- data/spec/vcr_cassettes/orders/find_id_1.yml +0 -67
- data/spec/vcr_cassettes/orders/find_new.yml +0 -65
- data/spec/vcr_cassettes/orders/housework_invalid_tax_reduction_type.yml +0 -61
- data/spec/vcr_cassettes/orders/housework_othercoses_invalid.yml +0 -61
- data/spec/vcr_cassettes/orders/housework_type_babysitting.yml +0 -65
- data/spec/vcr_cassettes/orders/housework_type_cleaning.yml +0 -65
- data/spec/vcr_cassettes/orders/housework_type_construction.yml +0 -65
- data/spec/vcr_cassettes/orders/housework_type_cooking.yml +0 -61
- data/spec/vcr_cassettes/orders/housework_type_electricity.yml +0 -65
- data/spec/vcr_cassettes/orders/housework_type_gardening.yml +0 -65
- data/spec/vcr_cassettes/orders/housework_type_glassmetalwork.yml +0 -65
- data/spec/vcr_cassettes/orders/housework_type_grounddrainagework.yml +0 -65
- data/spec/vcr_cassettes/orders/housework_type_hvac.yml +0 -65
- data/spec/vcr_cassettes/orders/housework_type_itservices.yml +0 -65
- data/spec/vcr_cassettes/orders/housework_type_majorappliancerepair.yml +0 -65
- data/spec/vcr_cassettes/orders/housework_type_masonry.yml +0 -65
- data/spec/vcr_cassettes/orders/housework_type_movingservices.yml +0 -65
- data/spec/vcr_cassettes/orders/housework_type_othercare.yml +0 -65
- data/spec/vcr_cassettes/orders/housework_type_othercosts.yml +0 -65
- data/spec/vcr_cassettes/orders/housework_type_paintingwallpapering.yml +0 -65
- data/spec/vcr_cassettes/orders/housework_type_snowplowing.yml +0 -65
- data/spec/vcr_cassettes/orders/housework_type_textileclothing.yml +0 -65
- data/spec/vcr_cassettes/orders/housework_type_tutoring.yml +0 -61
- data/spec/vcr_cassettes/orders/multi_param_find_by_hash.yml +0 -63
- data/spec/vcr_cassettes/orders/save_new.yml +0 -65
- data/spec/vcr_cassettes/orders/save_old.yml +0 -65
- data/spec/vcr_cassettes/orders/save_with_nested_model.yml +0 -65
- data/spec/vcr_cassettes/orders/search_by_name.yml +0 -63
- data/spec/vcr_cassettes/orders/search_miss.yml +0 -62
- data/spec/vcr_cassettes/orders/search_with_special_char.yml +0 -62
- data/spec/vcr_cassettes/orders/single_param_find_by_hash.yml +0 -64
- data/spec/vcr_cassettes/projects/all.yml +0 -64
- data/spec/vcr_cassettes/projects/find_by_hash_failure.yml +0 -62
- data/spec/vcr_cassettes/projects/find_failure.yml +0 -62
- data/spec/vcr_cassettes/projects/find_id_1.yml +0 -63
- data/spec/vcr_cassettes/projects/find_new.yml +0 -63
- data/spec/vcr_cassettes/projects/multi_param_find_by_hash.yml +0 -64
- data/spec/vcr_cassettes/projects/save_new.yml +0 -63
- data/spec/vcr_cassettes/projects/save_old.yml +0 -63
- data/spec/vcr_cassettes/projects/single_param_find_by_hash.yml +0 -63
- data/spec/vcr_cassettes/termsofpayments/all.yml +0 -68
- data/spec/vcr_cassettes/termsofpayments/find_failure.yml +0 -62
- data/spec/vcr_cassettes/termsofpayments/find_id_1.yml +0 -62
- data/spec/vcr_cassettes/termsofpayments/find_new.yml +0 -63
- data/spec/vcr_cassettes/termsofpayments/save_new.yml +0 -63
- data/spec/vcr_cassettes/termsofpayments/save_old.yml +0 -63
- data/spec/vcr_cassettes/units/all.yml +0 -64
- data/spec/vcr_cassettes/units/find_failure.yml +0 -62
- data/spec/vcr_cassettes/units/find_id_1.yml +0 -63
- data/spec/vcr_cassettes/units/find_new.yml +0 -63
- data/spec/vcr_cassettes/units/save_new.yml +0 -63
- data/spec/vcr_cassettes/units/save_old.yml +0 -63
- data/spec/vcr_cassettes/units/save_with_specially_named_attribute.yml +0 -63
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module Fortnox
|
|
4
|
-
module API
|
|
5
|
-
module RequestHandling
|
|
6
|
-
private
|
|
7
|
-
|
|
8
|
-
def raise_api_error(error, response)
|
|
9
|
-
message = (error['message'] || error['Message'] || 'Okänt fel')
|
|
10
|
-
|
|
11
|
-
message += "\n\n#{response.request.inspect}" if Fortnox::API.debugging
|
|
12
|
-
|
|
13
|
-
raise Fortnox::API::RemoteServerError, message
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
def validate_response(response)
|
|
17
|
-
return if response.code == 200
|
|
18
|
-
|
|
19
|
-
raise_content_type_error(response) if response.headers['content-type'].start_with?('text/html')
|
|
20
|
-
|
|
21
|
-
raise Fortnox::API::RemoteServerError, "Unauthorized request. Error: #{response.body}" if response.code == 401
|
|
22
|
-
raise Fortnox::API::RemoteServerError, "Forbidden request. Error: #{response.body}" if response.code == 403
|
|
23
|
-
|
|
24
|
-
api_error = response.parsed_response['ErrorInformation']
|
|
25
|
-
raise_api_error(api_error, response) if api_error
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
def raise_content_type_error(response)
|
|
29
|
-
raise Fortnox::API::RemoteServerError,
|
|
30
|
-
"Fortnox API's response has content type \"text/html\" instead of requested \"application/json\"." \
|
|
31
|
-
'This could be due to invalid endpoint or when the API is down. ' \
|
|
32
|
-
"Body: #{response.body}"
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
def validate_and_parse(response)
|
|
36
|
-
validate_response(response)
|
|
37
|
-
response.parsed_response
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
def execute
|
|
41
|
-
response = yield(self.class)
|
|
42
|
-
validate_and_parse response
|
|
43
|
-
end
|
|
44
|
-
end
|
|
45
|
-
end
|
|
46
|
-
end
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module Fortnox
|
|
4
|
-
module API
|
|
5
|
-
module Types
|
|
6
|
-
class DefaultDeliveryTypes < Types::Model
|
|
7
|
-
STUB = {}.freeze
|
|
8
|
-
|
|
9
|
-
# Default delivery type for invoices. Can be PRINT EMAIL or PRINTSERVICE.
|
|
10
|
-
attribute :invoice, Types::DefaultDeliveryType
|
|
11
|
-
|
|
12
|
-
# Default delivery type for orders. Can be PRINT EMAIL or PRINTSERVICE.
|
|
13
|
-
attribute :order, Types::DefaultDeliveryType
|
|
14
|
-
|
|
15
|
-
# Default delivery type for offers. Can be PRINT EMAIL or PRINTSERVICE.
|
|
16
|
-
attribute :offer, Types::DefaultDeliveryType
|
|
17
|
-
end
|
|
18
|
-
end
|
|
19
|
-
end
|
|
20
|
-
end
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module Fortnox
|
|
4
|
-
module API
|
|
5
|
-
module Types
|
|
6
|
-
class DefaultTemplates < Types::Model
|
|
7
|
-
STUB = {}.freeze
|
|
8
|
-
|
|
9
|
-
# Default template for orders. Must be a name of an existing print template.
|
|
10
|
-
attribute :order, Types::Required::String
|
|
11
|
-
|
|
12
|
-
# Default template for offers. Must be a name of an existing print template.
|
|
13
|
-
attribute :offer, Types::Required::String
|
|
14
|
-
|
|
15
|
-
# Default template for invoices. Must be a name of an existing print template.
|
|
16
|
-
attribute :invoice, Types::Required::String
|
|
17
|
-
|
|
18
|
-
# Default template for cash invoices. Must be a name of an existing print template.
|
|
19
|
-
attribute :cash_invoice, Types::Required::String
|
|
20
|
-
end
|
|
21
|
-
end
|
|
22
|
-
end
|
|
23
|
-
end
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module Fortnox
|
|
4
|
-
module API
|
|
5
|
-
module Types
|
|
6
|
-
class DocumentRow < Fortnox::API::Types::Model
|
|
7
|
-
# AccountNumber Account number. 4 digits
|
|
8
|
-
attribute :account_number, Types::AccountNumber
|
|
9
|
-
|
|
10
|
-
# ArticleNumber Article number. 50 characters
|
|
11
|
-
attribute :article_number, Types::Sized::String[50]
|
|
12
|
-
|
|
13
|
-
# ContributionPercent Contribution Percent.
|
|
14
|
-
attribute :contribution_percent, Types::Nullable::Float.with(private: true)
|
|
15
|
-
|
|
16
|
-
# ContributionValue Contribution Value.
|
|
17
|
-
attribute :contribution_value, Types::Nullable::Float.with(private: true)
|
|
18
|
-
|
|
19
|
-
# CostCenter Code of the cost center for the row.
|
|
20
|
-
attribute :cost_center, Types::Nullable::String
|
|
21
|
-
|
|
22
|
-
# DeliveredQuantity Delivered quantity. 14 digits
|
|
23
|
-
attribute :delivered_quantity, Types::Sized::Float[-9_999_999_999_999.9, 9_999_999_999_999.9]
|
|
24
|
-
|
|
25
|
-
# Description Description Row description.
|
|
26
|
-
attribute :description, Types::Sized::String[255]
|
|
27
|
-
|
|
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
|
-
|
|
34
|
-
# DiscountType The type of discount used for the row.
|
|
35
|
-
attribute :discount_type, Types::DiscountType
|
|
36
|
-
|
|
37
|
-
# HouseWork If the row is housework
|
|
38
|
-
attribute :housework, Types::Nullable::Boolean
|
|
39
|
-
|
|
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]
|
|
43
|
-
|
|
44
|
-
# HouseWorkType The type of housework.
|
|
45
|
-
attribute :housework_type, Types::HouseworkType
|
|
46
|
-
|
|
47
|
-
# Price Price per unit. 12 digits
|
|
48
|
-
attribute :price, Types::Sized::Float[-9_999_999_999, 99_999_999_999.9]
|
|
49
|
-
|
|
50
|
-
# Project Code of the project for the row.
|
|
51
|
-
attribute :project, Types::Nullable::String
|
|
52
|
-
|
|
53
|
-
# Total Total amount for the row.
|
|
54
|
-
attribute :total, Types::Nullable::Float.with(private: true)
|
|
55
|
-
|
|
56
|
-
# Unit Code of the unit for the row.
|
|
57
|
-
attribute :unit, Types::Nullable::String
|
|
58
|
-
|
|
59
|
-
# VAT VAT percentage of the row.
|
|
60
|
-
attribute :vat, Types::Nullable::Integer
|
|
61
|
-
end
|
|
62
|
-
end
|
|
63
|
-
end
|
|
64
|
-
end
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module Fortnox
|
|
4
|
-
module API
|
|
5
|
-
module Types
|
|
6
|
-
class EDIInformation < Types::Model
|
|
7
|
-
STUB = {}.freeze
|
|
8
|
-
|
|
9
|
-
# EDIGlobalLocationNumber Invoice address GLN for EDI
|
|
10
|
-
attribute :edi_global_location_number, Types::Nullable::String
|
|
11
|
-
|
|
12
|
-
# EDIGlobalLocationNumberDelivery Delivery address GLN for EDI
|
|
13
|
-
attribute :edi_global_location_number_delivery, Types::Nullable::String
|
|
14
|
-
|
|
15
|
-
# EDIInvoiceExtra1 Extra EDI Information
|
|
16
|
-
attribute :edi_invoice_extra1, Types::Nullable::String
|
|
17
|
-
|
|
18
|
-
# EDIInvoiceExtra2 Extra EDI Information
|
|
19
|
-
attribute :edi_invoice_extra2, Types::Nullable::String
|
|
20
|
-
|
|
21
|
-
# EDIOurElectronicReference Our electronic reference for EDI
|
|
22
|
-
attribute :edi_our_electronic_reference, Types::Nullable::String
|
|
23
|
-
|
|
24
|
-
# EDIYourElectronicReference Your electronic reference for EDI
|
|
25
|
-
attribute :edi_your_electronic_reference, Types::Nullable::String
|
|
26
|
-
end
|
|
27
|
-
end
|
|
28
|
-
end
|
|
29
|
-
end
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module Fortnox
|
|
4
|
-
module API
|
|
5
|
-
module Types
|
|
6
|
-
class EmailInformation < Types::Model
|
|
7
|
-
STUB = {}.freeze
|
|
8
|
-
|
|
9
|
-
# EmailAddressTo Customer e-mail address. Must be a valid e-mail address. 1024 characters
|
|
10
|
-
attribute :email_address_to, Types::Email
|
|
11
|
-
|
|
12
|
-
# EmailAddressCC Customer e-mail address, Carbon copy. Must be a valid e-mail address. 1024 characters
|
|
13
|
-
attribute :email_address_cc, Types::Email
|
|
14
|
-
|
|
15
|
-
# EmailAddressBCC Customer e-mail address, Blind carbon copy. Must be a valid e-mail address. 1024 characters
|
|
16
|
-
attribute :email_address_bcc, Types::Email
|
|
17
|
-
|
|
18
|
-
# EmailSubject Subject of the e-mail, 100 characters.
|
|
19
|
-
attribute :email_subject, Types::Sized::String[100]
|
|
20
|
-
|
|
21
|
-
# EmailBody Body of the e-mail, 20000 characters.
|
|
22
|
-
attribute :email_body, Types::Sized::String[20_000]
|
|
23
|
-
end
|
|
24
|
-
end
|
|
25
|
-
end
|
|
26
|
-
end
|
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module Fortnox
|
|
4
|
-
module API
|
|
5
|
-
module Types
|
|
6
|
-
module EnumConstructors
|
|
7
|
-
def self.sized(size)
|
|
8
|
-
lambda do |value|
|
|
9
|
-
return nil if value == ''
|
|
10
|
-
|
|
11
|
-
value.to_s.upcase[0...size] unless value.nil?
|
|
12
|
-
end
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
def self.default
|
|
16
|
-
lambda do |value|
|
|
17
|
-
return nil if value == ''
|
|
18
|
-
|
|
19
|
-
value&.to_s&.upcase
|
|
20
|
-
end
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
def self.lower_case
|
|
24
|
-
lambda do |value|
|
|
25
|
-
return nil if value == ''
|
|
26
|
-
|
|
27
|
-
value&.to_s&.downcase
|
|
28
|
-
end
|
|
29
|
-
end
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
ArticleTypes = Types::Strict::String.enum(
|
|
33
|
-
'SERVICE', 'STOCK'
|
|
34
|
-
)
|
|
35
|
-
DiscountTypes = Types::Strict::String.enum(
|
|
36
|
-
'AMOUNT', 'PERCENT'
|
|
37
|
-
)
|
|
38
|
-
HOUSEWORK_TYPES = {
|
|
39
|
-
rot: [
|
|
40
|
-
'CONSTRUCTION',
|
|
41
|
-
'ELECTRICITY',
|
|
42
|
-
'GLASSMETALWORK',
|
|
43
|
-
'GROUNDDRAINAGEWORK',
|
|
44
|
-
'HVAC',
|
|
45
|
-
'MASONRY',
|
|
46
|
-
'OTHERCOSTS',
|
|
47
|
-
'PAINTINGWALLPAPERING'
|
|
48
|
-
],
|
|
49
|
-
rut: [
|
|
50
|
-
'BABYSITTING',
|
|
51
|
-
'CLEANING',
|
|
52
|
-
'GARDENING',
|
|
53
|
-
'ITSERVICES',
|
|
54
|
-
'MAJORAPPLIANCEREPAIR',
|
|
55
|
-
'MOVINGSERVICES',
|
|
56
|
-
'OTHERCARE',
|
|
57
|
-
'OTHERCOSTS',
|
|
58
|
-
'SNOWPLOWING',
|
|
59
|
-
'TEXTILECLOTHING'
|
|
60
|
-
],
|
|
61
|
-
legacy_rut: ['COOKING', 'TUTORING']
|
|
62
|
-
}.freeze
|
|
63
|
-
|
|
64
|
-
# TODO: RUT to be added:
|
|
65
|
-
# HOMEMAINTENANCE FURNISHING TRANSPORTATIONSERVICES
|
|
66
|
-
# WASHINGANDCAREOFCLOTHING
|
|
67
|
-
#
|
|
68
|
-
# TODO: GREEN to be added:
|
|
69
|
-
# SOLARCELLS STORAGESELFPRODUCEDELECTRICTY
|
|
70
|
-
# CHARGINGSTATIONELECTRICVEHICLE OTHERCOSTS
|
|
71
|
-
|
|
72
|
-
HouseworkTypes = Types::Strict::String.enum(
|
|
73
|
-
*(HOUSEWORK_TYPES[:rot] +
|
|
74
|
-
HOUSEWORK_TYPES[:rut] +
|
|
75
|
-
HOUSEWORK_TYPES[:legacy_rut]).uniq
|
|
76
|
-
)
|
|
77
|
-
Currencies = Types::Strict::String.enum(
|
|
78
|
-
'AED', 'AFN', 'ALL', 'AMD', 'ANG', 'AOA', 'ARS', 'AUD', 'AWG', 'AZN',
|
|
79
|
-
'BAM', 'BBD', 'BDT', 'BGN', 'BHD', 'BIF', 'BMD', 'BND', 'BOB', 'BOV',
|
|
80
|
-
'BRL', 'BSD', 'BTN', 'BWP', 'BYR', 'BZD', 'CAD', 'CDF', 'CHE', 'CHF',
|
|
81
|
-
'CHW', 'CLF', 'CLP', 'CNY', 'COP', 'COU', 'CRC', 'CUP', 'CVE', 'CZK',
|
|
82
|
-
'DJF', 'DKK', 'DOP', 'DZD', 'EGP', 'ERN', 'ETB', 'EUR', 'FJD', 'FKP',
|
|
83
|
-
'GBP', 'GEL', 'GHS', 'GIP', 'GMD', 'GNF', 'GTQ', 'GYD', 'HKD', 'HNL',
|
|
84
|
-
'HRK', 'HTG', 'HUF', 'IDR', 'ILS', 'INR', 'IQD', 'IRR', 'ISK', 'JMD',
|
|
85
|
-
'JOD', 'JPY', 'KES', 'KGS', 'KHR', 'KUR', 'KMF', 'KPW', 'KRW', 'KWD',
|
|
86
|
-
'KYD', 'KZT', 'LAK', 'LBP', 'LKR', 'LRD', 'LSL', 'LYD', 'MAD', 'MDL',
|
|
87
|
-
'MGA', 'MKD', 'MMK', 'MNT', 'MOP', 'MRO', 'MUR', 'MVR', 'MWK', 'MXN',
|
|
88
|
-
'MXV', 'MYR', 'MZN', 'NAD', 'NGN', 'NIO', 'NOK', 'NPR', 'NZD', 'OMR',
|
|
89
|
-
'PAB', 'PEN', 'PGK', 'PHP', 'PKR', 'PLN', 'PYG', 'QAR', 'RON', 'RSD',
|
|
90
|
-
'RUB', 'RWF', 'SAR', 'SBD', 'SCR', 'SDG', 'SEK', 'SGD', 'SHP', 'SLL',
|
|
91
|
-
'SOS', 'SRD', 'SSP', 'STD', 'SYP', 'SZL', 'THB', 'TJS', 'TMM', 'TND',
|
|
92
|
-
'TOP', 'TRY', 'TTD', 'TWD', 'TZS', 'UAH', 'UGX', 'USD', 'USN', 'USS',
|
|
93
|
-
'UYU', 'UZS', 'VEF', 'VND', 'VUV', 'WST', 'XAF', 'XAG', 'XAU', 'XBA',
|
|
94
|
-
'XBB', 'XBC', 'XBD', 'XCD', 'XDR', 'XFU', 'XOF', 'XPD', 'XPF', 'XPT',
|
|
95
|
-
'XTS', 'XXX', 'YER', 'ZAR', 'ZMK', 'ZWD'
|
|
96
|
-
)
|
|
97
|
-
CustomerTypes = Types::Strict::String.enum(
|
|
98
|
-
'PRIVATE', 'COMPANY'
|
|
99
|
-
)
|
|
100
|
-
VATTypes = Types::Strict::String.enum(
|
|
101
|
-
'SEVAT', 'SEREVERSEDVAT', 'EUREVERSEDVAT', 'EUVAT', 'EXPORT'
|
|
102
|
-
)
|
|
103
|
-
DefaultDeliveryTypeValues = Types::Strict::String.enum(
|
|
104
|
-
'PRINT', 'EMAIL', 'PRINTSERVICE', 'ELECTRONICINVOICE'
|
|
105
|
-
)
|
|
106
|
-
ProjectStatusTypes = Types::Strict::String.enum(
|
|
107
|
-
'NOTSTARTED', 'ONGOING', 'COMPLETED'
|
|
108
|
-
)
|
|
109
|
-
# NOTE: Yes, these needs to be in lower case...
|
|
110
|
-
# I know, this is stupid... Fortnox: why?!
|
|
111
|
-
TaxReductionTypes = Types::Strict::String.enum(
|
|
112
|
-
'rot', 'rut', 'green', 'none'
|
|
113
|
-
)
|
|
114
|
-
end
|
|
115
|
-
end
|
|
116
|
-
end
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require_relative 'document_row'
|
|
4
|
-
|
|
5
|
-
module Fortnox
|
|
6
|
-
module API
|
|
7
|
-
module Types
|
|
8
|
-
class InvoiceRow < DocumentRow
|
|
9
|
-
STUB = {}.freeze
|
|
10
|
-
|
|
11
|
-
# PriceExcludingVAT Price per unit excluding VAT.
|
|
12
|
-
attribute :price_excluding_vat, Types::Nullable::Float.with(private: true)
|
|
13
|
-
|
|
14
|
-
# TotalExcludingVAT Total amount for the row excluding VAT.
|
|
15
|
-
attribute :total_excluding_vat, Types::Nullable::Float.with(private: true)
|
|
16
|
-
end
|
|
17
|
-
end
|
|
18
|
-
end
|
|
19
|
-
end
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module Fortnox
|
|
4
|
-
module API
|
|
5
|
-
module Types
|
|
6
|
-
class Model < Dry::Struct
|
|
7
|
-
transform_types(&:omittable)
|
|
8
|
-
transform_keys(&:to_sym)
|
|
9
|
-
|
|
10
|
-
def initialize(input_attributes)
|
|
11
|
-
if (missing_key = first_missing_required_key(input_attributes))
|
|
12
|
-
error_message = "Missing attribute #{missing_key.inspect} in attributes: #{input_attributes}"
|
|
13
|
-
raise Fortnox::API::MissingAttributeError, error_message
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
super
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
private
|
|
20
|
-
|
|
21
|
-
def missing_keys(attributes)
|
|
22
|
-
attribute_keys = attributes.compact.keys
|
|
23
|
-
schema_keys = self.class.schema.keys.map(&:name)
|
|
24
|
-
|
|
25
|
-
schema_keys - attribute_keys
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
def first_missing_required_key(attributes)
|
|
29
|
-
missing_keys(attributes).find do |name|
|
|
30
|
-
attribute = self.class.schema.keys.find { |key| key.name == name }
|
|
31
|
-
attribute.type.respond_to?(:options) && attribute.type.options[:required]
|
|
32
|
-
end
|
|
33
|
-
end
|
|
34
|
-
end
|
|
35
|
-
end
|
|
36
|
-
end
|
|
37
|
-
end
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require 'date'
|
|
4
|
-
|
|
5
|
-
module Fortnox
|
|
6
|
-
module API
|
|
7
|
-
module Types
|
|
8
|
-
module Nullable
|
|
9
|
-
String = Types::Strict::String.optional.constructor { |value| value&.to_s }
|
|
10
|
-
Float = Types::Strict::Float.optional.constructor { |value| value&.to_f }
|
|
11
|
-
Integer = Types::Strict::Integer.optional.constructor { |value| value&.to_i }
|
|
12
|
-
Boolean = Types::Bool.optional.constructor { |value| THE_TRUTH.fetch(value, false) }
|
|
13
|
-
Date = Types::Date.optional.constructor do |value|
|
|
14
|
-
next if value.nil? || value == ''
|
|
15
|
-
|
|
16
|
-
begin
|
|
17
|
-
::Date.parse(value.to_s)
|
|
18
|
-
rescue ::Date::Error
|
|
19
|
-
raise Fortnox::API::AttributeError, 'invalid date'
|
|
20
|
-
end
|
|
21
|
-
end
|
|
22
|
-
end
|
|
23
|
-
end
|
|
24
|
-
end
|
|
25
|
-
end
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require_relative 'document_row'
|
|
4
|
-
|
|
5
|
-
module Fortnox
|
|
6
|
-
module API
|
|
7
|
-
module Types
|
|
8
|
-
class OrderRow < DocumentRow
|
|
9
|
-
STUB = { ordered_quantity: 0 }.freeze
|
|
10
|
-
|
|
11
|
-
# OrderedQuantity Ordered quantity
|
|
12
|
-
attribute :ordered_quantity, Types::Required::Float
|
|
13
|
-
end
|
|
14
|
-
end
|
|
15
|
-
end
|
|
16
|
-
end
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module Fortnox
|
|
4
|
-
module API
|
|
5
|
-
module Types
|
|
6
|
-
module Required
|
|
7
|
-
String = Types::Strict::String.constructor { |value| value&.to_s }.is(:required)
|
|
8
|
-
Integer = Types::Strict::Integer.constructor { |value| value&.to_i }.is(:required)
|
|
9
|
-
Float = Types::Strict::Float.constructor { |value| value&.to_f }.is(:required)
|
|
10
|
-
end
|
|
11
|
-
end
|
|
12
|
-
end
|
|
13
|
-
end
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module Fortnox
|
|
4
|
-
module API
|
|
5
|
-
module Types
|
|
6
|
-
module Sized
|
|
7
|
-
module String
|
|
8
|
-
def self.[](size)
|
|
9
|
-
Types::Strict::String.constrained(max_size: size).optional.constructor do |value|
|
|
10
|
-
value&.to_s
|
|
11
|
-
end
|
|
12
|
-
end
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
module Integer
|
|
16
|
-
def self.[](low, high)
|
|
17
|
-
Types::Strict::Integer.constrained(gteq: low, lteq: high).optional.constructor do |value|
|
|
18
|
-
value&.to_i
|
|
19
|
-
end
|
|
20
|
-
end
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
module Float
|
|
24
|
-
def self.[](low, high)
|
|
25
|
-
Types::Strict::Float.constrained(gteq: low, lteq: high).optional.constructor do |value|
|
|
26
|
-
value&.to_f
|
|
27
|
-
end
|
|
28
|
-
end
|
|
29
|
-
end
|
|
30
|
-
end
|
|
31
|
-
end
|
|
32
|
-
end
|
|
33
|
-
end
|
data/lib/fortnox/api/types.rb
DELETED
|
@@ -1,144 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require 'dry-struct'
|
|
4
|
-
require 'dry-types'
|
|
5
|
-
require 'countries'
|
|
6
|
-
require_relative 'types/shim/country_string'
|
|
7
|
-
|
|
8
|
-
module Dry
|
|
9
|
-
module Types
|
|
10
|
-
module Options
|
|
11
|
-
def is(*option_names)
|
|
12
|
-
new_options = option_names.each_with_object({}) do |name, hash|
|
|
13
|
-
hash[name] = true
|
|
14
|
-
end
|
|
15
|
-
with(**new_options)
|
|
16
|
-
end
|
|
17
|
-
end
|
|
18
|
-
end
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
module Fortnox
|
|
22
|
-
module API
|
|
23
|
-
module Types
|
|
24
|
-
include Dry.Types(default: :nominal)
|
|
25
|
-
ISO3166.configure { |config| config.locales = %i[en sv] }
|
|
26
|
-
|
|
27
|
-
THE_TRUTH = { true => true, 'true' => true, false => false, 'false' => false }.freeze
|
|
28
|
-
|
|
29
|
-
require_relative 'types/required'
|
|
30
|
-
require_relative 'types/defaulted'
|
|
31
|
-
require_relative 'types/nullable'
|
|
32
|
-
|
|
33
|
-
require_relative 'types/enums'
|
|
34
|
-
require_relative 'types/sized'
|
|
35
|
-
|
|
36
|
-
AccountNumber = Strict::Integer
|
|
37
|
-
.constrained(gteq: 0, lteq: 9999)
|
|
38
|
-
.optional
|
|
39
|
-
.constructor do |value|
|
|
40
|
-
next nil if value.nil? || value == ''
|
|
41
|
-
|
|
42
|
-
value
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
ArticleType = Strict::String
|
|
46
|
-
.constrained(included_in: ArticleTypes.values)
|
|
47
|
-
.optional
|
|
48
|
-
.constructor(EnumConstructors.default)
|
|
49
|
-
|
|
50
|
-
Country = Strict::String
|
|
51
|
-
.optional
|
|
52
|
-
.constructor do |value|
|
|
53
|
-
next value if value.nil? || value == ''
|
|
54
|
-
|
|
55
|
-
# Fortnox only supports Swedish translation of Sweden
|
|
56
|
-
next CountryString.new('SE') if value.match?(/^s(e$|we|ve)/i)
|
|
57
|
-
|
|
58
|
-
country = ::ISO3166::Country[value] ||
|
|
59
|
-
::ISO3166::Country.find_country_by_any_name(value) ||
|
|
60
|
-
::ISO3166::Country.find_country_by_translated_names(value)
|
|
61
|
-
|
|
62
|
-
raise Dry::Types::ConstraintError.new('value violates constraints', value) if country.nil?
|
|
63
|
-
|
|
64
|
-
CountryString.new(country.alpha2)
|
|
65
|
-
end
|
|
66
|
-
|
|
67
|
-
CountryCode = Strict::String
|
|
68
|
-
.optional
|
|
69
|
-
.constructor do |value|
|
|
70
|
-
next value if value.nil? || value == ''
|
|
71
|
-
|
|
72
|
-
country = ::ISO3166::Country[value]
|
|
73
|
-
|
|
74
|
-
raise Dry::Types::ConstraintError.new('value violates constraints', value) if country.nil?
|
|
75
|
-
|
|
76
|
-
country.alpha2
|
|
77
|
-
end
|
|
78
|
-
|
|
79
|
-
Currency = Strict::String
|
|
80
|
-
.constrained(included_in: Currencies.values)
|
|
81
|
-
.optional
|
|
82
|
-
.constructor(EnumConstructors.sized(3))
|
|
83
|
-
CustomerType = Strict::String
|
|
84
|
-
.constrained(included_in: CustomerTypes.values)
|
|
85
|
-
.optional
|
|
86
|
-
.constructor(EnumConstructors.default)
|
|
87
|
-
|
|
88
|
-
DiscountType = Strict::String
|
|
89
|
-
.constrained(included_in: DiscountTypes.values)
|
|
90
|
-
.optional
|
|
91
|
-
.constructor(EnumConstructors.default)
|
|
92
|
-
|
|
93
|
-
Email = Strict::String
|
|
94
|
-
.constrained(max_size: 1024, format: /^$|\A[[[:alnum:]]._+-]+@[[[:alnum:]]._-]+\.[a-z]+\z/i)
|
|
95
|
-
.optional
|
|
96
|
-
.constructor { |v| v&.to_s&.downcase }
|
|
97
|
-
|
|
98
|
-
HouseworkType = Strict::String
|
|
99
|
-
.constrained(included_in: HouseworkTypes.values)
|
|
100
|
-
.optional
|
|
101
|
-
.constructor(EnumConstructors.default)
|
|
102
|
-
|
|
103
|
-
VATType = Strict::String
|
|
104
|
-
.constrained(included_in: VATTypes.values)
|
|
105
|
-
.optional
|
|
106
|
-
.constructor(EnumConstructors.default)
|
|
107
|
-
|
|
108
|
-
DefaultDeliveryType = Strict::String
|
|
109
|
-
.constrained(included_in: DefaultDeliveryTypeValues.values)
|
|
110
|
-
.optional
|
|
111
|
-
.constructor(EnumConstructors.default)
|
|
112
|
-
|
|
113
|
-
ProjectStatusType = Strict::String
|
|
114
|
-
.constrained(included_in: ProjectStatusTypes.values)
|
|
115
|
-
.optional
|
|
116
|
-
.constructor(EnumConstructors.default)
|
|
117
|
-
|
|
118
|
-
TaxReductionType = Strict::String
|
|
119
|
-
.constrained(included_in: TaxReductionTypes.values)
|
|
120
|
-
.optional
|
|
121
|
-
.constructor(EnumConstructors.lower_case)
|
|
122
|
-
|
|
123
|
-
# Some Fortnox endpoints returns a String and some returns an Integer...
|
|
124
|
-
# The documentation says it should be a string, so let's keep it as a string.
|
|
125
|
-
SalesAccount = Strict::String
|
|
126
|
-
.constrained(format: /^[0-9]{4}$/)
|
|
127
|
-
.optional
|
|
128
|
-
.constructor do |value|
|
|
129
|
-
next nil if value == '' || value.nil?
|
|
130
|
-
next value.to_s if value.is_a?(::Integer)
|
|
131
|
-
|
|
132
|
-
value
|
|
133
|
-
end
|
|
134
|
-
|
|
135
|
-
require_relative 'types/model'
|
|
136
|
-
require_relative 'types/default_delivery_types'
|
|
137
|
-
require_relative 'types/default_templates'
|
|
138
|
-
require_relative 'types/email_information'
|
|
139
|
-
require_relative 'types/edi_information'
|
|
140
|
-
require_relative 'types/invoice_row'
|
|
141
|
-
require_relative 'types/order_row'
|
|
142
|
-
end
|
|
143
|
-
end
|
|
144
|
-
end
|