Class: Dickless::Client
- Inherits:
-
Object
- Object
- Dickless::Client
- Defined in:
- lib/dickless/client.rb
Overview
Main client for the dickless.io REST API.
client = Dickless::Client.new(api_key: "dk_live_...")
result = client.moderate_text("hello world")
Instance Method Summary collapse
-
#chat(request_hash) ⇒ ChatResponse
Send a chat completion request through the unified AI gateway.
-
#get_credit_balance ⇒ CreditBalance
Get the current credit balance for dedicated mode.
-
#get_credit_transactions ⇒ Array<CreditTransaction>
Get credit transaction history.
-
#get_short_url_stats(code) ⇒ ShortUrlStats
Get click analytics for a short URL.
-
#initialize(api_key:, base_url: "https://dickless.io", default_gateway_mode: nil) ⇒ Client
constructor
A new instance of Client.
-
#moderate_image(image, format: nil) ⇒ ModerateResponse
Analyze an image for NSFW content.
-
#moderate_text(text) ⇒ ModerateResponse
Analyze text for toxicity, hate speech, violence, and other harmful content.
-
#ocr(image, format: nil, language: nil) ⇒ OcrResponse
Extract text from an image using OCR.
-
#redact(text, entities: nil) ⇒ RedactResponse
Strip personally identifiable information from text.
-
#roast(text, type: "general", severity: "brutal") ⇒ RoastResponse
Generate an AI roast for text content.
-
#sanitize(prompt, strict: false) ⇒ SanitizeResponse
Detect and neutralize prompt injection attacks.
-
#screenshot(url, format: nil, width: nil, height: nil, full_page: nil, wait_for: nil) ⇒ ScreenshotResponse
Capture a screenshot of a web page.
-
#sentiment(text, granularity: nil) ⇒ SentimentResponse
Analyze the sentiment of text.
-
#shorten(url, custom_code: nil) ⇒ ShortenResponse
Create a short URL with an optional QR code.
-
#summarize(text: nil, url: nil, max_length: nil, format: nil) ⇒ SummarizeResponse
Summarize text or a web page.
-
#translate(text, to:, from: nil, model: nil) ⇒ TranslateResponse
Translate text to a target language.
-
#validate(type, value, deep: nil) ⇒ ValidateResponse
Validate a value against a given type.
Constructor Details
#initialize(api_key:, base_url: "https://dickless.io", default_gateway_mode: nil) ⇒ Client
Returns a new instance of Client.
18 19 20 21 22 |
# File 'lib/dickless/client.rb', line 18 def initialize(api_key:, base_url: "https://dickless.io", default_gateway_mode: nil) @api_key = api_key @base_url = base_url.chomp("/") @default_gateway_mode = default_gateway_mode end |
Instance Method Details
#chat(request_hash) ⇒ ChatResponse
Send a chat completion request through the unified AI gateway.
69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/dickless/client.rb', line 69 def chat(request_hash) payload = symbolize_keys(request_hash) # Apply default gateway mode when the caller hasn't specified one. if @default_gateway_mode && !payload.key?(:gateway_mode) payload[:gateway_mode] = @default_gateway_mode end data = request(:post, "/api/v1/ai/chat", body: payload) ChatResponse.from_hash(data) end |
#get_credit_balance ⇒ CreditBalance
Get the current credit balance for dedicated mode.
84 85 86 87 |
# File 'lib/dickless/client.rb', line 84 def get_credit_balance data = request(:get, "/api/v1/ai/manage/credits/balance") CreditBalance.from_hash(data) end |
#get_credit_transactions ⇒ Array<CreditTransaction>
Get credit transaction history.
92 93 94 95 |
# File 'lib/dickless/client.rb', line 92 def get_credit_transactions data = request(:get, "/api/v1/ai/manage/credits/transactions") data.map { |t| CreditTransaction.from_hash(t) } end |
#get_short_url_stats(code) ⇒ ShortUrlStats
Get click analytics for a short URL.
129 130 131 132 |
# File 'lib/dickless/client.rb', line 129 def get_short_url_stats(code) data = request(:get, "/api/v1/shorten/#{code}/stats") ShortUrlStats.from_hash(data) end |
#moderate_image(image, format: nil) ⇒ ModerateResponse
Analyze an image for NSFW content.
40 41 42 43 44 45 |
# File 'lib/dickless/client.rb', line 40 def moderate_image(image, format: nil) payload = { image: image } payload[:format] = format if format data = request(:post, "/api/v1/moderate/image", body: payload) ModerateResponse.from_hash(data) end |
#moderate_text(text) ⇒ ModerateResponse
Analyze text for toxicity, hate speech, violence, and other harmful content.
30 31 32 33 |
# File 'lib/dickless/client.rb', line 30 def moderate_text(text) data = request(:post, "/api/v1/moderate/text", body: { text: text }) ModerateResponse.from_hash(data) end |
#ocr(image, format: nil, language: nil) ⇒ OcrResponse
Extract text from an image using OCR.
175 176 177 178 179 180 181 |
# File 'lib/dickless/client.rb', line 175 def ocr(image, format: nil, language: nil) payload = { image: image } payload[:format] = format if format payload[:language] = language if language data = request(:post, "/api/v1/ocr", body: payload) OcrResponse.from_hash(data) end |
#redact(text, entities: nil) ⇒ RedactResponse
Strip personally identifiable information from text.
54 55 56 57 58 59 |
# File 'lib/dickless/client.rb', line 54 def redact(text, entities: nil) payload = { text: text } payload[:entities] = entities if entities data = request(:post, "/api/v1/redact", body: payload) RedactResponse.from_hash(data) end |
#roast(text, type: "general", severity: "brutal") ⇒ RoastResponse
Generate an AI roast for text content.
143 144 145 146 147 148 149 150 |
# File 'lib/dickless/client.rb', line 143 def roast(text, type: "general", severity: "brutal") data = request(:post, "/api/v1/roast", body: { text: text, type: type, severity: severity }) RoastResponse.from_hash(data) end |
#sanitize(prompt, strict: false) ⇒ SanitizeResponse
Detect and neutralize prompt injection attacks.
104 105 106 107 108 109 |
# File 'lib/dickless/client.rb', line 104 def sanitize(prompt, strict: false) payload = { prompt: prompt } payload[:strict] = strict if strict data = request(:post, "/api/v1/sanitize", body: payload) SanitizeResponse.from_hash(data) end |
#screenshot(url, format: nil, width: nil, height: nil, full_page: nil, wait_for: nil) ⇒ ScreenshotResponse
Capture a screenshot of a web page.
211 212 213 214 215 216 217 218 219 220 |
# File 'lib/dickless/client.rb', line 211 def screenshot(url, format: nil, width: nil, height: nil, full_page: nil, wait_for: nil) payload = { url: url } payload[:format] = format if format payload[:width] = width if width payload[:height] = height if height payload[:fullPage] = full_page unless full_page.nil? payload[:waitFor] = wait_for if wait_for data = request(:post, "/api/v1/screenshot", body: payload) ScreenshotResponse.from_hash(data) end |
#sentiment(text, granularity: nil) ⇒ SentimentResponse
Analyze the sentiment of text.
229 230 231 232 233 234 |
# File 'lib/dickless/client.rb', line 229 def sentiment(text, granularity: nil) payload = { text: text } payload[:granularity] = granularity if granularity data = request(:post, "/api/v1/sentiment", body: payload) SentimentResponse.from_hash(data) end |
#shorten(url, custom_code: nil) ⇒ ShortenResponse
Create a short URL with an optional QR code.
118 119 120 121 122 123 |
# File 'lib/dickless/client.rb', line 118 def shorten(url, custom_code: nil) payload = { url: url } payload[:customCode] = custom_code if custom_code data = request(:post, "/api/v1/shorten", body: payload) ShortenResponse.from_hash(data) end |
#summarize(text: nil, url: nil, max_length: nil, format: nil) ⇒ SummarizeResponse
Summarize text or a web page.
245 246 247 248 249 250 251 252 253 |
# File 'lib/dickless/client.rb', line 245 def summarize(text: nil, url: nil, max_length: nil, format: nil) payload = {} payload[:text] = text if text payload[:url] = url if url payload[:maxLength] = max_length if max_length payload[:format] = format if format data = request(:post, "/api/v1/summarize", body: payload) SummarizeResponse.from_hash(data) end |
#translate(text, to:, from: nil, model: nil) ⇒ TranslateResponse
Translate text to a target language.
192 193 194 195 196 197 198 |
# File 'lib/dickless/client.rb', line 192 def translate(text, to:, from: nil, model: nil) payload = { text: text, to: to } payload[:from] = binding.local_variable_get(:from) if binding.local_variable_get(:from) payload[:model] = model if model data = request(:post, "/api/v1/translate", body: payload) TranslateResponse.from_hash(data) end |
#validate(type, value, deep: nil) ⇒ ValidateResponse
Validate a value against a given type.
160 161 162 163 164 165 |
# File 'lib/dickless/client.rb', line 160 def validate(type, value, deep: nil) payload = { type: type, value: value } payload[:deep] = deep unless deep.nil? data = request(:post, "/api/v1/validate", body: payload) ValidateResponse.from_hash(data) end |