e-invoice-api 0.1.0.pre.alpha.5

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 (233) hide show
  1. checksums.yaml +7 -0
  2. data/.ignore +2 -0
  3. data/CHANGELOG.md +57 -0
  4. data/README.md +285 -0
  5. data/SECURITY.md +27 -0
  6. data/lib/e_invoice_api/client.rb +94 -0
  7. data/lib/e_invoice_api/errors.rb +192 -0
  8. data/lib/e_invoice_api/file_part.rb +55 -0
  9. data/lib/e_invoice_api/internal/documents_number_page.rb +96 -0
  10. data/lib/e_invoice_api/internal/transport/base_client.rb +555 -0
  11. data/lib/e_invoice_api/internal/transport/pooled_net_requester.rb +209 -0
  12. data/lib/e_invoice_api/internal/type/array_of.rb +162 -0
  13. data/lib/e_invoice_api/internal/type/base_model.rb +482 -0
  14. data/lib/e_invoice_api/internal/type/base_page.rb +55 -0
  15. data/lib/e_invoice_api/internal/type/boolean.rb +71 -0
  16. data/lib/e_invoice_api/internal/type/converter.rb +292 -0
  17. data/lib/e_invoice_api/internal/type/enum.rb +148 -0
  18. data/lib/e_invoice_api/internal/type/file_input.rb +103 -0
  19. data/lib/e_invoice_api/internal/type/hash_of.rb +182 -0
  20. data/lib/e_invoice_api/internal/type/request_parameters.rb +42 -0
  21. data/lib/e_invoice_api/internal/type/union.rb +236 -0
  22. data/lib/e_invoice_api/internal/type/unknown.rb +75 -0
  23. data/lib/e_invoice_api/internal/util.rb +914 -0
  24. data/lib/e_invoice_api/internal.rb +20 -0
  25. data/lib/e_invoice_api/models/certificate.rb +34 -0
  26. data/lib/e_invoice_api/models/currency_code.rb +28 -0
  27. data/lib/e_invoice_api/models/document_attachment_create.rb +33 -0
  28. data/lib/e_invoice_api/models/document_create.rb +521 -0
  29. data/lib/e_invoice_api/models/document_create_params.rb +14 -0
  30. data/lib/e_invoice_api/models/document_delete_params.rb +14 -0
  31. data/lib/e_invoice_api/models/document_delete_response.rb +16 -0
  32. data/lib/e_invoice_api/models/document_direction.rb +15 -0
  33. data/lib/e_invoice_api/models/document_response.rb +418 -0
  34. data/lib/e_invoice_api/models/document_retrieve_params.rb +14 -0
  35. data/lib/e_invoice_api/models/document_send_params.rb +44 -0
  36. data/lib/e_invoice_api/models/document_state.rb +18 -0
  37. data/lib/e_invoice_api/models/document_type.rb +15 -0
  38. data/lib/e_invoice_api/models/documents/attachment_add_params.rb +22 -0
  39. data/lib/e_invoice_api/models/documents/attachment_delete_params.rb +22 -0
  40. data/lib/e_invoice_api/models/documents/attachment_delete_response.rb +18 -0
  41. data/lib/e_invoice_api/models/documents/attachment_list_params.rb +16 -0
  42. data/lib/e_invoice_api/models/documents/attachment_list_response.rb +11 -0
  43. data/lib/e_invoice_api/models/documents/attachment_retrieve_params.rb +22 -0
  44. data/lib/e_invoice_api/models/documents/document_attachment.rb +44 -0
  45. data/lib/e_invoice_api/models/documents/ubl_get_params.rb +16 -0
  46. data/lib/e_invoice_api/models/documents/ubl_get_response.rb +72 -0
  47. data/lib/e_invoice_api/models/inbox_list_credit_notes_params.rb +30 -0
  48. data/lib/e_invoice_api/models/inbox_list_invoices_params.rb +30 -0
  49. data/lib/e_invoice_api/models/inbox_list_params.rb +78 -0
  50. data/lib/e_invoice_api/models/lookup_retrieve_params.rb +26 -0
  51. data/lib/e_invoice_api/models/lookup_retrieve_response.rb +491 -0
  52. data/lib/e_invoice_api/models/outbox_list_draft_documents_params.rb +30 -0
  53. data/lib/e_invoice_api/models/outbox_list_received_documents_params.rb +78 -0
  54. data/lib/e_invoice_api/models/paginated_document_response.rb +39 -0
  55. data/lib/e_invoice_api/models/payment_detail_create.rb +33 -0
  56. data/lib/e_invoice_api/models/ubl_document_validation.rb +97 -0
  57. data/lib/e_invoice_api/models/unit_of_measure_code.rb +104 -0
  58. data/lib/e_invoice_api/models/validate_validate_json_params.rb +14 -0
  59. data/lib/e_invoice_api/models/validate_validate_peppol_id_params.rb +26 -0
  60. data/lib/e_invoice_api/models/validate_validate_peppol_id_response.rb +80 -0
  61. data/lib/e_invoice_api/models/validate_validate_ubl_params.rb +20 -0
  62. data/lib/e_invoice_api/models/webhook_create_params.rb +32 -0
  63. data/lib/e_invoice_api/models/webhook_delete_params.rb +14 -0
  64. data/lib/e_invoice_api/models/webhook_delete_response.rb +18 -0
  65. data/lib/e_invoice_api/models/webhook_list_params.rb +14 -0
  66. data/lib/e_invoice_api/models/webhook_list_response.rb +8 -0
  67. data/lib/e_invoice_api/models/webhook_response.rb +42 -0
  68. data/lib/e_invoice_api/models/webhook_retrieve_params.rb +14 -0
  69. data/lib/e_invoice_api/models/webhook_update_params.rb +32 -0
  70. data/lib/e_invoice_api/models.rb +105 -0
  71. data/lib/e_invoice_api/request_options.rb +77 -0
  72. data/lib/e_invoice_api/resources/documents/attachments.rb +109 -0
  73. data/lib/e_invoice_api/resources/documents/ubl.rb +35 -0
  74. data/lib/e_invoice_api/resources/documents.rb +188 -0
  75. data/lib/e_invoice_api/resources/inbox.rb +101 -0
  76. data/lib/e_invoice_api/resources/lookup.rb +43 -0
  77. data/lib/e_invoice_api/resources/outbox.rb +76 -0
  78. data/lib/e_invoice_api/resources/validate.rb +168 -0
  79. data/lib/e_invoice_api/resources/webhooks.rb +117 -0
  80. data/lib/e_invoice_api/version.rb +5 -0
  81. data/lib/e_invoice_api.rb +107 -0
  82. data/manifest.yaml +15 -0
  83. data/rbi/e_invoice_api/client.rbi +64 -0
  84. data/rbi/e_invoice_api/errors.rbi +162 -0
  85. data/rbi/e_invoice_api/file_part.rbi +37 -0
  86. data/rbi/e_invoice_api/internal/documents_number_page.rbi +28 -0
  87. data/rbi/e_invoice_api/internal/transport/base_client.rbi +298 -0
  88. data/rbi/e_invoice_api/internal/transport/pooled_net_requester.rbi +80 -0
  89. data/rbi/e_invoice_api/internal/type/array_of.rbi +104 -0
  90. data/rbi/e_invoice_api/internal/type/base_model.rbi +304 -0
  91. data/rbi/e_invoice_api/internal/type/base_page.rbi +43 -0
  92. data/rbi/e_invoice_api/internal/type/boolean.rbi +56 -0
  93. data/rbi/e_invoice_api/internal/type/converter.rbi +162 -0
  94. data/rbi/e_invoice_api/internal/type/enum.rbi +82 -0
  95. data/rbi/e_invoice_api/internal/type/file_input.rbi +59 -0
  96. data/rbi/e_invoice_api/internal/type/hash_of.rbi +104 -0
  97. data/rbi/e_invoice_api/internal/type/request_parameters.rbi +31 -0
  98. data/rbi/e_invoice_api/internal/type/union.rbi +116 -0
  99. data/rbi/e_invoice_api/internal/type/unknown.rbi +56 -0
  100. data/rbi/e_invoice_api/internal/util.rbi +487 -0
  101. data/rbi/e_invoice_api/internal.rbi +18 -0
  102. data/rbi/e_invoice_api/models/certificate.rbi +54 -0
  103. data/rbi/e_invoice_api/models/currency_code.rbi +34 -0
  104. data/rbi/e_invoice_api/models/document_attachment_create.rbi +57 -0
  105. data/rbi/e_invoice_api/models/document_create.rbi +638 -0
  106. data/rbi/e_invoice_api/models/document_create_params.rbi +30 -0
  107. data/rbi/e_invoice_api/models/document_delete_params.rbi +30 -0
  108. data/rbi/e_invoice_api/models/document_delete_response.rbi +26 -0
  109. data/rbi/e_invoice_api/models/document_direction.rbi +22 -0
  110. data/rbi/e_invoice_api/models/document_response.rbi +504 -0
  111. data/rbi/e_invoice_api/models/document_retrieve_params.rbi +30 -0
  112. data/rbi/e_invoice_api/models/document_send_params.rbi +65 -0
  113. data/rbi/e_invoice_api/models/document_state.rbi +24 -0
  114. data/rbi/e_invoice_api/models/document_type.rbi +21 -0
  115. data/rbi/e_invoice_api/models/documents/attachment_add_params.rbi +43 -0
  116. data/rbi/e_invoice_api/models/documents/attachment_delete_params.rbi +43 -0
  117. data/rbi/e_invoice_api/models/documents/attachment_delete_response.rbi +28 -0
  118. data/rbi/e_invoice_api/models/documents/attachment_list_params.rbi +34 -0
  119. data/rbi/e_invoice_api/models/documents/attachment_list_response.rbi +15 -0
  120. data/rbi/e_invoice_api/models/documents/attachment_retrieve_params.rbi +43 -0
  121. data/rbi/e_invoice_api/models/documents/document_attachment.rbi +72 -0
  122. data/rbi/e_invoice_api/models/documents/ubl_get_params.rbi +34 -0
  123. data/rbi/e_invoice_api/models/documents/ubl_get_response.rbi +97 -0
  124. data/rbi/e_invoice_api/models/inbox_list_credit_notes_params.rbi +60 -0
  125. data/rbi/e_invoice_api/models/inbox_list_invoices_params.rbi +60 -0
  126. data/rbi/e_invoice_api/models/inbox_list_params.rbi +105 -0
  127. data/rbi/e_invoice_api/models/lookup_retrieve_params.rbi +45 -0
  128. data/rbi/e_invoice_api/models/lookup_retrieve_response.rbi +852 -0
  129. data/rbi/e_invoice_api/models/outbox_list_draft_documents_params.rbi +60 -0
  130. data/rbi/e_invoice_api/models/outbox_list_received_documents_params.rbi +108 -0
  131. data/rbi/e_invoice_api/models/paginated_document_response.rbi +56 -0
  132. data/rbi/e_invoice_api/models/payment_detail_create.rbi +56 -0
  133. data/rbi/e_invoice_api/models/ubl_document_validation.rbi +159 -0
  134. data/rbi/e_invoice_api/models/unit_of_measure_code.rbi +149 -0
  135. data/rbi/e_invoice_api/models/validate_validate_json_params.rbi +30 -0
  136. data/rbi/e_invoice_api/models/validate_validate_peppol_id_params.rbi +45 -0
  137. data/rbi/e_invoice_api/models/validate_validate_peppol_id_response.rbi +141 -0
  138. data/rbi/e_invoice_api/models/validate_validate_ubl_params.rbi +41 -0
  139. data/rbi/e_invoice_api/models/webhook_create_params.rbi +54 -0
  140. data/rbi/e_invoice_api/models/webhook_delete_params.rbi +30 -0
  141. data/rbi/e_invoice_api/models/webhook_delete_response.rbi +27 -0
  142. data/rbi/e_invoice_api/models/webhook_list_params.rbi +27 -0
  143. data/rbi/e_invoice_api/models/webhook_list_response.rbi +11 -0
  144. data/rbi/e_invoice_api/models/webhook_response.rbi +57 -0
  145. data/rbi/e_invoice_api/models/webhook_retrieve_params.rbi +30 -0
  146. data/rbi/e_invoice_api/models/webhook_update_params.rbi +51 -0
  147. data/rbi/e_invoice_api/models.rbi +70 -0
  148. data/rbi/e_invoice_api/request_options.rbi +59 -0
  149. data/rbi/e_invoice_api/resources/documents/attachments.rbi +58 -0
  150. data/rbi/e_invoice_api/resources/documents/ubl.rbi +24 -0
  151. data/rbi/e_invoice_api/resources/documents.rbi +164 -0
  152. data/rbi/e_invoice_api/resources/inbox.rbi +93 -0
  153. data/rbi/e_invoice_api/resources/lookup.rbi +31 -0
  154. data/rbi/e_invoice_api/resources/outbox.rbi +72 -0
  155. data/rbi/e_invoice_api/resources/validate.rbi +145 -0
  156. data/rbi/e_invoice_api/resources/webhooks.rbi +72 -0
  157. data/rbi/e_invoice_api/version.rbi +5 -0
  158. data/sig/e_invoice_api/client.rbs +36 -0
  159. data/sig/e_invoice_api/errors.rbs +101 -0
  160. data/sig/e_invoice_api/file_part.rbs +21 -0
  161. data/sig/e_invoice_api/internal/documents_number_page.rbs +17 -0
  162. data/sig/e_invoice_api/internal/transport/base_client.rbs +131 -0
  163. data/sig/e_invoice_api/internal/transport/pooled_net_requester.rbs +45 -0
  164. data/sig/e_invoice_api/internal/type/array_of.rbs +48 -0
  165. data/sig/e_invoice_api/internal/type/base_model.rbs +102 -0
  166. data/sig/e_invoice_api/internal/type/base_page.rbs +24 -0
  167. data/sig/e_invoice_api/internal/type/boolean.rbs +26 -0
  168. data/sig/e_invoice_api/internal/type/converter.rbs +56 -0
  169. data/sig/e_invoice_api/internal/type/enum.rbs +32 -0
  170. data/sig/e_invoice_api/internal/type/file_input.rbs +25 -0
  171. data/sig/e_invoice_api/internal/type/hash_of.rbs +48 -0
  172. data/sig/e_invoice_api/internal/type/request_parameters.rbs +19 -0
  173. data/sig/e_invoice_api/internal/type/union.rbs +52 -0
  174. data/sig/e_invoice_api/internal/type/unknown.rbs +26 -0
  175. data/sig/e_invoice_api/internal/util.rbs +185 -0
  176. data/sig/e_invoice_api/internal.rbs +9 -0
  177. data/sig/e_invoice_api/models/certificate.rbs +26 -0
  178. data/sig/e_invoice_api/models/currency_code.rbs +42 -0
  179. data/sig/e_invoice_api/models/document_attachment_create.rbs +39 -0
  180. data/sig/e_invoice_api/models/document_create.rbs +403 -0
  181. data/sig/e_invoice_api/models/document_create_params.rbs +15 -0
  182. data/sig/e_invoice_api/models/document_delete_params.rbs +15 -0
  183. data/sig/e_invoice_api/models/document_delete_response.rbs +13 -0
  184. data/sig/e_invoice_api/models/document_direction.rbs +14 -0
  185. data/sig/e_invoice_api/models/document_response.rbs +358 -0
  186. data/sig/e_invoice_api/models/document_retrieve_params.rbs +15 -0
  187. data/sig/e_invoice_api/models/document_send_params.rbs +46 -0
  188. data/sig/e_invoice_api/models/document_state.rbs +17 -0
  189. data/sig/e_invoice_api/models/document_type.rbs +14 -0
  190. data/sig/e_invoice_api/models/documents/attachment_add_params.rbs +26 -0
  191. data/sig/e_invoice_api/models/documents/attachment_delete_params.rbs +26 -0
  192. data/sig/e_invoice_api/models/documents/attachment_delete_response.rbs +15 -0
  193. data/sig/e_invoice_api/models/documents/attachment_list_params.rbs +17 -0
  194. data/sig/e_invoice_api/models/documents/attachment_list_response.rbs +10 -0
  195. data/sig/e_invoice_api/models/documents/attachment_retrieve_params.rbs +26 -0
  196. data/sig/e_invoice_api/models/documents/document_attachment.rbs +48 -0
  197. data/sig/e_invoice_api/models/documents/ubl_get_params.rbs +17 -0
  198. data/sig/e_invoice_api/models/documents/ubl_get_response.rbs +69 -0
  199. data/sig/e_invoice_api/models/inbox_list_credit_notes_params.rbs +32 -0
  200. data/sig/e_invoice_api/models/inbox_list_invoices_params.rbs +32 -0
  201. data/sig/e_invoice_api/models/inbox_list_params.rbs +65 -0
  202. data/sig/e_invoice_api/models/lookup_retrieve_params.rbs +23 -0
  203. data/sig/e_invoice_api/models/lookup_retrieve_response.rbs +365 -0
  204. data/sig/e_invoice_api/models/outbox_list_draft_documents_params.rbs +32 -0
  205. data/sig/e_invoice_api/models/outbox_list_received_documents_params.rbs +65 -0
  206. data/sig/e_invoice_api/models/paginated_document_response.rbs +40 -0
  207. data/sig/e_invoice_api/models/payment_detail_create.rbs +35 -0
  208. data/sig/e_invoice_api/models/ubl_document_validation.rbs +98 -0
  209. data/sig/e_invoice_api/models/unit_of_measure_code.rbs +192 -0
  210. data/sig/e_invoice_api/models/validate_validate_json_params.rbs +15 -0
  211. data/sig/e_invoice_api/models/validate_validate_peppol_id_params.rbs +23 -0
  212. data/sig/e_invoice_api/models/validate_validate_peppol_id_response.rbs +65 -0
  213. data/sig/e_invoice_api/models/validate_validate_ubl_params.rbs +24 -0
  214. data/sig/e_invoice_api/models/webhook_create_params.rbs +34 -0
  215. data/sig/e_invoice_api/models/webhook_delete_params.rbs +15 -0
  216. data/sig/e_invoice_api/models/webhook_delete_response.rbs +13 -0
  217. data/sig/e_invoice_api/models/webhook_list_params.rbs +15 -0
  218. data/sig/e_invoice_api/models/webhook_list_response.rbs +7 -0
  219. data/sig/e_invoice_api/models/webhook_response.rbs +42 -0
  220. data/sig/e_invoice_api/models/webhook_retrieve_params.rbs +15 -0
  221. data/sig/e_invoice_api/models/webhook_update_params.rbs +32 -0
  222. data/sig/e_invoice_api/models.rbs +65 -0
  223. data/sig/e_invoice_api/request_options.rbs +36 -0
  224. data/sig/e_invoice_api/resources/documents/attachments.rbs +32 -0
  225. data/sig/e_invoice_api/resources/documents/ubl.rbs +14 -0
  226. data/sig/e_invoice_api/resources/documents.rbs +76 -0
  227. data/sig/e_invoice_api/resources/inbox.rbs +31 -0
  228. data/sig/e_invoice_api/resources/lookup.rbs +12 -0
  229. data/sig/e_invoice_api/resources/outbox.rbs +25 -0
  230. data/sig/e_invoice_api/resources/validate.rbs +62 -0
  231. data/sig/e_invoice_api/resources/webhooks.rbs +36 -0
  232. data/sig/e_invoice_api/version.rbs +3 -0
  233. metadata +290 -0
@@ -0,0 +1,292 @@
1
+ # frozen_string_literal: true
2
+
3
+ module EInvoiceAPI
4
+ module Internal
5
+ module Type
6
+ # @api private
7
+ module Converter
8
+ extend EInvoiceAPI::Internal::Util::SorbetRuntimeSupport
9
+
10
+ # rubocop:disable Lint/UnusedMethodArgument
11
+
12
+ # @api private
13
+ #
14
+ # @param value [Object]
15
+ #
16
+ # @param state [Hash{Symbol=>Object}] .
17
+ #
18
+ # @option state [Boolean, :strong] :strictness
19
+ #
20
+ # @option state [Hash{Symbol=>Object}] :exactness
21
+ #
22
+ # @option state [Integer] :branched
23
+ #
24
+ # @return [Object]
25
+ def coerce(value, state:) = (raise NotImplementedError)
26
+
27
+ # @api private
28
+ #
29
+ # @param value [Object]
30
+ #
31
+ # @param state [Hash{Symbol=>Object}] .
32
+ #
33
+ # @option state [Boolean] :can_retry
34
+ #
35
+ # @return [Object]
36
+ def dump(value, state:)
37
+ case value
38
+ in Array
39
+ value.map { EInvoiceAPI::Internal::Type::Unknown.dump(_1, state: state) }
40
+ in Hash
41
+ value.transform_values { EInvoiceAPI::Internal::Type::Unknown.dump(_1, state: state) }
42
+ in EInvoiceAPI::Internal::Type::BaseModel
43
+ value.class.dump(value, state: state)
44
+ in StringIO
45
+ value.string
46
+ in Pathname | IO
47
+ state[:can_retry] = false if value.is_a?(IO)
48
+ EInvoiceAPI::FilePart.new(value)
49
+ in EInvoiceAPI::FilePart
50
+ state[:can_retry] = false if value.content.is_a?(IO)
51
+ value
52
+ else
53
+ value
54
+ end
55
+ end
56
+
57
+ # @api private
58
+ #
59
+ # @param depth [Integer]
60
+ #
61
+ # @return [String]
62
+ def inspect(depth: 0)
63
+ super()
64
+ end
65
+
66
+ # rubocop:enable Lint/UnusedMethodArgument
67
+
68
+ class << self
69
+ # @api private
70
+ #
71
+ # @param spec [Hash{Symbol=>Object}, Proc, EInvoiceAPI::Internal::Type::Converter, Class] .
72
+ #
73
+ # @option spec [NilClass, TrueClass, FalseClass, Integer, Float, Symbol] :const
74
+ #
75
+ # @option spec [Proc] :enum
76
+ #
77
+ # @option spec [Proc] :union
78
+ #
79
+ # @option spec [Boolean] :"nil?"
80
+ #
81
+ # @return [Proc]
82
+ def type_info(spec)
83
+ case spec
84
+ in Proc
85
+ spec
86
+ in Hash
87
+ type_info(spec.slice(:const, :enum, :union).first&.last)
88
+ in true | false
89
+ -> { EInvoiceAPI::Internal::Type::Boolean }
90
+ in EInvoiceAPI::Internal::Type::Converter | Class | Symbol
91
+ -> { spec }
92
+ in NilClass | Integer | Float
93
+ -> { spec.class }
94
+ end
95
+ end
96
+
97
+ # @api private
98
+ #
99
+ # Based on `target`, transform `value` into `target`, to the extent possible:
100
+ #
101
+ # 1. if the given `value` conforms to `target` already, return the given `value`
102
+ # 2. if it's possible and safe to convert the given `value` to `target`, then the
103
+ # converted value
104
+ # 3. otherwise, the given `value` unaltered
105
+ #
106
+ # The coercion process is subject to improvement between minor release versions.
107
+ # See https://docs.pydantic.dev/latest/concepts/unions/#smart-mode
108
+ #
109
+ # @param target [EInvoiceAPI::Internal::Type::Converter, Class]
110
+ #
111
+ # @param value [Object]
112
+ #
113
+ # @param state [Hash{Symbol=>Object}] The `strictness` is one of `true`, `false`, or `:strong`. This informs the
114
+ # coercion strategy when we have to decide between multiple possible conversion
115
+ # targets:
116
+ #
117
+ # - `true`: the conversion must be exact, with minimum coercion.
118
+ # - `false`: the conversion can be approximate, with some coercion.
119
+ # - `:strong`: the conversion must be exact, with no coercion, and raise an error
120
+ # if not possible.
121
+ #
122
+ # The `exactness` is `Hash` with keys being one of `yes`, `no`, or `maybe`. For
123
+ # any given conversion attempt, the exactness will be updated based on how closely
124
+ # the value recursively matches the target type:
125
+ #
126
+ # - `yes`: the value can be converted to the target type with minimum coercion.
127
+ # - `maybe`: the value can be converted to the target type with some reasonable
128
+ # coercion.
129
+ # - `no`: the value cannot be converted to the target type.
130
+ #
131
+ # See implementation below for more details.
132
+ #
133
+ # @option state [Boolean, :strong] :strictness
134
+ #
135
+ # @option state [Hash{Symbol=>Object}] :exactness
136
+ #
137
+ # @option state [Integer] :branched
138
+ #
139
+ # @return [Object]
140
+ def coerce(
141
+ target,
142
+ value,
143
+ state: {strictness: true, exactness: {yes: 0, no: 0, maybe: 0}, branched: 0}
144
+ )
145
+ # rubocop:disable Lint/SuppressedException
146
+ # rubocop:disable Metrics/BlockNesting
147
+ strictness, exactness = state.fetch_values(:strictness, :exactness)
148
+
149
+ case target
150
+ in EInvoiceAPI::Internal::Type::Converter
151
+ return target.coerce(value, state: state)
152
+ in Class
153
+ if value.is_a?(target)
154
+ exactness[:yes] += 1
155
+ return value
156
+ end
157
+
158
+ case target
159
+ in -> { _1 <= NilClass }
160
+ exactness[value.nil? ? :yes : :maybe] += 1
161
+ return nil
162
+ in -> { _1 <= Integer }
163
+ if value.is_a?(Integer)
164
+ exactness[:yes] += 1
165
+ return value
166
+ elsif strictness == :strong && Integer(value, exception: false) != value
167
+ message = "no implicit conversion of #{value.class} into #{target.inspect}"
168
+ raise value.is_a?(Numeric) ? ArgumentError.new(message) : TypeError.new(message)
169
+ else
170
+ Kernel.then do
171
+ return Integer(value).tap { exactness[:maybe] += 1 }
172
+ rescue ArgumentError, TypeError
173
+ end
174
+ end
175
+ in -> { _1 <= Float }
176
+ if value.is_a?(Numeric)
177
+ exactness[:yes] += 1
178
+ return Float(value)
179
+ elsif strictness == :strong
180
+ message = "no implicit conversion of #{value.class} into #{target.inspect}"
181
+ raise TypeError.new(message)
182
+ else
183
+ Kernel.then do
184
+ return Float(value).tap { exactness[:maybe] += 1 }
185
+ rescue ArgumentError, TypeError
186
+ end
187
+ end
188
+ in -> { _1 <= String }
189
+ case value
190
+ in String | Symbol | Numeric
191
+ exactness[value.is_a?(Numeric) ? :maybe : :yes] += 1
192
+ return value.to_s
193
+ in StringIO
194
+ exactness[:yes] += 1
195
+ return value.string
196
+ else
197
+ if strictness == :strong
198
+ message = "no implicit conversion of #{value.class} into #{target.inspect}"
199
+ raise TypeError.new(message)
200
+ end
201
+ end
202
+ in -> { _1 <= Date || _1 <= Time }
203
+ Kernel.then do
204
+ return target.parse(value).tap { exactness[:yes] += 1 }
205
+ rescue ArgumentError, TypeError => e
206
+ raise e if strictness == :strong
207
+ end
208
+ in -> { _1 <= StringIO } if value.is_a?(String)
209
+ exactness[:yes] += 1
210
+ return StringIO.new(value.b)
211
+ else
212
+ end
213
+ in Symbol
214
+ case value
215
+ in Symbol | String
216
+ if value.to_sym == target
217
+ exactness[:yes] += 1
218
+ return target
219
+ else
220
+ exactness[:maybe] += 1
221
+ return value
222
+ end
223
+ else
224
+ if strictness == :strong
225
+ message = "cannot convert non-matching #{value.class} into #{target.inspect}"
226
+ raise ArgumentError.new(message)
227
+ end
228
+ end
229
+ else
230
+ end
231
+
232
+ exactness[:no] += 1
233
+ value
234
+ # rubocop:enable Metrics/BlockNesting
235
+ # rubocop:enable Lint/SuppressedException
236
+ end
237
+
238
+ # @api private
239
+ #
240
+ # @param target [EInvoiceAPI::Internal::Type::Converter, Class]
241
+ #
242
+ # @param value [Object]
243
+ #
244
+ # @param state [Hash{Symbol=>Object}] .
245
+ #
246
+ # @option state [Boolean] :can_retry
247
+ #
248
+ # @return [Object]
249
+ def dump(target, value, state: {can_retry: true})
250
+ case target
251
+ in EInvoiceAPI::Internal::Type::Converter
252
+ target.dump(value, state: state)
253
+ else
254
+ EInvoiceAPI::Internal::Type::Unknown.dump(value, state: state)
255
+ end
256
+ end
257
+
258
+ # @api private
259
+ #
260
+ # @param target [Object]
261
+ # @param depth [Integer]
262
+ #
263
+ # @return [String]
264
+ def inspect(target, depth:)
265
+ case target
266
+ in EInvoiceAPI::Internal::Type::Converter
267
+ target.inspect(depth: depth.succ)
268
+ else
269
+ target.inspect
270
+ end
271
+ end
272
+ end
273
+
274
+ define_sorbet_constant!(:Input) do
275
+ T.type_alias { T.any(EInvoiceAPI::Internal::Type::Converter, T::Class[T.anything]) }
276
+ end
277
+ define_sorbet_constant!(:CoerceState) do
278
+ T.type_alias do
279
+ {
280
+ strictness: T.any(T::Boolean, Symbol),
281
+ exactness: {yes: Integer, no: Integer, maybe: Integer},
282
+ branched: Integer
283
+ }
284
+ end
285
+ end
286
+ define_sorbet_constant!(:DumpState) do
287
+ T.type_alias { {can_retry: T::Boolean} }
288
+ end
289
+ end
290
+ end
291
+ end
292
+ end
@@ -0,0 +1,148 @@
1
+ # frozen_string_literal: true
2
+
3
+ module EInvoiceAPI
4
+ module Internal
5
+ module Type
6
+ # @api private
7
+ #
8
+ # A value from among a specified list of options. OpenAPI enum values map to Ruby
9
+ # values in the SDK as follows:
10
+ #
11
+ # 1. boolean => true | false
12
+ # 2. integer => Integer
13
+ # 3. float => Float
14
+ # 4. string => Symbol
15
+ #
16
+ # We can therefore convert string values to Symbols, but can't convert other
17
+ # values safely.
18
+ #
19
+ # @example
20
+ # # `currency_code` is a `EInvoiceAPI::CurrencyCode`
21
+ # case currency_code
22
+ # when EInvoiceAPI::CurrencyCode::EUR
23
+ # # ...
24
+ # when EInvoiceAPI::CurrencyCode::USD
25
+ # # ...
26
+ # when EInvoiceAPI::CurrencyCode::GBP
27
+ # # ...
28
+ # else
29
+ # puts(currency_code)
30
+ # end
31
+ #
32
+ # @example
33
+ # case currency_code
34
+ # in :EUR
35
+ # # ...
36
+ # in :USD
37
+ # # ...
38
+ # in :GBP
39
+ # # ...
40
+ # else
41
+ # puts(currency_code)
42
+ # end
43
+ module Enum
44
+ include EInvoiceAPI::Internal::Type::Converter
45
+ include EInvoiceAPI::Internal::Util::SorbetRuntimeSupport
46
+
47
+ # All of the valid Symbol values for this enum.
48
+ #
49
+ # @return [Array<NilClass, Boolean, Integer, Float, Symbol>]
50
+ def values = constants.map { const_get(_1) }
51
+
52
+ # @api public
53
+ #
54
+ # @param other [Object]
55
+ #
56
+ # @return [Boolean]
57
+ def ===(other) = values.include?(other)
58
+
59
+ # @api public
60
+ #
61
+ # @param other [Object]
62
+ #
63
+ # @return [Boolean]
64
+ def ==(other)
65
+ # rubocop:disable Style/CaseEquality
66
+ EInvoiceAPI::Internal::Type::Enum === other && other.values.to_set == values.to_set
67
+ # rubocop:enable Style/CaseEquality
68
+ end
69
+
70
+ # @api public
71
+ #
72
+ # @return [Integer]
73
+ def hash = values.to_set.hash
74
+
75
+ # @api private
76
+ #
77
+ # Unlike with primitives, `Enum` additionally validates that the value is a member
78
+ # of the enum.
79
+ #
80
+ # @param value [String, Symbol, Object]
81
+ #
82
+ # @param state [Hash{Symbol=>Object}] .
83
+ #
84
+ # @option state [Boolean, :strong] :strictness
85
+ #
86
+ # @option state [Hash{Symbol=>Object}] :exactness
87
+ #
88
+ # @option state [Integer] :branched
89
+ #
90
+ # @return [Symbol, Object]
91
+ def coerce(value, state:)
92
+ exactness = state.fetch(:exactness)
93
+ val = value.is_a?(String) ? value.to_sym : value
94
+
95
+ if values.include?(val)
96
+ exactness[:yes] += 1
97
+ val
98
+ else
99
+ exactness[values.first&.class == val.class ? :maybe : :no] += 1
100
+ value
101
+ end
102
+ end
103
+
104
+ # @!method dump(value, state:)
105
+ # @api private
106
+ #
107
+ # @param value [Symbol, Object]
108
+ #
109
+ # @param state [Hash{Symbol=>Object}] .
110
+ #
111
+ # @option state [Boolean] :can_retry
112
+ #
113
+ # @return [Symbol, Object]
114
+
115
+ # @api private
116
+ #
117
+ # @return [Object]
118
+ def to_sorbet_type
119
+ types = values.map { EInvoiceAPI::Internal::Util::SorbetRuntimeSupport.to_sorbet_type(_1) }.uniq
120
+ case types
121
+ in []
122
+ T.noreturn
123
+ in [type]
124
+ type
125
+ else
126
+ T.any(*types)
127
+ end
128
+ end
129
+
130
+ # @api private
131
+ #
132
+ # @param depth [Integer]
133
+ #
134
+ # @return [String]
135
+ def inspect(depth: 0)
136
+ if depth.positive?
137
+ return is_a?(Module) ? super() : self.class.name
138
+ end
139
+
140
+ members = values.map { EInvoiceAPI::Internal::Type::Converter.inspect(_1, depth: depth.succ) }
141
+ prefix = is_a?(Module) ? name : self.class.name
142
+
143
+ "#{prefix}[#{members.join(' | ')}]"
144
+ end
145
+ end
146
+ end
147
+ end
148
+ end
@@ -0,0 +1,103 @@
1
+ # frozen_string_literal: true
2
+
3
+ module EInvoiceAPI
4
+ module Internal
5
+ module Type
6
+ # @api private
7
+ #
8
+ # @abstract
9
+ #
10
+ # Either `Pathname` or `StringIO`, or `IO`, or
11
+ # `EInvoiceAPI::Internal::Type::FileInput`.
12
+ #
13
+ # Note: when `IO` is used, all retries are disabled, since many IO` streams are
14
+ # not rewindable.
15
+ class FileInput
16
+ extend EInvoiceAPI::Internal::Type::Converter
17
+
18
+ private_class_method :new
19
+
20
+ # @api public
21
+ #
22
+ # @param other [Object]
23
+ #
24
+ # @return [Boolean]
25
+ def self.===(other)
26
+ case other
27
+ in Pathname | StringIO | IO | String | EInvoiceAPI::FilePart
28
+ true
29
+ else
30
+ false
31
+ end
32
+ end
33
+
34
+ # @api public
35
+ #
36
+ # @param other [Object]
37
+ #
38
+ # @return [Boolean]
39
+ def self.==(other) = other.is_a?(Class) && other <= EInvoiceAPI::Internal::Type::FileInput
40
+
41
+ class << self
42
+ # @api private
43
+ #
44
+ # @param value [StringIO, String, Object]
45
+ #
46
+ # @param state [Hash{Symbol=>Object}] .
47
+ #
48
+ # @option state [Boolean, :strong] :strictness
49
+ #
50
+ # @option state [Hash{Symbol=>Object}] :exactness
51
+ #
52
+ # @option state [Integer] :branched
53
+ #
54
+ # @return [StringIO, Object]
55
+ def coerce(value, state:)
56
+ exactness = state.fetch(:exactness)
57
+ case value
58
+ in String
59
+ exactness[:yes] += 1
60
+ StringIO.new(value)
61
+ in StringIO
62
+ exactness[:yes] += 1
63
+ value
64
+ else
65
+ exactness[:no] += 1
66
+ value
67
+ end
68
+ end
69
+
70
+ # @api private
71
+ #
72
+ # @param value [Pathname, StringIO, IO, String, Object]
73
+ #
74
+ # @param state [Hash{Symbol=>Object}] .
75
+ #
76
+ # @option state [Boolean] :can_retry
77
+ #
78
+ # @return [Pathname, StringIO, IO, String, Object]
79
+ def dump(value, state:)
80
+ # rubocop:disable Lint/DuplicateBranch
81
+ case value
82
+ in IO
83
+ state[:can_retry] = false
84
+ in EInvoiceAPI::FilePart if value.content.is_a?(IO)
85
+ state[:can_retry] = false
86
+ else
87
+ end
88
+ # rubocop:enable Lint/DuplicateBranch
89
+
90
+ value
91
+ end
92
+
93
+ # @api private
94
+ #
95
+ # @return [Object]
96
+ def to_sorbet_type
97
+ T.any(Pathname, StringIO, IO, String, EInvoiceAPI::FilePart)
98
+ end
99
+ end
100
+ end
101
+ end
102
+ end
103
+ end