Class: Dickless::Client

Inherits:
Object
  • Object
show all
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

Constructor Details

#initialize(api_key:, base_url: "https://dickless.io", default_gateway_mode: nil) ⇒ Client

Returns a new instance of Client.

Parameters:

  • api_key (String)

    Your dickless.io API key (starts with dk_).

  • base_url (String) (defaults to: "https://dickless.io")

    API base URL. Defaults to dickless.io.

  • default_gateway_mode (String, nil) (defaults to: nil)

    Optional default gateway_mode applied to every chat call (“proxy” or “dedicated”).



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.

Parameters:

  • request_hash (Hash)

    Chat request parameters. Must include :model and :messages. May include :provider, :temperature, :max_tokens, :stream, and :gateway_mode.

Returns:



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_balanceCreditBalance

Get the current credit balance for dedicated mode.

Returns:



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_transactionsArray<CreditTransaction>

Get credit transaction history.

Returns:



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.

Parameters:

  • code (String)

    The short URL code.

Returns:



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.

Parameters:

  • image (String)

    Base-64 encoded image data or a public URL.

  • format (String, nil) (defaults to: nil)

    Optional image format hint (“png”, “jpeg”, “webp”).

Returns:



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.

Parameters:

  • text (String)

    The text to moderate.

Returns:



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.

Parameters:

  • image (String)

    Base-64 encoded image data or a public URL.

  • format (String, nil) (defaults to: nil)

    Optional image format hint.

  • language (String, nil) (defaults to: nil)

    Optional language hint.

Returns:



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.

Parameters:

  • text (String)

    The text to redact.

  • entities (Array<String>, nil) (defaults to: nil)

    Optional list of entity types to target.

Returns:



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.

Parameters:

  • text (String)

    The text to roast.

  • type (String) (defaults to: "general")

    Roast type: “resume”, “landing_page”, “code”, “linkedin”, or “general”.

  • severity (String) (defaults to: "brutal")

    Roast severity: “mild”, “medium”, or “brutal”.

Returns:



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.

Parameters:

  • prompt (String)

    The prompt to analyze.

  • strict (Boolean) (defaults to: false)

    Enable strict mode for stricter detection.

Returns:



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.

Parameters:

  • url (String)

    The URL to screenshot.

  • format (String, nil) (defaults to: nil)

    Optional image format.

  • width (Integer, nil) (defaults to: nil)

    Optional viewport width.

  • height (Integer, nil) (defaults to: nil)

    Optional viewport height.

  • full_page (Boolean, nil) (defaults to: nil)

    Optional full-page capture flag.

  • wait_for (String, nil) (defaults to: nil)

    Optional CSS selector or event to wait for.

Returns:



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.

Parameters:

  • text (String)

    The text to analyze.

  • granularity (String, nil) (defaults to: nil)

    Optional granularity level.

Returns:



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.

Parameters:

  • url (String)

    The target URL to shorten.

  • custom_code (String, nil) (defaults to: nil)

    Optional custom short code.

Returns:



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.

Parameters:

  • text (String, nil) (defaults to: nil)

    Optional text to summarize.

  • url (String, nil) (defaults to: nil)

    Optional URL to summarize.

  • max_length (Integer, nil) (defaults to: nil)

    Optional maximum summary length.

  • format (String, nil) (defaults to: nil)

    Optional output format.

Returns:



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.

Parameters:

  • text (String)

    The text to translate.

  • to (String)

    Target language code.

  • from (String, nil) (defaults to: nil)

    Optional source language code.

  • model (String, nil) (defaults to: nil)

    Optional translation model.

Returns:



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.

Parameters:

  • type (String)

    The validation type.

  • value (String)

    The value to validate.

  • deep (Boolean, nil) (defaults to: nil)

    Optional deep validation flag.

Returns:



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