Class: RunApi::Recraft::Resources::RemoveBackground

Inherits:
Object
  • Object
show all
Includes:
Core::ResourceHelpers
Defined in:
lib/runapi/recraft/resources/remove_background.rb

Constant Summary collapse

ENDPOINT =
"/api/v1/recraft/remove_background"
RESPONSE_CLASS =
Types::ImageTaskResponse
COMPLETED_RESPONSE_CLASS =
Types::CompletedImageTaskResponse

Instance Method Summary collapse

Constructor Details

#initialize(http) ⇒ RemoveBackground

Returns a new instance of RemoveBackground.



14
15
16
# File 'lib/runapi/recraft/resources/remove_background.rb', line 14

def initialize(http)
  @http = http
end

Instance Method Details

#create(**params) ⇒ Object



23
24
25
26
27
# File 'lib/runapi/recraft/resources/remove_background.rb', line 23

def create(**params)
  params = compact_params(params)
  validate_params!(params)
  request(:post, ENDPOINT, body: params)
end

#get(id) ⇒ Object



29
30
31
# File 'lib/runapi/recraft/resources/remove_background.rb', line 29

def get(id)
  request(:get, "#{ENDPOINT}/#{id}")
end

#run(**params) ⇒ Object



18
19
20
21
# File 'lib/runapi/recraft/resources/remove_background.rb', line 18

def run(**params)
  task = create(**params)
  poll_until_complete { get(task.id) }
end