fortnox-api 0.7.2 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.codeclimate.yml +1 -0
- data/.env.template +7 -0
- data/.env.test +11 -3
- data/.gitignore +7 -1
- data/.rubocop.yml +18 -2
- data/.tool-versions +1 -0
- data/.travis.yml +15 -19
- data/CHANGELOG.md +66 -1
- data/CONTRIBUTE.md +21 -9
- data/DEVELOPER_README.md +72 -0
- data/Guardfile +13 -4
- data/README.md +226 -61
- data/Rakefile +133 -0
- data/bin/get_tokens +79 -0
- data/bin/renew_tokens +28 -0
- data/fortnox-api.gemspec +31 -25
- data/lib/fortnox/api/mappers/article.rb +1 -1
- data/lib/fortnox/api/mappers/base/from_json.rb +7 -6
- data/lib/fortnox/api/mappers/base/to_json.rb +4 -5
- data/lib/fortnox/api/mappers/base.rb +3 -3
- data/lib/fortnox/api/mappers/customer.rb +1 -1
- data/lib/fortnox/api/mappers/default_delivery_types.rb +1 -1
- data/lib/fortnox/api/mappers/default_templates.rb +1 -1
- data/lib/fortnox/api/mappers/edi_information.rb +1 -1
- data/lib/fortnox/api/mappers/email_information.rb +1 -1
- data/lib/fortnox/api/mappers/invoice.rb +4 -4
- data/lib/fortnox/api/mappers/invoice_row.rb +1 -1
- data/lib/fortnox/api/mappers/order.rb +4 -4
- data/lib/fortnox/api/mappers/order_row.rb +1 -1
- data/lib/fortnox/api/mappers/project.rb +1 -1
- data/lib/fortnox/api/mappers/terms_of_payment.rb +1 -1
- data/lib/fortnox/api/mappers/unit.rb +1 -1
- data/lib/fortnox/api/mappers/value/country_string.rb +1 -1
- data/lib/fortnox/api/mappers.rb +18 -18
- data/lib/fortnox/api/models/article.rb +2 -2
- data/lib/fortnox/api/models/base.rb +23 -21
- data/lib/fortnox/api/models/customer.rb +57 -57
- data/lib/fortnox/api/models/document.rb +5 -2
- data/lib/fortnox/api/models/invoice.rb +2 -2
- data/lib/fortnox/api/models/label.rb +3 -3
- data/lib/fortnox/api/models/order.rb +2 -2
- data/lib/fortnox/api/models/project.rb +2 -2
- data/lib/fortnox/api/models/terms_of_payment.rb +2 -2
- data/lib/fortnox/api/models/unit.rb +2 -2
- data/lib/fortnox/api/models.rb +7 -7
- data/lib/fortnox/api/repositories/article.rb +3 -3
- data/lib/fortnox/api/repositories/authentication.rb +61 -0
- data/lib/fortnox/api/repositories/base/savers.rb +3 -1
- data/lib/fortnox/api/repositories/base.rb +25 -38
- data/lib/fortnox/api/repositories/customer.rb +3 -3
- data/lib/fortnox/api/repositories/invoice.rb +3 -3
- data/lib/fortnox/api/repositories/order.rb +3 -3
- data/lib/fortnox/api/repositories/project.rb +3 -3
- data/lib/fortnox/api/repositories/terms_of_payment.rb +3 -3
- data/lib/fortnox/api/repositories/unit.rb +3 -3
- data/lib/fortnox/api/repositories.rb +8 -7
- data/lib/fortnox/api/request_handling.rb +30 -18
- data/lib/fortnox/api/types/default_delivery_types.rb +0 -2
- data/lib/fortnox/api/types/default_templates.rb +0 -2
- data/lib/fortnox/api/types/document_row.rb +3 -3
- data/lib/fortnox/api/types/edi_information.rb +0 -2
- data/lib/fortnox/api/types/email_information.rb +0 -2
- data/lib/fortnox/api/types/enums.rb +54 -10
- data/lib/fortnox/api/types/invoice_row.rb +1 -1
- data/lib/fortnox/api/types/model.rb +5 -9
- data/lib/fortnox/api/types/nullable.rb +13 -9
- data/lib/fortnox/api/types/order_row.rb +1 -1
- data/lib/fortnox/api/types/required.rb +3 -3
- data/lib/fortnox/api/types/sized.rb +4 -4
- data/lib/fortnox/api/types.rb +37 -24
- data/lib/fortnox/api/version.rb +1 -1
- data/lib/fortnox/api.rb +21 -39
- data/spec/fortnox/api/mappers/base/canonical_name_sym_spec.rb +13 -11
- data/spec/fortnox/api/mappers/base/from_json_spec.rb +10 -12
- data/spec/fortnox/api/mappers/base/to_json_spec.rb +48 -57
- data/spec/fortnox/api/mappers/base_spec.rb +4 -7
- data/spec/fortnox/api/mappers/contexts/json_conversion.rb +38 -33
- data/spec/fortnox/api/mappers/default_delivery_types_spec.rb +1 -1
- data/spec/fortnox/api/mappers/examples/mapper.rb +1 -1
- data/spec/fortnox/api/mappers/unit_spec.rb +3 -4
- data/spec/fortnox/api/models/base_spec.rb +33 -22
- data/spec/fortnox/api/models/unit_spec.rb +5 -3
- data/spec/fortnox/api/repositories/article_spec.rb +14 -9
- data/spec/fortnox/api/repositories/authentication_spec.rb +103 -0
- data/spec/fortnox/api/repositories/base_spec.rb +105 -326
- data/spec/fortnox/api/repositories/customer_spec.rb +37 -7
- data/spec/fortnox/api/repositories/examples/all.rb +0 -1
- data/spec/fortnox/api/repositories/examples/find.rb +5 -8
- data/spec/fortnox/api/repositories/examples/only.rb +4 -13
- data/spec/fortnox/api/repositories/examples/save.rb +32 -18
- data/spec/fortnox/api/repositories/examples/save_with_nested_model.rb +0 -5
- data/spec/fortnox/api/repositories/examples/save_with_specially_named_attribute.rb +1 -4
- data/spec/fortnox/api/repositories/examples/search.rb +4 -7
- data/spec/fortnox/api/repositories/invoice_spec.rb +72 -29
- data/spec/fortnox/api/repositories/order_spec.rb +11 -9
- data/spec/fortnox/api/repositories/project_spec.rb +7 -6
- data/spec/fortnox/api/repositories/terms_of_payment_spec.rb +9 -7
- data/spec/fortnox/api/repositories/unit_spec.rb +13 -11
- data/spec/fortnox/api/types/country_spec.rb +1 -1
- data/spec/fortnox/api/types/email_spec.rb +2 -2
- data/spec/fortnox/api/types/enums_spec.rb +1 -0
- data/spec/fortnox/api/types/examples/document_row.rb +3 -3
- data/spec/fortnox/api/types/examples/enum.rb +4 -4
- data/spec/fortnox/api/types/examples/types.rb +1 -3
- data/spec/fortnox/api/types/housework_types_spec.rb +124 -43
- data/spec/fortnox/api/types/model_spec.rb +13 -23
- data/spec/fortnox/api/types/nullable_spec.rb +30 -10
- data/spec/fortnox/api/types/order_row_spec.rb +2 -2
- data/spec/fortnox/api/types/required_spec.rb +7 -15
- data/spec/fortnox/api/types/sales_account_spec.rb +57 -0
- data/spec/fortnox/api_spec.rb +19 -124
- data/spec/spec_helper.rb +0 -14
- data/spec/support/helpers/configuration_helper.rb +30 -3
- data/spec/support/helpers.rb +1 -1
- data/spec/support/matchers/type/attribute_matcher.rb +2 -2
- data/spec/support/matchers/type/enum_matcher.rb +1 -1
- data/spec/support/matchers/type/have_account_number_matcher.rb +1 -1
- data/spec/support/matchers/type/have_email_matcher.rb +1 -1
- data/spec/support/matchers/type/have_nullable_date_matcher.rb +7 -5
- data/spec/support/matchers/type/have_nullable_matcher.rb +1 -1
- data/spec/support/matchers/type/have_nullable_string_matcher.rb +5 -5
- data/spec/support/matchers/type/require_attribute_matcher.rb +5 -5
- data/spec/support/matchers/type/type_matcher.rb +1 -1
- data/spec/support/vcr_setup.rb +16 -0
- data/spec/vcr_cassettes/articles/all.yml +41 -42
- data/spec/vcr_cassettes/articles/find_by_hash_failure.yml +36 -19
- data/spec/vcr_cassettes/articles/find_failure.yml +36 -19
- data/spec/vcr_cassettes/articles/find_id_1.yml +38 -20
- data/spec/vcr_cassettes/articles/find_new.yml +39 -22
- data/spec/vcr_cassettes/articles/multi_param_find_by_hash.yml +38 -21
- data/spec/vcr_cassettes/articles/save_new.yml +37 -19
- data/spec/vcr_cassettes/articles/save_old.yml +39 -22
- data/spec/vcr_cassettes/articles/save_with_specially_named_attribute.yml +37 -19
- data/spec/vcr_cassettes/articles/search_by_name.yml +41 -21
- data/spec/vcr_cassettes/articles/search_miss.yml +36 -19
- data/spec/vcr_cassettes/articles/search_with_special_char.yml +36 -19
- data/spec/vcr_cassettes/articles/single_param_find_by_hash.yml +38 -32
- data/spec/vcr_cassettes/authentication/expired_token.yml +54 -0
- data/spec/vcr_cassettes/authentication/invalid_authorization.yml +57 -0
- data/spec/vcr_cassettes/authentication/invalid_refresh_token.yml +58 -0
- data/spec/vcr_cassettes/authentication/valid_request.yml +63 -0
- data/spec/vcr_cassettes/customers/all.yml +44 -132
- data/spec/vcr_cassettes/customers/find_by_hash_failure.yml +36 -19
- data/spec/vcr_cassettes/customers/find_failure.yml +36 -19
- data/spec/vcr_cassettes/customers/find_id_1.yml +39 -21
- data/spec/vcr_cassettes/customers/find_new.yml +38 -21
- data/spec/vcr_cassettes/customers/find_with_sales_account.yml +63 -0
- data/spec/vcr_cassettes/customers/multi_param_find_by_hash.yml +38 -21
- data/spec/vcr_cassettes/customers/save_new.yml +36 -18
- data/spec/vcr_cassettes/customers/save_new_with_country_code_SE.yml +32 -24
- data/spec/vcr_cassettes/customers/save_new_with_sales_account.yml +63 -0
- data/spec/vcr_cassettes/customers/save_old.yml +38 -21
- data/spec/vcr_cassettes/customers/save_with_specially_named_attribute.yml +36 -18
- data/spec/vcr_cassettes/customers/search_by_name.yml +38 -48
- data/spec/vcr_cassettes/customers/search_miss.yml +36 -19
- data/spec/vcr_cassettes/customers/search_with_special_char.yml +36 -19
- data/spec/vcr_cassettes/customers/single_param_find_by_hash.yml +39 -22
- data/spec/vcr_cassettes/invoices/all.yml +71 -114
- data/spec/vcr_cassettes/invoices/filter_hit.yml +39 -24
- data/spec/vcr_cassettes/invoices/filter_invalid.yml +35 -17
- data/spec/vcr_cassettes/invoices/find_by_hash_failure.yml +36 -19
- data/spec/vcr_cassettes/invoices/find_failure.yml +36 -19
- data/spec/vcr_cassettes/invoices/find_id_1.yml +40 -22
- data/spec/vcr_cassettes/invoices/find_new.yml +41 -24
- data/spec/vcr_cassettes/invoices/multi_param_find_by_hash.yml +38 -21
- data/spec/vcr_cassettes/invoices/row_description_limit.yml +65 -0
- data/spec/vcr_cassettes/invoices/save_new.yml +39 -21
- data/spec/vcr_cassettes/invoices/save_new_with_comments.yml +39 -21
- data/spec/vcr_cassettes/invoices/save_new_with_country.yml +35 -26
- data/spec/vcr_cassettes/invoices/save_new_with_country_GB.yml +36 -27
- data/spec/vcr_cassettes/invoices/save_new_with_country_Norge.yml +35 -26
- data/spec/vcr_cassettes/invoices/save_new_with_country_Norway.yml +35 -26
- data/spec/vcr_cassettes/invoices/save_new_with_country_Sverige.yml +35 -26
- data/spec/vcr_cassettes/invoices/save_new_with_country_VA.yml +36 -27
- data/spec/vcr_cassettes/invoices/save_new_with_country_VI.yml +36 -27
- data/spec/vcr_cassettes/invoices/save_new_with_country_empty_string.yml +35 -26
- data/spec/vcr_cassettes/invoices/save_new_with_country_nil.yml +35 -26
- data/spec/vcr_cassettes/invoices/save_new_with_unsaved_parent.yml +65 -0
- data/spec/vcr_cassettes/invoices/save_old.yml +41 -24
- data/spec/vcr_cassettes/invoices/save_old_with_empty_comments.yml +41 -24
- data/spec/vcr_cassettes/invoices/save_old_with_empty_country.yml +37 -29
- data/spec/vcr_cassettes/invoices/save_old_with_nil_comments.yml +41 -24
- data/spec/vcr_cassettes/invoices/save_old_with_nil_country.yml +37 -29
- data/spec/vcr_cassettes/invoices/save_with_nested_model.yml +40 -21
- data/spec/vcr_cassettes/invoices/save_with_specially_named_attribute.yml +39 -20
- data/spec/vcr_cassettes/invoices/search_by_name.yml +38 -27
- data/spec/vcr_cassettes/invoices/search_miss.yml +36 -19
- data/spec/vcr_cassettes/invoices/search_with_special_char.yml +36 -19
- data/spec/vcr_cassettes/invoices/single_param_find_by_hash.yml +39 -22
- data/spec/vcr_cassettes/orders/all.yml +44 -119
- data/spec/vcr_cassettes/orders/filter_hit.yml +39 -26
- data/spec/vcr_cassettes/orders/filter_invalid.yml +35 -17
- data/spec/vcr_cassettes/orders/find_by_hash_failure.yml +36 -19
- data/spec/vcr_cassettes/orders/find_failure.yml +36 -19
- data/spec/vcr_cassettes/orders/find_id_1.yml +42 -23
- data/spec/vcr_cassettes/orders/find_new.yml +41 -24
- data/spec/vcr_cassettes/orders/housework_invalid_tax_reduction_type.yml +61 -0
- data/spec/vcr_cassettes/orders/housework_othercoses_invalid.yml +61 -0
- data/spec/vcr_cassettes/orders/housework_type_babysitting.yml +40 -21
- data/spec/vcr_cassettes/orders/housework_type_cleaning.yml +40 -21
- data/spec/vcr_cassettes/orders/housework_type_construction.yml +40 -21
- data/spec/vcr_cassettes/orders/housework_type_cooking.yml +36 -18
- data/spec/vcr_cassettes/orders/housework_type_electricity.yml +40 -21
- data/spec/vcr_cassettes/orders/housework_type_gardening.yml +40 -21
- data/spec/vcr_cassettes/orders/housework_type_glassmetalwork.yml +40 -21
- data/spec/vcr_cassettes/orders/housework_type_grounddrainagework.yml +40 -21
- data/spec/vcr_cassettes/orders/housework_type_hvac.yml +40 -21
- data/spec/vcr_cassettes/orders/housework_type_itservices.yml +65 -0
- data/spec/vcr_cassettes/orders/housework_type_majorappliancerepair.yml +65 -0
- data/spec/vcr_cassettes/orders/housework_type_masonry.yml +40 -21
- data/spec/vcr_cassettes/orders/housework_type_movingservices.yml +65 -0
- data/spec/vcr_cassettes/orders/housework_type_othercare.yml +40 -21
- data/spec/vcr_cassettes/orders/housework_type_othercosts.yml +40 -21
- data/spec/vcr_cassettes/orders/housework_type_paintingwallpapering.yml +40 -21
- data/spec/vcr_cassettes/orders/housework_type_snowplowing.yml +40 -21
- data/spec/vcr_cassettes/orders/housework_type_textileclothing.yml +40 -21
- data/spec/vcr_cassettes/orders/housework_type_tutoring.yml +36 -18
- data/spec/vcr_cassettes/orders/multi_param_find_by_hash.yml +38 -21
- data/spec/vcr_cassettes/orders/save_new.yml +40 -22
- data/spec/vcr_cassettes/orders/save_old.yml +41 -24
- data/spec/vcr_cassettes/orders/save_with_nested_model.yml +40 -21
- data/spec/vcr_cassettes/orders/search_by_name.yml +38 -23
- data/spec/vcr_cassettes/orders/search_miss.yml +36 -19
- data/spec/vcr_cassettes/orders/search_with_special_char.yml +36 -19
- data/spec/vcr_cassettes/orders/single_param_find_by_hash.yml +39 -22
- data/spec/vcr_cassettes/projects/all.yml +39 -37
- data/spec/vcr_cassettes/projects/find_by_hash_failure.yml +36 -19
- data/spec/vcr_cassettes/projects/find_failure.yml +36 -19
- data/spec/vcr_cassettes/projects/find_id_1.yml +38 -21
- data/spec/vcr_cassettes/projects/find_new.yml +39 -22
- data/spec/vcr_cassettes/projects/multi_param_find_by_hash.yml +40 -22
- data/spec/vcr_cassettes/projects/save_new.yml +37 -19
- data/spec/vcr_cassettes/projects/save_old.yml +39 -22
- data/spec/vcr_cassettes/projects/single_param_find_by_hash.yml +38 -21
- data/spec/vcr_cassettes/termsofpayments/all.yml +43 -29
- data/spec/vcr_cassettes/termsofpayments/find_failure.yml +36 -19
- data/spec/vcr_cassettes/termsofpayments/find_id_1.yml +38 -22
- data/spec/vcr_cassettes/termsofpayments/find_new.yml +38 -21
- data/spec/vcr_cassettes/termsofpayments/save_new.yml +37 -19
- data/spec/vcr_cassettes/termsofpayments/save_old.yml +38 -21
- data/spec/vcr_cassettes/units/all.yml +38 -26
- data/spec/vcr_cassettes/units/find_failure.yml +36 -19
- data/spec/vcr_cassettes/units/find_id_1.yml +38 -21
- data/spec/vcr_cassettes/units/find_new.yml +38 -21
- data/spec/vcr_cassettes/units/save_new.yml +37 -19
- data/spec/vcr_cassettes/units/save_old.yml +38 -21
- data/spec/vcr_cassettes/units/save_with_specially_named_attribute.yml +37 -19
- metadata +133 -252
- data/lib/fortnox/api/circular_queue.rb +0 -39
- data/spec/fortnox/api/circular_queue_spec.rb +0 -52
- data/spec/support/helpers/dummy_class_helper.rb +0 -38
- data/spec/support/helpers/when_performing_helper.rb +0 -7
- data/spec/vcr_cassettes/invoices/save_new_with_country_KR.yml +0 -57
- data/temp.txt +0 -1
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
|
3
|
+
require_relative 'base'
|
4
|
+
require_relative '../types'
|
5
5
|
|
6
6
|
module Fortnox
|
7
7
|
module API
|
@@ -30,31 +30,31 @@ module Fortnox
|
|
30
30
|
# Url Direct URL to the record
|
31
31
|
attribute :url, Types::Nullable::String.is(:read_only)
|
32
32
|
|
33
|
-
# Address1
|
33
|
+
# Address1 First address of the customer. 1024 characters
|
34
34
|
attribute :address1, Types::Sized::String[1024]
|
35
35
|
|
36
|
-
# Address2
|
36
|
+
# Address2 Second address of the customer. 1024 characters
|
37
37
|
attribute :address2, Types::Sized::String[1024]
|
38
38
|
|
39
|
-
# City
|
39
|
+
# City City of the customer. 1024 characters
|
40
40
|
attribute :city, Types::Sized::String[1024]
|
41
41
|
|
42
|
-
# Country
|
42
|
+
# Country Country of the customer. Read-only.
|
43
43
|
attribute :country, Types::Nullable::String.is(:read_only)
|
44
44
|
|
45
|
-
# Comments
|
45
|
+
# Comments Comments. 1024 characters.
|
46
46
|
attribute :comments, Types::Sized::String[1024]
|
47
47
|
|
48
|
-
# Currency
|
48
|
+
# Currency Currency of the customer, 3 letters
|
49
49
|
attribute :currency, Types::Currency
|
50
50
|
|
51
|
-
# CostCenter
|
51
|
+
# CostCenter Cost center of the customer, Cost center in Fortnox
|
52
52
|
attribute :cost_center, Types::Nullable::String
|
53
53
|
|
54
|
-
# CountryCode
|
54
|
+
# CountryCode Country code of the customer, 2 letters
|
55
55
|
attribute :country_code, Types::CountryCode
|
56
56
|
|
57
|
-
# CustomerNumber
|
57
|
+
# CustomerNumber Customer number. 1024 characters
|
58
58
|
attribute :customer_number, Types::Sized::String[1024]
|
59
59
|
|
60
60
|
# DefaultDeliveryTypes The properties for this object is listed in the table for "Default Delivery Types".
|
@@ -63,146 +63,146 @@ module Fortnox
|
|
63
63
|
# The properties for this object is listed in the table for "Default Templates".
|
64
64
|
attribute :default_templates, Types::DefaultTemplates
|
65
65
|
|
66
|
-
# DeliveryAddress1
|
66
|
+
# DeliveryAddress1 First delivery address of the customer. 1024 characters
|
67
67
|
attribute :delivery_address1, Types::Sized::String[1024]
|
68
68
|
|
69
|
-
# DeliveryAddress2
|
69
|
+
# DeliveryAddress2 Second delivery address of the customer. 1024 characters
|
70
70
|
attribute :delivery_address2, Types::Sized::String[1024]
|
71
71
|
|
72
|
-
# DeliveryCity
|
72
|
+
# DeliveryCity Delivery city of the customer. 1024 characters
|
73
73
|
attribute :delivery_city, Types::Sized::String[1024]
|
74
74
|
|
75
|
-
# DeliveryCountry
|
75
|
+
# DeliveryCountry Delivery country of the customer. Read-only.
|
76
76
|
attribute :delivery_country, Types::Nullable::String.is(:read_only)
|
77
77
|
|
78
|
-
# DeliveryCountryCode
|
78
|
+
# DeliveryCountryCode Delivery country code of the customer, 2 letters
|
79
79
|
attribute :delivery_country_code, Types::CountryCode
|
80
80
|
|
81
|
-
# DeliveryFax
|
81
|
+
# DeliveryFax Delivery fax number of the customer. 1024 characters
|
82
82
|
attribute :delivery_fax, Types::Sized::String[1024]
|
83
83
|
|
84
|
-
# DeliveryName
|
84
|
+
# DeliveryName Delivery name of the customer. 1024 characters
|
85
85
|
attribute :delivery_name, Types::Sized::String[1024]
|
86
86
|
|
87
|
-
# DeliveryPhone1
|
87
|
+
# DeliveryPhone1 First delivery phone number of the customer. 1024 characters
|
88
88
|
attribute :delivery_phone1, Types::Sized::String[1024]
|
89
89
|
|
90
|
-
# DeliveryPhone2
|
90
|
+
# DeliveryPhone2 Second delivery phone number of the customer. 1024 characters
|
91
91
|
attribute :delivery_phone2, Types::Sized::String[1024]
|
92
92
|
|
93
|
-
# DeliveryZipCode
|
93
|
+
# DeliveryZipCode Delivery zip code of the customer. 1024 characters.
|
94
94
|
attribute :delivery_zip_code, Types::Sized::String[1024]
|
95
95
|
|
96
|
-
# Email
|
96
|
+
# Email Email address of the customer. 1024 characters
|
97
97
|
attribute :email, Types::Email
|
98
98
|
|
99
|
-
# EmailInvoice
|
99
|
+
# EmailInvoice Invoice email address of the customer. 1024 characters
|
100
100
|
attribute :email_invoice, Types::Email
|
101
101
|
|
102
|
-
# EmailInvoiceBCC
|
102
|
+
# EmailInvoiceBCC Invoice BCC email address of the customer. 1024 characters
|
103
103
|
attribute :email_invoice_bcc, Types::Email
|
104
104
|
|
105
|
-
# EmailInvoiceCC
|
105
|
+
# EmailInvoiceCC Invoice CC email address of the customer. 1024 characters
|
106
106
|
attribute :email_invoice_cc, Types::Email
|
107
107
|
|
108
|
-
# EmailOffer
|
108
|
+
# EmailOffer Offer email address of the customer. 1024 characters
|
109
109
|
attribute :email_offer, Types::Email
|
110
110
|
|
111
|
-
# EmailOfferBCC
|
111
|
+
# EmailOfferBCC Offer BCC email address of the customer. 1024 characters
|
112
112
|
attribute :email_offer_bcc, Types::Email
|
113
113
|
|
114
|
-
# EmailOfferCC
|
114
|
+
# EmailOfferCC Offer CC email address of the customer. 1024 characters
|
115
115
|
attribute :email_offer_cc, Types::Email
|
116
116
|
|
117
|
-
# EmailOrder
|
117
|
+
# EmailOrder Order email address of the customer. 1024 characters
|
118
118
|
attribute :email_order, Types::Email
|
119
119
|
|
120
|
-
# EmailOrderBCC
|
120
|
+
# EmailOrderBCC Order BCC email address of the customer. 1024 characters
|
121
121
|
attribute :email_order_bcc, Types::Email
|
122
122
|
|
123
|
-
# EmailOrderCC
|
123
|
+
# EmailOrderCC Order CC email address of the customer. 1024 characters
|
124
124
|
attribute :email_order_cc, Types::Email
|
125
125
|
|
126
|
-
# Fax
|
126
|
+
# Fax Fax number of the customer. 1024 characters
|
127
127
|
attribute :fax, Types::Sized::String[1024]
|
128
128
|
|
129
129
|
# InvoiceAdministrationFee Invoice administration fee of the customer, 12 digits (incl. decimals).
|
130
130
|
attribute :invoice_administration_fee,
|
131
131
|
Types::Sized::Float[0.0, 99_999_999_999.9]
|
132
132
|
|
133
|
-
# InvoiceDiscount
|
133
|
+
# InvoiceDiscount Invoice discount of the customer, 12 digits (incl. decimals)
|
134
134
|
attribute :invoice_discount, Types::Sized::Float[0.0, 99_999_999_999.9]
|
135
135
|
|
136
|
-
# InvoiceFreight
|
136
|
+
# InvoiceFreight Invoice freight fee of the customer, 12 digits (incl. decimals)
|
137
137
|
attribute :invoice_freight, Types::Sized::Float[0.0, 99_999_999_999.9]
|
138
138
|
|
139
|
-
# InvoiceRemark
|
139
|
+
# InvoiceRemark Invoice remark of the customer. 1024 characters
|
140
140
|
attribute :invoice_remark, Types::Sized::String[1024]
|
141
141
|
|
142
|
-
# Name
|
142
|
+
# Name Name of the customer, 1024 characters
|
143
143
|
attribute :name, Types::Sized::String[1024].is(:required)
|
144
144
|
|
145
|
-
# OrganisationNumber
|
145
|
+
# OrganisationNumber Organisation number of the customer. 30 characters
|
146
146
|
attribute :organisation_number, Types::Sized::String[30]
|
147
147
|
|
148
|
-
# OurReference
|
148
|
+
# OurReference Our reference of the customer. 50 characters
|
149
149
|
attribute :our_reference, Types::Sized::String[50]
|
150
150
|
|
151
|
-
# Phone1
|
151
|
+
# Phone1 First phone number of the customer. 1024 characters
|
152
152
|
attribute :phone1, Types::Sized::String[1024]
|
153
153
|
|
154
|
-
# Phone2
|
154
|
+
# Phone2 Second phone number of the customer. 1024 characters
|
155
155
|
attribute :phone2, Types::Sized::String[1024]
|
156
156
|
|
157
|
-
# PriceList
|
157
|
+
# PriceList Price list of the customer, Price list in Fortnox
|
158
158
|
attribute :price_list, Types::Nullable::String
|
159
159
|
|
160
|
-
# Project
|
160
|
+
# Project Project of the customer, Project in Fortnox
|
161
161
|
attribute :project, Types::Nullable::String
|
162
162
|
|
163
|
-
# SalesAccount
|
164
|
-
attribute :sales_account, Types::
|
163
|
+
# SalesAccount Sales account of the customer, 4 characters
|
164
|
+
attribute :sales_account, Types::SalesAccount
|
165
165
|
|
166
|
-
# ShowPriceVATIncluded
|
166
|
+
# ShowPriceVATIncluded Show prices with VAT included or not
|
167
167
|
attribute :show_price_vat_included, Types::Nullable::Boolean
|
168
168
|
|
169
|
-
# TermsOfDeliveryCode
|
169
|
+
# TermsOfDeliveryCode Terms of delivery code of the customer
|
170
170
|
attribute :terms_of_delivery, Types::Nullable::String
|
171
171
|
|
172
|
-
# TermsOfPaymentCode
|
172
|
+
# TermsOfPaymentCode Terms of payment code of the customer
|
173
173
|
attribute :terms_of_payment, Types::Nullable::String
|
174
174
|
|
175
|
-
# Type
|
175
|
+
# Type Customer type, PRIVATE / COMPANY
|
176
176
|
attribute :type, Types::CustomerType
|
177
177
|
|
178
|
-
# VATNumber
|
178
|
+
# VATNumber VAT number of the customer
|
179
179
|
attribute :vat_number, Types::Nullable::String
|
180
180
|
|
181
|
-
# VATType
|
181
|
+
# VATType VAT type of the customer, SEVAT / SEREVERSEDVAT / EUREVERSEDVAT / EUVAT / EXPORT
|
182
182
|
attribute :vat_type, Types::VATType
|
183
183
|
|
184
|
-
# VisitAddress
|
184
|
+
# VisitAddress Visit address of the customer. 128 characters
|
185
185
|
attribute :visiting_address, Types::Sized::String[128]
|
186
186
|
|
187
|
-
# VisitCity
|
187
|
+
# VisitCity Visit city of the customer. 128 characters
|
188
188
|
attribute :visiting_city, Types::Sized::String[128]
|
189
189
|
|
190
|
-
# VisitCountry
|
190
|
+
# VisitCountry Visit country of the customer, read-only
|
191
191
|
attribute :visiting_country, Types::Nullable::String.is(:read_only)
|
192
192
|
|
193
193
|
# VisitingCountryCode Code of the visiting country for the customer, 2 letters
|
194
194
|
attribute :visiting_country_code, Types::CountryCode
|
195
195
|
|
196
|
-
# VisitZipCode
|
196
|
+
# VisitZipCode Visit zip code of the customer. 10 characters
|
197
197
|
attribute :visiting_zip_code, Types::Sized::String[10]
|
198
198
|
|
199
|
-
# WayOfDeliveryCode
|
199
|
+
# WayOfDeliveryCode Way of delivery code of the customer
|
200
200
|
attribute :way_of_delivery, Types::Nullable::String
|
201
201
|
|
202
|
-
# YourReference
|
202
|
+
# YourReference Your reference of the customer. 50 characters
|
203
203
|
attribute :your_reference, Types::Sized::String[50]
|
204
204
|
|
205
|
-
# ZipCode
|
205
|
+
# ZipCode Zip code of the customer. 10 characters
|
206
206
|
attribute :zip_code, Types::Sized::String[10]
|
207
207
|
end
|
208
208
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
|
3
|
+
require_relative '../types'
|
4
|
+
require_relative 'label'
|
5
5
|
|
6
6
|
module Fortnox
|
7
7
|
module API
|
@@ -154,6 +154,9 @@ module Fortnox
|
|
154
154
|
# TaxReduction The amount of tax reduction.
|
155
155
|
attribute :tax_reduction, Types::Nullable::Integer.is(:read_only)
|
156
156
|
|
157
|
+
# TaxReductionType Tax Reduction Type
|
158
|
+
attribute :tax_reduction_type, Types::TaxReductionType
|
159
|
+
|
157
160
|
# TermsOfDelivery Code of the terms of delivery.
|
158
161
|
attribute :terms_of_delivery, Types::Nullable::String
|
159
162
|
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
3
|
+
require_relative '../types'
|
4
4
|
|
5
5
|
module Fortnox
|
6
6
|
module API
|
@@ -8,10 +8,10 @@ module Fortnox
|
|
8
8
|
class Label < Model::Base
|
9
9
|
STUB = {}.freeze
|
10
10
|
|
11
|
-
# Id
|
11
|
+
# Id integer, read-only. The ID of the label.
|
12
12
|
attribute :id, Types::Required::Integer.is(:read_only)
|
13
13
|
|
14
|
-
# Description
|
14
|
+
# Description string, 25 characters, required. Description of the label
|
15
15
|
attribute :description, Types::Sized::String[25].is(:read_only)
|
16
16
|
end
|
17
17
|
end
|
data/lib/fortnox/api/models.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
3
|
+
require_relative 'models/article'
|
4
|
+
require_relative 'models/customer'
|
5
|
+
require_relative 'models/invoice'
|
6
|
+
require_relative 'models/order'
|
7
|
+
require_relative 'models/project'
|
8
|
+
require_relative 'models/unit'
|
9
|
+
require_relative 'models/terms_of_payment'
|
@@ -1,8 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
3
|
+
require_relative 'base'
|
4
|
+
require_relative '../models/article'
|
5
|
+
require_relative '../mappers/article'
|
6
6
|
|
7
7
|
module Fortnox
|
8
8
|
module API
|
@@ -0,0 +1,61 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'base'
|
4
|
+
|
5
|
+
module Fortnox
|
6
|
+
module API
|
7
|
+
module Repository
|
8
|
+
class Authentication
|
9
|
+
def renew_tokens(refresh_token:, client_id:, client_secret:)
|
10
|
+
body = {
|
11
|
+
grant_type: 'refresh_token',
|
12
|
+
refresh_token: refresh_token
|
13
|
+
}
|
14
|
+
|
15
|
+
response = HTTParty.post(Fortnox::API.config.token_url,
|
16
|
+
headers: headers(client_id, client_secret),
|
17
|
+
body: body)
|
18
|
+
|
19
|
+
validate_response(response)
|
20
|
+
|
21
|
+
parsed_response_to_hash(response.parsed_response)
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def parsed_response_to_hash(parsed_response)
|
27
|
+
{
|
28
|
+
access_token: parsed_response['access_token'],
|
29
|
+
refresh_token: parsed_response['refresh_token'],
|
30
|
+
expires_in: parsed_response['expires_in'],
|
31
|
+
token_type: parsed_response['token_type'],
|
32
|
+
scope: parsed_response['scope']
|
33
|
+
}
|
34
|
+
end
|
35
|
+
|
36
|
+
def headers(client_id, client_secret)
|
37
|
+
credentials = Base64.encode64("#{client_id}:#{client_secret}")
|
38
|
+
|
39
|
+
{
|
40
|
+
'Content-type' => 'application/x-www-form-urlencoded',
|
41
|
+
Authorization: "Basic #{credentials}"
|
42
|
+
}
|
43
|
+
end
|
44
|
+
|
45
|
+
def validate_response(response)
|
46
|
+
return if response.code == 200
|
47
|
+
|
48
|
+
case response.code
|
49
|
+
when 400
|
50
|
+
raise Fortnox::API::RemoteServerError, "Bad request. Error: \"#{response.body}\""
|
51
|
+
when 401
|
52
|
+
raise Fortnox::API::RemoteServerError, "Unauthorized request. Error: \"#{response.body}\""
|
53
|
+
else
|
54
|
+
raise Exception, "Unable to renew access token. Response code: #{response.code}. " \
|
55
|
+
"Response message: #{response.message}. Response body: #{response.body}"
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -8,6 +8,7 @@ module Fortnox
|
|
8
8
|
return true if entity.saved?
|
9
9
|
|
10
10
|
return save_new(entity) if entity.new?
|
11
|
+
|
11
12
|
update_existing(entity)
|
12
13
|
end
|
13
14
|
|
@@ -33,8 +34,9 @@ module Fortnox
|
|
33
34
|
|
34
35
|
def get_changes_on(entity)
|
35
36
|
hash = @mapper.entity_to_hash(entity, @keys_filtered_on_save)
|
36
|
-
|
37
|
+
return hash unless entity.parent.saved?
|
37
38
|
|
39
|
+
parent_hash = @mapper.entity_to_hash(entity.parent, @keys_filtered_on_save)
|
38
40
|
@mapper.wrap_entity_json_hash(@mapper.diff(hash, parent_hash))
|
39
41
|
end
|
40
42
|
|
@@ -1,9 +1,12 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'httparty'
|
4
|
-
require '
|
5
|
-
require '
|
6
|
-
|
4
|
+
require 'jwt'
|
5
|
+
require 'base64'
|
6
|
+
|
7
|
+
require_relative 'base/loaders'
|
8
|
+
require_relative 'base/savers'
|
9
|
+
require_relative '../request_handling'
|
7
10
|
|
8
11
|
module Fortnox
|
9
12
|
module API
|
@@ -26,53 +29,47 @@ module Fortnox
|
|
26
29
|
attr_accessor :headers
|
27
30
|
attr_reader :mapper, :keys_filtered_on_save
|
28
31
|
|
29
|
-
def self.set_headers(headers = {})
|
32
|
+
def self.set_headers(headers = {})
|
30
33
|
self.headers.merge!(headers)
|
31
34
|
end
|
32
35
|
|
33
36
|
HTTP_METHODS.each do |method|
|
34
37
|
define_method method do |path, options = {}, &block|
|
35
38
|
provided_headers = options[:headers] || {}
|
36
|
-
provided_headers['
|
37
|
-
provided_headers['Access-Token'] = next_access_token
|
39
|
+
provided_headers['Authorization'] = "Bearer #{access_token}"
|
38
40
|
options[:headers] = provided_headers
|
39
41
|
options[:base_uri] ||= base_url
|
42
|
+
|
43
|
+
debug_log_request(path, options)
|
44
|
+
|
40
45
|
execute do |remote|
|
41
46
|
remote.send(method, path, options, &block)
|
42
47
|
end
|
43
48
|
end
|
44
49
|
end
|
45
50
|
|
46
|
-
def initialize(keys_filtered_on_save: [:url]
|
51
|
+
def initialize(keys_filtered_on_save: [:url])
|
47
52
|
@keys_filtered_on_save = keys_filtered_on_save
|
48
|
-
@token_store = token_store
|
49
53
|
@mapper = Registry[Mapper::Base.canonical_name_sym(self.class::MODEL)].new
|
50
|
-
|
54
|
+
return unless access_token.nil?
|
51
55
|
|
52
|
-
|
53
|
-
|
54
|
-
|
56
|
+
raise MissingAccessToken,
|
57
|
+
'No Access Token provided! You need to provide an Access Token: ' \
|
58
|
+
'Fortnox::API.access_token = token'
|
55
59
|
end
|
56
60
|
|
57
|
-
|
58
|
-
tokens_present = !(tokens.nil? || tokens.empty?)
|
59
|
-
return if tokens_present
|
60
|
-
error_message = "You have not provided any access tokens in token store #{@token_store.inspect}."
|
61
|
-
raise MissingConfiguration, error_message
|
62
|
-
end
|
61
|
+
private
|
63
62
|
|
64
|
-
def
|
65
|
-
|
66
|
-
tokens = config.token_store.fetch(@token_store)
|
67
|
-
rescue KeyError
|
68
|
-
token_store_not_found!(@token_store.inspect)
|
69
|
-
end
|
63
|
+
def debug_log_request(path, options)
|
64
|
+
return unless Fortnox::API.debugging
|
70
65
|
|
71
|
-
|
72
|
-
|
66
|
+
Fortnox::API.logger.debug("path: #{path.inspect}")
|
67
|
+
Fortnox::API.logger.debug("options: #{options.inspect}")
|
73
68
|
end
|
74
69
|
|
75
|
-
|
70
|
+
def access_token
|
71
|
+
Fortnox::API.access_token
|
72
|
+
end
|
76
73
|
|
77
74
|
def instantiate(hash)
|
78
75
|
hash[:new] = false
|
@@ -83,23 +80,13 @@ module Fortnox
|
|
83
80
|
def base_url
|
84
81
|
base_url = config.base_url
|
85
82
|
raise MissingConfiguration, 'You have to provide a base url.' unless base_url
|
86
|
-
base_url
|
87
|
-
end
|
88
83
|
|
89
|
-
|
90
|
-
client_secret = config.client_secret
|
91
|
-
raise MissingConfiguration, 'You have to provide your client secret.' unless client_secret
|
92
|
-
client_secret
|
84
|
+
base_url
|
93
85
|
end
|
94
86
|
|
95
87
|
def config
|
96
88
|
Fortnox::API.config
|
97
89
|
end
|
98
|
-
|
99
|
-
def token_store_not_found!(store_name)
|
100
|
-
raise MissingConfiguration,
|
101
|
-
"There is no token store named #{store_name}. Available stores are #{config.token_store.keys}."
|
102
|
-
end
|
103
90
|
end
|
104
91
|
end
|
105
92
|
end
|
@@ -1,8 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
3
|
+
require_relative 'base'
|
4
|
+
require_relative '../models/customer'
|
5
|
+
require_relative '../mappers/customer'
|
6
6
|
|
7
7
|
module Fortnox
|
8
8
|
module API
|
@@ -1,8 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
3
|
+
require_relative 'base'
|
4
|
+
require_relative '../models/invoice'
|
5
|
+
require_relative '../mappers/invoice'
|
6
6
|
|
7
7
|
module Fortnox
|
8
8
|
module API
|
@@ -1,8 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
3
|
+
require_relative 'base'
|
4
|
+
require_relative '../models/order'
|
5
|
+
require_relative '../mappers/order'
|
6
6
|
|
7
7
|
module Fortnox
|
8
8
|
module API
|
@@ -1,8 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
3
|
+
require_relative 'base'
|
4
|
+
require_relative '../models/project'
|
5
|
+
require_relative '../mappers/project'
|
6
6
|
|
7
7
|
module Fortnox
|
8
8
|
module API
|
@@ -1,8 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
3
|
+
require_relative 'base'
|
4
|
+
require_relative '../models/terms_of_payment'
|
5
|
+
require_relative '../mappers/terms_of_payment'
|
6
6
|
|
7
7
|
module Fortnox
|
8
8
|
module API
|
@@ -1,8 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
3
|
+
require_relative 'base'
|
4
|
+
require_relative '../models/unit'
|
5
|
+
require_relative '../mappers/unit'
|
6
6
|
|
7
7
|
module Fortnox
|
8
8
|
module API
|