Class: UserapiAi::Client

Inherits:
Object
  • Object
show all
Extended by:
HTTP
Defined in:
lib/userapi/client.rb

Constant Summary collapse

SERVICES =
{
  midjourney: {
    get: [:status],
    post: [:imagine, :describe, :upscale, :upsample, :variation, :inpaint, :blend, :reroll, :zoom, :pan, :info]
  }
}

Instance Method Summary collapse

Methods included from HTTP

conn, headers, json_get, json_post, multipart_parameters, to_json, uri

Constructor Details

#initialize(access_token: nil, uri_base: nil, request_timeout: nil, service: nil, extra_headers: {}) ⇒ Client

Returns a new instance of Client.



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/userapi/client.rb', line 12

def initialize(access_token: nil, uri_base: nil, request_timeout: nil, service: nil, extra_headers: {})
  UserapiAi.configuration.access_token = access_token if access_token
  UserapiAi.configuration.uri_base = uri_base if uri_base
  UserapiAi.configuration.request_timeout = request_timeout if request_timeout
  UserapiAi.configuration.extra_headers = extra_headers
  UserapiAi.configuration.service = service if service

  SERVICES[service].each do |http_method, actions|
    actions.each do |action|
      method_name = action
      method_name = "#{http_method}_#{action}" if methods.include? method_name.to_sym
      define_singleton_method method_name.to_sym do |parameters|
        UserapiAi::Client.public_send("json_#{http_method}", path: action, parameters: parameters)
      end
    end
  end
  
end