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.
Files changed (192) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +3 -0
  3. data/.rubocop.yml +9 -1104
  4. data/.travis.yml +22 -2
  5. data/Gemfile +3 -1
  6. data/Guardfile +4 -2
  7. data/README.md +2 -2
  8. data/Rakefile +3 -1
  9. data/bin/console +17 -3
  10. data/fortnox-api.gemspec +32 -27
  11. data/lib/fortnox/api.rb +17 -16
  12. data/lib/fortnox/api/circular_queue.rb +13 -7
  13. data/lib/fortnox/api/mappers.rb +29 -25
  14. data/lib/fortnox/api/mappers/article.rb +7 -6
  15. data/lib/fortnox/api/mappers/base.rb +18 -16
  16. data/lib/fortnox/api/mappers/base/from_json.rb +37 -30
  17. data/lib/fortnox/api/mappers/base/to_json.rb +39 -37
  18. data/lib/fortnox/api/mappers/customer.rb +7 -7
  19. data/lib/fortnox/api/mappers/default_delivery_types.rb +4 -2
  20. data/lib/fortnox/api/mappers/default_templates.rb +5 -4
  21. data/lib/fortnox/api/mappers/edi_information.rb +5 -4
  22. data/lib/fortnox/api/mappers/email_information.rb +5 -4
  23. data/lib/fortnox/api/mappers/invoice.rb +10 -8
  24. data/lib/fortnox/api/mappers/invoice_row.rb +12 -7
  25. data/lib/fortnox/api/mappers/order.rb +10 -7
  26. data/lib/fortnox/api/mappers/order_row.rb +13 -6
  27. data/lib/fortnox/api/mappers/project.rb +6 -4
  28. data/lib/fortnox/api/mappers/terms_of_payments.rb +17 -0
  29. data/lib/fortnox/api/mappers/unit.rb +17 -0
  30. data/lib/fortnox/api/models.rb +9 -5
  31. data/lib/fortnox/api/models/article.rb +68 -67
  32. data/lib/fortnox/api/models/base.rb +52 -36
  33. data/lib/fortnox/api/models/customer.rb +95 -94
  34. data/lib/fortnox/api/models/document.rb +186 -0
  35. data/lib/fortnox/api/models/invoice.rb +44 -44
  36. data/lib/fortnox/api/models/label.rb +5 -3
  37. data/lib/fortnox/api/models/order.rb +8 -8
  38. data/lib/fortnox/api/models/project.rb +10 -8
  39. data/lib/fortnox/api/models/terms_of_payments.rb +28 -0
  40. data/lib/fortnox/api/models/unit.rb +24 -0
  41. data/lib/fortnox/api/repositories.rb +9 -5
  42. data/lib/fortnox/api/repositories/article.rb +6 -4
  43. data/lib/fortnox/api/repositories/base.rb +49 -46
  44. data/lib/fortnox/api/repositories/base/loaders.rb +32 -36
  45. data/lib/fortnox/api/repositories/base/savers.rb +23 -21
  46. data/lib/fortnox/api/repositories/customer.rb +6 -4
  47. data/lib/fortnox/api/repositories/invoice.rb +6 -4
  48. data/lib/fortnox/api/repositories/order.rb +6 -4
  49. data/lib/fortnox/api/repositories/project.rb +6 -4
  50. data/lib/fortnox/api/repositories/terms_of_payments.rb +17 -0
  51. data/lib/fortnox/api/repositories/unit.rb +17 -0
  52. data/lib/fortnox/api/request_handling.rb +12 -12
  53. data/lib/fortnox/api/types.rb +62 -11
  54. data/lib/fortnox/api/types/default_delivery_types.rb +5 -3
  55. data/lib/fortnox/api/types/default_templates.rb +3 -1
  56. data/lib/fortnox/api/types/defaulted.rb +2 -2
  57. data/lib/fortnox/api/types/document_row.rb +41 -42
  58. data/lib/fortnox/api/types/edi_information.rb +10 -8
  59. data/lib/fortnox/api/types/email_information.rb +10 -8
  60. data/lib/fortnox/api/types/enums.rb +60 -47
  61. data/lib/fortnox/api/types/invoice_row.rb +8 -8
  62. data/lib/fortnox/api/types/model.rb +14 -10
  63. data/lib/fortnox/api/types/nullable.rb +7 -7
  64. data/lib/fortnox/api/types/order_row.rb +5 -5
  65. data/lib/fortnox/api/types/required.rb +5 -5
  66. data/lib/fortnox/api/types/sized.rb +14 -6
  67. data/lib/fortnox/api/version.rb +3 -1
  68. data/spec/fortnox/api/mappers/article_spec.rb +3 -1
  69. data/spec/fortnox/api/mappers/base/from_json_spec.rb +15 -13
  70. data/spec/fortnox/api/mappers/base/to_json_spec.rb +4 -3
  71. data/spec/fortnox/api/mappers/base_spec.rb +40 -35
  72. data/spec/fortnox/api/mappers/contexts/json_conversion.rb +12 -11
  73. data/spec/fortnox/api/mappers/customer_spec.rb +3 -1
  74. data/spec/fortnox/api/mappers/default_delivery_types_spec.rb +3 -1
  75. data/spec/fortnox/api/mappers/edi_information_spec.rb +4 -2
  76. data/spec/fortnox/api/mappers/email_information_spec.rb +4 -2
  77. data/spec/fortnox/api/mappers/examples/mapper.rb +17 -9
  78. data/spec/fortnox/api/mappers/invoice_row_spec.rb +8 -3
  79. data/spec/fortnox/api/mappers/invoice_spec.rb +4 -1
  80. data/spec/fortnox/api/mappers/order_row_spec.rb +9 -2
  81. data/spec/fortnox/api/mappers/order_spec.rb +4 -1
  82. data/spec/fortnox/api/mappers/project_spec.rb +3 -1
  83. data/spec/fortnox/api/mappers/terms_of_payments_spec.rb +16 -0
  84. data/spec/fortnox/api/mappers/unit_spec.rb +57 -0
  85. data/spec/fortnox/api/models/article_spec.rb +2 -0
  86. data/spec/fortnox/api/models/base_spec.rb +46 -38
  87. data/spec/fortnox/api/models/customer_spec.rb +2 -0
  88. data/spec/fortnox/api/models/examples/document_base.rb +5 -3
  89. data/spec/fortnox/api/models/examples/model.rb +12 -9
  90. data/spec/fortnox/api/models/invoice_spec.rb +2 -0
  91. data/spec/fortnox/api/models/order_spec.rb +2 -0
  92. data/spec/fortnox/api/models/project_spec.rb +2 -0
  93. data/spec/fortnox/api/models/terms_of_payments_spec.rb +9 -0
  94. data/spec/fortnox/api/models/unit_spec.rb +31 -0
  95. data/spec/fortnox/api/repositories/article_spec.rb +7 -5
  96. data/spec/fortnox/api/repositories/base_spec.rb +121 -100
  97. data/spec/fortnox/api/repositories/customer_spec.rb +7 -5
  98. data/spec/fortnox/api/repositories/examples/all.rb +5 -4
  99. data/spec/fortnox/api/repositories/examples/find.rb +50 -41
  100. data/spec/fortnox/api/repositories/examples/only.rb +14 -13
  101. data/spec/fortnox/api/repositories/examples/save.rb +23 -29
  102. data/spec/fortnox/api/repositories/examples/save_with_nested_model.rb +11 -11
  103. data/spec/fortnox/api/repositories/examples/save_with_specially_named_attribute.rb +11 -10
  104. data/spec/fortnox/api/repositories/examples/search.rb +15 -15
  105. data/spec/fortnox/api/repositories/invoice_spec.rb +8 -6
  106. data/spec/fortnox/api/repositories/order_spec.rb +8 -6
  107. data/spec/fortnox/api/repositories/project_spec.rb +7 -5
  108. data/spec/fortnox/api/repositories/terms_of_payments_spec.rb +30 -0
  109. data/spec/fortnox/api/repositories/unit_spec.rb +34 -0
  110. data/spec/fortnox/api/types/account_number_spec.rb +12 -9
  111. data/spec/fortnox/api/types/default_delivery_types_spec.rb +6 -4
  112. data/spec/fortnox/api/types/edi_information_spec.rb +9 -7
  113. data/spec/fortnox/api/types/email_information_spec.rb +8 -6
  114. data/spec/fortnox/api/types/email_spec.rb +27 -14
  115. data/spec/fortnox/api/types/enums_spec.rb +3 -1
  116. data/spec/fortnox/api/types/examples/document_row.rb +10 -8
  117. data/spec/fortnox/api/types/examples/enum.rb +29 -22
  118. data/spec/fortnox/api/types/examples/types.rb +8 -4
  119. data/spec/fortnox/api/types/housework_types_spec.rb +68 -0
  120. data/spec/fortnox/api/types/invoice_row_spec.rb +3 -1
  121. data/spec/fortnox/api/types/model_spec.rb +12 -9
  122. data/spec/fortnox/api/types/nullable_spec.rb +8 -6
  123. data/spec/fortnox/api/types/order_row_spec.rb +4 -2
  124. data/spec/fortnox/api/types/required_spec.rb +4 -2
  125. data/spec/fortnox/api/types/sized_spec.rb +18 -16
  126. data/spec/fortnox/api_spec.rb +45 -43
  127. data/spec/spec_helper.rb +9 -6
  128. data/spec/support/helpers.rb +3 -1
  129. data/spec/support/helpers/configuration_helper.rb +2 -0
  130. data/spec/support/helpers/dummy_class_helper.rb +7 -8
  131. data/spec/support/helpers/repository_helper.rb +2 -0
  132. data/spec/support/helpers/when_performing_helper.rb +3 -1
  133. data/spec/support/matchers.rb +2 -0
  134. data/spec/support/matchers/type.rb +3 -1
  135. data/spec/support/matchers/type/attribute_matcher.rb +15 -14
  136. data/spec/support/matchers/type/enum_matcher.rb +9 -7
  137. data/spec/support/matchers/type/have_account_number_matcher.rb +11 -9
  138. data/spec/support/matchers/type/have_country_code_matcher.rb +6 -4
  139. data/spec/support/matchers/type/have_currency_matcher.rb +4 -2
  140. data/spec/support/matchers/type/have_customer_type_matcher.rb +6 -4
  141. data/spec/support/matchers/type/have_default_delivery_type_matcher.rb +4 -2
  142. data/spec/support/matchers/type/have_discount_type_matcher.rb +4 -2
  143. data/spec/support/matchers/type/have_email_matcher.rb +11 -9
  144. data/spec/support/matchers/type/have_housework_type_matcher.rb +9 -0
  145. data/spec/support/matchers/type/have_nullable_date_matcher.rb +29 -29
  146. data/spec/support/matchers/type/have_nullable_matcher.rb +23 -21
  147. data/spec/support/matchers/type/have_nullable_string_matcher.rb +30 -32
  148. data/spec/support/matchers/type/have_sized_float_matcher.rb +4 -2
  149. data/spec/support/matchers/type/have_sized_integer_matcher.rb +4 -2
  150. data/spec/support/matchers/type/have_sized_string_matcher.rb +16 -15
  151. data/spec/support/matchers/type/have_vat_type_matcher.rb +4 -2
  152. data/spec/support/matchers/type/numeric_matcher.rb +25 -23
  153. data/spec/support/matchers/type/require_attribute_matcher.rb +36 -37
  154. data/spec/support/matchers/type/type_matcher.rb +18 -16
  155. data/spec/support/vcr_setup.rb +2 -0
  156. data/spec/vcr_cassettes/orders/{house_work_type_babysitting.yml → housework_type_babysitting.yml} +9 -10
  157. data/spec/vcr_cassettes/orders/{house_work_type_cleaning.yml → housework_type_cleaning.yml} +9 -10
  158. data/spec/vcr_cassettes/orders/{house_work_type_construction.yml → housework_type_construction.yml} +9 -10
  159. data/spec/vcr_cassettes/orders/{house_work_type_cooking.yml → housework_type_cooking.yml} +7 -7
  160. data/spec/vcr_cassettes/orders/{house_work_type_electricity.yml → housework_type_electricity.yml} +9 -10
  161. data/spec/vcr_cassettes/orders/{house_work_type_gardening.yml → housework_type_gardening.yml} +9 -10
  162. data/spec/vcr_cassettes/orders/{house_work_type_glassmetalwork.yml → housework_type_glassmetalwork.yml} +9 -10
  163. data/spec/vcr_cassettes/orders/{house_work_type_grounddrainagework.yml → housework_type_grounddrainagework.yml} +9 -10
  164. data/spec/vcr_cassettes/orders/{house_work_type_hvac.yml → housework_type_hvac.yml} +9 -10
  165. data/spec/vcr_cassettes/orders/{house_work_type_masonry.yml → housework_type_masonry.yml} +9 -10
  166. data/spec/vcr_cassettes/orders/{house_work_type_othercare.yml → housework_type_othercare.yml} +9 -10
  167. data/spec/vcr_cassettes/orders/{house_work_type_othercosts.yml → housework_type_othercosts.yml} +9 -10
  168. data/spec/vcr_cassettes/orders/{house_work_type_paintingwallpapering.yml → housework_type_paintingwallpapering.yml} +9 -10
  169. data/spec/vcr_cassettes/orders/{house_work_type_snowplowing.yml → housework_type_snowplowing.yml} +9 -10
  170. data/spec/vcr_cassettes/orders/{house_work_type_textileclothing.yml → housework_type_textileclothing.yml} +9 -10
  171. data/spec/vcr_cassettes/orders/{house_work_type_tutoring.yml → housework_type_tutoring.yml} +7 -7
  172. data/spec/vcr_cassettes/termsofpayments/all.yml +51 -0
  173. data/spec/vcr_cassettes/termsofpayments/find_failure.yml +45 -0
  174. data/spec/vcr_cassettes/termsofpayments/find_id_1.yml +46 -0
  175. data/spec/vcr_cassettes/termsofpayments/find_new.yml +46 -0
  176. data/spec/vcr_cassettes/termsofpayments/save_new.yml +45 -0
  177. data/spec/vcr_cassettes/termsofpayments/save_old.yml +46 -0
  178. data/spec/vcr_cassettes/units/all.yml +48 -0
  179. data/spec/vcr_cassettes/units/find_failure.yml +45 -0
  180. data/spec/vcr_cassettes/units/find_id_1.yml +46 -0
  181. data/spec/vcr_cassettes/units/find_new.yml +48 -0
  182. data/spec/vcr_cassettes/units/save_new.yml +47 -0
  183. data/spec/vcr_cassettes/units/save_old.yml +48 -0
  184. data/spec/vcr_cassettes/units/save_with_specially_named_attribute.yml +47 -0
  185. metadata +127 -88
  186. data/docs/account.rb +0 -59
  187. data/docs/extraction_script.js +0 -23
  188. data/docs/generation_script.rb +0 -43
  189. data/docs/json/account.json +0 -77
  190. data/lib/fortnox/api/models/document_base.rb +0 -189
  191. data/spec/fortnox/api/types/house_work_types_spec.rb +0 -64
  192. data/spec/support/matchers/type/have_house_work_type_matcher.rb +0 -7
@@ -1,4 +1,6 @@
1
- require "fortnox/api/types"
1
+ # frozen_string_literal: true
2
+
3
+ require 'fortnox/api/types'
2
4
 
3
5
  module Fortnox
4
6
  module API
@@ -1,11 +1,11 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Fortnox
2
4
  module API
3
5
  module Types
4
-
5
6
  module Defaulted
6
7
  String = Types::Strict::String.default('')
7
8
  end
8
-
9
9
  end
10
10
  end
11
11
  end
@@ -1,64 +1,63 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Fortnox
2
4
  module API
3
5
  module Types
4
- module DocumentRow
5
- def self.ify( base )
6
- base.class_eval do
7
- #AccountNumber Account number. 4 digits
8
- attribute :account_number, Types::AccountNumber
6
+ class DocumentRow < Fortnox::API::Types::Model
7
+ # AccountNumber Account number. 4 digits
8
+ attribute :account_number, Types::AccountNumber
9
9
 
10
- #ArticleNumber Article number. 50 characters
11
- attribute :article_number, Types::Sized::String[ 50 ]
10
+ # ArticleNumber Article number. 50 characters
11
+ attribute :article_number, Types::Sized::String[50]
12
12
 
13
- #ContributionPercent Contribution Percent.
14
- attribute :contribution_percent, Types::Nullable::Float.with( private: true )
13
+ # ContributionPercent Contribution Percent.
14
+ attribute :contribution_percent, Types::Nullable::Float.with(private: true)
15
15
 
16
- #ContributionValue Contribution Value.
17
- attribute :contribution_value, Types::Nullable::Float.with( private: true )
16
+ # ContributionValue Contribution Value.
17
+ attribute :contribution_value, Types::Nullable::Float.with(private: true)
18
18
 
19
- #CostCenter Code of the cost center for the row.
20
- attribute :cost_center, Types::Nullable::String
19
+ # CostCenter Code of the cost center for the row.
20
+ attribute :cost_center, Types::Nullable::String
21
21
 
22
- #DeliveredQuantity Delivered quantity. 14 digits
23
- attribute :delivered_quantity, Types::Sized::Float[ 0.0, 9_999_999_999_999.9 ]
22
+ # DeliveredQuantity Delivered quantity. 14 digits
23
+ attribute :delivered_quantity, Types::Sized::Float[0.0, 9_999_999_999_999.9]
24
24
 
25
- #Description Description Row description. 50 characters
26
- attribute :description, Types::Sized::String[ 50 ]
25
+ # Description Description Row description. 50 characters
26
+ attribute :description, Types::Sized::String[50]
27
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 ]
28
+ # Discount amount. 12 digits (for amount) / 5 digits (for percent)
29
+ # TODO(hannes): Verify that we can send in more than 5 digits through
30
+ # the actual API for DiscountType PERCENT. This cannot be done until
31
+ # we fix issue #62...
32
+ attribute :discount, Types::Sized::Float[0.0, 99_999_999_999.9]
33
33
 
34
- #DiscountType The type of discount used for the row.
35
- attribute :discount_type, Types::DiscountType
34
+ # DiscountType The type of discount used for the row.
35
+ attribute :discount_type, Types::DiscountType
36
36
 
37
- #HouseWork If the row is housework
38
- attribute :house_work, Types::Nullable::Boolean
37
+ # HouseWork If the row is housework
38
+ attribute :housework, Types::Nullable::Boolean
39
39
 
40
- #HouseWorkHoursToReport Hours to be reported if the quantity of the row should not be used as hours. 5 digits
41
- attribute :house_work_hours_to_report, Types::Sized::Integer[ 0, 99_999 ]
40
+ # HouseWorkHoursToReport Hours to be reported if the quantity of the row should not be used as hours.
41
+ # 5 digits
42
+ attribute :housework_hours_to_report, Types::Sized::Integer[0, 99_999]
42
43
 
43
- #HouseWorkType The type of house work.
44
- attribute :house_work_type, Types::HouseWorkType
44
+ # HouseWorkType The type of housework.
45
+ attribute :housework_type, Types::HouseworkType
45
46
 
46
- #Price Price per unit. 12 digits
47
- attribute :price, Types::Sized::Float[ 0.0, 99_999_999_999.9 ]
47
+ # Price Price per unit. 12 digits
48
+ attribute :price, Types::Sized::Float[0.0, 99_999_999_999.9]
48
49
 
49
- #Project Code of the project for the row.
50
- attribute :project, Types::Nullable::String
50
+ # Project Code of the project for the row.
51
+ attribute :project, Types::Nullable::String
51
52
 
52
- #Total Total amount for the row.
53
- attribute :total, Types::Nullable::Float.with( private: true )
53
+ # Total Total amount for the row.
54
+ attribute :total, Types::Nullable::Float.with(private: true)
54
55
 
55
- #Unit Code of the unit for the row.
56
- attribute :unit, Types::Nullable::String
56
+ # Unit Code of the unit for the row.
57
+ attribute :unit, Types::Nullable::String
57
58
 
58
- #VAT VAT percentage of the row.
59
- attribute :vat, Types::Nullable::Integer
60
- end
61
- end
59
+ # VAT VAT percentage of the row.
60
+ attribute :vat, Types::Nullable::Integer
62
61
  end
63
62
  end
64
63
  end
@@ -1,27 +1,29 @@
1
- require "fortnox/api/types"
1
+ # frozen_string_literal: true
2
+
3
+ require 'fortnox/api/types'
2
4
 
3
5
  module Fortnox
4
6
  module API
5
7
  module Types
6
8
  class EDIInformation < Types::Model
7
9
  STUB = {}.freeze
8
-
9
- #EDIGlobalLocationNumber Invoice address GLN for EDI
10
+
11
+ # EDIGlobalLocationNumber Invoice address GLN for EDI
10
12
  attribute :edi_global_location_number, Types::Nullable::String
11
13
 
12
- #EDIGlobalLocationNumberDelivery Delivery address GLN for EDI
14
+ # EDIGlobalLocationNumberDelivery Delivery address GLN for EDI
13
15
  attribute :edi_global_location_number_delivery, Types::Nullable::String
14
16
 
15
- #EDIInvoiceExtra1 Extra EDI Information
17
+ # EDIInvoiceExtra1 Extra EDI Information
16
18
  attribute :edi_invoice_extra1, Types::Nullable::String
17
19
 
18
- #EDIInvoiceExtra2 Extra EDI Information
20
+ # EDIInvoiceExtra2 Extra EDI Information
19
21
  attribute :edi_invoice_extra2, Types::Nullable::String
20
22
 
21
- #EDIOurElectronicReference Our electronic reference for EDI
23
+ # EDIOurElectronicReference Our electronic reference for EDI
22
24
  attribute :edi_our_electronic_reference, Types::Nullable::String
23
25
 
24
- #EDIYourElectronicReference Your electronic reference for EDI
26
+ # EDIYourElectronicReference Your electronic reference for EDI
25
27
  attribute :edi_your_electronic_reference, Types::Nullable::String
26
28
  end
27
29
  end
@@ -1,4 +1,6 @@
1
- require "fortnox/api/types"
1
+ # frozen_string_literal: true
2
+
3
+ require 'fortnox/api/types'
2
4
 
3
5
  module Fortnox
4
6
  module API
@@ -6,20 +8,20 @@ module Fortnox
6
8
  class EmailInformation < Types::Model
7
9
  STUB = {}.freeze
8
10
 
9
- #EmailAddressTo Customer e-mail address. Must be a valid e-mail address. 1024 characters
11
+ # EmailAddressTo Customer e-mail address. Must be a valid e-mail address. 1024 characters
10
12
  attribute :email_address_to, Types::Email
11
13
 
12
- #EmailAddressCC Customer e-mail address Carbon copy. Must be a valid e-mail address. 1024 characters
14
+ # EmailAddressCC Customer e-mail address, Carbon copy. Must be a valid e-mail address. 1024 characters
13
15
  attribute :email_address_cc, Types::Email
14
16
 
15
- #EmailAddressBCC Customer e-mail address Blind carbon copy. Must be a valid e-mail address. 1024 characters
17
+ # EmailAddressBCC Customer e-mail address, Blind carbon copy. Must be a valid e-mail address. 1024 characters
16
18
  attribute :email_address_bcc, Types::Email
17
19
 
18
- #EmailSubject Subject of the e-mail, 100 characters.
19
- attribute :email_subject, Types::Sized::String[ 100 ]
20
+ # EmailSubject Subject of the e-mail, 100 characters.
21
+ attribute :email_subject, Types::Sized::String[100]
20
22
 
21
- #EmailBody Body of the e-mail, 20000 characters.
22
- attribute :email_body, Types::Sized::String[ 20000 ]
23
+ # EmailBody Body of the e-mail, 20000 characters.
24
+ attribute :email_body, Types::Sized::String[20_000]
23
25
  end
24
26
  end
25
27
  end
@@ -1,69 +1,82 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Fortnox
2
4
  module API
3
5
  module Types
4
-
5
6
  module EnumConstructors
6
- def self.sized( size )
7
- ->(value){ return nil if value == ''; value.to_s.upcase[0...size] unless value.nil? }
7
+ def self.sized(size)
8
+ lambda do |value|
9
+ return nil if value == ''
10
+ value.to_s.upcase[0...size] unless value.nil?
11
+ end
8
12
  end
9
13
 
10
14
  def self.default
11
- ->(value){ return nil if value == ''; value.to_s.upcase unless value.nil? }
15
+ lambda do |value|
16
+ return nil if value == ''
17
+ value.to_s.upcase unless value.nil?
18
+ end
12
19
  end
13
20
  end
14
21
 
15
22
  ArticleTypes = Types::Strict::String.enum(
16
- 'SERVICE','STOCK'
23
+ 'SERVICE', 'STOCK'
17
24
  )
18
25
  DiscountTypes = Types::Strict::String.enum(
19
- 'AMOUNT','PERCENT'
26
+ 'AMOUNT', 'PERCENT'
20
27
  )
21
- CURRENT_HOUSE_WORK_TYPES = [
22
- 'CONSTRUCTION','ELECTRICITY','GLASSMETALWORK','GROUNDDRAINAGEWORK',
23
- 'MASONRY','PAINTINGWALLPAPERING','HVAC','MAJORAPPLIANCEREPAIR',
24
- 'MOVINGSERVICES','ITSERVICES','CLEANING','TEXTILECLOTHING',
25
- 'SNOWPLOWING','GARDENING','BABYSITTING','OTHERCARE', 'OTHERCOSTS'
28
+ CURRENT_HOUSEWORK_TYPES = %w[
29
+ CONSTRUCTION ELECTRICITY GLASSMETALWORK GROUNDDRAINAGEWORK
30
+ MASONRY PAINTINGWALLPAPERING HVAC MAJORAPPLIANCEREPAIR
31
+ MOVINGSERVICES ITSERVICES CLEANING TEXTILECLOTHING
32
+ SNOWPLOWING GARDENING BABYSITTING OTHERCARE OTHERCOSTS
26
33
  ].freeze
27
- LEGACY_HOUSE_WORK_TYPES = [ 'COOKING', 'TUTORING' ].freeze
28
- HouseWorkTypes = Types::Strict::String.enum(
29
- *(CURRENT_HOUSE_WORK_TYPES + LEGACY_HOUSE_WORK_TYPES)
34
+ LEGACY_HOUSEWORK_TYPES = %w[COOKING TUTORING].freeze
35
+ HouseworkTypes = Types::Strict::String.enum(
36
+ *(CURRENT_HOUSEWORK_TYPES + LEGACY_HOUSEWORK_TYPES)
30
37
  )
31
38
  CountryCodes = Types::Strict::String.enum(
32
- 'AF','AX','AL','DZ','AS','AD','AO','AI','AQ','AG','AR','AM','AW','AU',
33
- 'AT','AZ','BS','BH','BD','BB','BY','BE','BZ','BJ','BM','BT','BO','BQ',
34
- 'BA','BW','BV','BR','IO','BN','BG','BF','BI','CV','KH','CM','CA','KY',
35
- 'CF','TD','CL','CN','CX','CC','CO','KM','CG','CD','CK','CR','CI','HR',
36
- 'CU','CW','CY','CZ','DK','DJ','DM','DO','EC','EG','SV','GQ','ER','EE',
37
- 'ET','FK','FO','FJ','FI','FR','GF','PF','TF','GA','GM','GE','DE','GH',
38
- 'GI','GR','GL','GD','GP','GU','GT','GG','GN','GW','GY','HT','HM','VA',
39
- 'HN','HK','HU','IS','IN','ID','IR','IQ','IE','IM','IL','IT','JM','JP',
40
- 'JE','JO','KZ','KE','KI','KP','KR','KW','KG','LA','LV','LB','LS','LR',
41
- 'LY','LI','LT','LU','MO','MK','MG','MW','MY','MV','ML','MT','MH','MQ',
42
- 'MR','MU','YT','MX','FM','MD','MC','MN','ME','MS','MA','MZ','MM','NA',
43
- 'NR','NP','NL','NC','NZ','NI','NE','NG','NU','NF','MP','NO','OM','PK',
44
- 'PW','PS','PA','PG','PY','PE','PH','PN','PL','PT','PR','QA','RE','RO',
45
- 'RU','RW','BL','SH','KN','LC','MF','PM','VC','WS','SM','ST','SA','SN',
46
- 'RS','SC','SL','SG','SX','SK','SI','SB','SO','ZA','GS','SS','ES','LK',
47
- 'SD','SR','SJ','SZ','SE','CH','SY','TW','TJ','TZ','TH','TL','TG','TK',
48
- 'TO','TT','TN','TR','TM','TC','TV','UG','UA','AE','GB','US','UM','UY',
49
- 'UZ','VU','VE','VN','VG','VI','WF','EH','YE','ZM','ZW'
39
+ 'AF', 'AX', 'AL', 'DZ', 'AS', 'AD', 'AO', 'AI', 'AQ', 'AG', 'AR', 'AM',
40
+ 'AW', 'AU', 'AT', 'AZ', 'BS', 'BH', 'BD', 'BB', 'BY', 'BE', 'BZ', 'BJ',
41
+ 'BM', 'BT', 'BO', 'BQ', 'BA', 'BW', 'BV', 'BR', 'IO', 'BN', 'BG', 'BF',
42
+ 'BI', 'CV', 'KH', 'CM', 'CA', 'KY', 'CF', 'TD', 'CL', 'CN', 'CX', 'CC',
43
+ 'CO', 'KM', 'CG', 'CD', 'CK', 'CR', 'CI', 'HR', 'CU', 'CW', 'CY', 'CZ',
44
+ 'DK', 'DJ', 'DM', 'DO', 'EC', 'EG', 'SV', 'GQ', 'ER', 'EE', 'ET', 'FK',
45
+ 'FO', 'FJ', 'FI', 'FR', 'GF', 'PF', 'TF', 'GA', 'GM', 'GE', 'DE', 'GH',
46
+ 'GI', 'GR', 'GL', 'GD', 'GP', 'GU', 'GT', 'GG', 'GN', 'GW', 'GY', 'HT',
47
+ 'HM', 'VA', 'HN', 'HK', 'HU', 'IS', 'IN', 'ID', 'IR', 'IQ', 'IE', 'IM',
48
+ 'IL', 'IT', 'JM', 'JP', 'JE', 'JO', 'KZ', 'KE', 'KI', 'KP', 'KR', 'KW',
49
+ 'KG', 'LA', 'LV', 'LB', 'LS', 'LR', 'LY', 'LI', 'LT', 'LU', 'MO', 'MK',
50
+ 'MG', 'MW', 'MY', 'MV', 'ML', 'MT', 'MH', 'MQ', 'MR', 'MU', 'YT', 'MX',
51
+ 'FM', 'MD', 'MC', 'MN', 'ME', 'MS', 'MA', 'MZ', 'MM', 'NA', 'NR', 'NP',
52
+ 'NL', 'NC', 'NZ', 'NI', 'NE', 'NG', 'NU', 'NF', 'MP', 'NO', 'OM', 'PK',
53
+ 'PW', 'PS', 'PA', 'PG', 'PY', 'PE', 'PH', 'PN', 'PL', 'PT', 'PR', 'QA',
54
+ 'RE', 'RO', 'RU', 'RW', 'BL', 'SH', 'KN', 'LC', 'MF', 'PM', 'VC', 'WS',
55
+ 'SM', 'ST', 'SA', 'SN', 'RS', 'SC', 'SL', 'SG', 'SX', 'SK', 'SI', 'SB',
56
+ 'SO', 'ZA', 'GS', 'SS', 'ES', 'LK', 'SD', 'SR', 'SJ', 'SZ', 'SE', 'CH',
57
+ 'SY', 'TW', 'TJ', 'TZ', 'TH', 'TL', 'TG', 'TK', 'TO', 'TT', 'TN', 'TR',
58
+ 'TM', 'TC', 'TV', 'UG', 'UA', 'AE', 'GB', 'US', 'UM', 'UY', 'UZ', 'VU',
59
+ 'VE', 'VN', 'VG', 'VI', 'WF', 'EH', 'YE', 'ZM', 'ZW'
50
60
  )
51
61
  Currencies = Types::Strict::String.enum(
52
- 'AED','AFN','ALL','AMD','ANG','AOA','ARS','AUD','AWG','AZN','BAM','BBD',
53
- 'BDT','BGN','BHD','BIF','BMD','BND','BOB','BOV','BRL','BSD','BTN','BWP',
54
- 'BYR','BZD','CAD','CDF','CHE','CHF','CHW','CLF','CLP','CNY','COP','COU',
55
- 'CRC','CUP','CVE','CZK','DJF','DKK','DOP','DZD','EGP','ERN','ETB','EUR',
56
- 'FJD','FKP','GBP','GEL','GHS','GIP','GMD','GNF','GTQ','GYD','HKD','HNL',
57
- 'HRK','HTG','HUF','IDR','ILS','INR','IQD','IRR','ISK','JMD','JOD','JPY',
58
- 'KES','KGS','KHR','KUR','KMF','KPW','KRW','KWD','KYD','KZT','LAK','LBP',
59
- 'LKR','LRD','LSL','LYD','MAD','MDL','MGA','MKD','MMK','MNT','MOP','MRO',
60
- 'MUR','MVR','MWK','MXN','MXV','MYR','MZN','NAD','NGN','NIO','NOK','NPR',
61
- 'NZD','OMR','PAB','PEN','PGK','PHP','PKR','PLN','PYG','QAR','RON','RSD',
62
- 'RUB','RWF','SAR','SBD','SCR','SDG','SEK','SGD','SHP','SLL','SOS','SRD',
63
- 'SSP','STD','SYP','SZL','THB','TJS','TMM','TND','TOP','TRY','TTD','TWD',
64
- 'TZS','UAH','UGX','USD','USN','USS','UYU','UZS','VEF','VND','VUV','WST',
65
- 'XAF','XAG','XAU','XBA','XBB','XBC','XBD','XCD','XDR','XFU','XOF','XPD',
66
- 'XPF','XPT','XTS','XXX','YER','ZAR','ZMK','ZWD'
62
+ 'AED', 'AFN', 'ALL', 'AMD', 'ANG', 'AOA', 'ARS', 'AUD', 'AWG', 'AZN',
63
+ 'BAM', 'BBD', 'BDT', 'BGN', 'BHD', 'BIF', 'BMD', 'BND', 'BOB', 'BOV',
64
+ 'BRL', 'BSD', 'BTN', 'BWP', 'BYR', 'BZD', 'CAD', 'CDF', 'CHE', 'CHF',
65
+ 'CHW', 'CLF', 'CLP', 'CNY', 'COP', 'COU', 'CRC', 'CUP', 'CVE', 'CZK',
66
+ 'DJF', 'DKK', 'DOP', 'DZD', 'EGP', 'ERN', 'ETB', 'EUR', 'FJD', 'FKP',
67
+ 'GBP', 'GEL', 'GHS', 'GIP', 'GMD', 'GNF', 'GTQ', 'GYD', 'HKD', 'HNL',
68
+ 'HRK', 'HTG', 'HUF', 'IDR', 'ILS', 'INR', 'IQD', 'IRR', 'ISK', 'JMD',
69
+ 'JOD', 'JPY', 'KES', 'KGS', 'KHR', 'KUR', 'KMF', 'KPW', 'KRW', 'KWD',
70
+ 'KYD', 'KZT', 'LAK', 'LBP', 'LKR', 'LRD', 'LSL', 'LYD', 'MAD', 'MDL',
71
+ 'MGA', 'MKD', 'MMK', 'MNT', 'MOP', 'MRO', 'MUR', 'MVR', 'MWK', 'MXN',
72
+ 'MXV', 'MYR', 'MZN', 'NAD', 'NGN', 'NIO', 'NOK', 'NPR', 'NZD', 'OMR',
73
+ 'PAB', 'PEN', 'PGK', 'PHP', 'PKR', 'PLN', 'PYG', 'QAR', 'RON', 'RSD',
74
+ 'RUB', 'RWF', 'SAR', 'SBD', 'SCR', 'SDG', 'SEK', 'SGD', 'SHP', 'SLL',
75
+ 'SOS', 'SRD', 'SSP', 'STD', 'SYP', 'SZL', 'THB', 'TJS', 'TMM', 'TND',
76
+ 'TOP', 'TRY', 'TTD', 'TWD', 'TZS', 'UAH', 'UGX', 'USD', 'USN', 'USS',
77
+ 'UYU', 'UZS', 'VEF', 'VND', 'VUV', 'WST', 'XAF', 'XAG', 'XAU', 'XBA',
78
+ 'XBB', 'XBC', 'XBD', 'XCD', 'XDR', 'XFU', 'XOF', 'XPD', 'XPF', 'XPT',
79
+ 'XTS', 'XXX', 'YER', 'ZAR', 'ZMK', 'ZWD'
67
80
  )
68
81
  CustomerTypes = Types::Strict::String.enum(
69
82
  'PRIVATE', 'COMPANY'
@@ -1,18 +1,18 @@
1
- require "fortnox/api/types/document_row"
1
+ # frozen_string_literal: true
2
+
3
+ require 'fortnox/api/types/document_row'
2
4
 
3
5
  module Fortnox
4
6
  module API
5
7
  module Types
6
- class InvoiceRow < Fortnox::API::Types::Model
8
+ class InvoiceRow < DocumentRow
7
9
  STUB = {}.freeze
8
-
9
- DocumentRow.ify self
10
10
 
11
- #PriceExcludingVAT Price per unit excluding VAT.
12
- attribute :price_excluding_vat, Types::Nullable::Float.with( private: true )
11
+ # PriceExcludingVAT Price per unit excluding VAT.
12
+ attribute :price_excluding_vat, Types::Nullable::Float.with(private: true)
13
13
 
14
- #TotalExcludingVAT Total amount for the row excluding VAT.
15
- attribute :total_excluding_vat, Types::Nullable::Float.with( private: true )
14
+ # TotalExcludingVAT Total amount for the row excluding VAT.
15
+ attribute :total_excluding_vat, Types::Nullable::Float.with(private: true)
16
16
  end
17
17
  end
18
18
  end
@@ -1,21 +1,26 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Fortnox
2
4
  module API
3
5
  module Types
4
6
  class Model < Dry::Struct
5
7
  constructor_type(:schema)
6
8
 
7
- def initialize( input_attributes )
8
- if (missing_key = first_missing_required_key( input_attributes ))
9
- raise Fortnox::API::MissingAttributeError.new( "Missing attribute #{ missing_key.inspect } in attributes: #{ input_attributes }" )
9
+ def initialize(input_attributes)
10
+ if (missing_key = first_missing_required_key(input_attributes))
11
+ error_message = "Missing attribute #{missing_key.inspect} in attributes: #{input_attributes}"
12
+ raise Fortnox::API::MissingAttributeError, error_message
10
13
  end
11
14
 
12
15
  super
13
16
  end
14
17
 
15
- private
18
+ def self.is?(*_args) end
19
+
20
+ private
16
21
 
17
- def missing_keys( attributes )
18
- non_nil_attributes = attributes.select{ |_,value| !value.nil? }
22
+ def missing_keys(attributes)
23
+ non_nil_attributes = attributes.reject { |_, value| value.nil? }
19
24
 
20
25
  attribute_keys = non_nil_attributes.keys
21
26
  schema_keys = self.class.schema.keys
@@ -23,14 +28,13 @@ module Fortnox
23
28
  schema_keys - attribute_keys
24
29
  end
25
30
 
26
- def first_missing_required_key( attributes )
27
- missing_keys( attributes ).find do |name|
28
- attribute = self.class.schema[ name ]
31
+ def first_missing_required_key(attributes)
32
+ missing_keys(attributes).find do |name|
33
+ attribute = self.class.schema[name]
29
34
  attribute.respond_to?(:options) && attribute.options[:required]
30
35
  end
31
36
  end
32
37
  end
33
-
34
38
  end
35
39
  end
36
40
  end
@@ -1,21 +1,21 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'date'
2
4
 
3
5
  module Fortnox
4
6
  module API
5
7
  module Types
6
-
7
8
  module Nullable
8
- String = Types::Strict::String.optional.constructor{ |value| value.to_s unless value.nil? }
9
- Float = Types::Strict::Float.optional.constructor{ |value| value.to_f unless value.nil? }
10
- Integer = Types::Strict::Int.optional.constructor{ |value| value.to_i unless value.nil? }
11
- Boolean = Types::Bool.optional.constructor{ |value| THE_TRUTH.fetch( value ){ false } }
9
+ String = Types::Strict::String.optional.constructor { |value| value.to_s unless value.nil? }
10
+ Float = Types::Strict::Float.optional.constructor { |value| value.to_f unless value.nil? }
11
+ Integer = Types::Strict::Int.optional.constructor { |value| value.to_i unless value.nil? }
12
+ Boolean = Types::Bool.optional.constructor { |value| THE_TRUTH.fetch(value) { false } }
12
13
  # TODO: Improve parsing!
13
14
  # In case date parsing fails, ArgumentError is thrown. Currently, it is rescued in Repository::Loaders.find.
14
15
  # That method assumes that the exception is due to invalid argument to the find method, which is not the case
15
16
  # if it is raised from here!
16
- Date = Types::Date.optional.constructor{ |value| ::Date.parse( value.to_s ) unless value.nil? || value == '' }
17
+ Date = Types::Date.optional.constructor { |value| ::Date.parse(value.to_s) unless value.nil? || value == '' }
17
18
  end
18
-
19
19
  end
20
20
  end
21
21
  end
@@ -1,14 +1,14 @@
1
- require "fortnox/api/types/document_row"
1
+ # frozen_string_literal: true
2
+
3
+ require 'fortnox/api/types/document_row'
2
4
 
3
5
  module Fortnox
4
6
  module API
5
7
  module Types
6
- class OrderRow < Fortnox::API::Types::Model
8
+ class OrderRow < DocumentRow
7
9
  STUB = { ordered_quantity: 0 }.freeze
8
10
 
9
- DocumentRow.ify self
10
-
11
- #OrderedQuantity Ordered quantity
11
+ # OrderedQuantity Ordered quantity
12
12
  attribute :ordered_quantity, Types::Required::Float
13
13
  end
14
14
  end