vatsense 0.1.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 (245) hide show
  1. checksums.yaml +7 -0
  2. data/.ignore +2 -0
  3. data/CHANGELOG.md +14 -0
  4. data/README.md +235 -0
  5. data/SECURITY.md +27 -0
  6. data/lib/vatsense/client.rb +129 -0
  7. data/lib/vatsense/errors.rb +228 -0
  8. data/lib/vatsense/file_part.rb +58 -0
  9. data/lib/vatsense/internal/transport/base_client.rb +595 -0
  10. data/lib/vatsense/internal/transport/pooled_net_requester.rb +210 -0
  11. data/lib/vatsense/internal/type/array_of.rb +168 -0
  12. data/lib/vatsense/internal/type/base_model.rb +531 -0
  13. data/lib/vatsense/internal/type/base_page.rb +55 -0
  14. data/lib/vatsense/internal/type/boolean.rb +77 -0
  15. data/lib/vatsense/internal/type/converter.rb +327 -0
  16. data/lib/vatsense/internal/type/enum.rb +131 -0
  17. data/lib/vatsense/internal/type/file_input.rb +111 -0
  18. data/lib/vatsense/internal/type/hash_of.rb +188 -0
  19. data/lib/vatsense/internal/type/request_parameters.rb +42 -0
  20. data/lib/vatsense/internal/type/union.rb +237 -0
  21. data/lib/vatsense/internal/type/unknown.rb +81 -0
  22. data/lib/vatsense/internal/util.rb +951 -0
  23. data/lib/vatsense/internal.rb +20 -0
  24. data/lib/vatsense/models/country.rb +70 -0
  25. data/lib/vatsense/models/country_list_params.rb +34 -0
  26. data/lib/vatsense/models/country_list_provinces_params.rb +22 -0
  27. data/lib/vatsense/models/country_list_provinces_response.rb +67 -0
  28. data/lib/vatsense/models/country_list_response.rb +28 -0
  29. data/lib/vatsense/models/create_invoice.rb +171 -0
  30. data/lib/vatsense/models/currency_calculate_vat_price_params.rb +53 -0
  31. data/lib/vatsense/models/currency_calculate_vat_price_response.rb +28 -0
  32. data/lib/vatsense/models/currency_convert_params.rb +53 -0
  33. data/lib/vatsense/models/currency_convert_response.rb +87 -0
  34. data/lib/vatsense/models/currency_list_params.rb +45 -0
  35. data/lib/vatsense/models/currency_list_response.rb +72 -0
  36. data/lib/vatsense/models/find_rate.rb +28 -0
  37. data/lib/vatsense/models/invoice/invoice_item.rb +71 -0
  38. data/lib/vatsense/models/invoice/invoice_item_input.rb +52 -0
  39. data/lib/vatsense/models/invoice/item_add_params.rb +28 -0
  40. data/lib/vatsense/models/invoice/item_delete_params.rb +28 -0
  41. data/lib/vatsense/models/invoice/item_retrieve_params.rb +28 -0
  42. data/lib/vatsense/models/invoice/item_retrieve_response.rb +30 -0
  43. data/lib/vatsense/models/invoice/item_update_params.rb +28 -0
  44. data/lib/vatsense/models/invoice.rb +301 -0
  45. data/lib/vatsense/models/invoice_business_input.rb +80 -0
  46. data/lib/vatsense/models/invoice_conversion_input.rb +24 -0
  47. data/lib/vatsense/models/invoice_create_params.rb +14 -0
  48. data/lib/vatsense/models/invoice_customer_input.rb +59 -0
  49. data/lib/vatsense/models/invoice_delete_params.rb +20 -0
  50. data/lib/vatsense/models/invoice_delete_response.rb +22 -0
  51. data/lib/vatsense/models/invoice_list_params.rb +38 -0
  52. data/lib/vatsense/models/invoice_list_response.rb +28 -0
  53. data/lib/vatsense/models/invoice_response.rb +28 -0
  54. data/lib/vatsense/models/invoice_retrieve_params.rb +20 -0
  55. data/lib/vatsense/models/invoice_update_params.rb +20 -0
  56. data/lib/vatsense/models/rate.rb +74 -0
  57. data/lib/vatsense/models/rate_calculate_price_params.rb +88 -0
  58. data/lib/vatsense/models/rate_calculate_price_response.rb +79 -0
  59. data/lib/vatsense/models/rate_details_params.rb +69 -0
  60. data/lib/vatsense/models/rate_find_params.rb +69 -0
  61. data/lib/vatsense/models/rate_list_params.rb +51 -0
  62. data/lib/vatsense/models/rate_list_response.rb +28 -0
  63. data/lib/vatsense/models/rate_list_types_params.rb +14 -0
  64. data/lib/vatsense/models/rate_list_types_response.rb +28 -0
  65. data/lib/vatsense/models/rate_with_tax_rate.rb +49 -0
  66. data/lib/vatsense/models/sandbox_generate_key_params.rb +14 -0
  67. data/lib/vatsense/models/sandbox_generate_key_response.rb +68 -0
  68. data/lib/vatsense/models/tax_rate.rb +76 -0
  69. data/lib/vatsense/models/usage_retrieve_params.rb +14 -0
  70. data/lib/vatsense/models/usage_retrieve_response.rb +67 -0
  71. data/lib/vatsense/models/validate_check_params.rb +48 -0
  72. data/lib/vatsense/models/validate_check_response.rb +135 -0
  73. data/lib/vatsense/models/vat_price.rb +86 -0
  74. data/lib/vatsense/models.rb +103 -0
  75. data/lib/vatsense/request_options.rb +77 -0
  76. data/lib/vatsense/resources/countries.rb +70 -0
  77. data/lib/vatsense/resources/currency.rb +111 -0
  78. data/lib/vatsense/resources/invoice/item.rb +133 -0
  79. data/lib/vatsense/resources/invoice.rb +206 -0
  80. data/lib/vatsense/resources/rates.rb +190 -0
  81. data/lib/vatsense/resources/sandbox.rb +36 -0
  82. data/lib/vatsense/resources/usage.rb +33 -0
  83. data/lib/vatsense/resources/validate.rb +56 -0
  84. data/lib/vatsense/version.rb +5 -0
  85. data/lib/vatsense.rb +113 -0
  86. data/manifest.yaml +17 -0
  87. data/rbi/vatsense/client.rbi +93 -0
  88. data/rbi/vatsense/errors.rbi +205 -0
  89. data/rbi/vatsense/file_part.rbi +37 -0
  90. data/rbi/vatsense/internal/transport/base_client.rbi +300 -0
  91. data/rbi/vatsense/internal/transport/pooled_net_requester.rbi +83 -0
  92. data/rbi/vatsense/internal/type/array_of.rbi +104 -0
  93. data/rbi/vatsense/internal/type/base_model.rbi +306 -0
  94. data/rbi/vatsense/internal/type/base_page.rbi +42 -0
  95. data/rbi/vatsense/internal/type/boolean.rbi +58 -0
  96. data/rbi/vatsense/internal/type/converter.rbi +216 -0
  97. data/rbi/vatsense/internal/type/enum.rbi +82 -0
  98. data/rbi/vatsense/internal/type/file_input.rbi +59 -0
  99. data/rbi/vatsense/internal/type/hash_of.rbi +104 -0
  100. data/rbi/vatsense/internal/type/request_parameters.rbi +29 -0
  101. data/rbi/vatsense/internal/type/union.rbi +128 -0
  102. data/rbi/vatsense/internal/type/unknown.rbi +58 -0
  103. data/rbi/vatsense/internal/util.rbi +507 -0
  104. data/rbi/vatsense/internal.rbi +16 -0
  105. data/rbi/vatsense/models/country.rbi +111 -0
  106. data/rbi/vatsense/models/country_list_params.rbi +59 -0
  107. data/rbi/vatsense/models/country_list_provinces_params.rbi +43 -0
  108. data/rbi/vatsense/models/country_list_provinces_response.rbi +177 -0
  109. data/rbi/vatsense/models/country_list_response.rbi +55 -0
  110. data/rbi/vatsense/models/create_invoice.rbi +240 -0
  111. data/rbi/vatsense/models/currency_calculate_vat_price_params.rbi +100 -0
  112. data/rbi/vatsense/models/currency_calculate_vat_price_response.rbi +51 -0
  113. data/rbi/vatsense/models/currency_convert_params.rbi +81 -0
  114. data/rbi/vatsense/models/currency_convert_response.rbi +190 -0
  115. data/rbi/vatsense/models/currency_list_params.rbi +79 -0
  116. data/rbi/vatsense/models/currency_list_response.rbi +174 -0
  117. data/rbi/vatsense/models/find_rate.rbi +50 -0
  118. data/rbi/vatsense/models/invoice/invoice_item.rbi +129 -0
  119. data/rbi/vatsense/models/invoice/invoice_item_input.rbi +79 -0
  120. data/rbi/vatsense/models/invoice/item_add_params.rbi +45 -0
  121. data/rbi/vatsense/models/invoice/item_delete_params.rbi +48 -0
  122. data/rbi/vatsense/models/invoice/item_retrieve_params.rbi +48 -0
  123. data/rbi/vatsense/models/invoice/item_retrieve_response.rbi +57 -0
  124. data/rbi/vatsense/models/invoice/item_update_params.rbi +48 -0
  125. data/rbi/vatsense/models/invoice.rbi +481 -0
  126. data/rbi/vatsense/models/invoice_business_input.rbi +113 -0
  127. data/rbi/vatsense/models/invoice_conversion_input.rbi +35 -0
  128. data/rbi/vatsense/models/invoice_create_params.rbi +27 -0
  129. data/rbi/vatsense/models/invoice_customer_input.rbi +93 -0
  130. data/rbi/vatsense/models/invoice_delete_params.rbi +35 -0
  131. data/rbi/vatsense/models/invoice_delete_response.rbi +31 -0
  132. data/rbi/vatsense/models/invoice_list_params.rbi +68 -0
  133. data/rbi/vatsense/models/invoice_list_response.rbi +55 -0
  134. data/rbi/vatsense/models/invoice_response.rbi +48 -0
  135. data/rbi/vatsense/models/invoice_retrieve_params.rbi +35 -0
  136. data/rbi/vatsense/models/invoice_update_params.rbi +35 -0
  137. data/rbi/vatsense/models/rate.rbi +119 -0
  138. data/rbi/vatsense/models/rate_calculate_price_params.rbi +144 -0
  139. data/rbi/vatsense/models/rate_calculate_price_response.rbi +184 -0
  140. data/rbi/vatsense/models/rate_details_params.rbi +109 -0
  141. data/rbi/vatsense/models/rate_find_params.rbi +109 -0
  142. data/rbi/vatsense/models/rate_list_params.rbi +83 -0
  143. data/rbi/vatsense/models/rate_list_response.rbi +48 -0
  144. data/rbi/vatsense/models/rate_list_types_params.rbi +27 -0
  145. data/rbi/vatsense/models/rate_list_types_response.rbi +51 -0
  146. data/rbi/vatsense/models/rate_with_tax_rate.rbi +94 -0
  147. data/rbi/vatsense/models/sandbox_generate_key_params.rbi +27 -0
  148. data/rbi/vatsense/models/sandbox_generate_key_response.rbi +135 -0
  149. data/rbi/vatsense/models/tax_rate.rbi +109 -0
  150. data/rbi/vatsense/models/usage_retrieve_params.rbi +27 -0
  151. data/rbi/vatsense/models/usage_retrieve_response.rbi +155 -0
  152. data/rbi/vatsense/models/validate_check_params.rbi +82 -0
  153. data/rbi/vatsense/models/validate_check_response.rbi +285 -0
  154. data/rbi/vatsense/models/vat_price.rbi +136 -0
  155. data/rbi/vatsense/models.rbi +66 -0
  156. data/rbi/vatsense/request_options.rbi +59 -0
  157. data/rbi/vatsense/resources/countries.rbi +49 -0
  158. data/rbi/vatsense/resources/currency.rbi +82 -0
  159. data/rbi/vatsense/resources/invoice/item.rbi +97 -0
  160. data/rbi/vatsense/resources/invoice.rbi +191 -0
  161. data/rbi/vatsense/resources/rates.rbi +164 -0
  162. data/rbi/vatsense/resources/sandbox.rbi +24 -0
  163. data/rbi/vatsense/resources/usage.rbi +22 -0
  164. data/rbi/vatsense/resources/validate.rbi +51 -0
  165. data/rbi/vatsense/version.rbi +5 -0
  166. data/sig/vatsense/client.rbs +45 -0
  167. data/sig/vatsense/errors.rbs +117 -0
  168. data/sig/vatsense/file_part.rbs +21 -0
  169. data/sig/vatsense/internal/transport/base_client.rbs +135 -0
  170. data/sig/vatsense/internal/transport/pooled_net_requester.rbs +48 -0
  171. data/sig/vatsense/internal/type/array_of.rbs +48 -0
  172. data/sig/vatsense/internal/type/base_model.rbs +102 -0
  173. data/sig/vatsense/internal/type/base_page.rbs +24 -0
  174. data/sig/vatsense/internal/type/boolean.rbs +26 -0
  175. data/sig/vatsense/internal/type/converter.rbs +79 -0
  176. data/sig/vatsense/internal/type/enum.rbs +32 -0
  177. data/sig/vatsense/internal/type/file_input.rbs +25 -0
  178. data/sig/vatsense/internal/type/hash_of.rbs +48 -0
  179. data/sig/vatsense/internal/type/request_parameters.rbs +17 -0
  180. data/sig/vatsense/internal/type/union.rbs +52 -0
  181. data/sig/vatsense/internal/type/unknown.rbs +26 -0
  182. data/sig/vatsense/internal/util.rbs +195 -0
  183. data/sig/vatsense/internal.rbs +9 -0
  184. data/sig/vatsense/models/country.rbs +76 -0
  185. data/sig/vatsense/models/country_list_params.rbs +32 -0
  186. data/sig/vatsense/models/country_list_provinces_params.rbs +23 -0
  187. data/sig/vatsense/models/country_list_provinces_response.rbs +90 -0
  188. data/sig/vatsense/models/country_list_response.rbs +32 -0
  189. data/sig/vatsense/models/create_invoice.rbs +154 -0
  190. data/sig/vatsense/models/currency_calculate_vat_price_params.rbs +47 -0
  191. data/sig/vatsense/models/currency_calculate_vat_price_response.rbs +28 -0
  192. data/sig/vatsense/models/currency_convert_params.rbs +47 -0
  193. data/sig/vatsense/models/currency_convert_response.rbs +104 -0
  194. data/sig/vatsense/models/currency_list_params.rbs +45 -0
  195. data/sig/vatsense/models/currency_list_response.rbs +90 -0
  196. data/sig/vatsense/models/find_rate.rbs +32 -0
  197. data/sig/vatsense/models/invoice/invoice_item.rbs +85 -0
  198. data/sig/vatsense/models/invoice/invoice_item_input.rbs +46 -0
  199. data/sig/vatsense/models/invoice/item_add_params.rbs +33 -0
  200. data/sig/vatsense/models/invoice/item_delete_params.rbs +30 -0
  201. data/sig/vatsense/models/invoice/item_retrieve_params.rbs +30 -0
  202. data/sig/vatsense/models/invoice/item_retrieve_response.rbs +36 -0
  203. data/sig/vatsense/models/invoice/item_update_params.rbs +34 -0
  204. data/sig/vatsense/models/invoice.rbs +332 -0
  205. data/sig/vatsense/models/invoice_business_input.rbs +72 -0
  206. data/sig/vatsense/models/invoice_conversion_input.rbs +15 -0
  207. data/sig/vatsense/models/invoice_create_params.rbs +15 -0
  208. data/sig/vatsense/models/invoice_customer_input.rbs +62 -0
  209. data/sig/vatsense/models/invoice_delete_params.rbs +23 -0
  210. data/sig/vatsense/models/invoice_delete_response.rbs +15 -0
  211. data/sig/vatsense/models/invoice_list_params.rbs +38 -0
  212. data/sig/vatsense/models/invoice_list_response.rbs +34 -0
  213. data/sig/vatsense/models/invoice_response.rbs +32 -0
  214. data/sig/vatsense/models/invoice_retrieve_params.rbs +23 -0
  215. data/sig/vatsense/models/invoice_update_params.rbs +25 -0
  216. data/sig/vatsense/models/rate.rbs +79 -0
  217. data/sig/vatsense/models/rate_calculate_price_params.rbs +77 -0
  218. data/sig/vatsense/models/rate_calculate_price_response.rbs +104 -0
  219. data/sig/vatsense/models/rate_details_params.rbs +63 -0
  220. data/sig/vatsense/models/rate_find_params.rbs +63 -0
  221. data/sig/vatsense/models/rate_list_params.rbs +44 -0
  222. data/sig/vatsense/models/rate_list_response.rbs +32 -0
  223. data/sig/vatsense/models/rate_list_types_params.rbs +15 -0
  224. data/sig/vatsense/models/rate_list_types_response.rbs +28 -0
  225. data/sig/vatsense/models/rate_with_tax_rate.rbs +62 -0
  226. data/sig/vatsense/models/sandbox_generate_key_params.rbs +15 -0
  227. data/sig/vatsense/models/sandbox_generate_key_response.rbs +85 -0
  228. data/sig/vatsense/models/tax_rate.rbs +72 -0
  229. data/sig/vatsense/models/usage_retrieve_params.rbs +15 -0
  230. data/sig/vatsense/models/usage_retrieve_response.rbs +81 -0
  231. data/sig/vatsense/models/validate_check_params.rbs +38 -0
  232. data/sig/vatsense/models/validate_check_response.rbs +161 -0
  233. data/sig/vatsense/models/vat_price.rbs +89 -0
  234. data/sig/vatsense/models.rbs +63 -0
  235. data/sig/vatsense/request_options.rbs +34 -0
  236. data/sig/vatsense/resources/countries.rbs +18 -0
  237. data/sig/vatsense/resources/currency.rbs +27 -0
  238. data/sig/vatsense/resources/invoice/item.rbs +38 -0
  239. data/sig/vatsense/resources/invoice.rbs +69 -0
  240. data/sig/vatsense/resources/rates.rbs +50 -0
  241. data/sig/vatsense/resources/sandbox.rbs +11 -0
  242. data/sig/vatsense/resources/usage.rbs +11 -0
  243. data/sig/vatsense/resources/validate.rbs +14 -0
  244. data/sig/vatsense/version.rbs +3 -0
  245. metadata +316 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 41320914ca748d7abab0a4baa5c65b59f1131a9c16a2e0a0ed1f79014f343765
4
+ data.tar.gz: 2700b3a5120dbf857f342a585791240977997c9645e569e2e8089f06ec7db6f2
5
+ SHA512:
6
+ metadata.gz: 252a750b1486d10ceda68cbf607dff22fa9429ea65c12fceee157f231e3b24c62ebd71fc1b9c13a57b25aa81fa7a90937d61d2dd19d40f539ac23a156b04d948
7
+ data.tar.gz: 8701628a0b041007aef2be237944a01332e528f4558dc117b36242ff60c8eecd72e641108be767ffb66a0a97da17af2265dbe58b73ada82ac3a73f13d8f5ea25
data/.ignore ADDED
@@ -0,0 +1,2 @@
1
+ rbi/*
2
+ sig/*
data/CHANGELOG.md ADDED
@@ -0,0 +1,14 @@
1
+ # Changelog
2
+
3
+ ## 0.1.0 (2026-03-18)
4
+
5
+ Full Changelog: [v0.0.1...v0.1.0](https://github.com/VAT-Sense/vatsense-ruby/compare/v0.0.1...v0.1.0)
6
+
7
+ ### Features
8
+
9
+ * **api:** api update ([a2eaadb](https://github.com/VAT-Sense/vatsense-ruby/commit/a2eaadbc5c67c4bfd4e903dd09c49b28b554e548))
10
+
11
+
12
+ ### Chores
13
+
14
+ * configure new SDK language ([881bf6a](https://github.com/VAT-Sense/vatsense-ruby/commit/881bf6ab7dc391c411f134d88e8083df43f8ff04))
data/README.md ADDED
@@ -0,0 +1,235 @@
1
+ # Vat Sense Ruby API library
2
+
3
+ The Vat Sense Ruby library provides convenient access to the Vat Sense REST API from any Ruby 3.2.0+ application. It ships with comprehensive types & docstrings in Yard, RBS, and RBI – [see below](https://github.com/VAT-Sense/vatsense-ruby#Sorbet) for usage with Sorbet. The standard library's `net/http` is used as the HTTP transport, with connection pooling via the `connection_pool` gem.
4
+
5
+ It is generated with [Stainless](https://www.stainless.com/).
6
+
7
+ ## Documentation
8
+
9
+ Documentation for releases of this gem can be found [on RubyDoc](https://gemdocs.org/gems/vatsense).
10
+
11
+ The REST API documentation can be found on [vatsense.com](https://vatsense.com).
12
+
13
+ ## Installation
14
+
15
+ To use this gem, install via Bundler by adding the following to your application's `Gemfile`:
16
+
17
+ <!-- x-release-please-start-version -->
18
+
19
+ ```ruby
20
+ gem "vatsense", "~> 0.1.0"
21
+ ```
22
+
23
+ <!-- x-release-please-end -->
24
+
25
+ ## Usage
26
+
27
+ ```ruby
28
+ require "bundler/setup"
29
+ require "vatsense"
30
+
31
+ vat_sense = Vatsense::Client.new(
32
+ username: ENV["VAT_SENSE_USERNAME"], # This is the default and can be omitted
33
+ password: ENV["VAT_SENSE_PASSWORD"] # This is the default and can be omitted
34
+ )
35
+
36
+ rates = vat_sense.rates.list
37
+
38
+ puts(rates.code)
39
+ ```
40
+
41
+ ### Handling errors
42
+
43
+ When the library is unable to connect to the API, or if the API returns a non-success status code (i.e., 4xx or 5xx response), a subclass of `Vatsense::Errors::APIError` will be thrown:
44
+
45
+ ```ruby
46
+ begin
47
+ rate = vat_sense.rates.list
48
+ rescue Vatsense::Errors::APIConnectionError => e
49
+ puts("The server could not be reached")
50
+ puts(e.cause) # an underlying Exception, likely raised within `net/http`
51
+ rescue Vatsense::Errors::RateLimitError => e
52
+ puts("A 429 status code was received; we should back off a bit.")
53
+ rescue Vatsense::Errors::APIStatusError => e
54
+ puts("Another non-200-range status code was received")
55
+ puts(e.status)
56
+ end
57
+ ```
58
+
59
+ Error codes are as follows:
60
+
61
+ | Cause | Error Type |
62
+ | ---------------- | -------------------------- |
63
+ | HTTP 400 | `BadRequestError` |
64
+ | HTTP 401 | `AuthenticationError` |
65
+ | HTTP 403 | `PermissionDeniedError` |
66
+ | HTTP 404 | `NotFoundError` |
67
+ | HTTP 409 | `ConflictError` |
68
+ | HTTP 422 | `UnprocessableEntityError` |
69
+ | HTTP 429 | `RateLimitError` |
70
+ | HTTP >= 500 | `InternalServerError` |
71
+ | Other HTTP error | `APIStatusError` |
72
+ | Timeout | `APITimeoutError` |
73
+ | Network error | `APIConnectionError` |
74
+
75
+ ### Retries
76
+
77
+ Certain errors will be automatically retried 2 times by default, with a short exponential backoff.
78
+
79
+ Connection errors (for example, due to a network connectivity problem), 408 Request Timeout, 409 Conflict, 429 Rate Limit, >=500 Internal errors, and timeouts will all be retried by default.
80
+
81
+ You can use the `max_retries` option to configure or disable this:
82
+
83
+ ```ruby
84
+ # Configure the default for all requests:
85
+ vat_sense = Vatsense::Client.new(
86
+ max_retries: 0 # default is 2
87
+ )
88
+
89
+ # Or, configure per-request:
90
+ vat_sense.rates.list(request_options: {max_retries: 5})
91
+ ```
92
+
93
+ ### Timeouts
94
+
95
+ By default, requests will time out after 60 seconds. You can use the timeout option to configure or disable this:
96
+
97
+ ```ruby
98
+ # Configure the default for all requests:
99
+ vat_sense = Vatsense::Client.new(
100
+ timeout: nil # default is 60
101
+ )
102
+
103
+ # Or, configure per-request:
104
+ vat_sense.rates.list(request_options: {timeout: 5})
105
+ ```
106
+
107
+ On timeout, `Vatsense::Errors::APITimeoutError` is raised.
108
+
109
+ Note that requests that time out are retried by default.
110
+
111
+ ## Advanced concepts
112
+
113
+ ### BaseModel
114
+
115
+ All parameter and response objects inherit from `Vatsense::Internal::Type::BaseModel`, which provides several conveniences, including:
116
+
117
+ 1. All fields, including unknown ones, are accessible with `obj[:prop]` syntax, and can be destructured with `obj => {prop: prop}` or pattern-matching syntax.
118
+
119
+ 2. Structural equivalence for equality; if two API calls return the same values, comparing the responses with == will return true.
120
+
121
+ 3. Both instances and the classes themselves can be pretty-printed.
122
+
123
+ 4. Helpers such as `#to_h`, `#deep_to_h`, `#to_json`, and `#to_yaml`.
124
+
125
+ ### Making custom or undocumented requests
126
+
127
+ #### Undocumented properties
128
+
129
+ You can send undocumented parameters to any endpoint, and read undocumented response properties, like so:
130
+
131
+ Note: the `extra_` parameters of the same name overrides the documented parameters.
132
+
133
+ ```ruby
134
+ rates =
135
+ vat_sense.rates.list(
136
+ request_options: {
137
+ extra_query: {my_query_parameter: value},
138
+ extra_body: {my_body_parameter: value},
139
+ extra_headers: {"my-header": value}
140
+ }
141
+ )
142
+
143
+ puts(rates[:my_undocumented_property])
144
+ ```
145
+
146
+ #### Undocumented request params
147
+
148
+ If you want to explicitly send an extra param, you can do so with the `extra_query`, `extra_body`, and `extra_headers` under the `request_options:` parameter when making a request, as seen in the examples above.
149
+
150
+ #### Undocumented endpoints
151
+
152
+ To make requests to undocumented endpoints while retaining the benefit of auth, retries, and so on, you can make requests using `client.request`, like so:
153
+
154
+ ```ruby
155
+ response = client.request(
156
+ method: :post,
157
+ path: '/undocumented/endpoint',
158
+ query: {"dog": "woof"},
159
+ headers: {"useful-header": "interesting-value"},
160
+ body: {"hello": "world"}
161
+ )
162
+ ```
163
+
164
+ ### Concurrency & connection pooling
165
+
166
+ The `Vatsense::Client` instances are threadsafe, but are only are fork-safe when there are no in-flight HTTP requests.
167
+
168
+ Each instance of `Vatsense::Client` has its own HTTP connection pool with a default size of 99. As such, we recommend instantiating the client once per application in most settings.
169
+
170
+ When all available connections from the pool are checked out, requests wait for a new connection to become available, with queue time counting towards the request timeout.
171
+
172
+ Unless otherwise specified, other classes in the SDK do not have locks protecting their underlying data structure.
173
+
174
+ ## Sorbet
175
+
176
+ This library provides comprehensive [RBI](https://sorbet.org/docs/rbi) definitions, and has no dependency on sorbet-runtime.
177
+
178
+ You can provide typesafe request parameters like so:
179
+
180
+ ```ruby
181
+ vat_sense.rates.list
182
+ ```
183
+
184
+ Or, equivalently:
185
+
186
+ ```ruby
187
+ # Hashes work, but are not typesafe:
188
+ vat_sense.rates.list
189
+
190
+ # You can also splat a full Params class:
191
+ params = Vatsense::RateListParams.new
192
+ vat_sense.rates.list(**params)
193
+ ```
194
+
195
+ ### Enums
196
+
197
+ Since this library does not depend on `sorbet-runtime`, it cannot provide [`T::Enum`](https://sorbet.org/docs/tenum) instances. Instead, we provide "tagged symbols" instead, which is always a primitive at runtime:
198
+
199
+ ```ruby
200
+ # :incl
201
+ puts(Vatsense::RateCalculatePriceParams::TaxType::INCL)
202
+
203
+ # Revealed type: `T.all(Vatsense::RateCalculatePriceParams::TaxType, Symbol)`
204
+ T.reveal_type(Vatsense::RateCalculatePriceParams::TaxType::INCL)
205
+ ```
206
+
207
+ Enum parameters have a "relaxed" type, so you can either pass in enum constants or their literal value:
208
+
209
+ ```ruby
210
+ # Using the enum constants preserves the tagged type information:
211
+ vat_sense.rates.calculate_price(
212
+ tax_type: Vatsense::RateCalculatePriceParams::TaxType::INCL,
213
+ # …
214
+ )
215
+
216
+ # Literal values are also permissible:
217
+ vat_sense.rates.calculate_price(
218
+ tax_type: :incl,
219
+ # …
220
+ )
221
+ ```
222
+
223
+ ## Versioning
224
+
225
+ This package follows [SemVer](https://semver.org/spec/v2.0.0.html) conventions. As the library is in initial development and has a major version of `0`, APIs may change at any time.
226
+
227
+ This package considers improvements to the (non-runtime) `*.rbi` and `*.rbs` type definitions to be non-breaking changes.
228
+
229
+ ## Requirements
230
+
231
+ Ruby 3.2.0 or higher.
232
+
233
+ ## Contributing
234
+
235
+ See [the contributing documentation](https://github.com/VAT-Sense/vatsense-ruby/tree/main/CONTRIBUTING.md).
data/SECURITY.md ADDED
@@ -0,0 +1,27 @@
1
+ # Security Policy
2
+
3
+ ## Reporting Security Issues
4
+
5
+ This SDK is generated by [Stainless Software Inc](http://stainless.com). Stainless takes security seriously, and encourages you to report any security vulnerability promptly so that appropriate action can be taken.
6
+
7
+ To report a security issue, please contact the Stainless team at security@stainless.com.
8
+
9
+ ## Responsible Disclosure
10
+
11
+ We appreciate the efforts of security researchers and individuals who help us maintain the security of
12
+ SDKs we generate. If you believe you have found a security vulnerability, please adhere to responsible
13
+ disclosure practices by allowing us a reasonable amount of time to investigate and address the issue
14
+ before making any information public.
15
+
16
+ ## Reporting Non-SDK Related Security Issues
17
+
18
+ If you encounter security issues that are not directly related to SDKs but pertain to the services
19
+ or products provided by Vat Sense, please follow the respective company's security reporting guidelines.
20
+
21
+ ### Vat Sense Terms and Policies
22
+
23
+ Please contact support@vatsense.com for any questions or concerns regarding the security of our services.
24
+
25
+ ---
26
+
27
+ Thank you for helping us keep the SDKs and systems they interact with secure.
@@ -0,0 +1,129 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Vatsense
4
+ class Client < Vatsense::Internal::Transport::BaseClient
5
+ # Default max number of retries to attempt after a failed retryable request.
6
+ DEFAULT_MAX_RETRIES = 2
7
+
8
+ # Default per-request timeout.
9
+ DEFAULT_TIMEOUT_IN_SECONDS = 60.0
10
+
11
+ # Default initial retry delay in seconds.
12
+ # Overall delay is calculated using exponential backoff + jitter.
13
+ DEFAULT_INITIAL_RETRY_DELAY = 0.5
14
+
15
+ # Default max retry delay in seconds.
16
+ DEFAULT_MAX_RETRY_DELAY = 8.0
17
+
18
+ # Use HTTP Basic Auth with username `user` and your API key as the password.
19
+ # @return [String]
20
+ attr_reader :username
21
+
22
+ # Use HTTP Basic Auth with username `user` and your API key as the password.
23
+ # @return [String]
24
+ attr_reader :password
25
+
26
+ # VAT/GST rate lookups for countries worldwide
27
+ # @return [Vatsense::Resources::Rates]
28
+ attr_reader :rates
29
+
30
+ # Country and province information
31
+ # @return [Vatsense::Resources::Countries]
32
+ attr_reader :countries
33
+
34
+ # VAT and EORI number validation
35
+ # @return [Vatsense::Resources::Validate]
36
+ attr_reader :validate
37
+
38
+ # Currency exchange rates and conversion
39
+ # @return [Vatsense::Resources::Currency]
40
+ attr_reader :currency
41
+
42
+ # VAT-compliant invoice management
43
+ # @return [Vatsense::Resources::Invoice]
44
+ attr_reader :invoice
45
+
46
+ # API usage statistics
47
+ # @return [Vatsense::Resources::Usage]
48
+ attr_reader :usage
49
+
50
+ # Temporary sandbox API keys for testing
51
+ # @return [Vatsense::Resources::Sandbox]
52
+ attr_reader :sandbox
53
+
54
+ # @api private
55
+ #
56
+ # @param security [Hash{Symbol=>Boolean}]
57
+ #
58
+ # @return [Hash{String=>String}]
59
+ private def auth_headers(security:)
60
+ {basic_auth:}.slice(*security.keys).values.reduce({}, :merge)
61
+ end
62
+
63
+ # @api private
64
+ #
65
+ # @return [Hash{String=>String}]
66
+ private def basic_auth
67
+ return {} if @username.nil? || @password.nil?
68
+
69
+ base64_credentials = ["#{@username}:#{@password}"].pack("m0")
70
+ {"authorization" => "Basic #{base64_credentials}"}
71
+ end
72
+
73
+ # Creates and returns a new client for interacting with the API.
74
+ #
75
+ # @param username [String, nil] Use HTTP Basic Auth with username `user` and your API key as the password.
76
+ # Defaults to `ENV["VAT_SENSE_USERNAME"]`
77
+ #
78
+ # @param password [String, nil] Use HTTP Basic Auth with username `user` and your API key as the password.
79
+ # Defaults to `ENV["VAT_SENSE_PASSWORD"]`
80
+ #
81
+ # @param base_url [String, nil] Override the default base URL for the API, e.g.,
82
+ # `"https://api.example.com/v2/"`. Defaults to `ENV["VAT_SENSE_BASE_URL"]`
83
+ #
84
+ # @param max_retries [Integer] Max number of retries to attempt after a failed retryable request.
85
+ #
86
+ # @param timeout [Float]
87
+ #
88
+ # @param initial_retry_delay [Float]
89
+ #
90
+ # @param max_retry_delay [Float]
91
+ def initialize(
92
+ username: ENV["VAT_SENSE_USERNAME"],
93
+ password: ENV["VAT_SENSE_PASSWORD"],
94
+ base_url: ENV["VAT_SENSE_BASE_URL"],
95
+ max_retries: self.class::DEFAULT_MAX_RETRIES,
96
+ timeout: self.class::DEFAULT_TIMEOUT_IN_SECONDS,
97
+ initial_retry_delay: self.class::DEFAULT_INITIAL_RETRY_DELAY,
98
+ max_retry_delay: self.class::DEFAULT_MAX_RETRY_DELAY
99
+ )
100
+ base_url ||= "https://api.vatsense.com/1.0"
101
+
102
+ if username.nil?
103
+ raise ArgumentError.new("username is required, and can be set via environ: \"VAT_SENSE_USERNAME\"")
104
+ end
105
+ if password.nil?
106
+ raise ArgumentError.new("password is required, and can be set via environ: \"VAT_SENSE_PASSWORD\"")
107
+ end
108
+
109
+ @username = username.to_s
110
+ @password = password.to_s
111
+
112
+ super(
113
+ base_url: base_url,
114
+ timeout: timeout,
115
+ max_retries: max_retries,
116
+ initial_retry_delay: initial_retry_delay,
117
+ max_retry_delay: max_retry_delay
118
+ )
119
+
120
+ @rates = Vatsense::Resources::Rates.new(client: self)
121
+ @countries = Vatsense::Resources::Countries.new(client: self)
122
+ @validate = Vatsense::Resources::Validate.new(client: self)
123
+ @currency = Vatsense::Resources::Currency.new(client: self)
124
+ @invoice = Vatsense::Resources::Invoice.new(client: self)
125
+ @usage = Vatsense::Resources::Usage.new(client: self)
126
+ @sandbox = Vatsense::Resources::Sandbox.new(client: self)
127
+ end
128
+ end
129
+ end
@@ -0,0 +1,228 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Vatsense
4
+ module Errors
5
+ class Error < StandardError
6
+ # @!attribute cause
7
+ #
8
+ # @return [StandardError, nil]
9
+ end
10
+
11
+ class ConversionError < Vatsense::Errors::Error
12
+ # @return [StandardError, nil]
13
+ def cause = @cause.nil? ? super : @cause
14
+
15
+ # @api private
16
+ #
17
+ # @param on [Class<StandardError>]
18
+ # @param method [Symbol]
19
+ # @param target [Object]
20
+ # @param value [Object]
21
+ # @param cause [StandardError, nil]
22
+ def initialize(on:, method:, target:, value:, cause: nil)
23
+ cls = on.name.split("::").last
24
+
25
+ message = [
26
+ "Failed to parse #{cls}.#{method} from #{value.class} to #{target.inspect}.",
27
+ "To get the unparsed API response, use #{cls}[#{method.inspect}].",
28
+ cause && "Cause: #{cause.message}"
29
+ ].filter(&:itself).join(" ")
30
+
31
+ @cause = cause
32
+ super(message)
33
+ end
34
+ end
35
+
36
+ class APIError < Vatsense::Errors::Error
37
+ # @return [URI::Generic]
38
+ attr_accessor :url
39
+
40
+ # @return [Integer, nil]
41
+ attr_accessor :status
42
+
43
+ # @return [Hash{String=>String}, nil]
44
+ attr_accessor :headers
45
+
46
+ # @return [Object, nil]
47
+ attr_accessor :body
48
+
49
+ # @api private
50
+ #
51
+ # @param url [URI::Generic]
52
+ # @param status [Integer, nil]
53
+ # @param headers [Hash{String=>String}, nil]
54
+ # @param body [Object, nil]
55
+ # @param request [nil]
56
+ # @param response [nil]
57
+ # @param message [String, nil]
58
+ def initialize(url:, status: nil, headers: nil, body: nil, request: nil, response: nil, message: nil)
59
+ @url = url
60
+ @status = status
61
+ @headers = headers
62
+ @body = body
63
+ @request = request
64
+ @response = response
65
+ super(message)
66
+ end
67
+ end
68
+
69
+ class APIConnectionError < Vatsense::Errors::APIError
70
+ # @!attribute status
71
+ #
72
+ # @return [nil]
73
+
74
+ # @!attribute body
75
+ #
76
+ # @return [nil]
77
+
78
+ # @api private
79
+ #
80
+ # @param url [URI::Generic]
81
+ # @param status [nil]
82
+ # @param headers [Hash{String=>String}, nil]
83
+ # @param body [nil]
84
+ # @param request [nil]
85
+ # @param response [nil]
86
+ # @param message [String, nil]
87
+ def initialize(
88
+ url:,
89
+ status: nil,
90
+ headers: nil,
91
+ body: nil,
92
+ request: nil,
93
+ response: nil,
94
+ message: "Connection error."
95
+ )
96
+ super
97
+ end
98
+ end
99
+
100
+ class APITimeoutError < Vatsense::Errors::APIConnectionError
101
+ # @api private
102
+ #
103
+ # @param url [URI::Generic]
104
+ # @param status [nil]
105
+ # @param headers [Hash{String=>String}, nil]
106
+ # @param body [nil]
107
+ # @param request [nil]
108
+ # @param response [nil]
109
+ # @param message [String, nil]
110
+ def initialize(
111
+ url:,
112
+ status: nil,
113
+ headers: nil,
114
+ body: nil,
115
+ request: nil,
116
+ response: nil,
117
+ message: "Request timed out."
118
+ )
119
+ super
120
+ end
121
+ end
122
+
123
+ class APIStatusError < Vatsense::Errors::APIError
124
+ # @api private
125
+ #
126
+ # @param url [URI::Generic]
127
+ # @param status [Integer]
128
+ # @param headers [Hash{String=>String}, nil]
129
+ # @param body [Object, nil]
130
+ # @param request [nil]
131
+ # @param response [nil]
132
+ # @param message [String, nil]
133
+ #
134
+ # @return [self]
135
+ def self.for(url:, status:, headers:, body:, request:, response:, message: nil)
136
+ kwargs =
137
+ {
138
+ url: url,
139
+ status: status,
140
+ headers: headers,
141
+ body: body,
142
+ request: request,
143
+ response: response,
144
+ message: message
145
+ }
146
+
147
+ case status
148
+ in 400
149
+ Vatsense::Errors::BadRequestError.new(**kwargs)
150
+ in 401
151
+ Vatsense::Errors::AuthenticationError.new(**kwargs)
152
+ in 403
153
+ Vatsense::Errors::PermissionDeniedError.new(**kwargs)
154
+ in 404
155
+ Vatsense::Errors::NotFoundError.new(**kwargs)
156
+ in 409
157
+ Vatsense::Errors::ConflictError.new(**kwargs)
158
+ in 422
159
+ Vatsense::Errors::UnprocessableEntityError.new(**kwargs)
160
+ in 429
161
+ Vatsense::Errors::RateLimitError.new(**kwargs)
162
+ in (500..)
163
+ Vatsense::Errors::InternalServerError.new(**kwargs)
164
+ else
165
+ Vatsense::Errors::APIStatusError.new(**kwargs)
166
+ end
167
+ end
168
+
169
+ # @!parse
170
+ # # @return [Integer]
171
+ # attr_accessor :status
172
+
173
+ # @api private
174
+ #
175
+ # @param url [URI::Generic]
176
+ # @param status [Integer]
177
+ # @param headers [Hash{String=>String}, nil]
178
+ # @param body [Object, nil]
179
+ # @param request [nil]
180
+ # @param response [nil]
181
+ # @param message [String, nil]
182
+ def initialize(url:, status:, headers:, body:, request:, response:, message: nil)
183
+ message ||= {url: url.to_s, status: status, body: body}
184
+ super(
185
+ url: url,
186
+ status: status,
187
+ headers: headers,
188
+ body: body,
189
+ request: request,
190
+ response: response,
191
+ message: message&.to_s
192
+ )
193
+ end
194
+ end
195
+
196
+ class BadRequestError < Vatsense::Errors::APIStatusError
197
+ HTTP_STATUS = 400
198
+ end
199
+
200
+ class AuthenticationError < Vatsense::Errors::APIStatusError
201
+ HTTP_STATUS = 401
202
+ end
203
+
204
+ class PermissionDeniedError < Vatsense::Errors::APIStatusError
205
+ HTTP_STATUS = 403
206
+ end
207
+
208
+ class NotFoundError < Vatsense::Errors::APIStatusError
209
+ HTTP_STATUS = 404
210
+ end
211
+
212
+ class ConflictError < Vatsense::Errors::APIStatusError
213
+ HTTP_STATUS = 409
214
+ end
215
+
216
+ class UnprocessableEntityError < Vatsense::Errors::APIStatusError
217
+ HTTP_STATUS = 422
218
+ end
219
+
220
+ class RateLimitError < Vatsense::Errors::APIStatusError
221
+ HTTP_STATUS = 429
222
+ end
223
+
224
+ class InternalServerError < Vatsense::Errors::APIStatusError
225
+ HTTP_STATUS = (500..)
226
+ end
227
+ end
228
+ end
@@ -0,0 +1,58 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Vatsense
4
+ class FilePart
5
+ # @return [Pathname, StringIO, IO, String]
6
+ attr_reader :content
7
+
8
+ # @return [String, nil]
9
+ attr_reader :content_type
10
+
11
+ # @return [String, nil]
12
+ attr_reader :filename
13
+
14
+ # @api private
15
+ #
16
+ # @return [String]
17
+ private def read
18
+ case content
19
+ in Pathname
20
+ content.read(binmode: true)
21
+ in StringIO
22
+ content.string
23
+ in IO
24
+ content.read
25
+ in String
26
+ content
27
+ end
28
+ end
29
+
30
+ # @param a [Object]
31
+ #
32
+ # @return [String]
33
+ def to_json(*a) = read.to_json(*a)
34
+
35
+ # @param a [Object]
36
+ #
37
+ # @return [String]
38
+ def to_yaml(*a) = read.to_yaml(*a)
39
+
40
+ # @param content [Pathname, StringIO, IO, String]
41
+ # @param filename [Pathname, String, nil]
42
+ # @param content_type [String, nil]
43
+ def initialize(content, filename: nil, content_type: nil)
44
+ @content_type = content_type
45
+ @filename =
46
+ case [filename, (@content = content)]
47
+ in [String | Pathname, _]
48
+ ::File.basename(filename)
49
+ in [nil, Pathname]
50
+ content.basename.to_path
51
+ in [nil, IO]
52
+ content.to_path
53
+ else
54
+ filename
55
+ end
56
+ end
57
+ end
58
+ end