hermoso 0.1.4

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 (142) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +21 -0
  3. data/README.md +53 -0
  4. data/lib/hermoso/api/account_api.rb +156 -0
  5. data/lib/hermoso/api/analytics_api.rb +400 -0
  6. data/lib/hermoso/api/brands_api.rb +82 -0
  7. data/lib/hermoso/api/campaign_profit_api.rb +103 -0
  8. data/lib/hermoso/api/campaign_results_api.rb +289 -0
  9. data/lib/hermoso/api/channels_api.rb +82 -0
  10. data/lib/hermoso/api/clones_api.rb +93 -0
  11. data/lib/hermoso/api/connect_links_api.rb +228 -0
  12. data/lib/hermoso/api/connect_redirects_api.rb +153 -0
  13. data/lib/hermoso/api/connections_api.rb +151 -0
  14. data/lib/hermoso/api/credits_api.rb +85 -0
  15. data/lib/hermoso/api/edits_api.rb +102 -0
  16. data/lib/hermoso/api/events_api.rb +932 -0
  17. data/lib/hermoso/api/generations_api.rb +173 -0
  18. data/lib/hermoso/api/jobs_api.rb +226 -0
  19. data/lib/hermoso/api/library_api.rb +88 -0
  20. data/lib/hermoso/api/media_api.rb +158 -0
  21. data/lib/hermoso/api/models_api.rb +88 -0
  22. data/lib/hermoso/api/posts_api.rb +377 -0
  23. data/lib/hermoso/api/recasts_api.rb +102 -0
  24. data/lib/hermoso/api/signup_api.rb +164 -0
  25. data/lib/hermoso/api/tag_api.rb +570 -0
  26. data/lib/hermoso/api/tools_api.rb +252 -0
  27. data/lib/hermoso/api_client.rb +441 -0
  28. data/lib/hermoso/api_error.rb +58 -0
  29. data/lib/hermoso/api_model_base.rb +92 -0
  30. data/lib/hermoso/configuration.rb +400 -0
  31. data/lib/hermoso/helpers.rb +116 -0
  32. data/lib/hermoso/models/asset.rb +241 -0
  33. data/lib/hermoso/models/asset_list.rb +203 -0
  34. data/lib/hermoso/models/best_time.rb +250 -0
  35. data/lib/hermoso/models/best_time_slots_inner.rb +205 -0
  36. data/lib/hermoso/models/brand.rb +273 -0
  37. data/lib/hermoso/models/brand_list.rb +203 -0
  38. data/lib/hermoso/models/campaign_profit.rb +261 -0
  39. data/lib/hermoso/models/campaign_results.rb +250 -0
  40. data/lib/hermoso/models/campaign_results_upload.rb +171 -0
  41. data/lib/hermoso/models/campaign_results_upload_rows_inner.rb +259 -0
  42. data/lib/hermoso/models/channel.rb +326 -0
  43. data/lib/hermoso/models/channel_carousel.rb +188 -0
  44. data/lib/hermoso/models/channel_list.rb +203 -0
  45. data/lib/hermoso/models/clone_quote.rb +243 -0
  46. data/lib/hermoso/models/clone_quote_request.rb +227 -0
  47. data/lib/hermoso/models/clone_quote_step.rb +201 -0
  48. data/lib/hermoso/models/connect_link.rb +321 -0
  49. data/lib/hermoso/models/connect_link_account.rb +178 -0
  50. data/lib/hermoso/models/connect_link_create.rb +236 -0
  51. data/lib/hermoso/models/connect_link_error.rb +169 -0
  52. data/lib/hermoso/models/connect_redirects.rb +203 -0
  53. data/lib/hermoso/models/connect_redirects_set.rb +180 -0
  54. data/lib/hermoso/models/connection.rb +250 -0
  55. data/lib/hermoso/models/connection_accounts_inner.rb +178 -0
  56. data/lib/hermoso/models/connection_deleted.rb +228 -0
  57. data/lib/hermoso/models/connection_list.rb +203 -0
  58. data/lib/hermoso/models/contact_email.rb +189 -0
  59. data/lib/hermoso/models/contact_email_resend.rb +161 -0
  60. data/lib/hermoso/models/content_decay.rb +223 -0
  61. data/lib/hermoso/models/content_decay_buckets_inner.rb +187 -0
  62. data/lib/hermoso/models/conversion_destination_create.rb +317 -0
  63. data/lib/hermoso/models/conversion_destination_list.rb +223 -0
  64. data/lib/hermoso/models/conversion_destination_result.rb +221 -0
  65. data/lib/hermoso/models/conversion_event_list.rb +230 -0
  66. data/lib/hermoso/models/conversion_event_update.rb +195 -0
  67. data/lib/hermoso/models/conversion_events_send.rb +236 -0
  68. data/lib/hermoso/models/conversion_events_send_events_inner.rb +314 -0
  69. data/lib/hermoso/models/conversion_insights.rb +265 -0
  70. data/lib/hermoso/models/conversion_send_result.rb +257 -0
  71. data/lib/hermoso/models/conversion_send_result_destinations_inner.rb +286 -0
  72. data/lib/hermoso/models/credits.rb +240 -0
  73. data/lib/hermoso/models/credits_limits.rb +234 -0
  74. data/lib/hermoso/models/credits_limits_brands_inner.rb +218 -0
  75. data/lib/hermoso/models/credits_limits_brands_inner_members_inner.rb +196 -0
  76. data/lib/hermoso/models/deleted.rb +210 -0
  77. data/lib/hermoso/models/edit.rb +278 -0
  78. data/lib/hermoso/models/edit_create.rb +317 -0
  79. data/lib/hermoso/models/edit_preview.rb +199 -0
  80. data/lib/hermoso/models/edit_quote.rb +231 -0
  81. data/lib/hermoso/models/error.rb +198 -0
  82. data/lib/hermoso/models/error_error.rb +335 -0
  83. data/lib/hermoso/models/error_error_unknown_arguments_inner.rb +171 -0
  84. data/lib/hermoso/models/follower_history.rb +239 -0
  85. data/lib/hermoso/models/follower_history_accounts_inner.rb +207 -0
  86. data/lib/hermoso/models/follower_history_accounts_inner_points_inner.rb +178 -0
  87. data/lib/hermoso/models/follower_history_date_range.rb +169 -0
  88. data/lib/hermoso/models/generation_create.rb +435 -0
  89. data/lib/hermoso/models/generation_quote.rb +263 -0
  90. data/lib/hermoso/models/hermoso_tag.rb +230 -0
  91. data/lib/hermoso/models/hermoso_tag_audience_action.rb +325 -0
  92. data/lib/hermoso/models/hermoso_tag_audiences.rb +241 -0
  93. data/lib/hermoso/models/hermoso_tag_events.rb +223 -0
  94. data/lib/hermoso/models/hermoso_tag_events_send.rb +179 -0
  95. data/lib/hermoso/models/hermoso_tag_events_sent.rb +221 -0
  96. data/lib/hermoso/models/hermoso_tag_install.rb +246 -0
  97. data/lib/hermoso/models/hermoso_tag_install_result.rb +255 -0
  98. data/lib/hermoso/models/hermoso_tag_report.rb +261 -0
  99. data/lib/hermoso/models/hermoso_tag_tag.rb +211 -0
  100. data/lib/hermoso/models/hermoso_tag_update.rb +356 -0
  101. data/lib/hermoso/models/inbox_stats.rb +315 -0
  102. data/lib/hermoso/models/job.rb +359 -0
  103. data/lib/hermoso/models/job_cancel.rb +221 -0
  104. data/lib/hermoso/models/job_list.rb +232 -0
  105. data/lib/hermoso/models/media.rb +230 -0
  106. data/lib/hermoso/models/model.rb +327 -0
  107. data/lib/hermoso/models/model_list.rb +203 -0
  108. data/lib/hermoso/models/post.rb +382 -0
  109. data/lib/hermoso/models/post_create.rb +318 -0
  110. data/lib/hermoso/models/post_create_media_inner.rb +104 -0
  111. data/lib/hermoso/models/post_create_media_inner_one_of.rb +201 -0
  112. data/lib/hermoso/models/post_list.rb +221 -0
  113. data/lib/hermoso/models/post_media_inner.rb +169 -0
  114. data/lib/hermoso/models/post_results_inner.rb +205 -0
  115. data/lib/hermoso/models/post_results_inner_first_comment.rb +188 -0
  116. data/lib/hermoso/models/posting_frequency.rb +241 -0
  117. data/lib/hermoso/models/posting_frequency_frequency_inner.rb +205 -0
  118. data/lib/hermoso/models/profit_settings.rb +230 -0
  119. data/lib/hermoso/models/recast.rb +308 -0
  120. data/lib/hermoso/models/recast_create.rb +274 -0
  121. data/lib/hermoso/models/recast_person.rb +182 -0
  122. data/lib/hermoso/models/recast_quote.rb +232 -0
  123. data/lib/hermoso/models/recast_step.rb +201 -0
  124. data/lib/hermoso/models/recast_subject.rb +170 -0
  125. data/lib/hermoso/models/recast_voice.rb +178 -0
  126. data/lib/hermoso/models/recast_window.rb +179 -0
  127. data/lib/hermoso/models/signup.rb +329 -0
  128. data/lib/hermoso/models/signup_claim.rb +178 -0
  129. data/lib/hermoso/models/signup_create.rb +247 -0
  130. data/lib/hermoso/models/tool.rb +360 -0
  131. data/lib/hermoso/models/tool_invoke.rb +169 -0
  132. data/lib/hermoso/models/tool_job.rb +262 -0
  133. data/lib/hermoso/models/tool_list.rb +273 -0
  134. data/lib/hermoso/models/tool_list_areas_inner.rb +219 -0
  135. data/lib/hermoso/models/tool_list_search.rb +181 -0
  136. data/lib/hermoso/models/tool_result.rb +245 -0
  137. data/lib/hermoso/models/tool_result_images_inner.rb +170 -0
  138. data/lib/hermoso/models/warning.rb +244 -0
  139. data/lib/hermoso/spec.rb +8 -0
  140. data/lib/hermoso/version.rb +15 -0
  141. data/lib/hermoso.rb +174 -0
  142. metadata +237 -0
@@ -0,0 +1,400 @@
1
+ =begin
2
+ #Hermoso API
3
+
4
+ #The Hermoso public API. Guide: https://hermoso.ai/docs/api/ · OpenAPI: https://app.hermoso.ai/openapi.json
5
+
6
+ The version of the OpenAPI document: 2026-08-26
7
+
8
+ Generated by: https://openapi-generator.tech
9
+ Generator version: 7.27.0
10
+
11
+ =end
12
+
13
+ module Hermoso
14
+ class Configuration
15
+ # Defines url scheme
16
+ attr_accessor :scheme
17
+
18
+ # Defines url host
19
+ attr_accessor :host
20
+
21
+ # Defines url base path
22
+ attr_accessor :base_path
23
+
24
+ # Define server configuration index
25
+ attr_accessor :server_index
26
+
27
+ # Define server operation configuration index
28
+ attr_accessor :server_operation_index
29
+
30
+ # Default server variables
31
+ attr_accessor :server_variables
32
+
33
+ # Default server operation variables
34
+ attr_accessor :server_operation_variables
35
+
36
+ # Defines API keys used with API Key authentications.
37
+ #
38
+ # @return [Hash] key: parameter name, value: parameter value (API key)
39
+ #
40
+ # @example parameter name is "api_key", API key is "xxx" (e.g. "api_key=xxx" in query string)
41
+ # config.api_key['api_key'] = 'xxx'
42
+ attr_accessor :api_key
43
+
44
+ # Defines API key prefixes used with API Key authentications.
45
+ #
46
+ # @return [Hash] key: parameter name, value: API key prefix
47
+ #
48
+ # @example parameter name is "Authorization", API key prefix is "Token" (e.g. "Authorization: Token xxx" in headers)
49
+ # config.api_key_prefix['api_key'] = 'Token'
50
+ attr_accessor :api_key_prefix
51
+
52
+ # Defines the username used with HTTP basic authentication.
53
+ #
54
+ # @return [String]
55
+ attr_accessor :username
56
+
57
+ # Defines the password used with HTTP basic authentication.
58
+ #
59
+ # @return [String]
60
+ attr_accessor :password
61
+
62
+ # Defines the access token (Bearer) used with OAuth2.
63
+ attr_accessor :access_token
64
+
65
+ # Defines a Proc used to fetch or refresh access tokens (Bearer) used with OAuth2.
66
+ # Overrides the access_token if set
67
+ # @return [Proc]
68
+ attr_accessor :access_token_getter
69
+
70
+ # Set this to return data as binary instead of downloading a temp file. When enabled (set to true)
71
+ # HTTP responses with return type `File` will be returned as a stream of binary data.
72
+ # Default to false.
73
+ attr_accessor :return_binary_data
74
+
75
+ # Set this to enable/disable debugging. When enabled (set to true), HTTP request/response
76
+ # details will be logged with `logger.debug` (see the `logger` attribute).
77
+ # Default to false.
78
+ #
79
+ # @return [true, false]
80
+ attr_accessor :debugging
81
+
82
+ # Set this to ignore operation servers for the API client. This is useful when you need to
83
+ # send requests to a different server than the one specified in the OpenAPI document.
84
+ # Will default to the base url defined in the spec but can be overridden by setting
85
+ # `scheme`, `host`, `base_path` directly.
86
+ # Default to false.
87
+ # @return [true, false]
88
+ attr_accessor :ignore_operation_servers
89
+
90
+ # Defines the logger used for debugging.
91
+ # Default to `Rails.logger` (when in Rails) or logging to STDOUT.
92
+ #
93
+ # @return [#debug]
94
+ attr_accessor :logger
95
+
96
+ # Defines the temporary folder to store downloaded files
97
+ # (for API endpoints that have file response).
98
+ # Default to use `Tempfile`.
99
+ #
100
+ # @return [String]
101
+ attr_accessor :temp_folder_path
102
+
103
+ # The time limit for HTTP request in seconds.
104
+ # Default to 0 (never times out).
105
+ attr_accessor :timeout
106
+
107
+ # Set this to false to skip client side validation in the operation.
108
+ # Default to true.
109
+ # @return [true, false]
110
+ attr_accessor :client_side_validation
111
+
112
+ ### TLS/SSL setting
113
+ # Set this to false to skip verifying SSL certificate when calling API from https server.
114
+ # Default to true.
115
+ #
116
+ # @note Do NOT set it to false in production code, otherwise you would face multiple types of cryptographic attacks.
117
+ #
118
+ # @return [true, false]
119
+ attr_accessor :ssl_verify
120
+
121
+ ### TLS/SSL setting
122
+ # Any `OpenSSL::SSL::` constant (see https://ruby-doc.org/stdlib-2.5.1/libdoc/openssl/rdoc/OpenSSL/SSL.html)
123
+ #
124
+ # @note Do NOT set it to false in production code, otherwise you would face multiple types of cryptographic attacks.
125
+ #
126
+ attr_accessor :ssl_verify_mode
127
+
128
+ ### TLS/SSL setting
129
+ # Set this to customize the certificate file to verify the peer.
130
+ #
131
+ # @return [String] the path to the certificate file
132
+ attr_accessor :ssl_ca_file
133
+
134
+ ### TLS/SSL setting
135
+ # Client certificate file (for client certificate)
136
+ attr_accessor :ssl_client_cert
137
+
138
+ ### TLS/SSL setting
139
+ # Client private key file (for client certificate)
140
+ attr_accessor :ssl_client_key
141
+
142
+ ### Proxy setting
143
+ # HTTP Proxy settings
144
+ attr_accessor :proxy
145
+
146
+ # Set this to customize parameters encoder of array parameter.
147
+ # Default to nil. Faraday uses NestedParamsEncoder when nil.
148
+ #
149
+ # @see The params_encoder option of Faraday. Related source code:
150
+ # https://github.com/lostisland/faraday/tree/main/lib/faraday/encoders
151
+ attr_accessor :params_encoder
152
+
153
+
154
+ attr_accessor :inject_format
155
+
156
+ attr_accessor :force_ending_format
157
+
158
+ def initialize
159
+ @scheme = 'https'
160
+ @host = 'app.hermoso.ai'
161
+ @base_path = ''
162
+ @server_index = nil
163
+ @server_operation_index = {}
164
+ @server_variables = {}
165
+ @server_operation_variables = {}
166
+ @api_key = {}
167
+ @api_key_prefix = {}
168
+ @client_side_validation = true
169
+ @ssl_verify = true
170
+ @ssl_verify_mode = nil
171
+ @ssl_ca_file = nil
172
+ @ssl_client_cert = nil
173
+ @ssl_client_key = nil
174
+ @middlewares = Hash.new { |h, k| h[k] = [] }
175
+ @configure_connection_blocks = []
176
+ @timeout = 60
177
+ # return data as binary instead of file
178
+ @return_binary_data = false
179
+ @params_encoder = nil
180
+ @debugging = false
181
+ @ignore_operation_servers = false
182
+ @inject_format = false
183
+ @force_ending_format = false
184
+ @logger = defined?(Rails) ? Rails.logger : Logger.new(STDOUT)
185
+
186
+ yield(self) if block_given?
187
+ end
188
+
189
+ # The default Configuration object.
190
+ def self.default
191
+ @@default ||= Configuration.new
192
+ end
193
+
194
+ def configure
195
+ yield(self) if block_given?
196
+ end
197
+
198
+ def scheme=(scheme)
199
+ # remove :// from scheme
200
+ @scheme = scheme.sub(/:\/\//, '')
201
+ end
202
+
203
+ def host=(host)
204
+ # remove http(s):// and anything after a slash
205
+ @host = host.sub(/https?:\/\//, '').split('/').first
206
+ end
207
+
208
+ def base_path=(base_path)
209
+ # Add leading and trailing slashes to base_path
210
+ @base_path = "/#{base_path}".gsub(/\/+/, '/')
211
+ @base_path = '' if @base_path == '/'
212
+ end
213
+
214
+ # Returns base URL for specified operation based on server settings
215
+ def base_url(operation = nil)
216
+ return "#{scheme}://#{[host, base_path].join('/').gsub(/\/+/, '/')}".sub(/\/+\z/, '') if ignore_operation_servers
217
+ if operation_server_settings.key?(operation) then
218
+ index = server_operation_index.fetch(operation, server_index)
219
+ server_url(index.nil? ? 0 : index, server_operation_variables.fetch(operation, server_variables), operation_server_settings[operation])
220
+ else
221
+ server_index.nil? ? "#{scheme}://#{[host, base_path].join('/').gsub(/\/+/, '/')}".sub(/\/+\z/, '') : server_url(server_index, server_variables, nil)
222
+ end
223
+ end
224
+
225
+ # Gets API key (with prefix if set).
226
+ # @param [String] param_name the parameter name of API key auth
227
+ def api_key_with_prefix(param_name, param_alias = nil)
228
+ key = @api_key[param_name]
229
+ key = @api_key.fetch(param_alias, key) unless param_alias.nil?
230
+ if @api_key_prefix[param_name]
231
+ "#{@api_key_prefix[param_name]} #{key}"
232
+ else
233
+ key
234
+ end
235
+ end
236
+
237
+ # Gets access_token using access_token_getter or uses the static access_token
238
+ def access_token_with_refresh
239
+ return access_token if access_token_getter.nil?
240
+ access_token_getter.call
241
+ end
242
+
243
+ # Gets Basic Auth token string
244
+ def basic_auth_token
245
+ 'Basic ' + ["#{username}:#{password}"].pack('m').delete("\r\n")
246
+ end
247
+
248
+ # Returns Auth Settings hash for api client.
249
+ def auth_settings
250
+ {
251
+ 'bearerAuth' =>
252
+ {
253
+ type: 'bearer',
254
+ in: 'header',
255
+ format: 'hmk_...',
256
+ key: 'Authorization',
257
+ value: "Bearer #{access_token_with_refresh}"
258
+ },
259
+ 'apiKeyHeader' =>
260
+ {
261
+ type: 'api_key',
262
+ in: 'header',
263
+ key: 'X-Api-Key',
264
+ value: api_key_with_prefix('X-Api-Key')
265
+ },
266
+ }
267
+ end
268
+
269
+ # Returns an array of Server setting
270
+ def server_settings
271
+ [
272
+ {
273
+ url: "https://app.hermoso.ai",
274
+ description: "No description provided",
275
+ }
276
+ ]
277
+ end
278
+
279
+ def operation_server_settings
280
+ {
281
+ }
282
+ end
283
+
284
+ # Returns URL based on server settings
285
+ #
286
+ # @param index array index of the server settings
287
+ # @param variables hash of variable and the corresponding value
288
+ def server_url(index, variables = {}, servers = nil)
289
+ servers = server_settings if servers == nil
290
+
291
+ # check array index out of bound
292
+ if (index.nil? || index < 0 || index >= servers.size)
293
+ fail ArgumentError, "Invalid index #{index} when selecting the server. Must not be nil and must be less than #{servers.size}"
294
+ end
295
+
296
+ server = servers[index]
297
+ url = server[:url]
298
+
299
+ return url unless server.key? :variables
300
+
301
+ # go through variable and assign a value
302
+ server[:variables].each do |name, variable|
303
+ if variables.key?(name)
304
+ if (!server[:variables][name].key?(:enum_values) || server[:variables][name][:enum_values].include?(variables[name]))
305
+ url.gsub! "{" + name.to_s + "}", variables[name]
306
+ else
307
+ fail ArgumentError, "The variable `#{name}` in the server URL has invalid value #{variables[name]}. Must be #{server[:variables][name][:enum_values]}."
308
+ end
309
+ else
310
+ # use default value
311
+ url.gsub! "{" + name.to_s + "}", server[:variables][name][:default_value]
312
+ end
313
+ end
314
+
315
+ url
316
+ end
317
+
318
+ # Configure Faraday connection directly.
319
+ #
320
+ # ```
321
+ # c.configure_faraday_connection do |conn|
322
+ # conn.use Faraday::HttpCache, shared_cache: false, logger: logger
323
+ # conn.response :logger, nil, headers: true, bodies: true, log_level: :debug do |logger|
324
+ # logger.filter(/(Authorization: )(.*)/, '\1[REDACTED]')
325
+ # end
326
+ # end
327
+ #
328
+ # c.configure_faraday_connection do |conn|
329
+ # conn.adapter :typhoeus
330
+ # end
331
+ # ```
332
+ #
333
+ # @param block [Proc] `#call`able object that takes one arg, the connection
334
+ def configure_faraday_connection(&block)
335
+ @configure_connection_blocks << block
336
+ end
337
+
338
+ def configure_connection(conn)
339
+ @configure_connection_blocks.each do |block|
340
+ block.call(conn)
341
+ end
342
+ end
343
+
344
+ # Adds middleware to the stack
345
+ def use(*middleware)
346
+ set_faraday_middleware(:use, *middleware)
347
+ end
348
+
349
+ # Adds request middleware to the stack
350
+ def request(*middleware)
351
+ set_faraday_middleware(:request, *middleware)
352
+ end
353
+
354
+ # Adds response middleware to the stack
355
+ def response(*middleware)
356
+ set_faraday_middleware(:response, *middleware)
357
+ end
358
+
359
+ # Adds Faraday middleware setting information to the stack
360
+ #
361
+ # @example Use the `set_faraday_middleware` method to set middleware information
362
+ # config.set_faraday_middleware(:request, :retry, max: 3, methods: [:get, :post], retry_statuses: [503])
363
+ # config.set_faraday_middleware(:response, :logger, nil, { bodies: true, log_level: :debug })
364
+ # config.set_faraday_middleware(:use, Faraday::HttpCache, store: Rails.cache, shared_cache: false)
365
+ # config.set_faraday_middleware(:insert, 0, FaradayMiddleware::FollowRedirects, { standards_compliant: true, limit: 1 })
366
+ # config.set_faraday_middleware(:swap, 0, Faraday::Response::Logger)
367
+ # config.set_faraday_middleware(:delete, Faraday::Multipart::Middleware)
368
+ #
369
+ # @see https://github.com/lostisland/faraday/blob/v2.3.0/lib/faraday/rack_builder.rb#L92-L143
370
+ def set_faraday_middleware(operation, key, *args, &block)
371
+ unless [:request, :response, :use, :insert, :insert_before, :insert_after, :swap, :delete].include?(operation)
372
+ fail ArgumentError, "Invalid faraday middleware operation #{operation}. Must be" \
373
+ " :request, :response, :use, :insert, :insert_before, :insert_after, :swap or :delete."
374
+ end
375
+
376
+ @middlewares[operation] << [key, args, block]
377
+ end
378
+ ruby2_keywords(:set_faraday_middleware) if respond_to?(:ruby2_keywords, true)
379
+
380
+ # Set up middleware on the connection
381
+ def configure_middleware(connection)
382
+ return if @middlewares.empty?
383
+
384
+ [:request, :response, :use, :insert, :insert_before, :insert_after, :swap].each do |operation|
385
+ next unless @middlewares.key?(operation)
386
+
387
+ @middlewares[operation].each do |key, args, block|
388
+ connection.builder.send(operation, key, *args, &block)
389
+ end
390
+ end
391
+
392
+ if @middlewares.key?(:delete)
393
+ @middlewares[:delete].each do |key, _args, _block|
394
+ connection.builder.delete(key)
395
+ end
396
+ end
397
+ end
398
+
399
+ end
400
+ end
@@ -0,0 +1,116 @@
1
+ # frozen_string_literal: true
2
+
3
+ # The small hand-written layer over the generated client: a client that reads your key, a cursor paginator, a job
4
+ # waiter and a one-line tool call. Not generated; tools/sdk-generate.mjs copies it in from sdks/ruby/overlay.
5
+ require 'json'
6
+ require 'timeout'
7
+ require 'uri'
8
+
9
+ module Hermoso
10
+ DEFAULT_BASE_URL = 'https://app.hermoso.ai'
11
+
12
+ # An error answer from the API. +error+ is the parsed body (+error[:error][:code]+, +[:message]+) when there is one.
13
+ class HermosoError < StandardError
14
+ attr_reader :status, :error
15
+
16
+ def initialize(status, error)
17
+ @status = status
18
+ @error = error
19
+ detail = error.is_a?(Hash) ? error.dig(:error, :message) : nil
20
+ super(detail || "Hermoso API error#{status ? " (HTTP #{status})" : ''}")
21
+ end
22
+
23
+ def self.from_api_error(e)
24
+ body = begin
25
+ JSON.parse(e.response_body.to_s, symbolize_names: true)
26
+ rescue StandardError
27
+ nil
28
+ end
29
+ new(e.code, body)
30
+ end
31
+ end
32
+
33
+ # A client authenticated with your API key (default: the HERMOSO_API_KEY environment variable). +brand+ acts on that
34
+ # brand (an id from list_brands) instead of the one the key is pinned to. Pass it to any generated API class:
35
+ #
36
+ # client = Hermoso.client
37
+ # credits = Hermoso::CreditsApi.new(client).get_credits
38
+ def self.client(api_key: nil, brand: nil, base_url: DEFAULT_BASE_URL, timeout: 90)
39
+ key = api_key || ENV['HERMOSO_API_KEY']
40
+ if key.nil? || key.empty?
41
+ raise ArgumentError, 'No Hermoso API key: pass api_key: or set HERMOSO_API_KEY. Create one at https://app.hermoso.ai ' \
42
+ 'on the "API, MCP & CLI" tab, under "Terminal & API keys".'
43
+ end
44
+ uri = URI.parse(base_url)
45
+ config = Configuration.new
46
+ config.scheme = uri.scheme
47
+ config.host = uri.port && uri.port != uri.default_port ? "#{uri.host}:#{uri.port}" : uri.host
48
+ config.base_path = uri.path.to_s.sub(%r{/\z}, '')
49
+ config.server_index = nil
50
+ config.access_token = key
51
+ config.timeout = timeout
52
+ api_client = ApiClient.new(config)
53
+ api_client.default_headers['X-Hermoso-User'] = brand if brand
54
+ api_client
55
+ end
56
+
57
+ # Every item of a cursor-paginated list, following +next_cursor+ until +has_more+ is false. +api+ is a generated API
58
+ # instance and +operation+ its list method; the rest are that method's options:
59
+ #
60
+ # posts = Hermoso::PostsApi.new(client)
61
+ # Hermoso.paginate(posts, :list_posts, status: 'published').each { |post| puts post.id }
62
+ #
63
+ # list_conversion_events takes its cursor as +cursor+; every other list takes +starting_after+. That is detected.
64
+ def self.paginate(api, operation, **opts)
65
+ cursor_param = operation.to_sym == :list_conversion_events ? :cursor : :starting_after
66
+ Enumerator.new do |out|
67
+ cursor = nil
68
+ loop do
69
+ page = begin
70
+ api.public_send(operation, cursor ? opts.merge(cursor_param => cursor) : opts)
71
+ rescue ApiError => e
72
+ raise HermosoError.from_api_error(e)
73
+ end
74
+ (page.data || []).each { |item| out << item }
75
+ cursor = page.next_cursor
76
+ break if cursor.nil? || cursor.empty? || (page.respond_to?(:has_more) && page.has_more == false)
77
+ end
78
+ end
79
+ end
80
+
81
+ # Polls a job (a render, a stitch, an upscale…) until it is "done" or "error" and returns it; the file is +job.url+.
82
+ # Polling is free; calling the tool again would start (and bill) a second render.
83
+ def self.wait_for_job(job_id, client:, interval: 5, timeout: 1200)
84
+ jobs = JobsApi.new(client)
85
+ deadline = Process.clock_gettime(Process::CLOCK_MONOTONIC) + timeout
86
+ loop do
87
+ job = begin
88
+ jobs.get_job(job_id)
89
+ rescue ApiError => e
90
+ raise HermosoError.from_api_error(e)
91
+ end
92
+ return job if %w[done error].include?(job.status)
93
+ if Process.clock_gettime(Process::CLOCK_MONOTONIC) > deadline
94
+ raise Timeout::Error, "Job #{job_id} is still #{job.status}; it keeps running, call wait_for_job again."
95
+ end
96
+
97
+ sleep interval
98
+ end
99
+ end
100
+
101
+ # Runs any Hermoso tool through POST /v1/tools/{name} and returns its result: a ToolResult, or a ToolJob handle when
102
+ # it queued a render (pass +job_id+ to wait_for_job). ToolsApi#get_tool describes each tool's arguments.
103
+ #
104
+ # plan = Hermoso.run_tool('plan_ad', { product: 'our cold brew, summer offer', format: 'video' }, client: client)
105
+ def self.run_tool(name, args = {}, client:, wait: nil, idempotency_key: nil)
106
+ opts = { debug_return_type: 'Object' }
107
+ opts[:wait] = wait.to_s unless wait.nil?
108
+ opts[:idempotency_key] = idempotency_key if idempotency_key
109
+ data, status, = begin
110
+ ToolsApi.new(client).call_tool_with_http_info(name, args, opts)
111
+ rescue ApiError => e
112
+ raise HermosoError.from_api_error(e)
113
+ end
114
+ status == 202 ? ToolJob.build_from_hash(data) : ToolResult.build_from_hash(data)
115
+ end
116
+ end