dataleon 0.1.0.pre.alpha.1

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 (149) hide show
  1. checksums.yaml +7 -0
  2. data/.ignore +2 -0
  3. data/CHANGELOG.md +50 -0
  4. data/README.md +257 -0
  5. data/SECURITY.md +27 -0
  6. data/lib/dataleon/client.rb +80 -0
  7. data/lib/dataleon/errors.rb +214 -0
  8. data/lib/dataleon/file_part.rb +55 -0
  9. data/lib/dataleon/internal/transport/base_client.rb +563 -0
  10. data/lib/dataleon/internal/transport/pooled_net_requester.rb +201 -0
  11. data/lib/dataleon/internal/type/array_of.rb +168 -0
  12. data/lib/dataleon/internal/type/base_model.rb +531 -0
  13. data/lib/dataleon/internal/type/base_page.rb +55 -0
  14. data/lib/dataleon/internal/type/boolean.rb +77 -0
  15. data/lib/dataleon/internal/type/converter.rb +327 -0
  16. data/lib/dataleon/internal/type/enum.rb +131 -0
  17. data/lib/dataleon/internal/type/file_input.rb +108 -0
  18. data/lib/dataleon/internal/type/hash_of.rb +188 -0
  19. data/lib/dataleon/internal/type/request_parameters.rb +42 -0
  20. data/lib/dataleon/internal/type/union.rb +237 -0
  21. data/lib/dataleon/internal/type/unknown.rb +81 -0
  22. data/lib/dataleon/internal/util.rb +914 -0
  23. data/lib/dataleon/internal.rb +20 -0
  24. data/lib/dataleon/models/check.rb +50 -0
  25. data/lib/dataleon/models/companies/document_list_params.rb +16 -0
  26. data/lib/dataleon/models/companies/document_upload_params.rb +82 -0
  27. data/lib/dataleon/models/company_create_params.rb +228 -0
  28. data/lib/dataleon/models/company_delete_params.rb +14 -0
  29. data/lib/dataleon/models/company_list_params.rb +108 -0
  30. data/lib/dataleon/models/company_list_response.rb +8 -0
  31. data/lib/dataleon/models/company_registration.rb +964 -0
  32. data/lib/dataleon/models/company_retrieve_params.rb +30 -0
  33. data/lib/dataleon/models/company_update_params.rb +228 -0
  34. data/lib/dataleon/models/individual.rb +805 -0
  35. data/lib/dataleon/models/individual_create_params.rb +174 -0
  36. data/lib/dataleon/models/individual_delete_params.rb +14 -0
  37. data/lib/dataleon/models/individual_list_params.rb +108 -0
  38. data/lib/dataleon/models/individual_list_response.rb +8 -0
  39. data/lib/dataleon/models/individual_retrieve_params.rb +30 -0
  40. data/lib/dataleon/models/individual_update_params.rb +174 -0
  41. data/lib/dataleon/models/individuals/document_list_params.rb +16 -0
  42. data/lib/dataleon/models/individuals/document_response.rb +98 -0
  43. data/lib/dataleon/models/individuals/document_upload_params.rb +82 -0
  44. data/lib/dataleon/models/individuals/generic_document.rb +132 -0
  45. data/lib/dataleon/models/individuals/kbis.rb +326 -0
  46. data/lib/dataleon/models.rb +71 -0
  47. data/lib/dataleon/request_options.rb +77 -0
  48. data/lib/dataleon/resources/companies/documents.rb +65 -0
  49. data/lib/dataleon/resources/companies.rb +164 -0
  50. data/lib/dataleon/resources/individuals/documents.rb +65 -0
  51. data/lib/dataleon/resources/individuals.rb +164 -0
  52. data/lib/dataleon/version.rb +5 -0
  53. data/lib/dataleon.rb +79 -0
  54. data/manifest.yaml +15 -0
  55. data/rbi/dataleon/client.rbi +56 -0
  56. data/rbi/dataleon/errors.rbi +178 -0
  57. data/rbi/dataleon/file_part.rbi +37 -0
  58. data/rbi/dataleon/internal/transport/base_client.rbi +293 -0
  59. data/rbi/dataleon/internal/transport/pooled_net_requester.rbi +79 -0
  60. data/rbi/dataleon/internal/type/array_of.rbi +104 -0
  61. data/rbi/dataleon/internal/type/base_model.rbi +302 -0
  62. data/rbi/dataleon/internal/type/base_page.rbi +42 -0
  63. data/rbi/dataleon/internal/type/boolean.rbi +58 -0
  64. data/rbi/dataleon/internal/type/converter.rbi +216 -0
  65. data/rbi/dataleon/internal/type/enum.rbi +82 -0
  66. data/rbi/dataleon/internal/type/file_input.rbi +59 -0
  67. data/rbi/dataleon/internal/type/hash_of.rbi +104 -0
  68. data/rbi/dataleon/internal/type/request_parameters.rbi +29 -0
  69. data/rbi/dataleon/internal/type/union.rbi +128 -0
  70. data/rbi/dataleon/internal/type/unknown.rbi +58 -0
  71. data/rbi/dataleon/internal/util.rbi +487 -0
  72. data/rbi/dataleon/internal.rbi +16 -0
  73. data/rbi/dataleon/models/check.rbi +83 -0
  74. data/rbi/dataleon/models/companies/document_list_params.rbi +32 -0
  75. data/rbi/dataleon/models/companies/document_upload_params.rbi +266 -0
  76. data/rbi/dataleon/models/company_create_params.rbi +361 -0
  77. data/rbi/dataleon/models/company_delete_params.rbi +27 -0
  78. data/rbi/dataleon/models/company_list_params.rbi +182 -0
  79. data/rbi/dataleon/models/company_list_response.rbi +11 -0
  80. data/rbi/dataleon/models/company_registration.rbi +1628 -0
  81. data/rbi/dataleon/models/company_retrieve_params.rbi +57 -0
  82. data/rbi/dataleon/models/company_update_params.rbi +361 -0
  83. data/rbi/dataleon/models/individual.rbi +1281 -0
  84. data/rbi/dataleon/models/individual_create_params.rbi +323 -0
  85. data/rbi/dataleon/models/individual_delete_params.rbi +27 -0
  86. data/rbi/dataleon/models/individual_list_params.rbi +193 -0
  87. data/rbi/dataleon/models/individual_list_response.rbi +11 -0
  88. data/rbi/dataleon/models/individual_retrieve_params.rbi +57 -0
  89. data/rbi/dataleon/models/individual_update_params.rbi +323 -0
  90. data/rbi/dataleon/models/individuals/document_list_params.rbi +32 -0
  91. data/rbi/dataleon/models/individuals/document_response.rbi +190 -0
  92. data/rbi/dataleon/models/individuals/document_upload_params.rbi +266 -0
  93. data/rbi/dataleon/models/individuals/generic_document.rbi +252 -0
  94. data/rbi/dataleon/models/individuals/kbis.rbi +513 -0
  95. data/rbi/dataleon/models.rbi +33 -0
  96. data/rbi/dataleon/request_options.rbi +59 -0
  97. data/rbi/dataleon/resources/companies/documents.rbi +52 -0
  98. data/rbi/dataleon/resources/companies.rbi +135 -0
  99. data/rbi/dataleon/resources/individuals/documents.rbi +52 -0
  100. data/rbi/dataleon/resources/individuals.rbi +137 -0
  101. data/rbi/dataleon/version.rbi +5 -0
  102. data/sig/dataleon/client.rbs +28 -0
  103. data/sig/dataleon/errors.rbs +110 -0
  104. data/sig/dataleon/file_part.rbs +21 -0
  105. data/sig/dataleon/internal/transport/base_client.rbs +131 -0
  106. data/sig/dataleon/internal/transport/pooled_net_requester.rbs +45 -0
  107. data/sig/dataleon/internal/type/array_of.rbs +48 -0
  108. data/sig/dataleon/internal/type/base_model.rbs +102 -0
  109. data/sig/dataleon/internal/type/base_page.rbs +24 -0
  110. data/sig/dataleon/internal/type/boolean.rbs +26 -0
  111. data/sig/dataleon/internal/type/converter.rbs +79 -0
  112. data/sig/dataleon/internal/type/enum.rbs +32 -0
  113. data/sig/dataleon/internal/type/file_input.rbs +25 -0
  114. data/sig/dataleon/internal/type/hash_of.rbs +48 -0
  115. data/sig/dataleon/internal/type/request_parameters.rbs +17 -0
  116. data/sig/dataleon/internal/type/union.rbs +52 -0
  117. data/sig/dataleon/internal/type/unknown.rbs +26 -0
  118. data/sig/dataleon/internal/util.rbs +185 -0
  119. data/sig/dataleon/internal.rbs +9 -0
  120. data/sig/dataleon/models/check.rbs +50 -0
  121. data/sig/dataleon/models/companies/document_list_params.rbs +17 -0
  122. data/sig/dataleon/models/companies/document_upload_params.rbs +119 -0
  123. data/sig/dataleon/models/company_create_params.rbs +209 -0
  124. data/sig/dataleon/models/company_delete_params.rbs +15 -0
  125. data/sig/dataleon/models/company_list_params.rbs +120 -0
  126. data/sig/dataleon/models/company_list_response.rbs +7 -0
  127. data/sig/dataleon/models/company_registration.rbs +847 -0
  128. data/sig/dataleon/models/company_retrieve_params.rbs +32 -0
  129. data/sig/dataleon/models/company_update_params.rbs +209 -0
  130. data/sig/dataleon/models/individual.rbs +717 -0
  131. data/sig/dataleon/models/individual_create_params.rbs +172 -0
  132. data/sig/dataleon/models/individual_delete_params.rbs +15 -0
  133. data/sig/dataleon/models/individual_list_params.rbs +120 -0
  134. data/sig/dataleon/models/individual_list_response.rbs +7 -0
  135. data/sig/dataleon/models/individual_retrieve_params.rbs +32 -0
  136. data/sig/dataleon/models/individual_update_params.rbs +172 -0
  137. data/sig/dataleon/models/individuals/document_list_params.rbs +17 -0
  138. data/sig/dataleon/models/individuals/document_response.rbs +101 -0
  139. data/sig/dataleon/models/individuals/document_upload_params.rbs +119 -0
  140. data/sig/dataleon/models/individuals/generic_document.rbs +132 -0
  141. data/sig/dataleon/models/individuals/kbis.rbs +303 -0
  142. data/sig/dataleon/models.rbs +31 -0
  143. data/sig/dataleon/request_options.rbs +34 -0
  144. data/sig/dataleon/resources/companies/documents.rbs +22 -0
  145. data/sig/dataleon/resources/companies.rbs +50 -0
  146. data/sig/dataleon/resources/individuals/documents.rbs +22 -0
  147. data/sig/dataleon/resources/individuals.rbs +50 -0
  148. data/sig/dataleon/version.rbs +3 -0
  149. metadata +206 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 0dc362ad20f2e832ce2aa5dd12584e2baf33c8d7b1f00773cdea8f77e7f96f0d
4
+ data.tar.gz: 21f74a506b22d6cd8c2942e536b5e67a6bb4daf4593cad03f30fba2dc17e614e
5
+ SHA512:
6
+ metadata.gz: e10b2e99ad80466c9a13871932a06eda0eb0fdd360b8348c2f5436530c88fc8d795983e527421b943640044a0270d4dcc7017640d1698861219442c7424636a7
7
+ data.tar.gz: b56fff93e9e293da97e8ccc3edf9f7716b4ed50e6671f7d5509591de43011469060b77f83c445b8fe179d052cdc63df20df98916a3a89ce67cbde9b97a276858
data/.ignore ADDED
@@ -0,0 +1,2 @@
1
+ rbi/*
2
+ sig/*
data/CHANGELOG.md ADDED
@@ -0,0 +1,50 @@
1
+ # Changelog
2
+
3
+ ## 0.1.0-alpha.1 (2025-08-27)
4
+
5
+ Full Changelog: [v0.0.1-alpha.1...v0.1.0-alpha.1](https://github.com/dataleonlabs/dataleon-ruby/compare/v0.0.1-alpha.1...v0.1.0-alpha.1)
6
+
7
+ ### Features
8
+
9
+ * **api:** api update ([1909edc](https://github.com/dataleonlabs/dataleon-ruby/commit/1909edce91c6e37fecf0310e2a81672589bcd2dd))
10
+ * **api:** api update ([3ba0d52](https://github.com/dataleonlabs/dataleon-ruby/commit/3ba0d52cd5938dbd6b5193274e343602a3c06c50))
11
+ * **api:** api update ([fb6c613](https://github.com/dataleonlabs/dataleon-ruby/commit/fb6c61357e5fb4f8733a30f88611ed304b2e62f2))
12
+ * **api:** api update ([1aa4cd8](https://github.com/dataleonlabs/dataleon-ruby/commit/1aa4cd81d6e010d4604f7d65af3acff2724f6a78))
13
+ * **api:** api update ([0eacf41](https://github.com/dataleonlabs/dataleon-ruby/commit/0eacf412b108aef5b3c41472a3000daab150aab7))
14
+ * **api:** api update ([8944366](https://github.com/dataleonlabs/dataleon-ruby/commit/8944366fca978b8a616bb2fb187ef486890f513f))
15
+ * **api:** api update ([4725f22](https://github.com/dataleonlabs/dataleon-ruby/commit/4725f2275092fb357b370758d5476f9256b8645f))
16
+ * **api:** manual updates ([91ddf7e](https://github.com/dataleonlabs/dataleon-ruby/commit/91ddf7e0118b9c83d25f94c9352eb6c8dfbd3f2c))
17
+
18
+
19
+ ### Bug Fixes
20
+
21
+ * bump sorbet version and fix new type errors from the breaking change ([aea5af1](https://github.com/dataleonlabs/dataleon-ruby/commit/aea5af14130f20f6bc007a1a1acb9e24a27064a9))
22
+
23
+
24
+ ### Chores
25
+
26
+ * add json schema comment for rubocop.yml ([0649888](https://github.com/dataleonlabs/dataleon-ruby/commit/0649888bfbfa22db769a5334c4807633eea1cee3))
27
+ * collect metadata from type DSL ([55a6e7b](https://github.com/dataleonlabs/dataleon-ruby/commit/55a6e7b6d0b88f8099dbad479f0b40f90f9382a4))
28
+ * **internal:** codegen related update ([2cebfb3](https://github.com/dataleonlabs/dataleon-ruby/commit/2cebfb3b79566f5be976dd041c68a49cfbc9e24f))
29
+ * **internal:** update comment in script ([6f351c5](https://github.com/dataleonlabs/dataleon-ruby/commit/6f351c59c5ee7055b8f7151e032309c20d5e6b61))
30
+ * update @stainless-api/prism-cli to v5.15.0 ([de93c62](https://github.com/dataleonlabs/dataleon-ruby/commit/de93c6281e8ebe1ead9a1705017e11c7b46a4358))
31
+
32
+ ## 0.0.1-alpha.1 (2025-08-05)
33
+
34
+ Full Changelog: [v0.0.1-alpha.0...v0.0.1-alpha.1](https://github.com/dataleonlabs/dataleon-ruby/compare/v0.0.1-alpha.0...v0.0.1-alpha.1)
35
+
36
+ ### Features
37
+
38
+ * **api:** api update ([4fbd229](https://github.com/dataleonlabs/dataleon-ruby/commit/4fbd229218ff4ac84ef6b2a106d7418dcaad70f1))
39
+ * **api:** api update ([ebb92ab](https://github.com/dataleonlabs/dataleon-ruby/commit/ebb92ab84e34679223ac735fdac5282da39ba5a0))
40
+ * **api:** api update ([d20db7e](https://github.com/dataleonlabs/dataleon-ruby/commit/d20db7e939a6163e88ab056c04f1a38a65e11cff))
41
+ * **api:** api update ([2c40287](https://github.com/dataleonlabs/dataleon-ruby/commit/2c40287e148b21848d78834ddde5b6a2648f558f))
42
+ * **api:** manual updates ([d2586d4](https://github.com/dataleonlabs/dataleon-ruby/commit/d2586d4691891b0ad83c7ffd2d59a7512a971174))
43
+ * **api:** manual updates ([2f2cd40](https://github.com/dataleonlabs/dataleon-ruby/commit/2f2cd40bf75dc2194fa65c03d3d179b1f3a97998))
44
+ * **api:** manual updates ([75e26d7](https://github.com/dataleonlabs/dataleon-ruby/commit/75e26d72a0abd7b646bb06a052e9077edca2e77d))
45
+
46
+
47
+ ### Chores
48
+
49
+ * configure new SDK language ([3505532](https://github.com/dataleonlabs/dataleon-ruby/commit/3505532f7be7c6b13b8c5f6dfbaacde8c0f30c46))
50
+ * update SDK settings ([240f966](https://github.com/dataleonlabs/dataleon-ruby/commit/240f966205413ca59902b238e23451f89fbb6ead))
data/README.md ADDED
@@ -0,0 +1,257 @@
1
+ # Dataleon Ruby API library
2
+
3
+ The Dataleon Ruby library provides convenient access to the Dataleon 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/dataleonlabs/dataleon-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/dataleon).
10
+
11
+ The REST API documentation can be found on [docs.dataleon.ai](https://docs.dataleon.ai).
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 "dataleon", "~> 0.1.0.pre.alpha.1"
21
+ ```
22
+
23
+ <!-- x-release-please-end -->
24
+
25
+ ## Usage
26
+
27
+ ```ruby
28
+ require "bundler/setup"
29
+ require "dataleon"
30
+
31
+ dataleon = Dataleon::Client.new(
32
+ api_key: ENV["DATALEON_API_KEY"] # This is the default and can be omitted
33
+ )
34
+
35
+ individual = dataleon.individuals.create(workspace_id: "wk_123")
36
+
37
+ puts(individual.id)
38
+ ```
39
+
40
+ ### File uploads
41
+
42
+ Request parameters that correspond to file uploads can be passed as raw contents, a [`Pathname`](https://rubyapi.org/3.2/o/pathname) instance, [`StringIO`](https://rubyapi.org/3.2/o/stringio), or more.
43
+
44
+ ```ruby
45
+ require "pathname"
46
+
47
+ # Use `Pathname` to send the filename and/or avoid paging a large file into memory:
48
+ generic_document = dataleon.individuals.documents.upload(file: Pathname("/path/to/file"))
49
+
50
+ # Alternatively, pass file contents or a `StringIO` directly:
51
+ generic_document = dataleon.individuals.documents.upload(file: File.read("/path/to/file"))
52
+
53
+ # Or, to control the filename and/or content type:
54
+ file = Dataleon::FilePart.new(File.read("/path/to/file"), filename: "/path/to/file", content_type: "…")
55
+ generic_document = dataleon.individuals.documents.upload(file: file)
56
+
57
+ puts(generic_document.id)
58
+ ```
59
+
60
+ Note that you can also pass a raw `IO` descriptor, but this disables retries, as the library can't be sure if the descriptor is a file or pipe (which cannot be rewound).
61
+
62
+ ### Handling errors
63
+
64
+ 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 `Dataleon::Errors::APIError` will be thrown:
65
+
66
+ ```ruby
67
+ begin
68
+ individual = dataleon.individuals.create(workspace_id: "wk_123")
69
+ rescue Dataleon::Errors::APIConnectionError => e
70
+ puts("The server could not be reached")
71
+ puts(e.cause) # an underlying Exception, likely raised within `net/http`
72
+ rescue Dataleon::Errors::RateLimitError => e
73
+ puts("A 429 status code was received; we should back off a bit.")
74
+ rescue Dataleon::Errors::APIStatusError => e
75
+ puts("Another non-200-range status code was received")
76
+ puts(e.status)
77
+ end
78
+ ```
79
+
80
+ Error codes are as follows:
81
+
82
+ | Cause | Error Type |
83
+ | ---------------- | -------------------------- |
84
+ | HTTP 400 | `BadRequestError` |
85
+ | HTTP 401 | `AuthenticationError` |
86
+ | HTTP 403 | `PermissionDeniedError` |
87
+ | HTTP 404 | `NotFoundError` |
88
+ | HTTP 409 | `ConflictError` |
89
+ | HTTP 422 | `UnprocessableEntityError` |
90
+ | HTTP 429 | `RateLimitError` |
91
+ | HTTP >= 500 | `InternalServerError` |
92
+ | Other HTTP error | `APIStatusError` |
93
+ | Timeout | `APITimeoutError` |
94
+ | Network error | `APIConnectionError` |
95
+
96
+ ### Retries
97
+
98
+ Certain errors will be automatically retried 2 times by default, with a short exponential backoff.
99
+
100
+ 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.
101
+
102
+ You can use the `max_retries` option to configure or disable this:
103
+
104
+ ```ruby
105
+ # Configure the default for all requests:
106
+ dataleon = Dataleon::Client.new(
107
+ max_retries: 0 # default is 2
108
+ )
109
+
110
+ # Or, configure per-request:
111
+ dataleon.individuals.create(workspace_id: "wk_123", request_options: {max_retries: 5})
112
+ ```
113
+
114
+ ### Timeouts
115
+
116
+ By default, requests will time out after 60 seconds. You can use the timeout option to configure or disable this:
117
+
118
+ ```ruby
119
+ # Configure the default for all requests:
120
+ dataleon = Dataleon::Client.new(
121
+ timeout: nil # default is 60
122
+ )
123
+
124
+ # Or, configure per-request:
125
+ dataleon.individuals.create(workspace_id: "wk_123", request_options: {timeout: 5})
126
+ ```
127
+
128
+ On timeout, `Dataleon::Errors::APITimeoutError` is raised.
129
+
130
+ Note that requests that time out are retried by default.
131
+
132
+ ## Advanced concepts
133
+
134
+ ### BaseModel
135
+
136
+ All parameter and response objects inherit from `Dataleon::Internal::Type::BaseModel`, which provides several conveniences, including:
137
+
138
+ 1. All fields, including unknown ones, are accessible with `obj[:prop]` syntax, and can be destructured with `obj => {prop: prop}` or pattern-matching syntax.
139
+
140
+ 2. Structural equivalence for equality; if two API calls return the same values, comparing the responses with == will return true.
141
+
142
+ 3. Both instances and the classes themselves can be pretty-printed.
143
+
144
+ 4. Helpers such as `#to_h`, `#deep_to_h`, `#to_json`, and `#to_yaml`.
145
+
146
+ ### Making custom or undocumented requests
147
+
148
+ #### Undocumented properties
149
+
150
+ You can send undocumented parameters to any endpoint, and read undocumented response properties, like so:
151
+
152
+ Note: the `extra_` parameters of the same name overrides the documented parameters.
153
+
154
+ ```ruby
155
+ individual =
156
+ dataleon.individuals.create(
157
+ workspace_id: "wk_123",
158
+ request_options: {
159
+ extra_query: {my_query_parameter: value},
160
+ extra_body: {my_body_parameter: value},
161
+ extra_headers: {"my-header": value}
162
+ }
163
+ )
164
+
165
+ puts(individual[:my_undocumented_property])
166
+ ```
167
+
168
+ #### Undocumented request params
169
+
170
+ 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.
171
+
172
+ #### Undocumented endpoints
173
+
174
+ 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:
175
+
176
+ ```ruby
177
+ response = client.request(
178
+ method: :post,
179
+ path: '/undocumented/endpoint',
180
+ query: {"dog": "woof"},
181
+ headers: {"useful-header": "interesting-value"},
182
+ body: {"hello": "world"}
183
+ )
184
+ ```
185
+
186
+ ### Concurrency & connection pooling
187
+
188
+ The `Dataleon::Client` instances are threadsafe, but are only are fork-safe when there are no in-flight HTTP requests.
189
+
190
+ Each instance of `Dataleon::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.
191
+
192
+ 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.
193
+
194
+ Unless otherwise specified, other classes in the SDK do not have locks protecting their underlying data structure.
195
+
196
+ ## Sorbet
197
+
198
+ This library provides comprehensive [RBI](https://sorbet.org/docs/rbi) definitions, and has no dependency on sorbet-runtime.
199
+
200
+ You can provide typesafe request parameters like so:
201
+
202
+ ```ruby
203
+ dataleon.individuals.create(workspace_id: "wk_123")
204
+ ```
205
+
206
+ Or, equivalently:
207
+
208
+ ```ruby
209
+ # Hashes work, but are not typesafe:
210
+ dataleon.individuals.create(workspace_id: "wk_123")
211
+
212
+ # You can also splat a full Params class:
213
+ params = Dataleon::IndividualCreateParams.new(workspace_id: "wk_123")
214
+ dataleon.individuals.create(**params)
215
+ ```
216
+
217
+ ### Enums
218
+
219
+ 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:
220
+
221
+ ```ruby
222
+ # :VOID
223
+ puts(Dataleon::IndividualListParams::State::VOID)
224
+
225
+ # Revealed type: `T.all(Dataleon::IndividualListParams::State, Symbol)`
226
+ T.reveal_type(Dataleon::IndividualListParams::State::VOID)
227
+ ```
228
+
229
+ Enum parameters have a "relaxed" type, so you can either pass in enum constants or their literal value:
230
+
231
+ ```ruby
232
+ # Using the enum constants preserves the tagged type information:
233
+ dataleon.individuals.list(
234
+ state: Dataleon::IndividualListParams::State::VOID,
235
+ # …
236
+ )
237
+
238
+ # Literal values are also permissible:
239
+ dataleon.individuals.list(
240
+ state: :VOID,
241
+ # …
242
+ )
243
+ ```
244
+
245
+ ## Versioning
246
+
247
+ 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.
248
+
249
+ This package considers improvements to the (non-runtime) `*.rbi` and `*.rbs` type definitions to be non-breaking changes.
250
+
251
+ ## Requirements
252
+
253
+ Ruby 3.2.0 or higher.
254
+
255
+ ## Contributing
256
+
257
+ See [the contributing documentation](https://github.com/dataleonlabs/dataleon-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 Dataleon, please follow the respective company's security reporting guidelines.
20
+
21
+ ### Dataleon Terms and Policies
22
+
23
+ Please contact support@dataleon.ai 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,80 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Dataleon
4
+ class Client < Dataleon::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
+ # API key needed to authorize requests. You must provide a valid API key in the
19
+ # `Api-Key` header. Get your API key from the Dataleon dashboard.
20
+ # @return [String]
21
+ attr_reader :api_key
22
+
23
+ # @return [Dataleon::Resources::Individuals]
24
+ attr_reader :individuals
25
+
26
+ # @return [Dataleon::Resources::Companies]
27
+ attr_reader :companies
28
+
29
+ # @api private
30
+ #
31
+ # @return [Hash{String=>String}]
32
+ private def auth_headers
33
+ {"api-key" => @api_key}
34
+ end
35
+
36
+ # Creates and returns a new client for interacting with the API.
37
+ #
38
+ # @param api_key [String, nil] API key needed to authorize requests. You must provide a valid API key in the
39
+ # `Api-Key` header. Get your API key from the Dataleon dashboard. Defaults to
40
+ # `ENV["DATALEON_API_KEY"]`
41
+ #
42
+ # @param base_url [String, nil] Override the default base URL for the API, e.g.,
43
+ # `"https://api.example.com/v2/"`. Defaults to `ENV["DATALEON_BASE_URL"]`
44
+ #
45
+ # @param max_retries [Integer] Max number of retries to attempt after a failed retryable request.
46
+ #
47
+ # @param timeout [Float]
48
+ #
49
+ # @param initial_retry_delay [Float]
50
+ #
51
+ # @param max_retry_delay [Float]
52
+ def initialize(
53
+ api_key: ENV["DATALEON_API_KEY"],
54
+ base_url: ENV["DATALEON_BASE_URL"],
55
+ max_retries: self.class::DEFAULT_MAX_RETRIES,
56
+ timeout: self.class::DEFAULT_TIMEOUT_IN_SECONDS,
57
+ initial_retry_delay: self.class::DEFAULT_INITIAL_RETRY_DELAY,
58
+ max_retry_delay: self.class::DEFAULT_MAX_RETRY_DELAY
59
+ )
60
+ base_url ||= "https://inference.eu-west-1.dataleon.ai"
61
+
62
+ if api_key.nil?
63
+ raise ArgumentError.new("api_key is required, and can be set via environ: \"DATALEON_API_KEY\"")
64
+ end
65
+
66
+ @api_key = api_key.to_s
67
+
68
+ super(
69
+ base_url: base_url,
70
+ timeout: timeout,
71
+ max_retries: max_retries,
72
+ initial_retry_delay: initial_retry_delay,
73
+ max_retry_delay: max_retry_delay
74
+ )
75
+
76
+ @individuals = Dataleon::Resources::Individuals.new(client: self)
77
+ @companies = Dataleon::Resources::Companies.new(client: self)
78
+ end
79
+ end
80
+ end
@@ -0,0 +1,214 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Dataleon
4
+ module Errors
5
+ class Error < StandardError
6
+ # @!attribute cause
7
+ #
8
+ # @return [StandardError, nil]
9
+ end
10
+
11
+ class ConversionError < Dataleon::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 < Dataleon::Errors::Error
37
+ # @return [URI::Generic]
38
+ attr_accessor :url
39
+
40
+ # @return [Integer, nil]
41
+ attr_accessor :status
42
+
43
+ # @return [Object, nil]
44
+ attr_accessor :body
45
+
46
+ # @api private
47
+ #
48
+ # @param url [URI::Generic]
49
+ # @param status [Integer, nil]
50
+ # @param body [Object, nil]
51
+ # @param request [nil]
52
+ # @param response [nil]
53
+ # @param message [String, nil]
54
+ def initialize(url:, status: nil, body: nil, request: nil, response: nil, message: nil)
55
+ @url = url
56
+ @status = status
57
+ @body = body
58
+ @request = request
59
+ @response = response
60
+ super(message)
61
+ end
62
+ end
63
+
64
+ class APIConnectionError < Dataleon::Errors::APIError
65
+ # @!attribute status
66
+ #
67
+ # @return [nil]
68
+
69
+ # @!attribute body
70
+ #
71
+ # @return [nil]
72
+
73
+ # @api private
74
+ #
75
+ # @param url [URI::Generic]
76
+ # @param status [nil]
77
+ # @param body [nil]
78
+ # @param request [nil]
79
+ # @param response [nil]
80
+ # @param message [String, nil]
81
+ def initialize(
82
+ url:,
83
+ status: nil,
84
+ body: nil,
85
+ request: nil,
86
+ response: nil,
87
+ message: "Connection error."
88
+ )
89
+ super
90
+ end
91
+ end
92
+
93
+ class APITimeoutError < Dataleon::Errors::APIConnectionError
94
+ # @api private
95
+ #
96
+ # @param url [URI::Generic]
97
+ # @param status [nil]
98
+ # @param body [nil]
99
+ # @param request [nil]
100
+ # @param response [nil]
101
+ # @param message [String, nil]
102
+ def initialize(
103
+ url:,
104
+ status: nil,
105
+ body: nil,
106
+ request: nil,
107
+ response: nil,
108
+ message: "Request timed out."
109
+ )
110
+ super
111
+ end
112
+ end
113
+
114
+ class APIStatusError < Dataleon::Errors::APIError
115
+ # @api private
116
+ #
117
+ # @param url [URI::Generic]
118
+ # @param status [Integer]
119
+ # @param body [Object, nil]
120
+ # @param request [nil]
121
+ # @param response [nil]
122
+ # @param message [String, nil]
123
+ #
124
+ # @return [self]
125
+ def self.for(url:, status:, body:, request:, response:, message: nil)
126
+ kwargs = {
127
+ url: url,
128
+ status: status,
129
+ body: body,
130
+ request: request,
131
+ response: response,
132
+ message: message
133
+ }
134
+
135
+ case status
136
+ in 400
137
+ Dataleon::Errors::BadRequestError.new(**kwargs)
138
+ in 401
139
+ Dataleon::Errors::AuthenticationError.new(**kwargs)
140
+ in 403
141
+ Dataleon::Errors::PermissionDeniedError.new(**kwargs)
142
+ in 404
143
+ Dataleon::Errors::NotFoundError.new(**kwargs)
144
+ in 409
145
+ Dataleon::Errors::ConflictError.new(**kwargs)
146
+ in 422
147
+ Dataleon::Errors::UnprocessableEntityError.new(**kwargs)
148
+ in 429
149
+ Dataleon::Errors::RateLimitError.new(**kwargs)
150
+ in (500..)
151
+ Dataleon::Errors::InternalServerError.new(**kwargs)
152
+ else
153
+ Dataleon::Errors::APIStatusError.new(**kwargs)
154
+ end
155
+ end
156
+
157
+ # @!parse
158
+ # # @return [Integer]
159
+ # attr_accessor :status
160
+
161
+ # @api private
162
+ #
163
+ # @param url [URI::Generic]
164
+ # @param status [Integer]
165
+ # @param body [Object, nil]
166
+ # @param request [nil]
167
+ # @param response [nil]
168
+ # @param message [String, nil]
169
+ def initialize(url:, status:, body:, request:, response:, message: nil)
170
+ message ||= {url: url.to_s, status: status, body: body}
171
+ super(
172
+ url: url,
173
+ status: status,
174
+ body: body,
175
+ request: request,
176
+ response: response,
177
+ message: message&.to_s
178
+ )
179
+ end
180
+ end
181
+
182
+ class BadRequestError < Dataleon::Errors::APIStatusError
183
+ HTTP_STATUS = 400
184
+ end
185
+
186
+ class AuthenticationError < Dataleon::Errors::APIStatusError
187
+ HTTP_STATUS = 401
188
+ end
189
+
190
+ class PermissionDeniedError < Dataleon::Errors::APIStatusError
191
+ HTTP_STATUS = 403
192
+ end
193
+
194
+ class NotFoundError < Dataleon::Errors::APIStatusError
195
+ HTTP_STATUS = 404
196
+ end
197
+
198
+ class ConflictError < Dataleon::Errors::APIStatusError
199
+ HTTP_STATUS = 409
200
+ end
201
+
202
+ class UnprocessableEntityError < Dataleon::Errors::APIStatusError
203
+ HTTP_STATUS = 422
204
+ end
205
+
206
+ class RateLimitError < Dataleon::Errors::APIStatusError
207
+ HTTP_STATUS = 429
208
+ end
209
+
210
+ class InternalServerError < Dataleon::Errors::APIStatusError
211
+ HTTP_STATUS = (500..)
212
+ end
213
+ end
214
+ end
@@ -0,0 +1,55 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Dataleon
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 [String, nil]
42
+ # @param content_type [String, nil]
43
+ def initialize(content, filename: nil, content_type: nil)
44
+ @content = content
45
+ @filename =
46
+ case content
47
+ in Pathname
48
+ filename.nil? ? content.basename.to_path : ::File.basename(filename)
49
+ else
50
+ filename.nil? ? nil : ::File.basename(filename)
51
+ end
52
+ @content_type = content_type
53
+ end
54
+ end
55
+ end