fortnox-api 0.5.2 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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,67 +1,63 @@
1
- require "cgi"
1
+ # frozen_string_literal: true
2
+
3
+ require 'cgi'
2
4
 
3
5
  module Fortnox
4
6
  module API
5
7
  module Repository
6
8
  module Loaders
7
-
8
- def all()
9
- response_hash = get( self.class::URI )
10
- instantiate_collection_response( response_hash )
9
+ def all
10
+ response_hash = get(self.class::URI)
11
+ instantiate_collection_response(response_hash)
11
12
  end
12
13
 
13
- def only( filter )
14
- response_hash = get( "#{ self.class::URI }?filter=#{ filter }" )
15
- instantiate_collection_response( response_hash )
14
+ def only(filter)
15
+ response_hash = get("#{self.class::URI}?filter=#{filter}")
16
+ instantiate_collection_response(response_hash)
16
17
  end
17
18
 
18
- def search( hash )
19
+ def search(hash)
19
20
  attribute, value = hash.first
20
- uri_encoded_value = URI.encode(value)
21
- uri = "#{ self.class::URI }?#{ attribute }=#{ uri_encoded_value }".freeze
22
- response_hash = get( uri )
23
- instantiate_collection_response( response_hash )
21
+ uri_encoded_value = CGI.escape(value)
22
+ uri = "#{self.class::URI}?#{attribute}=#{uri_encoded_value}"
23
+ response_hash = get(uri)
24
+ instantiate_collection_response(response_hash)
24
25
  end
25
26
 
26
- def find( id_or_hash )
27
- return find_all_by( id_or_hash ) if id_or_hash.is_a? Hash
28
-
29
- id = Integer( id_or_hash )
30
- find_one_by( id )
27
+ def find(id_or_hash)
28
+ return find_all_by(id_or_hash) if id_or_hash.is_a? Hash
31
29
 
32
- rescue ArgumentError
33
- raise ArgumentError, "find only accepts a number or hash as argument"
30
+ find_one_by(id_or_hash)
34
31
  end
35
32
 
36
- def find_one_by( id )
37
- response_hash = get( "#{ self.class::URI }#{ id }" )
38
- instantiate( @mapper.wrapped_json_hash_to_entity_hash( response_hash ) )
33
+ def find_one_by(id)
34
+ response_hash = get("#{self.class::URI}#{id}")
35
+ instantiate(@mapper.wrapped_json_hash_to_entity_hash(response_hash))
39
36
  end
40
37
 
41
- def find_all_by( hash )
42
- response_hash = get( "#{ self.class::URI }?#{ to_query( hash ) }" )
43
- instantiate_collection_response( response_hash )
38
+ def find_all_by(hash)
39
+ response_hash = get("#{self.class::URI}?#{to_query(hash)}")
40
+ instantiate_collection_response(response_hash)
44
41
  end
45
42
 
46
- def to_query( hash )
43
+ def to_query(hash)
47
44
  hash.collect do |key, value|
48
- escape( key, value )
45
+ escape(key, value)
49
46
  end.sort * '&'
50
47
  end
51
48
 
52
- def escape( key, value )
53
- "#{ CGI.escape(key.to_s) }=#{ CGI.escape(value.to_s) }"
49
+ def escape(key, value)
50
+ "#{CGI.escape(key.to_s)}=#{CGI.escape(value.to_s)}"
54
51
  end
55
52
 
56
53
  private
57
54
 
58
- def instantiate_collection_response( response_hash )
59
- entities_hash = @mapper.wrapped_json_collection_to_entities_hash( response_hash )
60
- entities_hash.map do |entity_hash|
61
- instantiate( entity_hash )
62
- end
55
+ def instantiate_collection_response(response_hash)
56
+ entities_hash = @mapper.wrapped_json_collection_to_entities_hash(response_hash)
57
+ entities_hash.map do |entity_hash|
58
+ instantiate(entity_hash)
63
59
  end
64
-
60
+ end
65
61
  end
66
62
  end
67
63
  end
@@ -1,46 +1,48 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Fortnox
2
4
  module API
3
5
  module Repository
4
6
  module Savers
5
-
6
- def save( entity )
7
+ def save(entity)
7
8
  return true if entity.saved?
8
9
 
9
- return save_new( entity ) if entity.new?
10
- update_existing( entity )
10
+ return save_new(entity) if entity.new?
11
+ update_existing(entity)
11
12
  end
12
13
 
13
- private
14
- def execute_save( entity )
15
- body = get_changes_on( entity ).to_json
14
+ private
15
+
16
+ def execute_save(entity)
17
+ body = get_changes_on(entity).to_json
16
18
  result = yield body
17
- instantiate_saved( result )
19
+ instantiate_saved(result)
18
20
  end
19
21
 
20
- def save_new( entity )
21
- execute_save( entity ) do |body|
22
- post( self.class::URI, { body: body } )
22
+ def save_new(entity)
23
+ execute_save(entity) do |body|
24
+ post(self.class::URI, body: body)
23
25
  end
24
26
  end
25
27
 
26
- def update_existing( entity )
27
- execute_save( entity ) do |body|
28
- put( get_update_url_for( entity ), { body: body } )
28
+ def update_existing(entity)
29
+ execute_save(entity) do |body|
30
+ put(get_update_url_for(entity), body: body)
29
31
  end
30
32
  end
31
33
 
32
- def get_changes_on( entity )
33
- hash = @mapper.entity_to_hash( entity, @keys_filtered_on_save )
34
- parent_hash = @mapper.entity_to_hash( entity.parent, @keys_filtered_on_save )
34
+ def get_changes_on(entity)
35
+ hash = @mapper.entity_to_hash(entity, @keys_filtered_on_save)
36
+ parent_hash = @mapper.entity_to_hash(entity.parent, @keys_filtered_on_save)
35
37
 
36
- @mapper.wrap_entity_json_hash( @mapper.diff( hash, parent_hash ) )
38
+ @mapper.wrap_entity_json_hash(@mapper.diff(hash, parent_hash))
37
39
  end
38
40
 
39
- def get_update_url_for( entity )
40
- "#{ self.class::URI }#{ entity.unique_id }"
41
+ def get_update_url_for(entity)
42
+ "#{self.class::URI}#{entity.unique_id}"
41
43
  end
42
44
 
43
- def instantiate_saved( wrapped_json_hash )
45
+ def instantiate_saved(wrapped_json_hash)
44
46
  instantiate(
45
47
  @mapper.wrapped_json_hash_to_entity_hash(
46
48
  wrapped_json_hash
@@ -1,6 +1,8 @@
1
- require "fortnox/api/repositories/base"
2
- require "fortnox/api/models/customer"
3
- require "fortnox/api/mappers/customer"
1
+ # frozen_string_literal: true
2
+
3
+ require 'fortnox/api/repositories/base'
4
+ require 'fortnox/api/models/customer'
5
+ require 'fortnox/api/mappers/customer'
4
6
 
5
7
  module Fortnox
6
8
  module API
@@ -8,7 +10,7 @@ module Fortnox
8
10
  class Customer < Base
9
11
  MODEL = Model::Customer
10
12
  MAPPER = Mapper::Customer
11
- URI = '/customers/'.freeze
13
+ URI = '/customers/'
12
14
  end
13
15
  end
14
16
  end
@@ -1,6 +1,8 @@
1
- require "fortnox/api/repositories/base"
2
- require "fortnox/api/models/invoice"
3
- require "fortnox/api/mappers/invoice"
1
+ # frozen_string_literal: true
2
+
3
+ require 'fortnox/api/repositories/base'
4
+ require 'fortnox/api/models/invoice'
5
+ require 'fortnox/api/mappers/invoice'
4
6
 
5
7
  module Fortnox
6
8
  module API
@@ -8,7 +10,7 @@ module Fortnox
8
10
  class Invoice < Base
9
11
  MODEL = Model::Invoice
10
12
  MAPPER = Mapper::Invoice
11
- URI = '/invoices/'.freeze
13
+ URI = '/invoices/'
12
14
  end
13
15
  end
14
16
  end
@@ -1,6 +1,8 @@
1
- require "fortnox/api/repositories/base"
2
- require "fortnox/api/models/order"
3
- require "fortnox/api/mappers/order"
1
+ # frozen_string_literal: true
2
+
3
+ require 'fortnox/api/repositories/base'
4
+ require 'fortnox/api/models/order'
5
+ require 'fortnox/api/mappers/order'
4
6
 
5
7
  module Fortnox
6
8
  module API
@@ -8,7 +10,7 @@ module Fortnox
8
10
  class Order < Base
9
11
  MODEL = Model::Order
10
12
  MAPPER = Mapper::Order
11
- URI = '/orders/'.freeze
13
+ URI = '/orders/'
12
14
  end
13
15
  end
14
16
  end
@@ -1,6 +1,8 @@
1
- require "fortnox/api/repositories/base"
2
- require "fortnox/api/models/project"
3
- require "fortnox/api/mappers/project"
1
+ # frozen_string_literal: true
2
+
3
+ require 'fortnox/api/repositories/base'
4
+ require 'fortnox/api/models/project'
5
+ require 'fortnox/api/mappers/project'
4
6
 
5
7
  module Fortnox
6
8
  module API
@@ -8,7 +10,7 @@ module Fortnox
8
10
  class Project < Base
9
11
  MODEL = Model::Project
10
12
  MAPPER = Mapper::Project
11
- URI = '/projects/'.freeze
13
+ URI = '/projects/'
12
14
  end
13
15
  end
14
16
  end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'fortnox/api/repositories/base'
4
+ require 'fortnox/api/models/terms_of_payments'
5
+ require 'fortnox/api/mappers/terms_of_payments'
6
+
7
+ module Fortnox
8
+ module API
9
+ module Repository
10
+ class TermsOfPayments < Base
11
+ MODEL = Model::TermsOfPayments
12
+ MAPPER = Mapper::TermsOfPayments
13
+ URI = '/termsofpayments/'
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'fortnox/api/repositories/base'
4
+ require 'fortnox/api/models/unit'
5
+ require 'fortnox/api/mappers/unit'
6
+
7
+ module Fortnox
8
+ module API
9
+ module Repository
10
+ class Unit < Fortnox::API::Repository::Base
11
+ MODEL = Fortnox::API::Model::Unit
12
+ MAPPER = Fortnox::API::Mapper::Unit
13
+ URI = '/units/'
14
+ end
15
+ end
16
+ end
17
+ end
@@ -1,35 +1,35 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Fortnox
2
4
  module API
3
5
  module RequestHandling
4
-
5
6
  private
6
7
 
7
- def raise_api_error( error, response )
8
- message = ( error[ 'message' ] || error[ 'Message' ] || 'Okänt fel' )
8
+ def raise_api_error(error, response)
9
+ message = (error['message'] || error['Message'] || 'Okänt fel')
9
10
 
10
- message += "\n\n#{ response.request.inspect }" if Fortnox::API.debugging
11
+ message += "\n\n#{response.request.inspect}" if Fortnox::API.debugging
11
12
 
12
13
  raise Fortnox::API::RemoteServerError, message
13
14
  end
14
15
 
15
- def validate_response( response )
16
+ def validate_response(response)
16
17
  return if response.code == 200
17
18
 
18
- api_error = response.parsed_response[ 'ErrorInformation' ]
19
- raise_api_error( api_error, response ) if api_error
19
+ api_error = response.parsed_response['ErrorInformation']
20
+ raise_api_error(api_error, response) if api_error
20
21
  end
21
22
 
22
- def validate_and_parse( response )
23
- validate_response( response )
23
+ def validate_and_parse(response)
24
+ validate_response(response)
24
25
  response.parsed_response
25
26
  end
26
27
 
27
28
  def execute
28
- self.class.set_headers( @headers )
29
- response = yield( self.class )
29
+ self.class.set_headers(@headers)
30
+ response = yield(self.class)
30
31
  validate_and_parse response
31
32
  end
32
-
33
33
  end
34
34
  end
35
35
  end
@@ -1,6 +1,25 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'dry-struct'
2
4
  require 'dry-types'
3
5
 
6
+ module Dry
7
+ module Types
8
+ module Options
9
+ def is(*option_names)
10
+ new_options = option_names.each_with_object({}) do |name, hash|
11
+ hash[name] = true
12
+ end
13
+ with(new_options)
14
+ end
15
+
16
+ def is?(option_name)
17
+ @options[option_name]
18
+ end
19
+ end
20
+ end
21
+ end
22
+
4
23
  module Fortnox
5
24
  module API
6
25
  module Types
@@ -16,25 +35,57 @@ module Fortnox
16
35
 
17
36
  require 'fortnox/api/types/sized'
18
37
 
19
- AccountNumber = Strict::Int.constrained( gteq: 0, lteq: 9999 ).optional
38
+ AccountNumber = Strict::Int
39
+ .constrained(gteq: 0, lteq: 9999)
40
+ .optional
20
41
 
21
- ArticleType = Strict::String.constrained( included_in: ArticleTypes.values ).optional.constructor( EnumConstructors.default )
42
+ ArticleType = Strict::String
43
+ .constrained(included_in: ArticleTypes.values)
44
+ .optional
45
+ .constructor(EnumConstructors.default)
22
46
 
23
- CountryCode = Strict::String.constrained( included_in: CountryCodes.values ).optional.constructor( EnumConstructors.sized(2) )
24
- Currency = Strict::String.constrained( included_in: Currencies.values ).optional.constructor( EnumConstructors.sized(3) )
25
- CustomerType = Strict::String.constrained( included_in: CustomerTypes.values ).optional.constructor( EnumConstructors.default )
47
+ CountryCode = Strict::String
48
+ .constrained(included_in: CountryCodes.values)
49
+ .optional
50
+ .constructor(EnumConstructors.sized(2))
51
+ Currency = Strict::String
52
+ .constrained(included_in: Currencies.values)
53
+ .optional
54
+ .constructor(EnumConstructors.sized(3))
55
+ CustomerType = Strict::String
56
+ .constrained(included_in: CustomerTypes.values)
57
+ .optional
58
+ .constructor(EnumConstructors.default)
26
59
 
27
- DiscountType = Strict::String.constrained( included_in: DiscountTypes.values ).optional.constructor( EnumConstructors.default )
60
+ DiscountType = Strict::String
61
+ .constrained(included_in: DiscountTypes.values)
62
+ .optional
63
+ .constructor(EnumConstructors.default)
28
64
 
29
- Email = Strict::String.constrained( max_size: 1024, format: /\A^$|[\w+\-.]+@[a-z\d\-]+(\.[a-z]+)*\.[a-z]+\z/i ).optional.constructor{ |v| v.to_s.downcase unless v.nil? }
65
+ Email = Strict::String
66
+ .constrained(max_size: 1024, format: /^$|\A[\w+-_.]+@[\w+-_.]+\.[a-z]+\z/i)
67
+ .optional
68
+ .constructor { |v| v.to_s.downcase unless v.nil? }
30
69
 
31
- HouseWorkType = Strict::String.constrained( included_in: HouseWorkTypes.values ).optional.constructor( EnumConstructors.default )
70
+ HouseworkType = Strict::String
71
+ .constrained(included_in: HouseworkTypes.values)
72
+ .optional
73
+ .constructor(EnumConstructors.default)
32
74
 
33
- VATType = Strict::String.constrained( included_in: VATTypes.values ).optional.constructor( EnumConstructors.default )
75
+ VATType = Strict::String
76
+ .constrained(included_in: VATTypes.values)
77
+ .optional
78
+ .constructor(EnumConstructors.default)
34
79
 
35
- DefaultDeliveryType = Strict::String.constrained( included_in: DefaultDeliveryTypeValues.values ).optional.constructor( EnumConstructors.default )
80
+ DefaultDeliveryType = Strict::String
81
+ .constrained(included_in: DefaultDeliveryTypeValues.values)
82
+ .optional
83
+ .constructor(EnumConstructors.default)
36
84
 
37
- ProjectStatusType = Strict::String.constrained( included_in: ProjectStatusTypes.values ).optional.constructor( EnumConstructors.default )
85
+ ProjectStatusType = Strict::String
86
+ .constrained(included_in: ProjectStatusTypes.values)
87
+ .optional
88
+ .constructor(EnumConstructors.default)
38
89
 
39
90
  require 'fortnox/api/types/model'
40
91
  require 'fortnox/api/types/default_delivery_types'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'fortnox/api/types'
2
4
 
3
5
  module Fortnox
@@ -6,13 +8,13 @@ module Fortnox
6
8
  class DefaultDeliveryTypes < Types::Model
7
9
  STUB = {}.freeze
8
10
 
9
- #Default delivery type for invoices. Can be PRINT EMAIL or PRINTSERVICE.
11
+ # Default delivery type for invoices. Can be PRINT EMAIL or PRINTSERVICE.
10
12
  attribute :invoice, Types::DefaultDeliveryType
11
13
 
12
- #Default delivery type for orders. Can be PRINT EMAIL or PRINTSERVICE.
14
+ # Default delivery type for orders. Can be PRINT EMAIL or PRINTSERVICE.
13
15
  attribute :order, Types::DefaultDeliveryType
14
16
 
15
- #Default delivery type for offers. Can be PRINT EMAIL or PRINTSERVICE.
17
+ # Default delivery type for offers. Can be PRINT EMAIL or PRINTSERVICE.
16
18
  attribute :offer, Types::DefaultDeliveryType
17
19
  end
18
20
  end