brand.dev 0.0.1.pre.alpha.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.
- checksums.yaml +7 -0
- data/README.md +229 -0
- data/SECURITY.md +23 -0
- data/lib/brand_dev/client.rb +74 -0
- data/lib/brand_dev/errors.rb +192 -0
- data/lib/brand_dev/file_part.rb +55 -0
- data/lib/brand_dev/internal/transport/base_client.rb +555 -0
- data/lib/brand_dev/internal/transport/pooled_net_requester.rb +209 -0
- data/lib/brand_dev/internal/type/array_of.rb +162 -0
- data/lib/brand_dev/internal/type/base_model.rb +484 -0
- data/lib/brand_dev/internal/type/base_page.rb +55 -0
- data/lib/brand_dev/internal/type/boolean.rb +71 -0
- data/lib/brand_dev/internal/type/converter.rb +292 -0
- data/lib/brand_dev/internal/type/enum.rb +120 -0
- data/lib/brand_dev/internal/type/file_input.rb +103 -0
- data/lib/brand_dev/internal/type/hash_of.rb +182 -0
- data/lib/brand_dev/internal/type/request_parameters.rb +42 -0
- data/lib/brand_dev/internal/type/union.rb +227 -0
- data/lib/brand_dev/internal/type/unknown.rb +75 -0
- data/lib/brand_dev/internal/util.rb +915 -0
- data/lib/brand_dev/internal.rb +20 -0
- data/lib/brand_dev/models/brand_identify_from_transaction_params.rb +22 -0
- data/lib/brand_dev/models/brand_identify_from_transaction_response.rb +435 -0
- data/lib/brand_dev/models/brand_retrieve_by_ticker_params.rb +22 -0
- data/lib/brand_dev/models/brand_retrieve_by_ticker_response.rb +432 -0
- data/lib/brand_dev/models/brand_retrieve_naics_params.rb +27 -0
- data/lib/brand_dev/models/brand_retrieve_naics_response.rb +61 -0
- data/lib/brand_dev/models/brand_retrieve_params.rb +91 -0
- data/lib/brand_dev/models/brand_retrieve_response.rb +432 -0
- data/lib/brand_dev/models/brand_search_params.rb +22 -0
- data/lib/brand_dev/models/brand_search_response.rb +35 -0
- data/lib/brand_dev/models.rb +51 -0
- data/lib/brand_dev/request_options.rb +77 -0
- data/lib/brand_dev/resources/brand.rb +130 -0
- data/lib/brand_dev/version.rb +5 -0
- data/lib/brand_dev.rb +64 -0
- data/manifest.yaml +15 -0
- data/rbi/brand_dev/client.rbi +49 -0
- data/rbi/brand_dev/errors.rbi +162 -0
- data/rbi/brand_dev/file_part.rbi +37 -0
- data/rbi/brand_dev/internal/transport/base_client.rbi +293 -0
- data/rbi/brand_dev/internal/transport/pooled_net_requester.rbi +79 -0
- data/rbi/brand_dev/internal/type/array_of.rbi +104 -0
- data/rbi/brand_dev/internal/type/base_model.rbi +302 -0
- data/rbi/brand_dev/internal/type/base_page.rbi +42 -0
- data/rbi/brand_dev/internal/type/boolean.rbi +56 -0
- data/rbi/brand_dev/internal/type/converter.rbi +162 -0
- data/rbi/brand_dev/internal/type/enum.rbi +82 -0
- data/rbi/brand_dev/internal/type/file_input.rbi +59 -0
- data/rbi/brand_dev/internal/type/hash_of.rbi +104 -0
- data/rbi/brand_dev/internal/type/request_parameters.rbi +29 -0
- data/rbi/brand_dev/internal/type/union.rbi +116 -0
- data/rbi/brand_dev/internal/type/unknown.rbi +56 -0
- data/rbi/brand_dev/internal/util.rbi +485 -0
- data/rbi/brand_dev/internal.rbi +16 -0
- data/rbi/brand_dev/models/brand_identify_from_transaction_params.rbi +46 -0
- data/rbi/brand_dev/models/brand_identify_from_transaction_response.rbi +981 -0
- data/rbi/brand_dev/models/brand_retrieve_by_ticker_params.rbi +43 -0
- data/rbi/brand_dev/models/brand_retrieve_by_ticker_response.rbi +976 -0
- data/rbi/brand_dev/models/brand_retrieve_naics_params.rbi +44 -0
- data/rbi/brand_dev/models/brand_retrieve_naics_response.rbi +127 -0
- data/rbi/brand_dev/models/brand_retrieve_params.rbi +344 -0
- data/rbi/brand_dev/models/brand_retrieve_response.rbi +949 -0
- data/rbi/brand_dev/models/brand_search_params.rbi +40 -0
- data/rbi/brand_dev/models/brand_search_response.rbi +63 -0
- data/rbi/brand_dev/models.rbi +14 -0
- data/rbi/brand_dev/request_options.rbi +59 -0
- data/rbi/brand_dev/resources/brand.rbi +89 -0
- data/rbi/brand_dev/version.rbi +5 -0
- data/sig/brand_dev/client.rbs +26 -0
- data/sig/brand_dev/errors.rbs +101 -0
- data/sig/brand_dev/file_part.rbs +21 -0
- data/sig/brand_dev/internal/transport/base_client.rbs +131 -0
- data/sig/brand_dev/internal/transport/pooled_net_requester.rbs +45 -0
- data/sig/brand_dev/internal/type/array_of.rbs +48 -0
- data/sig/brand_dev/internal/type/base_model.rbs +102 -0
- data/sig/brand_dev/internal/type/base_page.rbs +24 -0
- data/sig/brand_dev/internal/type/boolean.rbs +26 -0
- data/sig/brand_dev/internal/type/converter.rbs +56 -0
- data/sig/brand_dev/internal/type/enum.rbs +32 -0
- data/sig/brand_dev/internal/type/file_input.rbs +25 -0
- data/sig/brand_dev/internal/type/hash_of.rbs +48 -0
- data/sig/brand_dev/internal/type/request_parameters.rbs +17 -0
- data/sig/brand_dev/internal/type/union.rbs +52 -0
- data/sig/brand_dev/internal/type/unknown.rbs +26 -0
- data/sig/brand_dev/internal/util.rbs +185 -0
- data/sig/brand_dev/internal.rbs +9 -0
- data/sig/brand_dev/models/brand_identify_from_transaction_params.rbs +24 -0
- data/sig/brand_dev/models/brand_identify_from_transaction_response.rbs +418 -0
- data/sig/brand_dev/models/brand_retrieve_by_ticker_params.rbs +23 -0
- data/sig/brand_dev/models/brand_retrieve_by_ticker_response.rbs +418 -0
- data/sig/brand_dev/models/brand_retrieve_naics_params.rbs +23 -0
- data/sig/brand_dev/models/brand_retrieve_naics_response.rbs +61 -0
- data/sig/brand_dev/models/brand_retrieve_params.rbs +148 -0
- data/sig/brand_dev/models/brand_retrieve_response.rbs +418 -0
- data/sig/brand_dev/models/brand_search_params.rbs +23 -0
- data/sig/brand_dev/models/brand_search_response.rbs +29 -0
- data/sig/brand_dev/models.rbs +11 -0
- data/sig/brand_dev/request_options.rbs +34 -0
- data/sig/brand_dev/resources/brand.rbs +33 -0
- data/sig/brand_dev/version.rbs +3 -0
- metadata +160 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 308ab90d3e6f03ff0fb725a2aece6d8c14bb16ff54ed00fab2fee5ad217a72fe
|
4
|
+
data.tar.gz: 92c6e324a4885ac710359c9556dad60e904d8630a25510c79c122de0d436f420
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 9d454dbf45c518f184acb12ec4f9f418add64888c748939005d7a88df98affd9f4935cc5346088aca69041fd18096d6d92d8f4c69b8dbcc537278050c4358e19
|
7
|
+
data.tar.gz: 9aa4d6101d29030416e70f1ded7cd38550c582baf2822b5face0f3706718c7989ac27d964f7bd9f08ab55fffdb3e4c5ef7f369fd7ecfea5e409fcc67a991ef49
|
data/README.md
ADDED
@@ -0,0 +1,229 @@
|
|
1
|
+
# Brand Dev Ruby API library
|
2
|
+
|
3
|
+
The Brand Dev Ruby library provides convenient access to the Brand Dev 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/stainless-sdks/brand.dev-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/brand.dev).
|
10
|
+
|
11
|
+
## Installation
|
12
|
+
|
13
|
+
To use this gem, install via Bundler by adding the following to your application's `Gemfile`:
|
14
|
+
|
15
|
+
```ruby
|
16
|
+
gem "brand.dev", "~> 0.0.1.pre.alpha.0"
|
17
|
+
```
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
```ruby
|
22
|
+
require "bundler/setup"
|
23
|
+
require "brand_dev"
|
24
|
+
|
25
|
+
brand_dev = BrandDev::Client.new(
|
26
|
+
api_key: ENV["BRAND_DEV_API_KEY"] # This is the default and can be omitted
|
27
|
+
)
|
28
|
+
|
29
|
+
brand = brand_dev.brand.retrieve(domain: "REPLACE_ME")
|
30
|
+
|
31
|
+
puts(brand.brand)
|
32
|
+
```
|
33
|
+
|
34
|
+
### Handling errors
|
35
|
+
|
36
|
+
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 `BrandDev::Errors::APIError` will be thrown:
|
37
|
+
|
38
|
+
```ruby
|
39
|
+
begin
|
40
|
+
brand = brand_dev.brand.retrieve(domain: "REPLACE_ME")
|
41
|
+
rescue BrandDev::Errors::APIConnectionError => e
|
42
|
+
puts("The server could not be reached")
|
43
|
+
puts(e.cause) # an underlying Exception, likely raised within `net/http`
|
44
|
+
rescue BrandDev::Errors::RateLimitError => e
|
45
|
+
puts("A 429 status code was received; we should back off a bit.")
|
46
|
+
rescue BrandDev::Errors::APIStatusError => e
|
47
|
+
puts("Another non-200-range status code was received")
|
48
|
+
puts(e.status)
|
49
|
+
end
|
50
|
+
```
|
51
|
+
|
52
|
+
Error codes are as follows:
|
53
|
+
|
54
|
+
| Cause | Error Type |
|
55
|
+
| ---------------- | -------------------------- |
|
56
|
+
| HTTP 400 | `BadRequestError` |
|
57
|
+
| HTTP 401 | `AuthenticationError` |
|
58
|
+
| HTTP 403 | `PermissionDeniedError` |
|
59
|
+
| HTTP 404 | `NotFoundError` |
|
60
|
+
| HTTP 409 | `ConflictError` |
|
61
|
+
| HTTP 422 | `UnprocessableEntityError` |
|
62
|
+
| HTTP 429 | `RateLimitError` |
|
63
|
+
| HTTP >= 500 | `InternalServerError` |
|
64
|
+
| Other HTTP error | `APIStatusError` |
|
65
|
+
| Timeout | `APITimeoutError` |
|
66
|
+
| Network error | `APIConnectionError` |
|
67
|
+
|
68
|
+
### Retries
|
69
|
+
|
70
|
+
Certain errors will be automatically retried 2 times by default, with a short exponential backoff.
|
71
|
+
|
72
|
+
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.
|
73
|
+
|
74
|
+
You can use the `max_retries` option to configure or disable this:
|
75
|
+
|
76
|
+
```ruby
|
77
|
+
# Configure the default for all requests:
|
78
|
+
brand_dev = BrandDev::Client.new(
|
79
|
+
max_retries: 0 # default is 2
|
80
|
+
)
|
81
|
+
|
82
|
+
# Or, configure per-request:
|
83
|
+
brand_dev.brand.retrieve(domain: "REPLACE_ME", request_options: {max_retries: 5})
|
84
|
+
```
|
85
|
+
|
86
|
+
### Timeouts
|
87
|
+
|
88
|
+
By default, requests will time out after 60 seconds. You can use the timeout option to configure or disable this:
|
89
|
+
|
90
|
+
```ruby
|
91
|
+
# Configure the default for all requests:
|
92
|
+
brand_dev = BrandDev::Client.new(
|
93
|
+
timeout: nil # default is 60
|
94
|
+
)
|
95
|
+
|
96
|
+
# Or, configure per-request:
|
97
|
+
brand_dev.brand.retrieve(domain: "REPLACE_ME", request_options: {timeout: 5})
|
98
|
+
```
|
99
|
+
|
100
|
+
On timeout, `BrandDev::Errors::APITimeoutError` is raised.
|
101
|
+
|
102
|
+
Note that requests that time out are retried by default.
|
103
|
+
|
104
|
+
## Advanced concepts
|
105
|
+
|
106
|
+
### BaseModel
|
107
|
+
|
108
|
+
All parameter and response objects inherit from `BrandDev::Internal::Type::BaseModel`, which provides several conveniences, including:
|
109
|
+
|
110
|
+
1. All fields, including unknown ones, are accessible with `obj[:prop]` syntax, and can be destructured with `obj => {prop: prop}` or pattern-matching syntax.
|
111
|
+
|
112
|
+
2. Structural equivalence for equality; if two API calls return the same values, comparing the responses with == will return true.
|
113
|
+
|
114
|
+
3. Both instances and the classes themselves can be pretty-printed.
|
115
|
+
|
116
|
+
4. Helpers such as `#to_h`, `#deep_to_h`, `#to_json`, and `#to_yaml`.
|
117
|
+
|
118
|
+
### Making custom or undocumented requests
|
119
|
+
|
120
|
+
#### Undocumented properties
|
121
|
+
|
122
|
+
You can send undocumented parameters to any endpoint, and read undocumented response properties, like so:
|
123
|
+
|
124
|
+
Note: the `extra_` parameters of the same name overrides the documented parameters.
|
125
|
+
|
126
|
+
```ruby
|
127
|
+
brand =
|
128
|
+
brand_dev.brand.retrieve(
|
129
|
+
domain: "REPLACE_ME",
|
130
|
+
request_options: {
|
131
|
+
extra_query: {my_query_parameter: value},
|
132
|
+
extra_body: {my_body_parameter: value},
|
133
|
+
extra_headers: {"my-header": value}
|
134
|
+
}
|
135
|
+
)
|
136
|
+
|
137
|
+
puts(brand[:my_undocumented_property])
|
138
|
+
```
|
139
|
+
|
140
|
+
#### Undocumented request params
|
141
|
+
|
142
|
+
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.
|
143
|
+
|
144
|
+
#### Undocumented endpoints
|
145
|
+
|
146
|
+
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:
|
147
|
+
|
148
|
+
```ruby
|
149
|
+
response = client.request(
|
150
|
+
method: :post,
|
151
|
+
path: '/undocumented/endpoint',
|
152
|
+
query: {"dog": "woof"},
|
153
|
+
headers: {"useful-header": "interesting-value"},
|
154
|
+
body: {"hello": "world"}
|
155
|
+
)
|
156
|
+
```
|
157
|
+
|
158
|
+
### Concurrency & connection pooling
|
159
|
+
|
160
|
+
The `BrandDev::Client` instances are threadsafe, but are only are fork-safe when there are no in-flight HTTP requests.
|
161
|
+
|
162
|
+
Each instance of `BrandDev::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.
|
163
|
+
|
164
|
+
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.
|
165
|
+
|
166
|
+
Unless otherwise specified, other classes in the SDK do not have locks protecting their underlying data structure.
|
167
|
+
|
168
|
+
## Sorbet
|
169
|
+
|
170
|
+
This library provides comprehensive [RBI](https://sorbet.org/docs/rbi) definitions, and has no dependency on sorbet-runtime.
|
171
|
+
|
172
|
+
You can provide typesafe request parameters like so:
|
173
|
+
|
174
|
+
```ruby
|
175
|
+
brand_dev.brand.retrieve(domain: "REPLACE_ME")
|
176
|
+
```
|
177
|
+
|
178
|
+
Or, equivalently:
|
179
|
+
|
180
|
+
```ruby
|
181
|
+
# Hashes work, but are not typesafe:
|
182
|
+
brand_dev.brand.retrieve(domain: "REPLACE_ME")
|
183
|
+
|
184
|
+
# You can also splat a full Params class:
|
185
|
+
params = BrandDev::BrandRetrieveParams.new(domain: "REPLACE_ME")
|
186
|
+
brand_dev.brand.retrieve(**params)
|
187
|
+
```
|
188
|
+
|
189
|
+
### Enums
|
190
|
+
|
191
|
+
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:
|
192
|
+
|
193
|
+
```ruby
|
194
|
+
# :albanian
|
195
|
+
puts(BrandDev::BrandRetrieveParams::ForceLanguage::ALBANIAN)
|
196
|
+
|
197
|
+
# Revealed type: `T.all(BrandDev::BrandRetrieveParams::ForceLanguage, Symbol)`
|
198
|
+
T.reveal_type(BrandDev::BrandRetrieveParams::ForceLanguage::ALBANIAN)
|
199
|
+
```
|
200
|
+
|
201
|
+
Enum parameters have a "relaxed" type, so you can either pass in enum constants or their literal value:
|
202
|
+
|
203
|
+
```ruby
|
204
|
+
# Using the enum constants preserves the tagged type information:
|
205
|
+
brand_dev.brand.retrieve(
|
206
|
+
force_language: BrandDev::BrandRetrieveParams::ForceLanguage::ALBANIAN,
|
207
|
+
# …
|
208
|
+
)
|
209
|
+
|
210
|
+
# Literal values are also permissible:
|
211
|
+
brand_dev.brand.retrieve(
|
212
|
+
force_language: :albanian,
|
213
|
+
# …
|
214
|
+
)
|
215
|
+
```
|
216
|
+
|
217
|
+
## Versioning
|
218
|
+
|
219
|
+
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.
|
220
|
+
|
221
|
+
This package considers improvements to the (non-runtime) `*.rbi` and `*.rbs` type definitions to be non-breaking changes.
|
222
|
+
|
223
|
+
## Requirements
|
224
|
+
|
225
|
+
Ruby 3.2.0 or higher.
|
226
|
+
|
227
|
+
## Contributing
|
228
|
+
|
229
|
+
See [the contributing documentation](https://github.com/stainless-sdks/brand.dev-ruby/tree/main/CONTRIBUTING.md).
|
data/SECURITY.md
ADDED
@@ -0,0 +1,23 @@
|
|
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 Brand Dev, please follow the respective company's security reporting guidelines.
|
20
|
+
|
21
|
+
---
|
22
|
+
|
23
|
+
Thank you for helping us keep the SDKs and systems they interact with secure.
|
@@ -0,0 +1,74 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module BrandDev
|
4
|
+
class Client < BrandDev::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
|
+
# @return [String]
|
19
|
+
attr_reader :api_key
|
20
|
+
|
21
|
+
# @return [BrandDev::Resources::Brand]
|
22
|
+
attr_reader :brand
|
23
|
+
|
24
|
+
# @api private
|
25
|
+
#
|
26
|
+
# @return [Hash{String=>String}]
|
27
|
+
private def auth_headers
|
28
|
+
return {} if @api_key.nil?
|
29
|
+
|
30
|
+
{"authorization" => "Bearer #{@api_key}"}
|
31
|
+
end
|
32
|
+
|
33
|
+
# Creates and returns a new client for interacting with the API.
|
34
|
+
#
|
35
|
+
# @param api_key [String, nil] Defaults to `ENV["BRAND_DEV_API_KEY"]`
|
36
|
+
#
|
37
|
+
# @param base_url [String, nil] Override the default base URL for the API, e.g.,
|
38
|
+
# `"https://api.example.com/v2/"`. Defaults to `ENV["BRAND_DEV_BASE_URL"]`
|
39
|
+
#
|
40
|
+
# @param max_retries [Integer] Max number of retries to attempt after a failed retryable request.
|
41
|
+
#
|
42
|
+
# @param timeout [Float]
|
43
|
+
#
|
44
|
+
# @param initial_retry_delay [Float]
|
45
|
+
#
|
46
|
+
# @param max_retry_delay [Float]
|
47
|
+
def initialize(
|
48
|
+
api_key: ENV["BRAND_DEV_API_KEY"],
|
49
|
+
base_url: ENV["BRAND_DEV_BASE_URL"],
|
50
|
+
max_retries: self.class::DEFAULT_MAX_RETRIES,
|
51
|
+
timeout: self.class::DEFAULT_TIMEOUT_IN_SECONDS,
|
52
|
+
initial_retry_delay: self.class::DEFAULT_INITIAL_RETRY_DELAY,
|
53
|
+
max_retry_delay: self.class::DEFAULT_MAX_RETRY_DELAY
|
54
|
+
)
|
55
|
+
base_url ||= "https://api.brand.dev/v1"
|
56
|
+
|
57
|
+
if api_key.nil?
|
58
|
+
raise ArgumentError.new("api_key is required, and can be set via environ: \"BRAND_DEV_API_KEY\"")
|
59
|
+
end
|
60
|
+
|
61
|
+
@api_key = api_key.to_s
|
62
|
+
|
63
|
+
super(
|
64
|
+
base_url: base_url,
|
65
|
+
timeout: timeout,
|
66
|
+
max_retries: max_retries,
|
67
|
+
initial_retry_delay: initial_retry_delay,
|
68
|
+
max_retry_delay: max_retry_delay
|
69
|
+
)
|
70
|
+
|
71
|
+
@brand = BrandDev::Resources::Brand.new(client: self)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
@@ -0,0 +1,192 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module BrandDev
|
4
|
+
module Errors
|
5
|
+
class Error < StandardError
|
6
|
+
# @!attribute cause
|
7
|
+
#
|
8
|
+
# @return [StandardError, nil]
|
9
|
+
end
|
10
|
+
|
11
|
+
class ConversionError < BrandDev::Errors::Error
|
12
|
+
end
|
13
|
+
|
14
|
+
class APIError < BrandDev::Errors::Error
|
15
|
+
# @return [URI::Generic]
|
16
|
+
attr_accessor :url
|
17
|
+
|
18
|
+
# @return [Integer, nil]
|
19
|
+
attr_accessor :status
|
20
|
+
|
21
|
+
# @return [Object, nil]
|
22
|
+
attr_accessor :body
|
23
|
+
|
24
|
+
# @api private
|
25
|
+
#
|
26
|
+
# @param url [URI::Generic]
|
27
|
+
# @param status [Integer, nil]
|
28
|
+
# @param body [Object, nil]
|
29
|
+
# @param request [nil]
|
30
|
+
# @param response [nil]
|
31
|
+
# @param message [String, nil]
|
32
|
+
def initialize(url:, status: nil, body: nil, request: nil, response: nil, message: nil)
|
33
|
+
@url = url
|
34
|
+
@status = status
|
35
|
+
@body = body
|
36
|
+
@request = request
|
37
|
+
@response = response
|
38
|
+
super(message)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
class APIConnectionError < BrandDev::Errors::APIError
|
43
|
+
# @!attribute status
|
44
|
+
#
|
45
|
+
# @return [nil]
|
46
|
+
|
47
|
+
# @!attribute body
|
48
|
+
#
|
49
|
+
# @return [nil]
|
50
|
+
|
51
|
+
# @api private
|
52
|
+
#
|
53
|
+
# @param url [URI::Generic]
|
54
|
+
# @param status [nil]
|
55
|
+
# @param body [nil]
|
56
|
+
# @param request [nil]
|
57
|
+
# @param response [nil]
|
58
|
+
# @param message [String, nil]
|
59
|
+
def initialize(
|
60
|
+
url:,
|
61
|
+
status: nil,
|
62
|
+
body: nil,
|
63
|
+
request: nil,
|
64
|
+
response: nil,
|
65
|
+
message: "Connection error."
|
66
|
+
)
|
67
|
+
super
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
class APITimeoutError < BrandDev::Errors::APIConnectionError
|
72
|
+
# @api private
|
73
|
+
#
|
74
|
+
# @param url [URI::Generic]
|
75
|
+
# @param status [nil]
|
76
|
+
# @param body [nil]
|
77
|
+
# @param request [nil]
|
78
|
+
# @param response [nil]
|
79
|
+
# @param message [String, nil]
|
80
|
+
def initialize(
|
81
|
+
url:,
|
82
|
+
status: nil,
|
83
|
+
body: nil,
|
84
|
+
request: nil,
|
85
|
+
response: nil,
|
86
|
+
message: "Request timed out."
|
87
|
+
)
|
88
|
+
super
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
class APIStatusError < BrandDev::Errors::APIError
|
93
|
+
# @api private
|
94
|
+
#
|
95
|
+
# @param url [URI::Generic]
|
96
|
+
# @param status [Integer]
|
97
|
+
# @param body [Object, nil]
|
98
|
+
# @param request [nil]
|
99
|
+
# @param response [nil]
|
100
|
+
# @param message [String, nil]
|
101
|
+
#
|
102
|
+
# @return [self]
|
103
|
+
def self.for(url:, status:, body:, request:, response:, message: nil)
|
104
|
+
kwargs = {
|
105
|
+
url: url,
|
106
|
+
status: status,
|
107
|
+
body: body,
|
108
|
+
request: request,
|
109
|
+
response: response,
|
110
|
+
message: message
|
111
|
+
}
|
112
|
+
|
113
|
+
case status
|
114
|
+
in 400
|
115
|
+
BrandDev::Errors::BadRequestError.new(**kwargs)
|
116
|
+
in 401
|
117
|
+
BrandDev::Errors::AuthenticationError.new(**kwargs)
|
118
|
+
in 403
|
119
|
+
BrandDev::Errors::PermissionDeniedError.new(**kwargs)
|
120
|
+
in 404
|
121
|
+
BrandDev::Errors::NotFoundError.new(**kwargs)
|
122
|
+
in 409
|
123
|
+
BrandDev::Errors::ConflictError.new(**kwargs)
|
124
|
+
in 422
|
125
|
+
BrandDev::Errors::UnprocessableEntityError.new(**kwargs)
|
126
|
+
in 429
|
127
|
+
BrandDev::Errors::RateLimitError.new(**kwargs)
|
128
|
+
in (500..)
|
129
|
+
BrandDev::Errors::InternalServerError.new(**kwargs)
|
130
|
+
else
|
131
|
+
BrandDev::Errors::APIStatusError.new(**kwargs)
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
# @!parse
|
136
|
+
# # @return [Integer]
|
137
|
+
# attr_accessor :status
|
138
|
+
|
139
|
+
# @api private
|
140
|
+
#
|
141
|
+
# @param url [URI::Generic]
|
142
|
+
# @param status [Integer]
|
143
|
+
# @param body [Object, nil]
|
144
|
+
# @param request [nil]
|
145
|
+
# @param response [nil]
|
146
|
+
# @param message [String, nil]
|
147
|
+
def initialize(url:, status:, body:, request:, response:, message: nil)
|
148
|
+
message ||= {url: url.to_s, status: status, body: body}
|
149
|
+
super(
|
150
|
+
url: url,
|
151
|
+
status: status,
|
152
|
+
body: body,
|
153
|
+
request: request,
|
154
|
+
response: response,
|
155
|
+
message: message&.to_s
|
156
|
+
)
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
class BadRequestError < BrandDev::Errors::APIStatusError
|
161
|
+
HTTP_STATUS = 400
|
162
|
+
end
|
163
|
+
|
164
|
+
class AuthenticationError < BrandDev::Errors::APIStatusError
|
165
|
+
HTTP_STATUS = 401
|
166
|
+
end
|
167
|
+
|
168
|
+
class PermissionDeniedError < BrandDev::Errors::APIStatusError
|
169
|
+
HTTP_STATUS = 403
|
170
|
+
end
|
171
|
+
|
172
|
+
class NotFoundError < BrandDev::Errors::APIStatusError
|
173
|
+
HTTP_STATUS = 404
|
174
|
+
end
|
175
|
+
|
176
|
+
class ConflictError < BrandDev::Errors::APIStatusError
|
177
|
+
HTTP_STATUS = 409
|
178
|
+
end
|
179
|
+
|
180
|
+
class UnprocessableEntityError < BrandDev::Errors::APIStatusError
|
181
|
+
HTTP_STATUS = 422
|
182
|
+
end
|
183
|
+
|
184
|
+
class RateLimitError < BrandDev::Errors::APIStatusError
|
185
|
+
HTTP_STATUS = 429
|
186
|
+
end
|
187
|
+
|
188
|
+
class InternalServerError < BrandDev::Errors::APIStatusError
|
189
|
+
HTTP_STATUS = (500..)
|
190
|
+
end
|
191
|
+
end
|
192
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module BrandDev
|
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
|