Class: RemoveBg::ApiClient

Inherits:
Object
  • Object
show all
Includes:
Api
Defined in:
lib/remove_bg/api_client.rb

Constant Summary

Constants included from Api

RemoveBg::Api::URL

Instance Method Summary collapse

Constructor Details

#initialize(connection: RemoveBg::HttpConnection.build) ⇒ ApiClient

Returns a new instance of ApiClient.

Parameters:

  • connection (Faraday::Connection) (defaults to: RemoveBg::HttpConnection.build)


23
24
25
# File 'lib/remove_bg/api_client.rb', line 23

def initialize(connection: RemoveBg::HttpConnection.build)
  @connection = connection
end

Instance Method Details

#account_info(options) ⇒ RemoveBg::AccountInfo

Fetches account information

Parameters:

Returns:

Raises:



55
56
57
# File 'lib/remove_bg/api_client.rb', line 55

def (options)
  (options.api_key)
end

#remove_from_file(image_path, options) ⇒ RemoveBg::Result|RemoveBg::CompositeResult

Removes the background from an image on the local file system

Parameters:

Returns:

Raises:



33
34
35
36
# File 'lib/remove_bg/api_client.rb', line 33

def remove_from_file(image_path, options)
  data = options.data.merge(image_file: Upload.for_file(image_path))
  request_remove_bg(data, options.api_key)
end

#remove_from_url(image_url, options) ⇒ RemoveBg::Result|RemoveBg::CompositeResult

Removes the background from the image at the URL specified

Parameters:

Returns:

Raises:



44
45
46
47
48
# File 'lib/remove_bg/api_client.rb', line 44

def remove_from_url(image_url, options)
  RemoveBg::UrlValidator.validate(image_url)
  data = options.data.merge(image_url:)
  request_remove_bg(data, options.api_key)
end