imgwire 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.
- checksums.yaml +7 -0
- data/AGENTS.md +8 -0
- data/CODEGEN_VERSION +1 -0
- data/LICENSE +21 -0
- data/README.md +159 -0
- data/generated/lib/imgwire-generated/api/cors_origins_api.rb +355 -0
- data/generated/lib/imgwire-generated/api/custom_domain_api.rb +253 -0
- data/generated/lib/imgwire-generated/api/images_api.rb +534 -0
- data/generated/lib/imgwire-generated/api/metrics_api.rb +156 -0
- data/generated/lib/imgwire-generated/api_client.rb +392 -0
- data/generated/lib/imgwire-generated/api_error.rb +58 -0
- data/generated/lib/imgwire-generated/configuration.rb +301 -0
- data/generated/lib/imgwire-generated/models/bulk_delete_images_schema.rb +248 -0
- data/generated/lib/imgwire-generated/models/cache_hit_ratio_dataset_point_schema.rb +263 -0
- data/generated/lib/imgwire-generated/models/cors_origin_create_schema.rb +246 -0
- data/generated/lib/imgwire-generated/models/cors_origin_schema.rb +341 -0
- data/generated/lib/imgwire-generated/models/cors_origin_update_schema.rb +246 -0
- data/generated/lib/imgwire-generated/models/custom_domain_certificate_status.rb +41 -0
- data/generated/lib/imgwire-generated/models/custom_domain_create_schema.rb +237 -0
- data/generated/lib/imgwire-generated/models/custom_domain_schema.rb +531 -0
- data/generated/lib/imgwire-generated/models/custom_domain_status.rb +41 -0
- data/generated/lib/imgwire-generated/models/custom_metadata_value.rb +106 -0
- data/generated/lib/imgwire-generated/models/http_validation_error.rb +222 -0
- data/generated/lib/imgwire-generated/models/image_download_job_create_schema.rb +248 -0
- data/generated/lib/imgwire-generated/models/image_download_job_schema.rb +389 -0
- data/generated/lib/imgwire-generated/models/image_download_status.rb +42 -0
- data/generated/lib/imgwire-generated/models/image_schema.rb +659 -0
- data/generated/lib/imgwire-generated/models/image_status.rb +42 -0
- data/generated/lib/imgwire-generated/models/location_inner.rb +104 -0
- data/generated/lib/imgwire-generated/models/metrics_dataset_interval.rb +42 -0
- data/generated/lib/imgwire-generated/models/metrics_datasets_schema.rb +379 -0
- data/generated/lib/imgwire-generated/models/metrics_stat_value_schema.rb +275 -0
- data/generated/lib/imgwire-generated/models/metrics_stats_schema.rb +367 -0
- data/generated/lib/imgwire-generated/models/requests_dataset_point_schema.rb +263 -0
- data/generated/lib/imgwire-generated/models/standard_upload_create_schema.rb +415 -0
- data/generated/lib/imgwire-generated/models/standard_upload_response_schema.rb +263 -0
- data/generated/lib/imgwire-generated/models/storage_bytes_dataset_point_schema.rb +289 -0
- data/generated/lib/imgwire-generated/models/supported_mime_type.rb +43 -0
- data/generated/lib/imgwire-generated/models/transfer_bytes_dataset_point_schema.rb +263 -0
- data/generated/lib/imgwire-generated/models/transformations_dataset_point_schema.rb +263 -0
- data/generated/lib/imgwire-generated/models/upload_token_create_response_schema.rb +379 -0
- data/generated/lib/imgwire-generated/models/uploads_dataset_point_schema.rb +263 -0
- data/generated/lib/imgwire-generated/models/validation_error.rb +291 -0
- data/generated/lib/imgwire-generated/version.rb +15 -0
- data/generated/lib/imgwire-generated.rb +74 -0
- data/lib/imgwire/client.rb +52 -0
- data/lib/imgwire/client_options.rb +14 -0
- data/lib/imgwire/http/upload_client.rb +53 -0
- data/lib/imgwire/image.rb +137 -0
- data/lib/imgwire/pagination.rb +82 -0
- data/lib/imgwire/resources/base_resource.rb +29 -0
- data/lib/imgwire/resources/cors_origins_resource.rb +47 -0
- data/lib/imgwire/resources/custom_domain_resource.rb +30 -0
- data/lib/imgwire/resources/images_resource.rb +106 -0
- data/lib/imgwire/resources/metrics_resource.rb +24 -0
- data/lib/imgwire/uploads.rb +78 -0
- data/lib/imgwire/version.rb +5 -0
- data/lib/imgwire.rb +18 -0
- metadata +158 -0
|
@@ -0,0 +1,291 @@
|
|
|
1
|
+
=begin
|
|
2
|
+
#imgwire.dev Backend API development
|
|
3
|
+
|
|
4
|
+
#No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
|
|
5
|
+
|
|
6
|
+
The version of the OpenAPI document: 0.1.0
|
|
7
|
+
|
|
8
|
+
Generated by: https://openapi-generator.tech
|
|
9
|
+
Generator version: 7.14.0
|
|
10
|
+
|
|
11
|
+
=end
|
|
12
|
+
|
|
13
|
+
require 'date'
|
|
14
|
+
require 'time'
|
|
15
|
+
|
|
16
|
+
module ImgwireGenerated
|
|
17
|
+
class ValidationError
|
|
18
|
+
attr_accessor :loc
|
|
19
|
+
|
|
20
|
+
attr_accessor :msg
|
|
21
|
+
|
|
22
|
+
attr_accessor :type
|
|
23
|
+
|
|
24
|
+
# Attribute mapping from ruby-style variable name to JSON key.
|
|
25
|
+
def self.attribute_map
|
|
26
|
+
{
|
|
27
|
+
:'loc' => :'loc',
|
|
28
|
+
:'msg' => :'msg',
|
|
29
|
+
:'type' => :'type'
|
|
30
|
+
}
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
# Returns attribute mapping this model knows about
|
|
34
|
+
def self.acceptable_attribute_map
|
|
35
|
+
attribute_map
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
# Returns all the JSON keys this model knows about
|
|
39
|
+
def self.acceptable_attributes
|
|
40
|
+
acceptable_attribute_map.values
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
# Attribute type mapping.
|
|
44
|
+
def self.openapi_types
|
|
45
|
+
{
|
|
46
|
+
:'loc' => :'Array<LocationInner>',
|
|
47
|
+
:'msg' => :'String',
|
|
48
|
+
:'type' => :'String'
|
|
49
|
+
}
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
# List of attributes with nullable: true
|
|
53
|
+
def self.openapi_nullable
|
|
54
|
+
Set.new([
|
|
55
|
+
])
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
# Initializes the object
|
|
59
|
+
# @param [Hash] attributes Model attributes in the form of hash
|
|
60
|
+
def initialize(attributes = {})
|
|
61
|
+
if (!attributes.is_a?(Hash))
|
|
62
|
+
fail ArgumentError, "The input argument (attributes) must be a hash in `ImgwireGenerated::ValidationError` initialize method"
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
# check to see if the attribute exists and convert string to symbol for hash key
|
|
66
|
+
acceptable_attribute_map = self.class.acceptable_attribute_map
|
|
67
|
+
attributes = attributes.each_with_object({}) { |(k, v), h|
|
|
68
|
+
if (!acceptable_attribute_map.key?(k.to_sym))
|
|
69
|
+
fail ArgumentError, "`#{k}` is not a valid attribute in `ImgwireGenerated::ValidationError`. Please check the name to make sure it's valid. List of attributes: " + acceptable_attribute_map.keys.inspect
|
|
70
|
+
end
|
|
71
|
+
h[k.to_sym] = v
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
if attributes.key?(:'loc')
|
|
75
|
+
if (value = attributes[:'loc']).is_a?(Array)
|
|
76
|
+
self.loc = value
|
|
77
|
+
end
|
|
78
|
+
else
|
|
79
|
+
self.loc = nil
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
if attributes.key?(:'msg')
|
|
83
|
+
self.msg = attributes[:'msg']
|
|
84
|
+
else
|
|
85
|
+
self.msg = nil
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
if attributes.key?(:'type')
|
|
89
|
+
self.type = attributes[:'type']
|
|
90
|
+
else
|
|
91
|
+
self.type = nil
|
|
92
|
+
end
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
# Show invalid properties with the reasons. Usually used together with valid?
|
|
96
|
+
# @return Array for valid properties with the reasons
|
|
97
|
+
def list_invalid_properties
|
|
98
|
+
warn '[DEPRECATED] the `list_invalid_properties` method is obsolete'
|
|
99
|
+
invalid_properties = Array.new
|
|
100
|
+
if @loc.nil?
|
|
101
|
+
invalid_properties.push('invalid value for "loc", loc cannot be nil.')
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
if @msg.nil?
|
|
105
|
+
invalid_properties.push('invalid value for "msg", msg cannot be nil.')
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
if @type.nil?
|
|
109
|
+
invalid_properties.push('invalid value for "type", type cannot be nil.')
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
invalid_properties
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
# Check to see if the all the properties in the model are valid
|
|
116
|
+
# @return true if the model is valid
|
|
117
|
+
def valid?
|
|
118
|
+
warn '[DEPRECATED] the `valid?` method is obsolete'
|
|
119
|
+
return false if @loc.nil?
|
|
120
|
+
return false if @msg.nil?
|
|
121
|
+
return false if @type.nil?
|
|
122
|
+
true
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
# Custom attribute writer method with validation
|
|
126
|
+
# @param [Object] loc Value to be assigned
|
|
127
|
+
def loc=(loc)
|
|
128
|
+
if loc.nil?
|
|
129
|
+
fail ArgumentError, 'loc cannot be nil'
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
@loc = loc
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
# Custom attribute writer method with validation
|
|
136
|
+
# @param [Object] msg Value to be assigned
|
|
137
|
+
def msg=(msg)
|
|
138
|
+
if msg.nil?
|
|
139
|
+
fail ArgumentError, 'msg cannot be nil'
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
@msg = msg
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
# Custom attribute writer method with validation
|
|
146
|
+
# @param [Object] type Value to be assigned
|
|
147
|
+
def type=(type)
|
|
148
|
+
if type.nil?
|
|
149
|
+
fail ArgumentError, 'type cannot be nil'
|
|
150
|
+
end
|
|
151
|
+
|
|
152
|
+
@type = type
|
|
153
|
+
end
|
|
154
|
+
|
|
155
|
+
# Checks equality by comparing each attribute.
|
|
156
|
+
# @param [Object] Object to be compared
|
|
157
|
+
def ==(o)
|
|
158
|
+
return true if self.equal?(o)
|
|
159
|
+
self.class == o.class &&
|
|
160
|
+
loc == o.loc &&
|
|
161
|
+
msg == o.msg &&
|
|
162
|
+
type == o.type
|
|
163
|
+
end
|
|
164
|
+
|
|
165
|
+
# @see the `==` method
|
|
166
|
+
# @param [Object] Object to be compared
|
|
167
|
+
def eql?(o)
|
|
168
|
+
self == o
|
|
169
|
+
end
|
|
170
|
+
|
|
171
|
+
# Calculates hash code according to all attributes.
|
|
172
|
+
# @return [Integer] Hash code
|
|
173
|
+
def hash
|
|
174
|
+
[loc, msg, type].hash
|
|
175
|
+
end
|
|
176
|
+
|
|
177
|
+
# Builds the object from hash
|
|
178
|
+
# @param [Hash] attributes Model attributes in the form of hash
|
|
179
|
+
# @return [Object] Returns the model itself
|
|
180
|
+
def self.build_from_hash(attributes)
|
|
181
|
+
return nil unless attributes.is_a?(Hash)
|
|
182
|
+
attributes = attributes.transform_keys(&:to_sym)
|
|
183
|
+
transformed_hash = {}
|
|
184
|
+
openapi_types.each_pair do |key, type|
|
|
185
|
+
if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil?
|
|
186
|
+
transformed_hash["#{key}"] = nil
|
|
187
|
+
elsif type =~ /\AArray<(.*)>/i
|
|
188
|
+
# check to ensure the input is an array given that the attribute
|
|
189
|
+
# is documented as an array but the input is not
|
|
190
|
+
if attributes[attribute_map[key]].is_a?(Array)
|
|
191
|
+
transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) }
|
|
192
|
+
end
|
|
193
|
+
elsif !attributes[attribute_map[key]].nil?
|
|
194
|
+
transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]])
|
|
195
|
+
end
|
|
196
|
+
end
|
|
197
|
+
new(transformed_hash)
|
|
198
|
+
end
|
|
199
|
+
|
|
200
|
+
# Deserializes the data based on type
|
|
201
|
+
# @param string type Data type
|
|
202
|
+
# @param string value Value to be deserialized
|
|
203
|
+
# @return [Object] Deserialized data
|
|
204
|
+
def self._deserialize(type, value)
|
|
205
|
+
case type.to_sym
|
|
206
|
+
when :Time
|
|
207
|
+
Time.parse(value)
|
|
208
|
+
when :Date
|
|
209
|
+
Date.parse(value)
|
|
210
|
+
when :String
|
|
211
|
+
value.to_s
|
|
212
|
+
when :Integer
|
|
213
|
+
value.to_i
|
|
214
|
+
when :Float
|
|
215
|
+
value.to_f
|
|
216
|
+
when :Boolean
|
|
217
|
+
if value.to_s =~ /\A(true|t|yes|y|1)\z/i
|
|
218
|
+
true
|
|
219
|
+
else
|
|
220
|
+
false
|
|
221
|
+
end
|
|
222
|
+
when :Object
|
|
223
|
+
# generic object (usually a Hash), return directly
|
|
224
|
+
value
|
|
225
|
+
when /\AArray<(?<inner_type>.+)>\z/
|
|
226
|
+
inner_type = Regexp.last_match[:inner_type]
|
|
227
|
+
value.map { |v| _deserialize(inner_type, v) }
|
|
228
|
+
when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
|
|
229
|
+
k_type = Regexp.last_match[:k_type]
|
|
230
|
+
v_type = Regexp.last_match[:v_type]
|
|
231
|
+
{}.tap do |hash|
|
|
232
|
+
value.each do |k, v|
|
|
233
|
+
hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
|
|
234
|
+
end
|
|
235
|
+
end
|
|
236
|
+
else # model
|
|
237
|
+
# models (e.g. Pet) or oneOf
|
|
238
|
+
klass = ImgwireGenerated.const_get(type)
|
|
239
|
+
klass.respond_to?(:openapi_any_of) || klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value)
|
|
240
|
+
end
|
|
241
|
+
end
|
|
242
|
+
|
|
243
|
+
# Returns the string representation of the object
|
|
244
|
+
# @return [String] String presentation of the object
|
|
245
|
+
def to_s
|
|
246
|
+
to_hash.to_s
|
|
247
|
+
end
|
|
248
|
+
|
|
249
|
+
# to_body is an alias to to_hash (backward compatibility)
|
|
250
|
+
# @return [Hash] Returns the object in the form of hash
|
|
251
|
+
def to_body
|
|
252
|
+
to_hash
|
|
253
|
+
end
|
|
254
|
+
|
|
255
|
+
# Returns the object in the form of hash
|
|
256
|
+
# @return [Hash] Returns the object in the form of hash
|
|
257
|
+
def to_hash
|
|
258
|
+
hash = {}
|
|
259
|
+
self.class.attribute_map.each_pair do |attr, param|
|
|
260
|
+
value = self.send(attr)
|
|
261
|
+
if value.nil?
|
|
262
|
+
is_nullable = self.class.openapi_nullable.include?(attr)
|
|
263
|
+
next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
|
|
264
|
+
end
|
|
265
|
+
|
|
266
|
+
hash[param] = _to_hash(value)
|
|
267
|
+
end
|
|
268
|
+
hash
|
|
269
|
+
end
|
|
270
|
+
|
|
271
|
+
# Outputs non-array value in the form of hash
|
|
272
|
+
# For object, use to_hash. Otherwise, just return the value
|
|
273
|
+
# @param [Object] value Any valid value
|
|
274
|
+
# @return [Hash] Returns the value in the form of hash
|
|
275
|
+
def _to_hash(value)
|
|
276
|
+
if value.is_a?(Array)
|
|
277
|
+
value.compact.map { |v| _to_hash(v) }
|
|
278
|
+
elsif value.is_a?(Hash)
|
|
279
|
+
{}.tap do |hash|
|
|
280
|
+
value.each { |k, v| hash[k] = _to_hash(v) }
|
|
281
|
+
end
|
|
282
|
+
elsif value.respond_to? :to_hash
|
|
283
|
+
value.to_hash
|
|
284
|
+
else
|
|
285
|
+
value
|
|
286
|
+
end
|
|
287
|
+
end
|
|
288
|
+
|
|
289
|
+
end
|
|
290
|
+
|
|
291
|
+
end
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
=begin
|
|
2
|
+
#imgwire.dev Backend API development
|
|
3
|
+
|
|
4
|
+
#No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
|
|
5
|
+
|
|
6
|
+
The version of the OpenAPI document: 0.1.0
|
|
7
|
+
|
|
8
|
+
Generated by: https://openapi-generator.tech
|
|
9
|
+
Generator version: 7.14.0
|
|
10
|
+
|
|
11
|
+
=end
|
|
12
|
+
|
|
13
|
+
module ImgwireGenerated
|
|
14
|
+
VERSION = '0.1.0'
|
|
15
|
+
end
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
=begin
|
|
2
|
+
#imgwire.dev Backend API development
|
|
3
|
+
|
|
4
|
+
#No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
|
|
5
|
+
|
|
6
|
+
The version of the OpenAPI document: 0.1.0
|
|
7
|
+
|
|
8
|
+
Generated by: https://openapi-generator.tech
|
|
9
|
+
Generator version: 7.14.0
|
|
10
|
+
|
|
11
|
+
=end
|
|
12
|
+
|
|
13
|
+
# Common files
|
|
14
|
+
require 'imgwire-generated/api_client'
|
|
15
|
+
require 'imgwire-generated/api_error'
|
|
16
|
+
require 'imgwire-generated/version'
|
|
17
|
+
require 'imgwire-generated/configuration'
|
|
18
|
+
|
|
19
|
+
# Models
|
|
20
|
+
require 'imgwire-generated/models/bulk_delete_images_schema'
|
|
21
|
+
require 'imgwire-generated/models/cache_hit_ratio_dataset_point_schema'
|
|
22
|
+
require 'imgwire-generated/models/cors_origin_create_schema'
|
|
23
|
+
require 'imgwire-generated/models/cors_origin_schema'
|
|
24
|
+
require 'imgwire-generated/models/cors_origin_update_schema'
|
|
25
|
+
require 'imgwire-generated/models/custom_domain_certificate_status'
|
|
26
|
+
require 'imgwire-generated/models/custom_domain_create_schema'
|
|
27
|
+
require 'imgwire-generated/models/custom_domain_schema'
|
|
28
|
+
require 'imgwire-generated/models/custom_domain_status'
|
|
29
|
+
require 'imgwire-generated/models/custom_metadata_value'
|
|
30
|
+
require 'imgwire-generated/models/http_validation_error'
|
|
31
|
+
require 'imgwire-generated/models/image_download_job_create_schema'
|
|
32
|
+
require 'imgwire-generated/models/image_download_job_schema'
|
|
33
|
+
require 'imgwire-generated/models/image_download_status'
|
|
34
|
+
require 'imgwire-generated/models/image_schema'
|
|
35
|
+
require 'imgwire-generated/models/image_status'
|
|
36
|
+
require 'imgwire-generated/models/location_inner'
|
|
37
|
+
require 'imgwire-generated/models/metrics_dataset_interval'
|
|
38
|
+
require 'imgwire-generated/models/metrics_datasets_schema'
|
|
39
|
+
require 'imgwire-generated/models/metrics_stat_value_schema'
|
|
40
|
+
require 'imgwire-generated/models/metrics_stats_schema'
|
|
41
|
+
require 'imgwire-generated/models/requests_dataset_point_schema'
|
|
42
|
+
require 'imgwire-generated/models/standard_upload_create_schema'
|
|
43
|
+
require 'imgwire-generated/models/standard_upload_response_schema'
|
|
44
|
+
require 'imgwire-generated/models/storage_bytes_dataset_point_schema'
|
|
45
|
+
require 'imgwire-generated/models/supported_mime_type'
|
|
46
|
+
require 'imgwire-generated/models/transfer_bytes_dataset_point_schema'
|
|
47
|
+
require 'imgwire-generated/models/transformations_dataset_point_schema'
|
|
48
|
+
require 'imgwire-generated/models/upload_token_create_response_schema'
|
|
49
|
+
require 'imgwire-generated/models/uploads_dataset_point_schema'
|
|
50
|
+
require 'imgwire-generated/models/validation_error'
|
|
51
|
+
|
|
52
|
+
# APIs
|
|
53
|
+
require 'imgwire-generated/api/cors_origins_api'
|
|
54
|
+
require 'imgwire-generated/api/custom_domain_api'
|
|
55
|
+
require 'imgwire-generated/api/images_api'
|
|
56
|
+
require 'imgwire-generated/api/metrics_api'
|
|
57
|
+
|
|
58
|
+
module ImgwireGenerated
|
|
59
|
+
class << self
|
|
60
|
+
# Customize default settings for the SDK using block.
|
|
61
|
+
# ImgwireGenerated.configure do |config|
|
|
62
|
+
# config.username = "xxx"
|
|
63
|
+
# config.password = "xxx"
|
|
64
|
+
# end
|
|
65
|
+
# If no block given, return the default Configuration object.
|
|
66
|
+
def configure
|
|
67
|
+
if block_given?
|
|
68
|
+
yield(Configuration.default)
|
|
69
|
+
else
|
|
70
|
+
Configuration.default
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
end
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'uri'
|
|
4
|
+
|
|
5
|
+
module Imgwire
|
|
6
|
+
class Client
|
|
7
|
+
attr_reader :api_client, :options, :images, :custom_domain, :cors_origins, :metrics
|
|
8
|
+
|
|
9
|
+
def initialize(
|
|
10
|
+
api_key:,
|
|
11
|
+
base_url: 'https://api.imgwire.dev',
|
|
12
|
+
environment_id: nil,
|
|
13
|
+
timeout: 30,
|
|
14
|
+
max_retries: 2,
|
|
15
|
+
backoff_factor: 0.5,
|
|
16
|
+
upload_http_client: nil
|
|
17
|
+
)
|
|
18
|
+
@options = ClientOptions.new(
|
|
19
|
+
api_key: api_key,
|
|
20
|
+
base_url: base_url.sub(%r{/\z}, ''),
|
|
21
|
+
environment_id: environment_id,
|
|
22
|
+
timeout: timeout,
|
|
23
|
+
max_retries: max_retries,
|
|
24
|
+
backoff_factor: backoff_factor,
|
|
25
|
+
upload_http_client: upload_http_client || HTTP::UploadClient.new
|
|
26
|
+
)
|
|
27
|
+
|
|
28
|
+
configuration = ImgwireGenerated::Configuration.new
|
|
29
|
+
apply_base_url(configuration, @options.base_url)
|
|
30
|
+
configuration.timeout = @options.timeout
|
|
31
|
+
|
|
32
|
+
@api_client = ImgwireGenerated::ApiClient.new(configuration)
|
|
33
|
+
@api_client.default_headers['Authorization'] = "Bearer #{api_key}"
|
|
34
|
+
@api_client.default_headers['User-Agent'] = "imgwire-ruby/#{Imgwire::VERSION}"
|
|
35
|
+
@api_client.default_headers['X-Environment-Id'] = environment_id if environment_id
|
|
36
|
+
|
|
37
|
+
@images = Resources::ImagesResource.new(@api_client, @options)
|
|
38
|
+
@custom_domain = Resources::CustomDomainResource.new(@api_client)
|
|
39
|
+
@cors_origins = Resources::CorsOriginsResource.new(@api_client)
|
|
40
|
+
@metrics = Resources::MetricsResource.new(@api_client)
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
private
|
|
44
|
+
|
|
45
|
+
def apply_base_url(configuration, base_url)
|
|
46
|
+
uri = URI.parse(base_url)
|
|
47
|
+
configuration.scheme = uri.scheme
|
|
48
|
+
configuration.host = uri.host.to_s
|
|
49
|
+
configuration.base_path = uri.path
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
end
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'net/http'
|
|
4
|
+
require 'uri'
|
|
5
|
+
|
|
6
|
+
module Imgwire
|
|
7
|
+
module HTTP
|
|
8
|
+
class UploadClient
|
|
9
|
+
RETRYABLE_ERRORS = [
|
|
10
|
+
Errno::ECONNRESET,
|
|
11
|
+
Errno::ETIMEDOUT,
|
|
12
|
+
IOError,
|
|
13
|
+
Net::OpenTimeout,
|
|
14
|
+
Net::ReadTimeout
|
|
15
|
+
].freeze
|
|
16
|
+
|
|
17
|
+
def put(url, upload, timeout:, max_retries:, backoff_factor:)
|
|
18
|
+
uri = URI.parse(url)
|
|
19
|
+
attempts = 0
|
|
20
|
+
|
|
21
|
+
begin
|
|
22
|
+
attempts += 1
|
|
23
|
+
upload.rewind if upload.respond_to?(:rewind)
|
|
24
|
+
|
|
25
|
+
request = Net::HTTP::Put.new(uri)
|
|
26
|
+
request['Content-Length'] = upload.content_length.to_s
|
|
27
|
+
request['Content-Type'] = upload.mime_type if upload.mime_type
|
|
28
|
+
request.body_stream = upload.io
|
|
29
|
+
request.content_length = upload.content_length
|
|
30
|
+
|
|
31
|
+
Net::HTTP.start(
|
|
32
|
+
uri.host,
|
|
33
|
+
uri.port,
|
|
34
|
+
use_ssl: uri.scheme == 'https',
|
|
35
|
+
open_timeout: timeout,
|
|
36
|
+
read_timeout: timeout,
|
|
37
|
+
write_timeout: timeout
|
|
38
|
+
) do |http|
|
|
39
|
+
response = http.request(request)
|
|
40
|
+
return response if response.is_a?(Net::HTTPSuccess)
|
|
41
|
+
|
|
42
|
+
raise "Upload failed with status #{response.code}: #{response.body}"
|
|
43
|
+
end
|
|
44
|
+
rescue *RETRYABLE_ERRORS => e
|
|
45
|
+
raise e if attempts > max_retries + 1
|
|
46
|
+
|
|
47
|
+
sleep(backoff_factor * (2**(attempts - 1)))
|
|
48
|
+
retry
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
end
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'uri'
|
|
4
|
+
|
|
5
|
+
module Imgwire
|
|
6
|
+
class Image < ImgwireGenerated::ImageSchema
|
|
7
|
+
PRESETS = %w[thumbnail small medium large].freeze
|
|
8
|
+
ROTATE_ANGLES = [0, 90, 180, 270, 360].freeze
|
|
9
|
+
FORMATS = %w[jpg png avif gif webp].freeze
|
|
10
|
+
|
|
11
|
+
RULES = {
|
|
12
|
+
'background' => %w[background bg],
|
|
13
|
+
'crop' => %w[crop],
|
|
14
|
+
'enlarge' => %w[enlarge],
|
|
15
|
+
'format' => %w[format fm],
|
|
16
|
+
'gravity' => %w[gravity],
|
|
17
|
+
'height' => %w[height h],
|
|
18
|
+
'quality' => %w[quality q],
|
|
19
|
+
'rotate' => %w[rotate rot],
|
|
20
|
+
'strip_metadata' => %w[strip_metadata strip],
|
|
21
|
+
'width' => %w[width w]
|
|
22
|
+
}.freeze
|
|
23
|
+
|
|
24
|
+
def self.wrap(value)
|
|
25
|
+
return value if value.is_a?(self)
|
|
26
|
+
|
|
27
|
+
if value.is_a?(ImgwireGenerated::ImageSchema)
|
|
28
|
+
attributes = ImgwireGenerated::ImageSchema.attribute_map.keys.to_h do |attribute|
|
|
29
|
+
[attribute, value.public_send(attribute)]
|
|
30
|
+
end
|
|
31
|
+
return new(attributes)
|
|
32
|
+
end
|
|
33
|
+
return build_from_hash(value.to_hash) if value.respond_to?(:to_hash)
|
|
34
|
+
|
|
35
|
+
build_from_hash(value)
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def url(options = {})
|
|
39
|
+
options = symbolize_keys(options)
|
|
40
|
+
path = build_preset_path(options[:preset])
|
|
41
|
+
query = build_query(options.except(:preset))
|
|
42
|
+
|
|
43
|
+
uri = URI.parse(cdn_url)
|
|
44
|
+
uri.path = path
|
|
45
|
+
uri.query = query.empty? ? nil : URI.encode_www_form(query.sort_by(&:first))
|
|
46
|
+
uri.to_s
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
private
|
|
50
|
+
|
|
51
|
+
def symbolize_keys(hash)
|
|
52
|
+
hash.each_with_object({}) do |(key, value), result|
|
|
53
|
+
result[key.to_sym] = value
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def build_preset_path(preset)
|
|
58
|
+
return URI.parse(cdn_url).path if preset.nil?
|
|
59
|
+
|
|
60
|
+
preset = preset.to_s
|
|
61
|
+
raise ArgumentError, 'Invalid transformation rule value for preset' unless PRESETS.include?(preset)
|
|
62
|
+
|
|
63
|
+
uri = URI.parse(cdn_url)
|
|
64
|
+
slash_index = uri.path.rindex('/')
|
|
65
|
+
prefix = slash_index ? uri.path[0..slash_index] : ''
|
|
66
|
+
file_name = slash_index ? uri.path[(slash_index + 1)..] : uri.path
|
|
67
|
+
dot_index = file_name.rindex('.')
|
|
68
|
+
raise ArgumentError, 'Cannot apply a preset to a CDN URL without a file extension.' if dot_index.nil?
|
|
69
|
+
|
|
70
|
+
"#{prefix}#{file_name}@#{preset}"
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def build_query(options)
|
|
74
|
+
present = []
|
|
75
|
+
|
|
76
|
+
RULES.each do |canonical, aliases|
|
|
77
|
+
matches = aliases.filter_map do |name|
|
|
78
|
+
symbol = name.to_sym
|
|
79
|
+
[symbol, options[symbol]] if options.key?(symbol)
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
next if matches.empty?
|
|
83
|
+
raise ArgumentError, "Duplicate transformation rule: #{canonical}" if matches.length > 1
|
|
84
|
+
|
|
85
|
+
value = normalize_rule(canonical, matches.first.last)
|
|
86
|
+
present << [canonical, value] unless value.nil?
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
present
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
def normalize_rule(canonical, value)
|
|
93
|
+
case canonical
|
|
94
|
+
when 'background'
|
|
95
|
+
string = value.to_s.delete_prefix('#')
|
|
96
|
+
unless string.match?(/\A[\da-fA-F]{6}\z/)
|
|
97
|
+
raise ArgumentError,
|
|
98
|
+
"Invalid transformation rule value for #{canonical}"
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
string.downcase
|
|
102
|
+
when 'crop', 'gravity'
|
|
103
|
+
value.to_s
|
|
104
|
+
when 'enlarge', 'strip_metadata'
|
|
105
|
+
value ? 'true' : nil
|
|
106
|
+
when 'format'
|
|
107
|
+
string = value.to_s
|
|
108
|
+
unless FORMATS.include?(string)
|
|
109
|
+
raise ArgumentError,
|
|
110
|
+
"Invalid transformation rule value for #{canonical}"
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
string
|
|
114
|
+
when 'height', 'quality', 'width'
|
|
115
|
+
integer = Integer(value)
|
|
116
|
+
unless integer.positive?
|
|
117
|
+
raise ArgumentError,
|
|
118
|
+
"Invalid transformation rule value for #{canonical}"
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
integer.to_s
|
|
122
|
+
when 'rotate'
|
|
123
|
+
integer = Integer(value)
|
|
124
|
+
unless ROTATE_ANGLES.include?(integer)
|
|
125
|
+
raise ArgumentError,
|
|
126
|
+
"Invalid transformation rule value for #{canonical}"
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
integer.to_s
|
|
130
|
+
else
|
|
131
|
+
raise ArgumentError, "Unsupported transformation rule: #{canonical}"
|
|
132
|
+
end
|
|
133
|
+
rescue ArgumentError, TypeError
|
|
134
|
+
raise ArgumentError, "Invalid transformation rule value for #{canonical}"
|
|
135
|
+
end
|
|
136
|
+
end
|
|
137
|
+
end
|