fortnox-api 0.5.2 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +3 -0
- data/.rubocop.yml +9 -1104
- data/.travis.yml +22 -2
- data/Gemfile +3 -1
- data/Guardfile +4 -2
- data/README.md +2 -2
- data/Rakefile +3 -1
- data/bin/console +17 -3
- data/fortnox-api.gemspec +32 -27
- data/lib/fortnox/api.rb +17 -16
- data/lib/fortnox/api/circular_queue.rb +13 -7
- data/lib/fortnox/api/mappers.rb +29 -25
- data/lib/fortnox/api/mappers/article.rb +7 -6
- data/lib/fortnox/api/mappers/base.rb +18 -16
- data/lib/fortnox/api/mappers/base/from_json.rb +37 -30
- data/lib/fortnox/api/mappers/base/to_json.rb +39 -37
- data/lib/fortnox/api/mappers/customer.rb +7 -7
- data/lib/fortnox/api/mappers/default_delivery_types.rb +4 -2
- data/lib/fortnox/api/mappers/default_templates.rb +5 -4
- data/lib/fortnox/api/mappers/edi_information.rb +5 -4
- data/lib/fortnox/api/mappers/email_information.rb +5 -4
- data/lib/fortnox/api/mappers/invoice.rb +10 -8
- data/lib/fortnox/api/mappers/invoice_row.rb +12 -7
- data/lib/fortnox/api/mappers/order.rb +10 -7
- data/lib/fortnox/api/mappers/order_row.rb +13 -6
- data/lib/fortnox/api/mappers/project.rb +6 -4
- data/lib/fortnox/api/mappers/terms_of_payments.rb +17 -0
- data/lib/fortnox/api/mappers/unit.rb +17 -0
- data/lib/fortnox/api/models.rb +9 -5
- data/lib/fortnox/api/models/article.rb +68 -67
- data/lib/fortnox/api/models/base.rb +52 -36
- data/lib/fortnox/api/models/customer.rb +95 -94
- data/lib/fortnox/api/models/document.rb +186 -0
- data/lib/fortnox/api/models/invoice.rb +44 -44
- data/lib/fortnox/api/models/label.rb +5 -3
- data/lib/fortnox/api/models/order.rb +8 -8
- data/lib/fortnox/api/models/project.rb +10 -8
- data/lib/fortnox/api/models/terms_of_payments.rb +28 -0
- data/lib/fortnox/api/models/unit.rb +24 -0
- data/lib/fortnox/api/repositories.rb +9 -5
- data/lib/fortnox/api/repositories/article.rb +6 -4
- data/lib/fortnox/api/repositories/base.rb +49 -46
- data/lib/fortnox/api/repositories/base/loaders.rb +32 -36
- data/lib/fortnox/api/repositories/base/savers.rb +23 -21
- data/lib/fortnox/api/repositories/customer.rb +6 -4
- data/lib/fortnox/api/repositories/invoice.rb +6 -4
- data/lib/fortnox/api/repositories/order.rb +6 -4
- data/lib/fortnox/api/repositories/project.rb +6 -4
- data/lib/fortnox/api/repositories/terms_of_payments.rb +17 -0
- data/lib/fortnox/api/repositories/unit.rb +17 -0
- data/lib/fortnox/api/request_handling.rb +12 -12
- data/lib/fortnox/api/types.rb +62 -11
- data/lib/fortnox/api/types/default_delivery_types.rb +5 -3
- data/lib/fortnox/api/types/default_templates.rb +3 -1
- data/lib/fortnox/api/types/defaulted.rb +2 -2
- data/lib/fortnox/api/types/document_row.rb +41 -42
- data/lib/fortnox/api/types/edi_information.rb +10 -8
- data/lib/fortnox/api/types/email_information.rb +10 -8
- data/lib/fortnox/api/types/enums.rb +60 -47
- data/lib/fortnox/api/types/invoice_row.rb +8 -8
- data/lib/fortnox/api/types/model.rb +14 -10
- data/lib/fortnox/api/types/nullable.rb +7 -7
- data/lib/fortnox/api/types/order_row.rb +5 -5
- data/lib/fortnox/api/types/required.rb +5 -5
- data/lib/fortnox/api/types/sized.rb +14 -6
- data/lib/fortnox/api/version.rb +3 -1
- data/spec/fortnox/api/mappers/article_spec.rb +3 -1
- data/spec/fortnox/api/mappers/base/from_json_spec.rb +15 -13
- data/spec/fortnox/api/mappers/base/to_json_spec.rb +4 -3
- data/spec/fortnox/api/mappers/base_spec.rb +40 -35
- data/spec/fortnox/api/mappers/contexts/json_conversion.rb +12 -11
- data/spec/fortnox/api/mappers/customer_spec.rb +3 -1
- data/spec/fortnox/api/mappers/default_delivery_types_spec.rb +3 -1
- data/spec/fortnox/api/mappers/edi_information_spec.rb +4 -2
- data/spec/fortnox/api/mappers/email_information_spec.rb +4 -2
- data/spec/fortnox/api/mappers/examples/mapper.rb +17 -9
- data/spec/fortnox/api/mappers/invoice_row_spec.rb +8 -3
- data/spec/fortnox/api/mappers/invoice_spec.rb +4 -1
- data/spec/fortnox/api/mappers/order_row_spec.rb +9 -2
- data/spec/fortnox/api/mappers/order_spec.rb +4 -1
- data/spec/fortnox/api/mappers/project_spec.rb +3 -1
- data/spec/fortnox/api/mappers/terms_of_payments_spec.rb +16 -0
- data/spec/fortnox/api/mappers/unit_spec.rb +57 -0
- data/spec/fortnox/api/models/article_spec.rb +2 -0
- data/spec/fortnox/api/models/base_spec.rb +46 -38
- data/spec/fortnox/api/models/customer_spec.rb +2 -0
- data/spec/fortnox/api/models/examples/document_base.rb +5 -3
- data/spec/fortnox/api/models/examples/model.rb +12 -9
- data/spec/fortnox/api/models/invoice_spec.rb +2 -0
- data/spec/fortnox/api/models/order_spec.rb +2 -0
- data/spec/fortnox/api/models/project_spec.rb +2 -0
- data/spec/fortnox/api/models/terms_of_payments_spec.rb +9 -0
- data/spec/fortnox/api/models/unit_spec.rb +31 -0
- data/spec/fortnox/api/repositories/article_spec.rb +7 -5
- data/spec/fortnox/api/repositories/base_spec.rb +121 -100
- data/spec/fortnox/api/repositories/customer_spec.rb +7 -5
- data/spec/fortnox/api/repositories/examples/all.rb +5 -4
- data/spec/fortnox/api/repositories/examples/find.rb +50 -41
- data/spec/fortnox/api/repositories/examples/only.rb +14 -13
- data/spec/fortnox/api/repositories/examples/save.rb +23 -29
- data/spec/fortnox/api/repositories/examples/save_with_nested_model.rb +11 -11
- data/spec/fortnox/api/repositories/examples/save_with_specially_named_attribute.rb +11 -10
- data/spec/fortnox/api/repositories/examples/search.rb +15 -15
- data/spec/fortnox/api/repositories/invoice_spec.rb +8 -6
- data/spec/fortnox/api/repositories/order_spec.rb +8 -6
- data/spec/fortnox/api/repositories/project_spec.rb +7 -5
- data/spec/fortnox/api/repositories/terms_of_payments_spec.rb +30 -0
- data/spec/fortnox/api/repositories/unit_spec.rb +34 -0
- data/spec/fortnox/api/types/account_number_spec.rb +12 -9
- data/spec/fortnox/api/types/default_delivery_types_spec.rb +6 -4
- data/spec/fortnox/api/types/edi_information_spec.rb +9 -7
- data/spec/fortnox/api/types/email_information_spec.rb +8 -6
- data/spec/fortnox/api/types/email_spec.rb +27 -14
- data/spec/fortnox/api/types/enums_spec.rb +3 -1
- data/spec/fortnox/api/types/examples/document_row.rb +10 -8
- data/spec/fortnox/api/types/examples/enum.rb +29 -22
- data/spec/fortnox/api/types/examples/types.rb +8 -4
- data/spec/fortnox/api/types/housework_types_spec.rb +68 -0
- data/spec/fortnox/api/types/invoice_row_spec.rb +3 -1
- data/spec/fortnox/api/types/model_spec.rb +12 -9
- data/spec/fortnox/api/types/nullable_spec.rb +8 -6
- data/spec/fortnox/api/types/order_row_spec.rb +4 -2
- data/spec/fortnox/api/types/required_spec.rb +4 -2
- data/spec/fortnox/api/types/sized_spec.rb +18 -16
- data/spec/fortnox/api_spec.rb +45 -43
- data/spec/spec_helper.rb +9 -6
- data/spec/support/helpers.rb +3 -1
- data/spec/support/helpers/configuration_helper.rb +2 -0
- data/spec/support/helpers/dummy_class_helper.rb +7 -8
- data/spec/support/helpers/repository_helper.rb +2 -0
- data/spec/support/helpers/when_performing_helper.rb +3 -1
- data/spec/support/matchers.rb +2 -0
- data/spec/support/matchers/type.rb +3 -1
- data/spec/support/matchers/type/attribute_matcher.rb +15 -14
- data/spec/support/matchers/type/enum_matcher.rb +9 -7
- data/spec/support/matchers/type/have_account_number_matcher.rb +11 -9
- data/spec/support/matchers/type/have_country_code_matcher.rb +6 -4
- data/spec/support/matchers/type/have_currency_matcher.rb +4 -2
- data/spec/support/matchers/type/have_customer_type_matcher.rb +6 -4
- data/spec/support/matchers/type/have_default_delivery_type_matcher.rb +4 -2
- data/spec/support/matchers/type/have_discount_type_matcher.rb +4 -2
- data/spec/support/matchers/type/have_email_matcher.rb +11 -9
- data/spec/support/matchers/type/have_housework_type_matcher.rb +9 -0
- data/spec/support/matchers/type/have_nullable_date_matcher.rb +29 -29
- data/spec/support/matchers/type/have_nullable_matcher.rb +23 -21
- data/spec/support/matchers/type/have_nullable_string_matcher.rb +30 -32
- data/spec/support/matchers/type/have_sized_float_matcher.rb +4 -2
- data/spec/support/matchers/type/have_sized_integer_matcher.rb +4 -2
- data/spec/support/matchers/type/have_sized_string_matcher.rb +16 -15
- data/spec/support/matchers/type/have_vat_type_matcher.rb +4 -2
- data/spec/support/matchers/type/numeric_matcher.rb +25 -23
- data/spec/support/matchers/type/require_attribute_matcher.rb +36 -37
- data/spec/support/matchers/type/type_matcher.rb +18 -16
- data/spec/support/vcr_setup.rb +2 -0
- data/spec/vcr_cassettes/orders/{house_work_type_babysitting.yml → housework_type_babysitting.yml} +9 -10
- data/spec/vcr_cassettes/orders/{house_work_type_cleaning.yml → housework_type_cleaning.yml} +9 -10
- data/spec/vcr_cassettes/orders/{house_work_type_construction.yml → housework_type_construction.yml} +9 -10
- data/spec/vcr_cassettes/orders/{house_work_type_cooking.yml → housework_type_cooking.yml} +7 -7
- data/spec/vcr_cassettes/orders/{house_work_type_electricity.yml → housework_type_electricity.yml} +9 -10
- data/spec/vcr_cassettes/orders/{house_work_type_gardening.yml → housework_type_gardening.yml} +9 -10
- data/spec/vcr_cassettes/orders/{house_work_type_glassmetalwork.yml → housework_type_glassmetalwork.yml} +9 -10
- data/spec/vcr_cassettes/orders/{house_work_type_grounddrainagework.yml → housework_type_grounddrainagework.yml} +9 -10
- data/spec/vcr_cassettes/orders/{house_work_type_hvac.yml → housework_type_hvac.yml} +9 -10
- data/spec/vcr_cassettes/orders/{house_work_type_masonry.yml → housework_type_masonry.yml} +9 -10
- data/spec/vcr_cassettes/orders/{house_work_type_othercare.yml → housework_type_othercare.yml} +9 -10
- data/spec/vcr_cassettes/orders/{house_work_type_othercosts.yml → housework_type_othercosts.yml} +9 -10
- data/spec/vcr_cassettes/orders/{house_work_type_paintingwallpapering.yml → housework_type_paintingwallpapering.yml} +9 -10
- data/spec/vcr_cassettes/orders/{house_work_type_snowplowing.yml → housework_type_snowplowing.yml} +9 -10
- data/spec/vcr_cassettes/orders/{house_work_type_textileclothing.yml → housework_type_textileclothing.yml} +9 -10
- data/spec/vcr_cassettes/orders/{house_work_type_tutoring.yml → housework_type_tutoring.yml} +7 -7
- data/spec/vcr_cassettes/termsofpayments/all.yml +51 -0
- data/spec/vcr_cassettes/termsofpayments/find_failure.yml +45 -0
- data/spec/vcr_cassettes/termsofpayments/find_id_1.yml +46 -0
- data/spec/vcr_cassettes/termsofpayments/find_new.yml +46 -0
- data/spec/vcr_cassettes/termsofpayments/save_new.yml +45 -0
- data/spec/vcr_cassettes/termsofpayments/save_old.yml +46 -0
- data/spec/vcr_cassettes/units/all.yml +48 -0
- data/spec/vcr_cassettes/units/find_failure.yml +45 -0
- data/spec/vcr_cassettes/units/find_id_1.yml +46 -0
- data/spec/vcr_cassettes/units/find_new.yml +48 -0
- data/spec/vcr_cassettes/units/save_new.yml +47 -0
- data/spec/vcr_cassettes/units/save_old.yml +48 -0
- data/spec/vcr_cassettes/units/save_with_specially_named_attribute.yml +47 -0
- metadata +127 -88
- data/docs/account.rb +0 -59
- data/docs/extraction_script.js +0 -23
- data/docs/generation_script.rb +0 -43
- data/docs/json/account.json +0 -77
- data/lib/fortnox/api/models/document_base.rb +0 -189
- data/spec/fortnox/api/types/house_work_types_spec.rb +0 -64
- data/spec/support/matchers/type/have_house_work_type_matcher.rb +0 -7
@@ -1,86 +1,86 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'fortnox/api/models/base'
|
4
|
+
require 'fortnox/api/models/document'
|
3
5
|
|
4
6
|
module Fortnox
|
5
7
|
module API
|
6
8
|
module Model
|
7
|
-
class Invoice <
|
9
|
+
class Invoice < Document
|
8
10
|
UNIQUE_ID = :document_number
|
9
11
|
STUB = { customer_number: '' }.freeze
|
10
12
|
|
11
|
-
|
12
|
-
|
13
|
-
#UrlTaxReductionList Direct url to the tax reduction for the invoice.
|
14
|
-
attribute :url_tax_reduction_list, Types::Nullable::String.with( read_only: true )
|
13
|
+
# UrlTaxReductionList Direct url to the tax reduction for the invoice.
|
14
|
+
attribute :url_tax_reduction_list, Types::Nullable::String.is(:read_only)
|
15
15
|
|
16
|
-
#AccountingMethod Accounting Method.
|
16
|
+
# AccountingMethod Accounting Method.
|
17
17
|
attribute :accounting_method, Types::Nullable::String
|
18
18
|
|
19
|
-
#Balance Balance of the invoice.
|
20
|
-
attribute :balance, Types::Nullable::Float.
|
19
|
+
# Balance Balance of the invoice.
|
20
|
+
attribute :balance, Types::Nullable::Float.is(:read_only)
|
21
21
|
|
22
|
-
#Booked If the invoice is bookkept.
|
23
|
-
attribute :booked, Types::Nullable::Boolean.
|
22
|
+
# Booked If the invoice is bookkept.
|
23
|
+
attribute :booked, Types::Nullable::Boolean.is(:read_only)
|
24
24
|
|
25
|
-
#Credit If the invoice is a credit invoice.
|
26
|
-
attribute :credit, Types::Nullable::Boolean.
|
25
|
+
# Credit If the invoice is a credit invoice.
|
26
|
+
attribute :credit, Types::Nullable::Boolean.is(:read_only)
|
27
27
|
|
28
|
-
#CreditInvoiceReference Reference to the credit invoice, if one exits.
|
28
|
+
# CreditInvoiceReference Reference to the credit invoice, if one exits.
|
29
29
|
attribute :credit_invoice_reference, Types::Nullable::Integer
|
30
30
|
|
31
|
-
#ContractReference Reference to the contract, if one exists.
|
32
|
-
attribute :contract_reference, Types::Nullable::Integer.
|
31
|
+
# ContractReference Reference to the contract, if one exists.
|
32
|
+
attribute :contract_reference, Types::Nullable::Integer.is(:read_only)
|
33
33
|
|
34
|
-
#DueDate Due date of the invoice.
|
34
|
+
# DueDate Due date of the invoice.
|
35
35
|
attribute :due_date, Types::Nullable::Date
|
36
36
|
|
37
|
-
#EDIInformation Separate EDIInformation object
|
37
|
+
# EDIInformation Separate EDIInformation object
|
38
38
|
attribute :edi_information, Types::EDIInformation
|
39
39
|
|
40
|
-
#EUQuarterlyReport EU Quarterly Report On / Off
|
40
|
+
# EUQuarterlyReport EU Quarterly Report On / Off
|
41
41
|
attribute :eu_quarterly_report, Types::Nullable::Boolean
|
42
42
|
|
43
|
-
#InvoiceDate Invoice date.
|
43
|
+
# InvoiceDate Invoice date.
|
44
44
|
attribute :invoice_date, Types::Nullable::Date
|
45
45
|
|
46
|
-
#InvoicePeriodStart Start date of the invoice period.
|
47
|
-
attribute :invoice_period_start, Types::Nullable::Date.
|
46
|
+
# InvoicePeriodStart Start date of the invoice period.
|
47
|
+
attribute :invoice_period_start, Types::Nullable::Date.is(:read_only)
|
48
48
|
|
49
|
-
#InvoicePeriodEnd End date of the invoice period.
|
50
|
-
attribute :invoice_period_end, Types::Nullable::Date.
|
49
|
+
# InvoicePeriodEnd End date of the invoice period.
|
50
|
+
attribute :invoice_period_end, Types::Nullable::Date.is(:read_only)
|
51
51
|
|
52
|
-
#InvoiceRows Separate object
|
53
|
-
attribute :invoice_rows, Types::Strict::Array.member(
|
52
|
+
# InvoiceRows Separate object
|
53
|
+
attribute :invoice_rows, Types::Strict::Array.member(Types::InvoiceRow)
|
54
54
|
|
55
|
-
#InvoiceType The type of invoice.
|
55
|
+
# InvoiceType The type of invoice.
|
56
56
|
attribute :invoice_type, Types::Nullable::String
|
57
57
|
|
58
|
-
#Language Language code.
|
58
|
+
# Language Language code.
|
59
59
|
attribute :language, Types::Nullable::String
|
60
60
|
|
61
|
-
#LastRemindDate Date of last reminder.
|
62
|
-
attribute :last_remind_date, Types::Nullable::Date.
|
61
|
+
# LastRemindDate Date of last reminder.
|
62
|
+
attribute :last_remind_date, Types::Nullable::Date.is(:read_only)
|
63
63
|
|
64
|
-
#NoxFinans If the invoice is managed by NoxFinans
|
65
|
-
attribute :nox_finans, Types::Nullable::Boolean.
|
64
|
+
# NoxFinans If the invoice is managed by NoxFinans
|
65
|
+
attribute :nox_finans, Types::Nullable::Boolean.is(:read_only)
|
66
66
|
|
67
|
-
#OCR OCR number of the invoice.
|
67
|
+
# OCR OCR number of the invoice.
|
68
68
|
attribute :ocr, Types::Nullable::String
|
69
69
|
|
70
|
-
#OrderReference Reference to the order, if one exists.
|
71
|
-
attribute :order_reference, Types::Nullable::Integer.
|
70
|
+
# OrderReference Reference to the order, if one exists.
|
71
|
+
attribute :order_reference, Types::Nullable::Integer.is(:read_only)
|
72
72
|
|
73
|
-
#Reminders Number of reminders sent to the customer.
|
74
|
-
attribute :reminders, Types::Nullable::Integer.
|
73
|
+
# Reminders Number of reminders sent to the customer.
|
74
|
+
attribute :reminders, Types::Nullable::Integer.is(:read_only)
|
75
75
|
|
76
|
-
#VoucherNumber Voucher number for the invoice.
|
77
|
-
attribute :voucher_number, Types::Nullable::Integer.
|
76
|
+
# VoucherNumber Voucher number for the invoice.
|
77
|
+
attribute :voucher_number, Types::Nullable::Integer.is(:read_only)
|
78
78
|
|
79
|
-
#VoucherSeries Voucher series for the invoice.
|
80
|
-
attribute :voucher_series, Types::Nullable::String.
|
79
|
+
# VoucherSeries Voucher series for the invoice.
|
80
|
+
attribute :voucher_series, Types::Nullable::String.is(:read_only)
|
81
81
|
|
82
|
-
#VoucherYear Voucher year for the invoice.
|
83
|
-
attribute :voucher_year, Types::Nullable::Integer.
|
82
|
+
# VoucherYear Voucher year for the invoice.
|
83
|
+
attribute :voucher_year, Types::Nullable::Integer.is(:read_only)
|
84
84
|
end
|
85
85
|
end
|
86
86
|
end
|
@@ -1,4 +1,6 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'fortnox/api/types'
|
2
4
|
|
3
5
|
module Fortnox
|
4
6
|
module API
|
@@ -7,10 +9,10 @@ module Fortnox
|
|
7
9
|
STUB = {}.freeze
|
8
10
|
|
9
11
|
# Id integer, read-only. The ID of the label.
|
10
|
-
attribute :id, Types::Required::Integer.
|
12
|
+
attribute :id, Types::Required::Integer.is(:read_only)
|
11
13
|
|
12
14
|
# Description string, 25 characters, required. Description of the label
|
13
|
-
attribute :description, Types::Sized::String[
|
15
|
+
attribute :description, Types::Sized::String[25].is(:read_only)
|
14
16
|
end
|
15
17
|
end
|
16
18
|
end
|
@@ -1,26 +1,26 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'fortnox/api/models/base'
|
4
|
+
require 'fortnox/api/models/document'
|
3
5
|
|
4
6
|
module Fortnox
|
5
7
|
module API
|
6
8
|
module Model
|
7
|
-
class Order <
|
9
|
+
class Order < Document
|
8
10
|
UNIQUE_ID = :document_number
|
9
11
|
STUB = { customer_number: '', order_rows: [] }.freeze
|
10
12
|
|
11
|
-
|
12
|
-
|
13
|
-
#CopyRemarks I remarks shall copies from order to invoice
|
13
|
+
# CopyRemarks I remarks shall copies from order to invoice
|
14
14
|
attribute :copy_remarks, Types::Nullable::Boolean
|
15
15
|
|
16
16
|
# InvoiceReference Reference if an invoice is created from order
|
17
|
-
attribute :invoice_reference, Types::Nullable::Integer.
|
17
|
+
attribute :invoice_reference, Types::Nullable::Integer.is(:read_only)
|
18
18
|
|
19
19
|
# OrderDate Date of order
|
20
20
|
attribute :order_date, Types::Nullable::Date
|
21
21
|
|
22
22
|
# OrderRows Separate object
|
23
|
-
attribute :order_rows, Types::Strict::Array.member(
|
23
|
+
attribute :order_rows, Types::Strict::Array.member(Types::OrderRow)
|
24
24
|
end
|
25
25
|
end
|
26
26
|
end
|
@@ -1,5 +1,7 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'fortnox/api/types'
|
4
|
+
require 'fortnox/api/models/base'
|
3
5
|
|
4
6
|
module Fortnox
|
5
7
|
module API
|
@@ -9,25 +11,25 @@ module Fortnox
|
|
9
11
|
STUB = { description: '' }.freeze
|
10
12
|
|
11
13
|
# Url Direct URL to the record
|
12
|
-
attribute :url, Types::Nullable::String.
|
14
|
+
attribute :url, Types::Nullable::String.is(:read_only)
|
13
15
|
|
14
16
|
# Comments Comments on project. 512 characters
|
15
|
-
attribute :comments, Types::Sized::String[
|
17
|
+
attribute :comments, Types::Sized::String[512]
|
16
18
|
|
17
19
|
# ContactPerson ContactPerson for project. 50 characters
|
18
|
-
attribute :contact_person, Types::Sized::String[
|
20
|
+
attribute :contact_person, Types::Sized::String[50]
|
19
21
|
|
20
22
|
# Description Description of the project. 50 characters
|
21
|
-
attribute :description, Types::Sized::String[
|
23
|
+
attribute :description, Types::Sized::String[50]
|
22
24
|
|
23
25
|
# EndDate End date of the project.
|
24
26
|
attribute :end_date, Types::Nullable::Date
|
25
27
|
|
26
28
|
# ProjectLeader Projectleader. 50 characters
|
27
|
-
attribute :project_leader, Types::Sized::String[
|
29
|
+
attribute :project_leader, Types::Sized::String[50]
|
28
30
|
|
29
31
|
# ProjectNumber Projectnumber. 20 characters
|
30
|
-
attribute :project_number, Types::Sized::String[
|
32
|
+
attribute :project_number, Types::Sized::String[20]
|
31
33
|
|
32
34
|
# Status Status of the project
|
33
35
|
attribute :status, Types::ProjectStatusType
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'fortnox/api/types'
|
4
|
+
require 'fortnox/api/models/base'
|
5
|
+
|
6
|
+
module Fortnox
|
7
|
+
module API
|
8
|
+
module Model
|
9
|
+
class TermsOfPayments < Fortnox::API::Model::Base
|
10
|
+
UNIQUE_ID = :code
|
11
|
+
STUB = { code: '', description: '' }.freeze
|
12
|
+
|
13
|
+
# Direct URL to the record
|
14
|
+
attribute :url, Types::Nullable::String.with(read_only: true)
|
15
|
+
|
16
|
+
# The code of the term of payment. Sortable
|
17
|
+
# TODO: Only writable during POST.
|
18
|
+
# TODO: Must be alphanumeric
|
19
|
+
# TODO: 30days is a valid value, but the API rewrites it as 30DAYS
|
20
|
+
# and you will not find the resource with a GET with value '30days'
|
21
|
+
attribute :code, Types::Required::String
|
22
|
+
|
23
|
+
# The description of the term of payment
|
24
|
+
attribute :description, Types::Required::String
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'fortnox/api/types'
|
4
|
+
require 'fortnox/api/models/base'
|
5
|
+
|
6
|
+
module Fortnox
|
7
|
+
module API
|
8
|
+
module Model
|
9
|
+
class Unit < Fortnox::API::Model::Base
|
10
|
+
UNIQUE_ID = :code
|
11
|
+
STUB = { code: '' }.freeze
|
12
|
+
|
13
|
+
# Url Direct URL to the record
|
14
|
+
attribute :url, Types::Nullable::String.is(:read_only)
|
15
|
+
|
16
|
+
# Comments Comments on project. 512 characters
|
17
|
+
attribute :code, Types::Required::String.is(:read_only)
|
18
|
+
|
19
|
+
# ContactPerson ContactPerson for project. 50 characters
|
20
|
+
attribute :description, Types::Nullable::String
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -1,5 +1,9 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'fortnox/api/repositories/article'
|
4
|
+
require 'fortnox/api/repositories/customer'
|
5
|
+
require 'fortnox/api/repositories/invoice'
|
6
|
+
require 'fortnox/api/repositories/order'
|
7
|
+
require 'fortnox/api/repositories/project'
|
8
|
+
require 'fortnox/api/repositories/unit'
|
9
|
+
require 'fortnox/api/repositories/terms_of_payments'
|
@@ -1,6 +1,8 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'fortnox/api/repositories/base'
|
4
|
+
require 'fortnox/api/models/article'
|
5
|
+
require 'fortnox/api/mappers/article'
|
4
6
|
|
5
7
|
module Fortnox
|
6
8
|
module API
|
@@ -8,7 +10,7 @@ module Fortnox
|
|
8
10
|
class Article < Base
|
9
11
|
MODEL = Model::Article
|
10
12
|
MAPPER = Mapper::Article
|
11
|
-
URI = '/articles/'
|
13
|
+
URI = '/articles/'
|
12
14
|
end
|
13
15
|
end
|
14
16
|
end
|
@@ -1,7 +1,9 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'httparty'
|
2
4
|
require 'fortnox/api/request_handling'
|
3
|
-
require
|
4
|
-
require
|
5
|
+
require 'fortnox/api/repositories/base/loaders'
|
6
|
+
require 'fortnox/api/repositories/base/savers'
|
5
7
|
|
6
8
|
module Fortnox
|
7
9
|
module API
|
@@ -12,93 +14,94 @@ module Fortnox
|
|
12
14
|
include Loaders
|
13
15
|
include Savers
|
14
16
|
|
15
|
-
HTTParty::Parser::SupportedFormats[
|
17
|
+
HTTParty::Parser::SupportedFormats['text/html'] = :json
|
16
18
|
|
17
19
|
DEFAULT_HEADERS = {
|
18
20
|
'Content-Type' => 'application/json',
|
19
|
-
'Accept' => 'application/json'
|
21
|
+
'Accept' => 'application/json'
|
20
22
|
}.freeze
|
21
23
|
|
22
|
-
HTTP_METHODS = [
|
24
|
+
HTTP_METHODS = %i[get put post delete].freeze
|
23
25
|
|
24
26
|
attr_accessor :headers
|
25
27
|
attr_reader :mapper, :keys_filtered_on_save
|
26
28
|
|
27
|
-
def self.set_headers(
|
28
|
-
self.headers.merge!(
|
29
|
+
def self.set_headers(headers = {}) # rubocop:disable Naming/AccessorMethodName
|
30
|
+
self.headers.merge!(headers)
|
29
31
|
end
|
30
32
|
|
31
33
|
HTTP_METHODS.each do |method|
|
32
34
|
define_method method do |*args|
|
33
|
-
|
35
|
+
headers['Access-Token'] = next_access_token
|
34
36
|
execute do |remote|
|
35
|
-
remote.send(
|
37
|
+
remote.send(method, *args)
|
36
38
|
end
|
37
39
|
end
|
38
40
|
end
|
39
41
|
|
40
|
-
def initialize(
|
41
|
-
self.class.base_uri(
|
42
|
+
def initialize(keys_filtered_on_save: [:url], token_store: :default)
|
43
|
+
self.class.base_uri(base_url)
|
42
44
|
|
43
|
-
self.headers = DEFAULT_HEADERS.merge(
|
44
|
-
'Client-Secret' =>
|
45
|
-
|
45
|
+
self.headers = DEFAULT_HEADERS.merge(
|
46
|
+
'Client-Secret' => client_secret
|
47
|
+
)
|
46
48
|
|
47
49
|
@keys_filtered_on_save = keys_filtered_on_save
|
48
50
|
@token_store = token_store
|
49
|
-
@mapper = Registry[
|
51
|
+
@mapper = Registry[Mapper::Base.canonical_name_sym(self.class::MODEL)].new
|
50
52
|
end
|
51
53
|
|
52
54
|
def next_access_token
|
53
|
-
@access_tokens ||= CircularQueue.new(
|
55
|
+
@access_tokens ||= CircularQueue.new(*access_tokens)
|
54
56
|
@access_tokens.next
|
55
57
|
end
|
56
58
|
|
57
|
-
def check_access_tokens!(
|
58
|
-
|
59
|
-
|
60
|
-
|
59
|
+
def check_access_tokens!(tokens)
|
60
|
+
tokens_present = !(tokens.nil? || tokens.empty?)
|
61
|
+
return if tokens_present
|
62
|
+
error_message = "You have not provided any access tokens in token store #{@token_store.inspect}."
|
63
|
+
raise MissingConfiguration, error_message
|
61
64
|
end
|
62
65
|
|
63
|
-
def
|
66
|
+
def access_tokens
|
64
67
|
begin
|
65
|
-
tokens = config.token_store.fetch(
|
68
|
+
tokens = config.token_store.fetch(@token_store)
|
66
69
|
rescue KeyError
|
67
|
-
token_store_not_found!(
|
70
|
+
token_store_not_found!(@token_store.inspect)
|
68
71
|
end
|
69
72
|
|
70
|
-
check_access_tokens!(
|
73
|
+
check_access_tokens!(tokens)
|
71
74
|
tokens
|
72
75
|
end
|
73
76
|
|
74
77
|
private
|
75
78
|
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
79
|
+
def instantiate(hash)
|
80
|
+
hash[:new] = false
|
81
|
+
hash[:unsaved] = false
|
82
|
+
self.class::MODEL.new(hash)
|
83
|
+
end
|
81
84
|
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
85
|
+
def base_url
|
86
|
+
base_url = config.base_url
|
87
|
+
raise MissingConfiguration, 'You have to provide a base url.' unless base_url
|
88
|
+
base_url
|
89
|
+
end
|
87
90
|
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
91
|
+
def client_secret
|
92
|
+
client_secret = config.client_secret
|
93
|
+
raise MissingConfiguration, 'You have to provide your client secret.' unless client_secret
|
94
|
+
client_secret
|
95
|
+
end
|
93
96
|
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
+
def config
|
98
|
+
Fortnox::API.config
|
99
|
+
end
|
97
100
|
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
101
|
+
def token_store_not_found!(store_name)
|
102
|
+
raise MissingConfiguration,
|
103
|
+
"There is no token store named #{store_name}. Available stores are #{config.token_store.keys}."
|
104
|
+
end
|
102
105
|
end
|
103
106
|
end
|
104
107
|
end
|