legnext-ruby-sdk 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (29) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +21 -0
  3. data/README.md +129 -0
  4. data/lib/openapi_client/api/account_management_api.rb +82 -0
  5. data/lib/openapi_client/api/image_api.rb +821 -0
  6. data/lib/openapi_client/api/video_api.rb +289 -0
  7. data/lib/openapi_client/api_client.rb +396 -0
  8. data/lib/openapi_client/api_error.rb +58 -0
  9. data/lib/openapi_client/api_model_base.rb +88 -0
  10. data/lib/openapi_client/configuration.rb +301 -0
  11. data/lib/openapi_client/models/api_v1_diffusion_post200_response.rb +205 -0
  12. data/lib/openapi_client/models/api_v1_diffusion_post200_response_config.rb +156 -0
  13. data/lib/openapi_client/models/api_v1_diffusion_post200_response_config_webhook_config.rb +156 -0
  14. data/lib/openapi_client/models/api_v1_diffusion_post200_response_meta.rb +156 -0
  15. data/lib/openapi_client/models/api_v1_diffusion_post200_response_meta_usage.rb +165 -0
  16. data/lib/openapi_client/models/api_v1_diffusion_post200_response_output.rb +168 -0
  17. data/lib/openapi_client/models/api_v1_edit_post200_response.rb +205 -0
  18. data/lib/openapi_client/models/api_v1_job_job_id_get200_response.rb +246 -0
  19. data/lib/openapi_client/models/api_v1_job_job_id_get200_response_error.rb +175 -0
  20. data/lib/openapi_client/models/api_v1_job_job_id_get200_response_meta.rb +174 -0
  21. data/lib/openapi_client/models/api_v1_job_job_id_get200_response_output.rb +177 -0
  22. data/lib/openapi_client/models/api_v1_job_job_id_get200_response_output_available_actions.rb +224 -0
  23. data/lib/openapi_client/models/api_v1_pan_post200_response.rb +205 -0
  24. data/lib/openapi_client/models/balance_response.rb +167 -0
  25. data/lib/openapi_client/models/balance_response_data.rb +208 -0
  26. data/lib/openapi_client/models/task_response.rb +206 -0
  27. data/lib/openapi_client/version.rb +15 -0
  28. data/lib/openapi_client.rb +59 -0
  29. metadata +115 -0
@@ -0,0 +1,396 @@
1
+ =begin
2
+ #Midjourney api-unofficial by Legnext.ai
3
+
4
+ ## **Legnext.ai Midjourney API: The Ultimate AI Image Generation Toolkit** Unlock the full creative potential of Midjourney directly within your applications and development workflows using the **Legnext.ai Midjourney API (Unofficial)**. This comprehensive collection offers a ready-to-integrate solution for professional image and video creation, manipulation, and high-fidelity upscaling. We provide developers with **stable, high-performance API access** to the Midjourney model. Crucially, integrating our service requires **no Midjourney account**, eliminating the hassle of managing official subscriptions or Discord interactions. Our toolkit simplifies the entire text-to-image process, supporting complex prompts, aspect ratio adjustments, and advanced style parameters. Focus on innovation while we handle the AI infrastructure. Start building scalable, visually stunning applications today with reliable access to the world’s leading generative AI model.
5
+
6
+ The version of the OpenAPI document: 1.0.0
7
+
8
+ Generated by: https://openapi-generator.tech
9
+ Generator version: 7.18.0
10
+
11
+ =end
12
+
13
+ require 'date'
14
+ require 'json'
15
+ require 'logger'
16
+ require 'tempfile'
17
+ require 'time'
18
+ require 'typhoeus'
19
+
20
+
21
+ module OpenapiClient
22
+ class ApiClient
23
+ # The Configuration object holding settings to be used in the API client.
24
+ attr_accessor :config
25
+
26
+ # Defines the headers to be used in HTTP requests of all API calls by default.
27
+ #
28
+ # @return [Hash]
29
+ attr_accessor :default_headers
30
+
31
+ # Initializes the ApiClient
32
+ # @option config [Configuration] Configuration for initializing the object, default to Configuration.default
33
+ def initialize(config = Configuration.default)
34
+ @config = config
35
+ @user_agent = "OpenAPI-Generator/#{VERSION}/ruby"
36
+ @default_headers = {
37
+ 'Content-Type' => 'application/json',
38
+ 'User-Agent' => @user_agent
39
+ }
40
+ end
41
+
42
+ def self.default
43
+ @@default ||= ApiClient.new
44
+ end
45
+
46
+ # Call an API with given options.
47
+ #
48
+ # @return [Array<(Object, Integer, Hash)>] an array of 3 elements:
49
+ # the data deserialized from response body (may be a Tempfile or nil), response status code and response headers.
50
+ def call_api(http_method, path, opts = {})
51
+ request = build_request(http_method, path, opts)
52
+ tempfile = nil
53
+ (download_file(request) { tempfile = _1 }) if opts[:return_type] == 'File'
54
+ response = request.run
55
+
56
+ if @config.debugging
57
+ @config.logger.debug "HTTP response body ~BEGIN~\n#{response.body}\n~END~\n"
58
+ end
59
+
60
+ unless response.success?
61
+ if response.timed_out?
62
+ fail ApiError.new('Connection timed out')
63
+ elsif response.code == 0
64
+ # Errors from libcurl will be made visible here
65
+ fail ApiError.new(:code => 0,
66
+ :message => response.return_message)
67
+ else
68
+ fail ApiError.new(:code => response.code,
69
+ :response_headers => response.headers,
70
+ :response_body => response.body),
71
+ response.status_message
72
+ end
73
+ end
74
+
75
+ if opts[:return_type] == 'File'
76
+ data = tempfile
77
+ elsif opts[:return_type]
78
+ data = deserialize(response, opts[:return_type])
79
+ else
80
+ data = nil
81
+ end
82
+ return data, response.code, response.headers
83
+ end
84
+
85
+ # Builds the HTTP request
86
+ #
87
+ # @param [String] http_method HTTP method/verb (e.g. POST)
88
+ # @param [String] path URL path (e.g. /account/new)
89
+ # @option opts [Hash] :header_params Header parameters
90
+ # @option opts [Hash] :query_params Query parameters
91
+ # @option opts [Hash] :form_params Query parameters
92
+ # @option opts [Object] :body HTTP body (JSON/XML)
93
+ # @return [Typhoeus::Request] A Typhoeus Request
94
+ def build_request(http_method, path, opts = {})
95
+ url = build_request_url(path, opts)
96
+ http_method = http_method.to_sym.downcase
97
+
98
+ header_params = @default_headers.merge(opts[:header_params] || {})
99
+ query_params = opts[:query_params] || {}
100
+ form_params = opts[:form_params] || {}
101
+ follow_location = opts[:follow_location] || true
102
+
103
+
104
+ # set ssl_verifyhosts option based on @config.verify_ssl_host (true/false)
105
+ _verify_ssl_host = @config.verify_ssl_host ? 2 : 0
106
+
107
+ req_opts = {
108
+ :method => http_method,
109
+ :headers => header_params,
110
+ :params => query_params,
111
+ :params_encoding => @config.params_encoding,
112
+ :timeout => @config.timeout,
113
+ :ssl_verifypeer => @config.verify_ssl,
114
+ :ssl_verifyhost => _verify_ssl_host,
115
+ :sslcert => @config.cert_file,
116
+ :sslkey => @config.key_file,
117
+ :verbose => @config.debugging,
118
+ :followlocation => follow_location
119
+ }
120
+
121
+ # set custom cert, if provided
122
+ req_opts[:cainfo] = @config.ssl_ca_cert if @config.ssl_ca_cert
123
+
124
+ if [:post, :patch, :put, :delete].include?(http_method)
125
+ req_body = build_request_body(header_params, form_params, opts[:body])
126
+ req_opts.update :body => req_body
127
+ if @config.debugging
128
+ @config.logger.debug "HTTP request body param ~BEGIN~\n#{req_body}\n~END~\n"
129
+ end
130
+ end
131
+
132
+ Typhoeus::Request.new(url, req_opts)
133
+ end
134
+
135
+ # Builds the HTTP request body
136
+ #
137
+ # @param [Hash] header_params Header parameters
138
+ # @param [Hash] form_params Query parameters
139
+ # @param [Object] body HTTP body (JSON/XML)
140
+ # @return [String] HTTP body data in the form of string
141
+ def build_request_body(header_params, form_params, body)
142
+ # http form
143
+ if header_params['Content-Type'] == 'application/x-www-form-urlencoded' ||
144
+ header_params['Content-Type'] == 'multipart/form-data'
145
+ data = {}
146
+ form_params.each do |key, value|
147
+ case value
148
+ when ::File, ::Array, nil
149
+ # let typhoeus handle File, Array and nil parameters
150
+ data[key] = value
151
+ else
152
+ data[key] = value.to_s
153
+ end
154
+ end
155
+ elsif body
156
+ data = body.is_a?(String) ? body : body.to_json
157
+ else
158
+ data = nil
159
+ end
160
+ data
161
+ end
162
+
163
+ # Save response body into a file in (the defined) temporary folder, using the filename
164
+ # from the "Content-Disposition" header if provided, otherwise a random filename.
165
+ # The response body is written to the file in chunks in order to handle files which
166
+ # size is larger than maximum Ruby String or even larger than the maximum memory a Ruby
167
+ # process can use.
168
+ #
169
+ # @see Configuration#temp_folder_path
170
+ #
171
+ # @return [Tempfile] the tempfile generated
172
+ def download_file(request)
173
+ tempfile = nil
174
+ encoding = nil
175
+ request.on_headers do |response|
176
+ content_disposition = response.headers['Content-Disposition']
177
+ if content_disposition && content_disposition =~ /filename=/i
178
+ filename = content_disposition[/filename=['"]?([^'"\s]+)['"]?/, 1]
179
+ prefix = sanitize_filename(filename)
180
+ else
181
+ prefix = 'download-'
182
+ end
183
+ prefix = prefix + '-' unless prefix.end_with?('-')
184
+ encoding = response.body.encoding
185
+ tempfile = Tempfile.open(prefix, @config.temp_folder_path, encoding: encoding)
186
+ end
187
+ request.on_body do |chunk|
188
+ chunk.force_encoding(encoding)
189
+ tempfile.write(chunk)
190
+ end
191
+ request.on_complete do
192
+ if !tempfile
193
+ fail ApiError.new("Failed to create the tempfile based on the HTTP response from the server: #{request.inspect}")
194
+ end
195
+ tempfile.close
196
+ @config.logger.info "Temp file written to #{tempfile.path}, please copy the file to a proper folder "\
197
+ "with e.g. `FileUtils.cp(tempfile.path, '/new/file/path')` otherwise the temp file "\
198
+ "will be deleted automatically with GC. It's also recommended to delete the temp file "\
199
+ "explicitly with `tempfile.delete`"
200
+ yield tempfile if block_given?
201
+ end
202
+ end
203
+
204
+ # Check if the given MIME is a JSON MIME.
205
+ # JSON MIME examples:
206
+ # application/json
207
+ # application/json; charset=UTF8
208
+ # APPLICATION/JSON
209
+ # */*
210
+ # @param [String] mime MIME
211
+ # @return [Boolean] True if the MIME is application/json
212
+ def json_mime?(mime)
213
+ (mime == '*/*') || !(mime =~ /^Application\/.*json(?!p)(;.*)?/i).nil?
214
+ end
215
+
216
+ # Deserialize the response to the given return type.
217
+ #
218
+ # @param [Response] response HTTP response
219
+ # @param [String] return_type some examples: "User", "Array<User>", "Hash<String, Integer>"
220
+ def deserialize(response, return_type)
221
+ body = response.body
222
+ return nil if body.nil? || body.empty?
223
+
224
+ # return response body directly for String return type
225
+ return body.to_s if return_type == 'String'
226
+
227
+ # ensuring a default content type
228
+ content_type = response.headers['Content-Type'] || 'application/json'
229
+
230
+ fail "Content-Type is not supported: #{content_type}" unless json_mime?(content_type)
231
+
232
+ begin
233
+ data = JSON.parse("[#{body}]", :symbolize_names => true)[0]
234
+ rescue JSON::ParserError => e
235
+ if %w(String Date Time).include?(return_type)
236
+ data = body
237
+ else
238
+ raise e
239
+ end
240
+ end
241
+
242
+ convert_to_type data, return_type
243
+ end
244
+
245
+ # Convert data to the given return type.
246
+ # @param [Object] data Data to be converted
247
+ # @param [String] return_type Return type
248
+ # @return [Mixed] Data in a particular type
249
+ def convert_to_type(data, return_type)
250
+ return nil if data.nil?
251
+ case return_type
252
+ when 'String'
253
+ data.to_s
254
+ when 'Integer'
255
+ data.to_i
256
+ when 'Float'
257
+ data.to_f
258
+ when 'Boolean'
259
+ data == true
260
+ when 'Time'
261
+ # parse date time (expecting ISO 8601 format)
262
+ Time.parse data
263
+ when 'Date'
264
+ # parse date time (expecting ISO 8601 format)
265
+ Date.parse data
266
+ when 'Object'
267
+ # generic object (usually a Hash), return directly
268
+ data
269
+ when /\AArray<(.+)>\z/
270
+ # e.g. Array<Pet>
271
+ sub_type = $1
272
+ data.map { |item| convert_to_type(item, sub_type) }
273
+ when /\AHash\<String, (.+)\>\z/
274
+ # e.g. Hash<String, Integer>
275
+ sub_type = $1
276
+ {}.tap do |hash|
277
+ data.each { |k, v| hash[k] = convert_to_type(v, sub_type) }
278
+ end
279
+ else
280
+ # models (e.g. Pet) or oneOf/anyOf
281
+ klass = OpenapiClient.const_get(return_type)
282
+ if klass.respond_to?(:openapi_one_of) || klass.respond_to?(:openapi_any_of)
283
+ klass.build(data)
284
+ else
285
+ klass.build_from_hash(data)
286
+ end
287
+ end
288
+ end
289
+
290
+ # Sanitize filename by removing path.
291
+ # e.g. ../../sun.gif becomes sun.gif
292
+ #
293
+ # @param [String] filename the filename to be sanitized
294
+ # @return [String] the sanitized filename
295
+ def sanitize_filename(filename)
296
+ filename.split(/[\/\\]/).last
297
+ end
298
+
299
+ def build_request_url(path, opts = {})
300
+ # Add leading and trailing slashes to path
301
+ path = "/#{path}".gsub(/\/+/, '/')
302
+ @config.base_url(opts[:operation]) + path
303
+ end
304
+
305
+ # Update header and query params based on authentication settings.
306
+ #
307
+ # @param [Hash] header_params Header parameters
308
+ # @param [Hash] query_params Query parameters
309
+ # @param [String] auth_names Authentication scheme name
310
+ def update_params_for_auth!(header_params, query_params, auth_names)
311
+ Array(auth_names).each do |auth_name|
312
+ auth_setting = @config.auth_settings[auth_name]
313
+ next unless auth_setting
314
+ case auth_setting[:in]
315
+ when 'header' then header_params[auth_setting[:key]] = auth_setting[:value]
316
+ when 'query' then query_params[auth_setting[:key]] = auth_setting[:value]
317
+ else fail ArgumentError, 'Authentication token must be in `query` or `header`'
318
+ end
319
+ end
320
+ end
321
+
322
+ # Sets user agent in HTTP header
323
+ #
324
+ # @param [String] user_agent User agent (e.g. openapi-generator/ruby/1.0.0)
325
+ def user_agent=(user_agent)
326
+ @user_agent = user_agent
327
+ @default_headers['User-Agent'] = @user_agent
328
+ end
329
+
330
+ # Return Accept header based on an array of accepts provided.
331
+ # @param [Array] accepts array for Accept
332
+ # @return [String] the Accept header (e.g. application/json)
333
+ def select_header_accept(accepts)
334
+ return nil if accepts.nil? || accepts.empty?
335
+ # use JSON when present, otherwise use all of the provided
336
+ json_accept = accepts.find { |s| json_mime?(s) }
337
+ json_accept || accepts.join(',')
338
+ end
339
+
340
+ # Return Content-Type header based on an array of content types provided.
341
+ # @param [Array] content_types array for Content-Type
342
+ # @return [String] the Content-Type header (e.g. application/json)
343
+ def select_header_content_type(content_types)
344
+ # return nil by default
345
+ return if content_types.nil? || content_types.empty?
346
+ # use JSON when present, otherwise use the first one
347
+ json_content_type = content_types.find { |s| json_mime?(s) }
348
+ json_content_type || content_types.first
349
+ end
350
+
351
+ # Convert object (array, hash, object, etc) to JSON string.
352
+ # @param [Object] model object to be converted into JSON string
353
+ # @return [String] JSON string representation of the object
354
+ def object_to_http_body(model)
355
+ return model if model.nil? || model.is_a?(String)
356
+ local_body = nil
357
+ if model.is_a?(Array)
358
+ local_body = model.map { |m| object_to_hash(m) }
359
+ else
360
+ local_body = object_to_hash(model)
361
+ end
362
+ local_body.to_json
363
+ end
364
+
365
+ # Convert object(non-array) to hash.
366
+ # @param [Object] obj object to be converted into JSON string
367
+ # @return [String] JSON string representation of the object
368
+ def object_to_hash(obj)
369
+ if obj.respond_to?(:to_hash)
370
+ obj.to_hash
371
+ else
372
+ obj
373
+ end
374
+ end
375
+
376
+ # Build parameter value according to the given collection format.
377
+ # @param [String] collection_format one of :csv, :ssv, :tsv, :pipes and :multi
378
+ def build_collection_param(param, collection_format)
379
+ case collection_format
380
+ when :csv
381
+ param.join(',')
382
+ when :ssv
383
+ param.join(' ')
384
+ when :tsv
385
+ param.join("\t")
386
+ when :pipes
387
+ param.join('|')
388
+ when :multi
389
+ # return the array directly as typhoeus will handle it as expected
390
+ param
391
+ else
392
+ fail "unknown collection format: #{collection_format.inspect}"
393
+ end
394
+ end
395
+ end
396
+ end
@@ -0,0 +1,58 @@
1
+ =begin
2
+ #Midjourney api-unofficial by Legnext.ai
3
+
4
+ ## **Legnext.ai Midjourney API: The Ultimate AI Image Generation Toolkit** Unlock the full creative potential of Midjourney directly within your applications and development workflows using the **Legnext.ai Midjourney API (Unofficial)**. This comprehensive collection offers a ready-to-integrate solution for professional image and video creation, manipulation, and high-fidelity upscaling. We provide developers with **stable, high-performance API access** to the Midjourney model. Crucially, integrating our service requires **no Midjourney account**, eliminating the hassle of managing official subscriptions or Discord interactions. Our toolkit simplifies the entire text-to-image process, supporting complex prompts, aspect ratio adjustments, and advanced style parameters. Focus on innovation while we handle the AI infrastructure. Start building scalable, visually stunning applications today with reliable access to the world’s leading generative AI model.
5
+
6
+ The version of the OpenAPI document: 1.0.0
7
+
8
+ Generated by: https://openapi-generator.tech
9
+ Generator version: 7.18.0
10
+
11
+ =end
12
+
13
+ module OpenapiClient
14
+ class ApiError < StandardError
15
+ attr_reader :code, :response_headers, :response_body
16
+
17
+ # Usage examples:
18
+ # ApiError.new
19
+ # ApiError.new("message")
20
+ # ApiError.new(:code => 500, :response_headers => {}, :response_body => "")
21
+ # ApiError.new(:code => 404, :message => "Not Found")
22
+ def initialize(arg = nil)
23
+ if arg.is_a? Hash
24
+ if arg.key?(:message) || arg.key?('message')
25
+ super(arg[:message] || arg['message'])
26
+ else
27
+ super arg
28
+ end
29
+
30
+ arg.each do |k, v|
31
+ instance_variable_set "@#{k}", v
32
+ end
33
+ else
34
+ super arg
35
+ @message = arg
36
+ end
37
+ end
38
+
39
+ # Override to_s to display a friendly error message
40
+ def to_s
41
+ message
42
+ end
43
+
44
+ def message
45
+ if @message.nil?
46
+ msg = "Error message: the server returns an error"
47
+ else
48
+ msg = @message
49
+ end
50
+
51
+ msg += "\nHTTP status code: #{code}" if code
52
+ msg += "\nResponse headers: #{response_headers}" if response_headers
53
+ msg += "\nResponse body: #{response_body}" if response_body
54
+
55
+ msg
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,88 @@
1
+ =begin
2
+ #Midjourney api-unofficial by Legnext.ai
3
+
4
+ ## **Legnext.ai Midjourney API: The Ultimate AI Image Generation Toolkit** Unlock the full creative potential of Midjourney directly within your applications and development workflows using the **Legnext.ai Midjourney API (Unofficial)**. This comprehensive collection offers a ready-to-integrate solution for professional image and video creation, manipulation, and high-fidelity upscaling. We provide developers with **stable, high-performance API access** to the Midjourney model. Crucially, integrating our service requires **no Midjourney account**, eliminating the hassle of managing official subscriptions or Discord interactions. Our toolkit simplifies the entire text-to-image process, supporting complex prompts, aspect ratio adjustments, and advanced style parameters. Focus on innovation while we handle the AI infrastructure. Start building scalable, visually stunning applications today with reliable access to the world’s leading generative AI model.
5
+
6
+ The version of the OpenAPI document: 1.0.0
7
+
8
+ Generated by: https://openapi-generator.tech
9
+ Generator version: 7.18.0
10
+
11
+ =end
12
+
13
+ module OpenapiClient
14
+ class ApiModelBase
15
+ # Deserializes the data based on type
16
+ # @param string type Data type
17
+ # @param string value Value to be deserialized
18
+ # @return [Object] Deserialized data
19
+ def self._deserialize(type, value)
20
+ case type.to_sym
21
+ when :Time
22
+ Time.parse(value)
23
+ when :Date
24
+ Date.parse(value)
25
+ when :String
26
+ value.to_s
27
+ when :Integer
28
+ value.to_i
29
+ when :Float
30
+ value.to_f
31
+ when :Boolean
32
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
33
+ true
34
+ else
35
+ false
36
+ end
37
+ when :Object
38
+ # generic object (usually a Hash), return directly
39
+ value
40
+ when /\AArray<(?<inner_type>.+)>\z/
41
+ inner_type = Regexp.last_match[:inner_type]
42
+ value.map { |v| _deserialize(inner_type, v) }
43
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
44
+ k_type = Regexp.last_match[:k_type]
45
+ v_type = Regexp.last_match[:v_type]
46
+ {}.tap do |hash|
47
+ value.each do |k, v|
48
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
49
+ end
50
+ end
51
+ else # model
52
+ # models (e.g. Pet) or oneOf
53
+ klass = OpenapiClient.const_get(type)
54
+ klass.respond_to?(:openapi_any_of) || klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value)
55
+ end
56
+ end
57
+
58
+ # Returns the string representation of the object
59
+ # @return [String] String presentation of the object
60
+ def to_s
61
+ to_hash.to_s
62
+ end
63
+
64
+ # to_body is an alias to to_hash (backward compatibility)
65
+ # @return [Hash] Returns the object in the form of hash
66
+ def to_body
67
+ to_hash
68
+ end
69
+
70
+ # Outputs non-array value in the form of hash
71
+ # For object, use to_hash. Otherwise, just return the value
72
+ # @param [Object] value Any valid value
73
+ # @return [Hash] Returns the value in the form of hash
74
+ def _to_hash(value)
75
+ if value.is_a?(Array)
76
+ value.compact.map { |v| _to_hash(v) }
77
+ elsif value.is_a?(Hash)
78
+ {}.tap do |hash|
79
+ value.each { |k, v| hash[k] = _to_hash(v) }
80
+ end
81
+ elsif value.respond_to? :to_hash
82
+ value.to_hash
83
+ else
84
+ value
85
+ end
86
+ end
87
+ end
88
+ end