fortnox-api 0.8.0 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (255) hide show
  1. checksums.yaml +4 -4
  2. data/.codeclimate.yml +1 -0
  3. data/.env.template +7 -0
  4. data/.env.test +11 -3
  5. data/.gitignore +7 -1
  6. data/.rubocop.yml +18 -2
  7. data/.tool-versions +1 -0
  8. data/.travis.yml +15 -12
  9. data/CHANGELOG.md +58 -3
  10. data/CONTRIBUTE.md +21 -9
  11. data/DEVELOPER_README.md +72 -0
  12. data/Guardfile +13 -4
  13. data/README.md +226 -64
  14. data/Rakefile +128 -0
  15. data/bin/get_tokens +79 -0
  16. data/bin/renew_tokens +28 -0
  17. data/fortnox-api.gemspec +31 -25
  18. data/lib/fortnox/api/mappers/article.rb +1 -1
  19. data/lib/fortnox/api/mappers/base/from_json.rb +5 -4
  20. data/lib/fortnox/api/mappers/base/to_json.rb +4 -5
  21. data/lib/fortnox/api/mappers/base.rb +3 -3
  22. data/lib/fortnox/api/mappers/customer.rb +1 -1
  23. data/lib/fortnox/api/mappers/default_delivery_types.rb +1 -1
  24. data/lib/fortnox/api/mappers/default_templates.rb +1 -1
  25. data/lib/fortnox/api/mappers/edi_information.rb +1 -1
  26. data/lib/fortnox/api/mappers/email_information.rb +1 -1
  27. data/lib/fortnox/api/mappers/invoice.rb +4 -4
  28. data/lib/fortnox/api/mappers/invoice_row.rb +1 -1
  29. data/lib/fortnox/api/mappers/order.rb +4 -4
  30. data/lib/fortnox/api/mappers/order_row.rb +1 -1
  31. data/lib/fortnox/api/mappers/project.rb +1 -1
  32. data/lib/fortnox/api/mappers/terms_of_payment.rb +1 -1
  33. data/lib/fortnox/api/mappers/unit.rb +1 -1
  34. data/lib/fortnox/api/mappers/value/country_string.rb +1 -1
  35. data/lib/fortnox/api/mappers.rb +18 -18
  36. data/lib/fortnox/api/models/article.rb +2 -2
  37. data/lib/fortnox/api/models/base.rb +23 -21
  38. data/lib/fortnox/api/models/customer.rb +57 -57
  39. data/lib/fortnox/api/models/document.rb +2 -2
  40. data/lib/fortnox/api/models/invoice.rb +2 -2
  41. data/lib/fortnox/api/models/label.rb +3 -3
  42. data/lib/fortnox/api/models/order.rb +2 -2
  43. data/lib/fortnox/api/models/project.rb +2 -2
  44. data/lib/fortnox/api/models/terms_of_payment.rb +2 -2
  45. data/lib/fortnox/api/models/unit.rb +2 -2
  46. data/lib/fortnox/api/models.rb +7 -7
  47. data/lib/fortnox/api/repositories/article.rb +3 -3
  48. data/lib/fortnox/api/repositories/authentication.rb +61 -0
  49. data/lib/fortnox/api/repositories/base/savers.rb +3 -1
  50. data/lib/fortnox/api/repositories/base.rb +25 -38
  51. data/lib/fortnox/api/repositories/customer.rb +3 -3
  52. data/lib/fortnox/api/repositories/invoice.rb +3 -3
  53. data/lib/fortnox/api/repositories/order.rb +3 -3
  54. data/lib/fortnox/api/repositories/project.rb +3 -3
  55. data/lib/fortnox/api/repositories/terms_of_payment.rb +3 -3
  56. data/lib/fortnox/api/repositories/unit.rb +3 -3
  57. data/lib/fortnox/api/repositories.rb +8 -7
  58. data/lib/fortnox/api/request_handling.rb +30 -18
  59. data/lib/fortnox/api/types/default_delivery_types.rb +0 -2
  60. data/lib/fortnox/api/types/default_templates.rb +0 -2
  61. data/lib/fortnox/api/types/document_row.rb +3 -3
  62. data/lib/fortnox/api/types/edi_information.rb +0 -2
  63. data/lib/fortnox/api/types/email_information.rb +0 -2
  64. data/lib/fortnox/api/types/enums.rb +27 -11
  65. data/lib/fortnox/api/types/invoice_row.rb +1 -1
  66. data/lib/fortnox/api/types/model.rb +5 -9
  67. data/lib/fortnox/api/types/nullable.rb +13 -9
  68. data/lib/fortnox/api/types/order_row.rb +1 -1
  69. data/lib/fortnox/api/types/required.rb +3 -3
  70. data/lib/fortnox/api/types/sized.rb +4 -4
  71. data/lib/fortnox/api/types.rb +31 -23
  72. data/lib/fortnox/api/version.rb +1 -1
  73. data/lib/fortnox/api.rb +21 -39
  74. data/spec/fortnox/api/mappers/base/canonical_name_sym_spec.rb +13 -11
  75. data/spec/fortnox/api/mappers/base/from_json_spec.rb +10 -12
  76. data/spec/fortnox/api/mappers/base/to_json_spec.rb +48 -57
  77. data/spec/fortnox/api/mappers/base_spec.rb +4 -7
  78. data/spec/fortnox/api/mappers/contexts/json_conversion.rb +38 -33
  79. data/spec/fortnox/api/mappers/default_delivery_types_spec.rb +1 -1
  80. data/spec/fortnox/api/mappers/examples/mapper.rb +1 -1
  81. data/spec/fortnox/api/mappers/unit_spec.rb +3 -4
  82. data/spec/fortnox/api/models/base_spec.rb +33 -22
  83. data/spec/fortnox/api/models/unit_spec.rb +5 -3
  84. data/spec/fortnox/api/repositories/article_spec.rb +14 -9
  85. data/spec/fortnox/api/repositories/authentication_spec.rb +103 -0
  86. data/spec/fortnox/api/repositories/base_spec.rb +105 -326
  87. data/spec/fortnox/api/repositories/customer_spec.rb +37 -7
  88. data/spec/fortnox/api/repositories/examples/all.rb +0 -1
  89. data/spec/fortnox/api/repositories/examples/find.rb +5 -8
  90. data/spec/fortnox/api/repositories/examples/only.rb +4 -13
  91. data/spec/fortnox/api/repositories/examples/save.rb +32 -18
  92. data/spec/fortnox/api/repositories/examples/save_with_nested_model.rb +0 -5
  93. data/spec/fortnox/api/repositories/examples/save_with_specially_named_attribute.rb +1 -4
  94. data/spec/fortnox/api/repositories/examples/search.rb +4 -7
  95. data/spec/fortnox/api/repositories/invoice_spec.rb +64 -21
  96. data/spec/fortnox/api/repositories/order_spec.rb +11 -9
  97. data/spec/fortnox/api/repositories/project_spec.rb +7 -6
  98. data/spec/fortnox/api/repositories/terms_of_payment_spec.rb +9 -7
  99. data/spec/fortnox/api/repositories/unit_spec.rb +13 -11
  100. data/spec/fortnox/api/types/country_spec.rb +1 -1
  101. data/spec/fortnox/api/types/email_spec.rb +2 -2
  102. data/spec/fortnox/api/types/examples/document_row.rb +3 -3
  103. data/spec/fortnox/api/types/examples/enum.rb +4 -4
  104. data/spec/fortnox/api/types/examples/types.rb +1 -3
  105. data/spec/fortnox/api/types/housework_types_spec.rb +54 -90
  106. data/spec/fortnox/api/types/model_spec.rb +13 -23
  107. data/spec/fortnox/api/types/nullable_spec.rb +30 -10
  108. data/spec/fortnox/api/types/order_row_spec.rb +2 -2
  109. data/spec/fortnox/api/types/required_spec.rb +7 -15
  110. data/spec/fortnox/api/types/sales_account_spec.rb +57 -0
  111. data/spec/fortnox/api_spec.rb +19 -124
  112. data/spec/spec_helper.rb +0 -14
  113. data/spec/support/helpers/configuration_helper.rb +30 -3
  114. data/spec/support/helpers.rb +1 -1
  115. data/spec/support/matchers/type/attribute_matcher.rb +2 -2
  116. data/spec/support/matchers/type/enum_matcher.rb +1 -1
  117. data/spec/support/matchers/type/have_account_number_matcher.rb +1 -1
  118. data/spec/support/matchers/type/have_email_matcher.rb +1 -1
  119. data/spec/support/matchers/type/have_nullable_date_matcher.rb +7 -5
  120. data/spec/support/matchers/type/have_nullable_matcher.rb +1 -1
  121. data/spec/support/matchers/type/have_nullable_string_matcher.rb +5 -5
  122. data/spec/support/matchers/type/require_attribute_matcher.rb +5 -5
  123. data/spec/support/matchers/type/type_matcher.rb +1 -1
  124. data/spec/support/vcr_setup.rb +16 -0
  125. data/spec/vcr_cassettes/articles/all.yml +32 -49
  126. data/spec/vcr_cassettes/articles/find_by_hash_failure.yml +27 -23
  127. data/spec/vcr_cassettes/articles/find_failure.yml +27 -23
  128. data/spec/vcr_cassettes/articles/find_id_1.yml +29 -24
  129. data/spec/vcr_cassettes/articles/find_new.yml +30 -26
  130. data/spec/vcr_cassettes/articles/multi_param_find_by_hash.yml +29 -25
  131. data/spec/vcr_cassettes/articles/save_new.yml +29 -25
  132. data/spec/vcr_cassettes/articles/save_old.yml +30 -26
  133. data/spec/vcr_cassettes/articles/save_with_specially_named_attribute.yml +29 -25
  134. data/spec/vcr_cassettes/articles/search_by_name.yml +32 -25
  135. data/spec/vcr_cassettes/articles/search_miss.yml +27 -23
  136. data/spec/vcr_cassettes/articles/search_with_special_char.yml +27 -23
  137. data/spec/vcr_cassettes/articles/single_param_find_by_hash.yml +29 -36
  138. data/spec/vcr_cassettes/authentication/expired_token.yml +54 -0
  139. data/spec/vcr_cassettes/authentication/invalid_authorization.yml +57 -0
  140. data/spec/vcr_cassettes/authentication/invalid_refresh_token.yml +58 -0
  141. data/spec/vcr_cassettes/authentication/valid_request.yml +63 -0
  142. data/spec/vcr_cassettes/customers/all.yml +35 -136
  143. data/spec/vcr_cassettes/customers/find_by_hash_failure.yml +27 -23
  144. data/spec/vcr_cassettes/customers/find_failure.yml +27 -23
  145. data/spec/vcr_cassettes/customers/find_id_1.yml +30 -25
  146. data/spec/vcr_cassettes/customers/find_new.yml +29 -25
  147. data/spec/vcr_cassettes/customers/find_with_sales_account.yml +63 -0
  148. data/spec/vcr_cassettes/customers/multi_param_find_by_hash.yml +29 -25
  149. data/spec/vcr_cassettes/customers/save_new.yml +28 -24
  150. data/spec/vcr_cassettes/customers/save_new_with_country_code_SE.yml +28 -24
  151. data/spec/vcr_cassettes/customers/save_new_with_sales_account.yml +63 -0
  152. data/spec/vcr_cassettes/customers/save_old.yml +29 -25
  153. data/spec/vcr_cassettes/customers/save_with_specially_named_attribute.yml +28 -24
  154. data/spec/vcr_cassettes/customers/search_by_name.yml +29 -53
  155. data/spec/vcr_cassettes/customers/search_miss.yml +27 -23
  156. data/spec/vcr_cassettes/customers/search_with_special_char.yml +27 -23
  157. data/spec/vcr_cassettes/customers/single_param_find_by_hash.yml +30 -26
  158. data/spec/vcr_cassettes/invoices/all.yml +62 -121
  159. data/spec/vcr_cassettes/invoices/filter_hit.yml +30 -28
  160. data/spec/vcr_cassettes/invoices/filter_invalid.yml +27 -23
  161. data/spec/vcr_cassettes/invoices/find_by_hash_failure.yml +27 -23
  162. data/spec/vcr_cassettes/invoices/find_failure.yml +27 -23
  163. data/spec/vcr_cassettes/invoices/find_id_1.yml +31 -26
  164. data/spec/vcr_cassettes/invoices/find_new.yml +32 -28
  165. data/spec/vcr_cassettes/invoices/multi_param_find_by_hash.yml +29 -25
  166. data/spec/vcr_cassettes/invoices/row_description_limit.yml +65 -0
  167. data/spec/vcr_cassettes/invoices/save_new.yml +31 -27
  168. data/spec/vcr_cassettes/invoices/save_new_with_comments.yml +31 -27
  169. data/spec/vcr_cassettes/invoices/save_new_with_country.yml +31 -26
  170. data/spec/vcr_cassettes/invoices/save_new_with_country_GB.yml +32 -27
  171. data/spec/vcr_cassettes/invoices/save_new_with_country_Norge.yml +31 -26
  172. data/spec/vcr_cassettes/invoices/save_new_with_country_Norway.yml +31 -26
  173. data/spec/vcr_cassettes/invoices/save_new_with_country_Sverige.yml +31 -26
  174. data/spec/vcr_cassettes/invoices/save_new_with_country_VA.yml +32 -27
  175. data/spec/vcr_cassettes/invoices/save_new_with_country_VI.yml +32 -27
  176. data/spec/vcr_cassettes/invoices/save_new_with_country_empty_string.yml +31 -26
  177. data/spec/vcr_cassettes/invoices/save_new_with_country_nil.yml +31 -26
  178. data/spec/vcr_cassettes/invoices/save_new_with_unsaved_parent.yml +65 -0
  179. data/spec/vcr_cassettes/invoices/save_old.yml +32 -28
  180. data/spec/vcr_cassettes/invoices/save_old_with_empty_comments.yml +32 -28
  181. data/spec/vcr_cassettes/invoices/save_old_with_empty_country.yml +32 -27
  182. data/spec/vcr_cassettes/invoices/save_old_with_nil_comments.yml +32 -28
  183. data/spec/vcr_cassettes/invoices/save_old_with_nil_country.yml +32 -27
  184. data/spec/vcr_cassettes/invoices/save_with_nested_model.yml +32 -27
  185. data/spec/vcr_cassettes/invoices/save_with_specially_named_attribute.yml +31 -26
  186. data/spec/vcr_cassettes/invoices/search_by_name.yml +29 -31
  187. data/spec/vcr_cassettes/invoices/search_miss.yml +27 -23
  188. data/spec/vcr_cassettes/invoices/search_with_special_char.yml +27 -23
  189. data/spec/vcr_cassettes/invoices/single_param_find_by_hash.yml +30 -26
  190. data/spec/vcr_cassettes/orders/all.yml +35 -123
  191. data/spec/vcr_cassettes/orders/filter_hit.yml +30 -30
  192. data/spec/vcr_cassettes/orders/filter_invalid.yml +27 -23
  193. data/spec/vcr_cassettes/orders/find_by_hash_failure.yml +27 -23
  194. data/spec/vcr_cassettes/orders/find_failure.yml +27 -23
  195. data/spec/vcr_cassettes/orders/find_id_1.yml +33 -27
  196. data/spec/vcr_cassettes/orders/find_new.yml +32 -28
  197. data/spec/vcr_cassettes/orders/housework_invalid_tax_reduction_type.yml +28 -24
  198. data/spec/vcr_cassettes/orders/housework_othercoses_invalid.yml +28 -24
  199. data/spec/vcr_cassettes/orders/housework_type_babysitting.yml +32 -27
  200. data/spec/vcr_cassettes/orders/housework_type_cleaning.yml +32 -27
  201. data/spec/vcr_cassettes/orders/housework_type_construction.yml +32 -27
  202. data/spec/vcr_cassettes/orders/housework_type_cooking.yml +28 -24
  203. data/spec/vcr_cassettes/orders/housework_type_electricity.yml +32 -27
  204. data/spec/vcr_cassettes/orders/housework_type_gardening.yml +32 -27
  205. data/spec/vcr_cassettes/orders/housework_type_glassmetalwork.yml +32 -27
  206. data/spec/vcr_cassettes/orders/housework_type_grounddrainagework.yml +32 -27
  207. data/spec/vcr_cassettes/orders/housework_type_hvac.yml +32 -27
  208. data/spec/vcr_cassettes/orders/housework_type_itservices.yml +32 -27
  209. data/spec/vcr_cassettes/orders/housework_type_majorappliancerepair.yml +32 -27
  210. data/spec/vcr_cassettes/orders/housework_type_masonry.yml +32 -27
  211. data/spec/vcr_cassettes/orders/housework_type_movingservices.yml +32 -27
  212. data/spec/vcr_cassettes/orders/housework_type_othercare.yml +32 -27
  213. data/spec/vcr_cassettes/orders/housework_type_othercosts.yml +32 -27
  214. data/spec/vcr_cassettes/orders/housework_type_paintingwallpapering.yml +32 -27
  215. data/spec/vcr_cassettes/orders/housework_type_snowplowing.yml +32 -27
  216. data/spec/vcr_cassettes/orders/housework_type_textileclothing.yml +32 -27
  217. data/spec/vcr_cassettes/orders/housework_type_tutoring.yml +28 -24
  218. data/spec/vcr_cassettes/orders/multi_param_find_by_hash.yml +29 -25
  219. data/spec/vcr_cassettes/orders/save_new.yml +32 -28
  220. data/spec/vcr_cassettes/orders/save_old.yml +32 -28
  221. data/spec/vcr_cassettes/orders/save_with_nested_model.yml +32 -27
  222. data/spec/vcr_cassettes/orders/search_by_name.yml +29 -27
  223. data/spec/vcr_cassettes/orders/search_miss.yml +27 -23
  224. data/spec/vcr_cassettes/orders/search_with_special_char.yml +27 -23
  225. data/spec/vcr_cassettes/orders/single_param_find_by_hash.yml +30 -26
  226. data/spec/vcr_cassettes/projects/all.yml +30 -43
  227. data/spec/vcr_cassettes/projects/find_by_hash_failure.yml +27 -23
  228. data/spec/vcr_cassettes/projects/find_failure.yml +27 -23
  229. data/spec/vcr_cassettes/projects/find_id_1.yml +29 -25
  230. data/spec/vcr_cassettes/projects/find_new.yml +30 -26
  231. data/spec/vcr_cassettes/projects/multi_param_find_by_hash.yml +31 -26
  232. data/spec/vcr_cassettes/projects/save_new.yml +29 -25
  233. data/spec/vcr_cassettes/projects/save_old.yml +30 -26
  234. data/spec/vcr_cassettes/projects/single_param_find_by_hash.yml +29 -25
  235. data/spec/vcr_cassettes/termsofpayments/all.yml +32 -32
  236. data/spec/vcr_cassettes/termsofpayments/find_failure.yml +27 -23
  237. data/spec/vcr_cassettes/termsofpayments/find_id_1.yml +29 -26
  238. data/spec/vcr_cassettes/termsofpayments/find_new.yml +29 -25
  239. data/spec/vcr_cassettes/termsofpayments/save_new.yml +29 -25
  240. data/spec/vcr_cassettes/termsofpayments/save_old.yml +29 -25
  241. data/spec/vcr_cassettes/units/all.yml +29 -32
  242. data/spec/vcr_cassettes/units/find_failure.yml +27 -23
  243. data/spec/vcr_cassettes/units/find_id_1.yml +29 -25
  244. data/spec/vcr_cassettes/units/find_new.yml +29 -25
  245. data/spec/vcr_cassettes/units/save_new.yml +29 -25
  246. data/spec/vcr_cassettes/units/save_old.yml +29 -25
  247. data/spec/vcr_cassettes/units/save_with_specially_named_attribute.yml +29 -25
  248. metadata +130 -261
  249. data/lib/fortnox/api/circular_queue.rb +0 -39
  250. data/spec/fortnox/api/circular_queue_spec.rb +0 -52
  251. data/spec/support/helpers/dummy_class_helper.rb +0 -38
  252. data/spec/support/helpers/when_performing_helper.rb +0 -7
  253. data/spec/vcr_cassettes/invoices/save_new_with_country_KR.yml +0 -61
  254. data/spec/vcr_cassettes/orders/housework_without_tax_reduction_type.yml +0 -57
  255. data/temp.txt +0 -1
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'fortnox/api/types'
4
- require 'fortnox/api/models/base'
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 First address of the customer. 1024 characters
33
+ # Address1 First address of the customer. 1024 characters
34
34
  attribute :address1, Types::Sized::String[1024]
35
35
 
36
- # Address2 Second address of the customer. 1024 characters
36
+ # Address2 Second address of the customer. 1024 characters
37
37
  attribute :address2, Types::Sized::String[1024]
38
38
 
39
- # City City of the customer. 1024 characters
39
+ # City City of the customer. 1024 characters
40
40
  attribute :city, Types::Sized::String[1024]
41
41
 
42
- # Country Country of the customer. Read-only.
42
+ # Country Country of the customer. Read-only.
43
43
  attribute :country, Types::Nullable::String.is(:read_only)
44
44
 
45
- # Comments Comments. 1024 characters.
45
+ # Comments Comments. 1024 characters.
46
46
  attribute :comments, Types::Sized::String[1024]
47
47
 
48
- # Currency Currency of the customer, 3 letters
48
+ # Currency Currency of the customer, 3 letters
49
49
  attribute :currency, Types::Currency
50
50
 
51
- # CostCenter Cost center of the customer, Cost center in Fortnox
51
+ # CostCenter Cost center of the customer, Cost center in Fortnox
52
52
  attribute :cost_center, Types::Nullable::String
53
53
 
54
- # CountryCode Country code of the customer, 2 letters
54
+ # CountryCode Country code of the customer, 2 letters
55
55
  attribute :country_code, Types::CountryCode
56
56
 
57
- # CustomerNumber Customer number. 1024 characters
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 First delivery address of the customer. 1024 characters
66
+ # DeliveryAddress1 First delivery address of the customer. 1024 characters
67
67
  attribute :delivery_address1, Types::Sized::String[1024]
68
68
 
69
- # DeliveryAddress2 Second delivery address of the customer. 1024 characters
69
+ # DeliveryAddress2 Second delivery address of the customer. 1024 characters
70
70
  attribute :delivery_address2, Types::Sized::String[1024]
71
71
 
72
- # DeliveryCity Delivery city of the customer. 1024 characters
72
+ # DeliveryCity Delivery city of the customer. 1024 characters
73
73
  attribute :delivery_city, Types::Sized::String[1024]
74
74
 
75
- # DeliveryCountry Delivery country of the customer. Read-only.
75
+ # DeliveryCountry Delivery country of the customer. Read-only.
76
76
  attribute :delivery_country, Types::Nullable::String.is(:read_only)
77
77
 
78
- # DeliveryCountryCode Delivery country code of the customer, 2 letters
78
+ # DeliveryCountryCode Delivery country code of the customer, 2 letters
79
79
  attribute :delivery_country_code, Types::CountryCode
80
80
 
81
- # DeliveryFax Delivery fax number of the customer. 1024 characters
81
+ # DeliveryFax Delivery fax number of the customer. 1024 characters
82
82
  attribute :delivery_fax, Types::Sized::String[1024]
83
83
 
84
- # DeliveryName Delivery name of the customer. 1024 characters
84
+ # DeliveryName Delivery name of the customer. 1024 characters
85
85
  attribute :delivery_name, Types::Sized::String[1024]
86
86
 
87
- # DeliveryPhone1 First delivery phone number of the customer. 1024 characters
87
+ # DeliveryPhone1 First delivery phone number of the customer. 1024 characters
88
88
  attribute :delivery_phone1, Types::Sized::String[1024]
89
89
 
90
- # DeliveryPhone2 Second delivery phone number of the customer. 1024 characters
90
+ # DeliveryPhone2 Second delivery phone number of the customer. 1024 characters
91
91
  attribute :delivery_phone2, Types::Sized::String[1024]
92
92
 
93
- # DeliveryZipCode Delivery zip code of the customer. 1024 characters.
93
+ # DeliveryZipCode Delivery zip code of the customer. 1024 characters.
94
94
  attribute :delivery_zip_code, Types::Sized::String[1024]
95
95
 
96
- # Email Email address of the customer. 1024 characters
96
+ # Email Email address of the customer. 1024 characters
97
97
  attribute :email, Types::Email
98
98
 
99
- # EmailInvoice Invoice email address of the customer. 1024 characters
99
+ # EmailInvoice Invoice email address of the customer. 1024 characters
100
100
  attribute :email_invoice, Types::Email
101
101
 
102
- # EmailInvoiceBCC Invoice BCC email address of the customer. 1024 characters
102
+ # EmailInvoiceBCC Invoice BCC email address of the customer. 1024 characters
103
103
  attribute :email_invoice_bcc, Types::Email
104
104
 
105
- # EmailInvoiceCC Invoice CC email address of the customer. 1024 characters
105
+ # EmailInvoiceCC Invoice CC email address of the customer. 1024 characters
106
106
  attribute :email_invoice_cc, Types::Email
107
107
 
108
- # EmailOffer Offer email address of the customer. 1024 characters
108
+ # EmailOffer Offer email address of the customer. 1024 characters
109
109
  attribute :email_offer, Types::Email
110
110
 
111
- # EmailOfferBCC Offer BCC email address of the customer. 1024 characters
111
+ # EmailOfferBCC Offer BCC email address of the customer. 1024 characters
112
112
  attribute :email_offer_bcc, Types::Email
113
113
 
114
- # EmailOfferCC Offer CC email address of the customer. 1024 characters
114
+ # EmailOfferCC Offer CC email address of the customer. 1024 characters
115
115
  attribute :email_offer_cc, Types::Email
116
116
 
117
- # EmailOrder Order email address of the customer. 1024 characters
117
+ # EmailOrder Order email address of the customer. 1024 characters
118
118
  attribute :email_order, Types::Email
119
119
 
120
- # EmailOrderBCC Order BCC email address of the customer. 1024 characters
120
+ # EmailOrderBCC Order BCC email address of the customer. 1024 characters
121
121
  attribute :email_order_bcc, Types::Email
122
122
 
123
- # EmailOrderCC Order CC email address of the customer. 1024 characters
123
+ # EmailOrderCC Order CC email address of the customer. 1024 characters
124
124
  attribute :email_order_cc, Types::Email
125
125
 
126
- # Fax Fax number of the customer. 1024 characters
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 Invoice discount of the customer, 12 digits (incl. decimals)
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 Invoice freight fee of the customer, 12 digits (incl. decimals)
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 Invoice remark of the customer. 1024 characters
139
+ # InvoiceRemark Invoice remark of the customer. 1024 characters
140
140
  attribute :invoice_remark, Types::Sized::String[1024]
141
141
 
142
- # Name Name of the customer, 1024 characters
142
+ # Name Name of the customer, 1024 characters
143
143
  attribute :name, Types::Sized::String[1024].is(:required)
144
144
 
145
- # OrganisationNumber Organisation number of the customer. 30 characters
145
+ # OrganisationNumber Organisation number of the customer. 30 characters
146
146
  attribute :organisation_number, Types::Sized::String[30]
147
147
 
148
- # OurReference Our reference of the customer. 50 characters
148
+ # OurReference Our reference of the customer. 50 characters
149
149
  attribute :our_reference, Types::Sized::String[50]
150
150
 
151
- # Phone1 First phone number of the customer. 1024 characters
151
+ # Phone1 First phone number of the customer. 1024 characters
152
152
  attribute :phone1, Types::Sized::String[1024]
153
153
 
154
- # Phone2 Second phone number of the customer. 1024 characters
154
+ # Phone2 Second phone number of the customer. 1024 characters
155
155
  attribute :phone2, Types::Sized::String[1024]
156
156
 
157
- # PriceList Price list of the customer, Price list in Fortnox
157
+ # PriceList Price list of the customer, Price list in Fortnox
158
158
  attribute :price_list, Types::Nullable::String
159
159
 
160
- # Project Project of the customer, Project in Fortnox
160
+ # Project Project of the customer, Project in Fortnox
161
161
  attribute :project, Types::Nullable::String
162
162
 
163
- # SalesAccount Sales account of the customer, 4 digits
164
- attribute :sales_account, Types::AccountNumber
163
+ # SalesAccount Sales account of the customer, 4 characters
164
+ attribute :sales_account, Types::SalesAccount
165
165
 
166
- # ShowPriceVATIncluded Show prices with VAT included or not
166
+ # ShowPriceVATIncluded Show prices with VAT included or not
167
167
  attribute :show_price_vat_included, Types::Nullable::Boolean
168
168
 
169
- # TermsOfDeliveryCode Terms of delivery code of the customer
169
+ # TermsOfDeliveryCode Terms of delivery code of the customer
170
170
  attribute :terms_of_delivery, Types::Nullable::String
171
171
 
172
- # TermsOfPaymentCode Terms of payment code of the customer
172
+ # TermsOfPaymentCode Terms of payment code of the customer
173
173
  attribute :terms_of_payment, Types::Nullable::String
174
174
 
175
- # Type Customer type, PRIVATE / COMPANY
175
+ # Type Customer type, PRIVATE / COMPANY
176
176
  attribute :type, Types::CustomerType
177
177
 
178
- # VATNumber VAT number of the customer
178
+ # VATNumber VAT number of the customer
179
179
  attribute :vat_number, Types::Nullable::String
180
180
 
181
- # VATType VAT type of the customer, SEVAT / SEREVERSEDVAT / EUREVERSEDVAT / EUVAT / EXPORT
181
+ # VATType VAT type of the customer, SEVAT / SEREVERSEDVAT / EUREVERSEDVAT / EUVAT / EXPORT
182
182
  attribute :vat_type, Types::VATType
183
183
 
184
- # VisitAddress Visit address of the customer. 128 characters
184
+ # VisitAddress Visit address of the customer. 128 characters
185
185
  attribute :visiting_address, Types::Sized::String[128]
186
186
 
187
- # VisitCity Visit city of the customer. 128 characters
187
+ # VisitCity Visit city of the customer. 128 characters
188
188
  attribute :visiting_city, Types::Sized::String[128]
189
189
 
190
- # VisitCountry Visit country of the customer, read-only
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 Visit zip code of the customer. 10 characters
196
+ # VisitZipCode Visit zip code of the customer. 10 characters
197
197
  attribute :visiting_zip_code, Types::Sized::String[10]
198
198
 
199
- # WayOfDeliveryCode Way of delivery code of the customer
199
+ # WayOfDeliveryCode Way of delivery code of the customer
200
200
  attribute :way_of_delivery, Types::Nullable::String
201
201
 
202
- # YourReference Your reference of the customer. 50 characters
202
+ # YourReference Your reference of the customer. 50 characters
203
203
  attribute :your_reference, Types::Sized::String[50]
204
204
 
205
- # ZipCode Zip code of the customer. 10 characters
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
- require 'fortnox/api/types'
4
- require 'fortnox/api/models/label'
3
+ require_relative '../types'
4
+ require_relative 'label'
5
5
 
6
6
  module Fortnox
7
7
  module API
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'fortnox/api/models/base'
4
- require 'fortnox/api/models/document'
3
+ require_relative 'base'
4
+ require_relative 'document'
5
5
 
6
6
  module Fortnox
7
7
  module API
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'fortnox/api/types'
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 integer, read-only. The ID of the label.
11
+ # Id integer, read-only. The ID of the label.
12
12
  attribute :id, Types::Required::Integer.is(:read_only)
13
13
 
14
- # Description string, 25 characters, required. Description of the label
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
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'fortnox/api/models/base'
4
- require 'fortnox/api/models/document'
3
+ require_relative 'base'
4
+ require_relative 'document'
5
5
 
6
6
  module Fortnox
7
7
  module API
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'fortnox/api/types'
4
- require 'fortnox/api/models/base'
3
+ require_relative 'base'
4
+ require_relative '../types'
5
5
 
6
6
  module Fortnox
7
7
  module API
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'fortnox/api/types'
4
- require 'fortnox/api/models/base'
3
+ require_relative '../types'
4
+ require_relative '../models/base'
5
5
 
6
6
  module Fortnox
7
7
  module API
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'fortnox/api/types'
4
- require 'fortnox/api/models/base'
3
+ require_relative 'base'
4
+ require_relative '../types'
5
5
 
6
6
  module Fortnox
7
7
  module API
@@ -1,9 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'fortnox/api/models/article'
4
- require 'fortnox/api/models/customer'
5
- require 'fortnox/api/models/invoice'
6
- require 'fortnox/api/models/order'
7
- require 'fortnox/api/models/project'
8
- require 'fortnox/api/models/unit'
9
- require 'fortnox/api/models/terms_of_payment'
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
- require 'fortnox/api/repositories/base'
4
- require 'fortnox/api/models/article'
5
- require 'fortnox/api/mappers/article'
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
- parent_hash = @mapper.entity_to_hash(entity.parent, @keys_filtered_on_save)
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 'fortnox/api/request_handling'
5
- require 'fortnox/api/repositories/base/loaders'
6
- require 'fortnox/api/repositories/base/savers'
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 = {}) # rubocop:disable Naming/AccessorMethodName
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['Client-Secret'] = client_secret
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], token_store: :default)
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
- end
54
+ return unless access_token.nil?
51
55
 
52
- def next_access_token
53
- @access_tokens ||= CircularQueue.new(*access_tokens)
54
- @access_tokens.next
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
- def check_access_tokens!(tokens)
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 access_tokens
65
- begin
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
- check_access_tokens!(tokens)
72
- tokens
66
+ Fortnox::API.logger.debug("path: #{path.inspect}")
67
+ Fortnox::API.logger.debug("options: #{options.inspect}")
73
68
  end
74
69
 
75
- private
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
- def client_secret
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
- require 'fortnox/api/repositories/base'
4
- require 'fortnox/api/models/customer'
5
- require 'fortnox/api/mappers/customer'
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
- require 'fortnox/api/repositories/base'
4
- require 'fortnox/api/models/invoice'
5
- require 'fortnox/api/mappers/invoice'
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
- require 'fortnox/api/repositories/base'
4
- require 'fortnox/api/models/order'
5
- require 'fortnox/api/mappers/order'
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
- require 'fortnox/api/repositories/base'
4
- require 'fortnox/api/models/project'
5
- require 'fortnox/api/mappers/project'
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
- require 'fortnox/api/repositories/base'
4
- require 'fortnox/api/models/terms_of_payment'
5
- require 'fortnox/api/mappers/terms_of_payment'
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
- require 'fortnox/api/repositories/base'
4
- require 'fortnox/api/models/unit'
5
- require 'fortnox/api/mappers/unit'
3
+ require_relative 'base'
4
+ require_relative '../models/unit'
5
+ require_relative '../mappers/unit'
6
6
 
7
7
  module Fortnox
8
8
  module API
@@ -1,9 +1,10 @@
1
1
  # frozen_string_literal: true
2
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_payment'
3
+ require_relative 'repositories/article'
4
+ require_relative 'repositories/customer'
5
+ require_relative 'repositories/invoice'
6
+ require_relative 'repositories/order'
7
+ require_relative 'repositories/project'
8
+ require_relative 'repositories/unit'
9
+ require_relative 'repositories/terms_of_payment'
10
+ require_relative 'repositories/authentication'