Skip to content

Commit c3ce0d4

Browse files
committed
More changes for extensions.
1 parent dec9cc0 commit c3ce0d4

File tree

3 files changed

+36
-14
lines changed

3 files changed

+36
-14
lines changed

DOCUMENTATION.md

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -766,10 +766,6 @@ module. Custom engines must implement the `generate` method:
766766
module ScreenKit
767767
module TTS
768768
class CustomEngine < Base
769-
# If you're using shell commands, you can include Shell,
770-
# which provides helper methods.
771-
# extend Shell
772-
773769
# Optional: Define schema path for validation
774770
def self.schema_path
775771
File.join(__dir__, "yourschema.json")
@@ -801,20 +797,18 @@ module ScreenKit
801797
# Write output to output_path
802798
# Optionally log to log_path
803799

804-
# Example implementation calling a command:
800+
# Example calling a command (provided by ScreenKit::Shell)
805801
# self.class.run_command "some-command",
806802
# "-o", output_path.sub_ext(".wav"),
807803
# text,
808804
# log_path:
809805

810-
# Example implementation using an API:
811-
# response = Aitch.post(
806+
# Example using an API (provided by ScreenKit::HTTP)
807+
# response = json_post(
812808
# url: "https://api.example.com/tts",
813-
# headers: {
814-
# content_type: "application/json",
815-
# authorization: "Bearer #{api_key}"
816-
# },
817-
# options: {expect: 200}
809+
# headers: {authorization: "Bearer #{api_key}"},
810+
# api_key:,
811+
# log_path:
818812
# )
819813
end
820814
end
@@ -842,6 +836,7 @@ The engine name is camelized (e.g., `custom_engine` → `CustomEngine`,
842836

843837
- [Search Github](https://github.com/topics/screenkit-tts)
844838
- [Google Text to Speech](https://github.com/fnando/screenkit-tts-google)
839+
- [Minimax Text to Speech](https://github.com/fnando/screenkit-tts-minimax)
845840

846841
> [!TIP]
847842
>

lib/screenkit/http.rb

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22

33
module ScreenKit
44
module HTTP
5+
# Sends a POST request.
6+
# @param url [String] The request URL.
7+
# @param params [Hash] The request parameters.
8+
# @param headers [Hash] The request headers.
9+
# @param api_key [String] The API key to redact from logs.
10+
# @param log_path [String, nil] The path to log the request details.
11+
# @return [Aitch::Response] The response.
512
def post(url:, params:, headers:, api_key:, log_path: nil)
613
if log_path
714
File.open(log_path, "w") do |f|
@@ -16,19 +23,30 @@ def post(url:, params:, headers:, api_key:, log_path: nil)
1623

1724
client.post(
1825
url:,
19-
body: params,
26+
params:,
2027
options: {expect: 200},
2128
headers: headers.merge(user_agent: "ScreenKit/#{ScreenKit::VERSION}")
2229
)
2330
ensure
2431
redact_file(log_path, api_key)
2532
end
2633

34+
# Sends a JSON POST request.
35+
# @param url [String] The request URL.
36+
# @param params [Hash] The request parameters.
37+
# @param headers [Hash] The request headers.
38+
# @param api_key [String] The API key to redact from logs.
39+
# @param log_path [String, nil] The path to log the request details.
40+
# @return [Aitch::Response] The response.
2741
def json_post(headers:, **)
2842
headers = headers.merge(content_type: "application/json")
2943
post(headers:, **)
3044
end
3145

46+
# Redacts sensitive text from a file.
47+
# @param path [String] The file path.
48+
# @param text [String] The text to redact.
49+
# @return [void]
3250
def redact_file(path, text)
3351
return unless path
3452
return unless File.file?(path)

lib/screenkit/tts/base.rb

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,21 @@
11
# frozen_string_literal: true
22

3+
require "json-schema"
4+
require "aitch"
5+
require "logger"
6+
37
module ScreenKit
48
module TTS
59
class Base
6-
require_relative "../core_ext"
710
require_relative "../schema_validator"
11+
require_relative "../shell"
12+
require_relative "../http"
13+
require_relative "../core_ext"
14+
require_relative "../version"
815

916
extend SchemaValidator
17+
extend Shell
18+
include HTTP
1019

1120
using CoreExt
1221

0 commit comments

Comments
 (0)