runapi-recraft 0.2.5 → 0.2.7

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ac78d7e6f131188a636f5e2a83ffa3438ceb02d00275c558375c1000980ae43e
4
- data.tar.gz: bf40d14ed407faf3c15250c2c1778f37e5f342c904efa20374be1f8d0c80446b
3
+ metadata.gz: 477bd23affda1ef60acfcd9d9add3cbfb216c0e8fe9ecaca17bfa053077cd144
4
+ data.tar.gz: d754513ee14f79f3af3e94658994b5d5128f9775dabbbc9f57b1e75ac18a20e0
5
5
  SHA512:
6
- metadata.gz: e9cedf23b2a3730afe9a2bfeb3fa7fbc819ea2935524cbdce26e25a412f301c9c7128f63c213da60e45378339c1da35d02cf7c2568d42ac91e253370ed149960
7
- data.tar.gz: 41c554461a6c770ecacfca8536440dec5d4b671438cd56e28a0fc9f8ffb6703ec669dd642805e48e71731d8c60bfd7afd78bbcc481335601a6f141d2a6a67c36
6
+ metadata.gz: 2ef6f4ecaafd2a69e537fd2acdbabde0b2fb5623b2d12ce8dc589b196019b8626a0c3c60df77a07b32c14563f9b5dda7603d4380bcd13457013ded2463cf711a
7
+ data.tar.gz: fb15f2bd59d56d4316095e2e1e29a71e3be9fa80bc791a69d0fa8358aaacaf6eb1dc769c5b707357bccf8e2718e092d1ac6ee0a8c979c660785e91e46b204125
data/README.md CHANGED
@@ -1,8 +1,8 @@
1
- # Recraft API Ruby SDK for RunAPI
1
+ # Recraft Ruby SDK for RunAPI
2
2
 
3
- The recraft api Ruby SDK is the language-specific package for Recraft on RunAPI. Use this recraft api package for text-to-image, image editing, and creative production flows when your application needs JSON request bodies, task status lookup, and consistent RunAPI errors in Ruby.
3
+ The Recraft Ruby SDK is the language-specific package for Recraft on RunAPI. Use this package for image generation, image editing, and creative production workflows when your application needs request bodies, task status lookup, and consistent RunAPI errors in Ruby.
4
4
 
5
- This recraft api README is the Ruby package guide inside the public `recraft-sdk` repository. For the repository overview, start at `../README.md`; for model details, use https://runapi.ai/models/recraft; for API reference, use https://runapi.ai/docs#recraft; for SDK docs, use https://runapi.ai/docs#sdk-recraft.
5
+ This README is the Ruby package guide inside the public `recraft-sdk` repository. For the repository overview, start at `../README.md`; for model details, use https://runapi.ai/models/recraft; for API reference, use https://runapi.ai/docs#recraft; for SDK docs, use https://runapi.ai/docs#sdk-recraft.
6
6
 
7
7
  ## Install
8
8
 
@@ -16,17 +16,19 @@ gem install runapi-recraft
16
16
  require "runapi-recraft"
17
17
 
18
18
  client = RunApi::Recraft::Client.new
19
- task = client.upscales.create(
19
+ task = client.upscale_image.create(
20
20
  # Pass the Recraft JSON request body from https://runapi.ai/docs#recraft.
21
21
  )
22
- status = client.upscales.get(task.id)
22
+ status = client.upscale_image.get(task.id)
23
23
  ```
24
24
 
25
25
  Use `create` when you want to submit a task and return quickly, `get` when you need the latest task state, and `run` when a script should create and poll until completion. In web request handlers, prefer `create` plus webhook or later `get` polling so a worker is not held open.
26
26
 
27
+ RunAPI-generated file URLs are temporary. Download and store generated images, videos, audio, or other files in your own durable storage within 7 days; do not treat returned URLs as long-term assets.
28
+
27
29
  ## Language notes
28
30
 
29
- Use Ruby keyword arguments and the `RunApi::Recraft` error classes when building image jobs, Rails workers, or scripts. The available resources include upscales, and background removals. Keep `RUNAPI_API_KEY` in the environment or your secret manager; never commit API keys or callback secrets.
31
+ Use Ruby keyword arguments and the `RunApi::Recraft` error classes when building image jobs, Rails workers, or scripts. The available resources are `upscale_image` and `remove_background`. Keep `RUNAPI_API_KEY` in the environment or your secret manager; never commit API keys or callback secrets.
30
32
 
31
33
  ## Links
32
34
 
@@ -2,14 +2,30 @@
2
2
 
3
3
  module RunApi
4
4
  module Recraft
5
- class Client
6
- attr_reader :upscale_image, :remove_background
5
+ # Recraft image post-processing API client.
6
+ #
7
+ # Provides AI-powered image upscaling and background removal.
8
+ #
9
+ # @example
10
+ # client = RunApi::Recraft::Client.new(api_key: "your-api-key")
11
+ #
12
+ # upscaled = client.upscale_image.run(
13
+ # model: "recraft-crisp-upscale",
14
+ # source_image_url: "https://cdn.runapi.ai/public/samples/image.jpg"
15
+ # )
16
+ #
17
+ # cutout = client.remove_background.run(
18
+ # model: "recraft-remove-background",
19
+ # source_image_url: "https://cdn.runapi.ai/public/samples/image.jpg"
20
+ # )
21
+ class Client < RunApi::Core::Client
22
+ # @return [Resources::UpscaleImage] AI-powered image upscaling operations.
23
+ attr_reader :upscale_image
24
+ # @return [Resources::RemoveBackground] Background removal operations.
25
+ attr_reader :remove_background
7
26
 
8
27
  def initialize(api_key: nil, **options)
9
- @api_key = Core::Auth.resolve_api_key(api_key)
10
-
11
- client_options = Core::ClientOptions.new(api_key: @api_key, **options)
12
- http = client_options.http_client || Core::HttpClient.new(client_options)
28
+ super
13
29
  @upscale_image = Resources::UpscaleImage.new(http)
14
30
  @remove_background = Resources::RemoveBackground.new(http)
15
31
  end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RunApi
4
+ module Recraft
5
+ CONTRACT = {
6
+ "remove-background" => {
7
+ "models" => ["recraft-remove-background"],
8
+ "fields_by_model" => {
9
+ "recraft-remove-background" => {
10
+ "source_image_url" => {
11
+ "required" => true
12
+ }
13
+ }
14
+ }
15
+ },
16
+ "upscale-image" => {
17
+ "models" => ["recraft-crisp-upscale"],
18
+ "fields_by_model" => {
19
+ "recraft-crisp-upscale" => {
20
+ "source_image_url" => {
21
+ "required" => true
22
+ }
23
+ }
24
+ }
25
+ }
26
+ }.freeze
27
+ end
28
+ end
@@ -3,6 +3,8 @@
3
3
  module RunApi
4
4
  module Recraft
5
5
  module Resources
6
+ # Background removal resource.
7
+ # Produces a transparent cutout by removing the image background.
6
8
  class RemoveBackground
7
9
  include RunApi::Core::ResourceHelpers
8
10
 
@@ -22,25 +24,13 @@ module RunApi
22
24
 
23
25
  def create(**params)
24
26
  params = compact_params(params)
25
- validate_params!(params)
27
+ validate_contract!(CONTRACT["remove-background"], params)
26
28
  request(:post, ENDPOINT, body: params)
27
29
  end
28
30
 
29
31
  def get(id)
30
32
  request(:get, "#{ENDPOINT}/#{id}")
31
33
  end
32
-
33
- private
34
-
35
- def validate_params!(params)
36
- raise Core::ValidationError, "model is required" unless param(params, :model)
37
- raise Core::ValidationError, "source_image_url is required" unless param(params, :source_image_url)
38
-
39
- model = param(params, :model)
40
- unless Types::REMOVE_BACKGROUND_MODELS.include?(model)
41
- raise Core::ValidationError, "Invalid model: #{model}. Must be one of: #{Types::REMOVE_BACKGROUND_MODELS.join(", ")}"
42
- end
43
- end
44
34
  end
45
35
  end
46
36
  end
@@ -3,6 +3,8 @@
3
3
  module RunApi
4
4
  module Recraft
5
5
  module Resources
6
+ # AI-powered image upscaling resource.
7
+ # Enhance image resolution while preserving detail.
6
8
  class UpscaleImage
7
9
  include RunApi::Core::ResourceHelpers
8
10
 
@@ -22,25 +24,13 @@ module RunApi
22
24
 
23
25
  def create(**params)
24
26
  params = compact_params(params)
25
- validate_params!(params)
27
+ validate_contract!(CONTRACT["upscale-image"], params)
26
28
  request(:post, ENDPOINT, body: params)
27
29
  end
28
30
 
29
31
  def get(id)
30
32
  request(:get, "#{ENDPOINT}/#{id}")
31
33
  end
32
-
33
- private
34
-
35
- def validate_params!(params)
36
- raise Core::ValidationError, "model is required" unless param(params, :model)
37
- raise Core::ValidationError, "source_image_url is required" unless param(params, :source_image_url)
38
-
39
- model = param(params, :model)
40
- unless Types::UPSCALE_IMAGE_MODELS.include?(model)
41
- raise Core::ValidationError, "Invalid model: #{model}. Must be one of: #{Types::UPSCALE_IMAGE_MODELS.join(", ")}"
42
- end
43
- end
44
34
  end
45
35
  end
46
36
  end
@@ -2,14 +2,14 @@
2
2
 
3
3
  module RunApi
4
4
  module Recraft
5
+ # Type definitions and constants for the Recraft image processing API.
5
6
  module Types
6
- UPSCALE_IMAGE_MODELS = %w[recraft-crisp-upscale].freeze
7
- REMOVE_BACKGROUND_MODELS = %w[recraft-remove-background].freeze
8
-
7
+ # URL to a processed image (upscaled or background-removed).
9
8
  class Image < RunApi::Core::BaseModel
10
9
  optional :url, String
11
10
  end
12
11
 
12
+ # Async image task result shared by upscale and background removal operations.
13
13
  class ImageTaskResponse < RunApi::Core::TaskResponse
14
14
  required :id, String
15
15
  optional :status, String, enum: -> { RunApi::Core::TaskResponse::Status::ALL }
@@ -17,6 +17,8 @@ module RunApi
17
17
  optional :error, String
18
18
  end
19
19
 
20
+ # Narrowed response returned by +run+ once polling confirms completion.
21
+ # Images are guaranteed present.
20
22
  class CompletedImageTaskResponse < ImageTaskResponse
21
23
  required :images, [-> { Image }]
22
24
  end
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative "recraft/types"
4
+ require_relative "recraft/contract_gen"
4
5
  require_relative "recraft/resources/upscale_image"
5
6
  require_relative "recraft/resources/remove_background"
6
7
  require_relative "recraft/client"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: runapi-recraft
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.5
4
+ version: 0.2.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - RunAPI
@@ -15,18 +15,18 @@ dependencies:
15
15
  requirements:
16
16
  - - "~>"
17
17
  - !ruby/object:Gem::Version
18
- version: 0.2.5
18
+ version: 0.2.7
19
19
  type: :runtime
20
20
  prerelease: false
21
21
  version_requirements: !ruby/object:Gem::Requirement
22
22
  requirements:
23
23
  - - "~>"
24
24
  - !ruby/object:Gem::Version
25
- version: 0.2.5
26
- description: The recraft api Ruby SDK is the language-specific package for Recraft
27
- on RunAPI. Use this recraft api package for text-to-image, image editing, and creative
28
- production flows when your application needs JSON request bodies, task status lookup,
29
- and consistent RunAPI errors in Ruby.
25
+ version: 0.2.7
26
+ description: The Recraft Ruby SDK is the language-specific package for Recraft on
27
+ RunAPI. Use this package for image generation, image editing, and creative production
28
+ workflows when your application needs request bodies, task status lookup, and consistent
29
+ RunAPI errors in Ruby.
30
30
  email:
31
31
  - contact@runapi.ai
32
32
  executables: []
@@ -39,6 +39,7 @@ files:
39
39
  - lib/runapi-recraft.rb
40
40
  - lib/runapi/recraft.rb
41
41
  - lib/runapi/recraft/client.rb
42
+ - lib/runapi/recraft/contract_gen.rb
42
43
  - lib/runapi/recraft/resources/remove_background.rb
43
44
  - lib/runapi/recraft/resources/upscale_image.rb
44
45
  - lib/runapi/recraft/types.rb
@@ -46,9 +47,11 @@ homepage: https://runapi.ai/models/recraft
46
47
  licenses:
47
48
  - Apache-2.0
48
49
  metadata:
50
+ runapi_slug: recraft
49
51
  homepage_uri: https://runapi.ai/models/recraft
50
52
  documentation_uri: https://github.com/runapi-ai/recraft-sdk/blob/main/ruby/README.md
51
53
  source_code_uri: https://github.com/runapi-ai/recraft-sdk
54
+ bug_tracker_uri: https://github.com/runapi-ai/recraft-sdk/issues
52
55
  changelog_uri: https://github.com/runapi-ai/recraft-sdk/blob/main/CHANGELOG.md
53
56
  rdoc_options: []
54
57
  require_paths:
@@ -66,5 +69,5 @@ required_rubygems_version: !ruby/object:Gem::Requirement
66
69
  requirements: []
67
70
  rubygems_version: 4.0.10
68
71
  specification_version: 4
69
- summary: Recraft API Ruby SDK for RunAPI
72
+ summary: Recraft Ruby SDK for RunAPI
70
73
  test_files: []