Class: Skald
- Inherits:
-
Object
- Object
- Skald
- Defined in:
- lib/skald.rb
Overview
Skald Ruby SDK
A Ruby client library for interacting with the Skald API platform. Provides methods for managing memos, searching, chatting, and generating documents.
Constant Summary collapse
- DEFAULT_BASE_URL =
Base URL for the Skald API
"https://api.useskald.com"
Instance Attribute Summary collapse
-
#api_key ⇒ String
readonly
The API key used for authentication.
-
#base_url ⇒ String
readonly
The base URL for API requests.
Instance Method Summary collapse
-
#chat(chat_params) ⇒ Hash
Chat with your memos (non-streaming).
-
#create_memo(memo_data) ⇒ Hash
Create a new memo.
-
#delete_memo(memo_id, id_type = "memo_uuid") ⇒ nil
Delete a memo.
-
#generate_doc(generate_params) ⇒ Hash
Generate a document (non-streaming).
-
#get_memo(memo_id, id_type = "memo_uuid") ⇒ Hash
Get a memo by ID.
-
#initialize(api_key, base_url = DEFAULT_BASE_URL) ⇒ Skald
constructor
Initialize a new Skald client.
-
#list_memos(params = {}) ⇒ Hash
List memos with pagination.
-
#search(search_params) ⇒ Hash
Search for memos.
-
#streamed_chat(chat_params) ⇒ Enumerator
Chat with your memos (streaming).
-
#streamed_generate_doc(generate_params) ⇒ Enumerator
Generate a document (streaming).
-
#update_memo(memo_id, update_data, id_type = "memo_uuid") ⇒ Hash
Update an existing memo.
Constructor Details
#initialize(api_key, base_url = DEFAULT_BASE_URL) ⇒ Skald
Initialize a new Skald client
31 32 33 34 35 36 |
# File 'lib/skald.rb', line 31 def initialize(api_key, base_url = DEFAULT_BASE_URL) raise ArgumentError, "API key is required" if api_key.nil? || api_key.empty? @api_key = api_key @base_url = base_url.gsub(%r{/+$}, "") # Remove trailing slashes end |
Instance Attribute Details
#api_key ⇒ String (readonly)
Returns the API key used for authentication.
17 18 19 |
# File 'lib/skald.rb', line 17 def api_key @api_key end |
#base_url ⇒ String (readonly)
Returns the base URL for API requests.
20 21 22 |
# File 'lib/skald.rb', line 20 def base_url @base_url end |
Instance Method Details
#chat(chat_params) ⇒ Hash
Chat with your memos (non-streaming)
176 177 178 179 180 |
# File 'lib/skald.rb', line 176 def chat(chat_params) params = chat_params.dup params[:stream] = false request(:post, "/api/v1/chat", params) end |
#create_memo(memo_data) ⇒ Hash
Create a new memo
58 59 60 61 62 63 |
# File 'lib/skald.rb', line 58 def create_memo(memo_data) data = memo_data.dup data[:metadata] ||= {} request(:post, "/api/v1/memo", data) end |
#delete_memo(memo_id, id_type = "memo_uuid") ⇒ nil
Delete a memo
138 139 140 141 142 143 |
# File 'lib/skald.rb', line 138 def delete_memo(memo_id, id_type = "memo_uuid") encoded_id = CGI.escape(memo_id) params = id_type != "memo_uuid" ? "?id_type=#{id_type}" : "" request(:delete, "/api/v1/memo/#{encoded_id}#{params}") nil end |
#generate_doc(generate_params) ⇒ Hash
Generate a document (non-streaming)
219 220 221 222 223 |
# File 'lib/skald.rb', line 219 def generate_doc(generate_params) params = generate_params.dup params[:stream] = false request(:post, "/api/v1/generate", params) end |
#get_memo(memo_id, id_type = "memo_uuid") ⇒ Hash
Get a memo by ID
76 77 78 79 80 |
# File 'lib/skald.rb', line 76 def get_memo(memo_id, id_type = "memo_uuid") encoded_id = CGI.escape(memo_id) params = id_type != "memo_uuid" ? "?id_type=#{id_type}" : "" request(:get, "/api/v1/memo/#{encoded_id}#{params}") end |
#list_memos(params = {}) ⇒ Hash
List memos with pagination
95 96 97 98 99 100 101 102 |
# File 'lib/skald.rb', line 95 def list_memos(params = {}) query_params = [] query_params << "page=#{params[:page]}" if params[:page] query_params << "page_size=#{params[:page_size]}" if params[:page_size] query_string = query_params.empty? ? "" : "?#{query_params.join('&')}" request(:get, "/api/v1/memo#{query_string}") end |
#search(search_params) ⇒ Hash
Search for memos
161 162 163 |
# File 'lib/skald.rb', line 161 def search(search_params) request(:post, "/api/v1/search", search_params) end |
#streamed_chat(chat_params) ⇒ Enumerator
Chat with your memos (streaming)
198 199 200 201 202 |
# File 'lib/skald.rb', line 198 def streamed_chat(chat_params) params = chat_params.dup params[:stream] = true stream_request(:post, "/api/v1/chat", params) end |
#streamed_generate_doc(generate_params) ⇒ Enumerator
Generate a document (streaming)
242 243 244 245 246 |
# File 'lib/skald.rb', line 242 def streamed_generate_doc(generate_params) params = generate_params.dup params[:stream] = true stream_request(:post, "/api/v1/generate", params) end |
#update_memo(memo_id, update_data, id_type = "memo_uuid") ⇒ Hash
Update an existing memo
123 124 125 126 127 |
# File 'lib/skald.rb', line 123 def update_memo(memo_id, update_data, id_type = "memo_uuid") encoded_id = CGI.escape(memo_id) params = id_type != "memo_uuid" ? "?id_type=#{id_type}" : "" request(:patch, "/api/v1/memo/#{encoded_id}#{params}", update_data) end |