Class: Deepgram::Read::Client

Inherits:
Base
  • Object
show all
Defined in:
lib/deepgram/read.rb

Overview

The Client class extends the Base class to handle read operations specific to the Deepgram ‘Read’ API endpoint.

Instance Method Summary collapse

Methods inherited from Base

#request

Methods included from Deepgram::ResponseHandler

#handle_response

Constructor Details

#initialize(language = 'en') ⇒ Client

Initializes a Client object for the Deepgram ‘Read’ service. Sets the default language and appropriate headers for JSON requests.

Parameters:

  • language (String) (defaults to: 'en')

    The default language to use for analysis (defaults to ‘en’).



14
15
16
17
18
19
# File 'lib/deepgram/read.rb', line 14

def initialize(language = 'en')
  super()
  @connection.path_prefix = 'v1/read'
  @connection.params[:language] = language
  @connection.headers['Content-Type'] = 'application/json'
end

Instance Method Details

#analyze(text:, **kwargs) ⇒ Deepgram::Read::Response

Sends a POST request to analyze text using the Deepgram Read API. Returns a Response object containing the analysis results.

Parameters:

  • text (String)

    The text to be analyzed.

  • kwargs (Hash)

    Additional keyword arguments to be sent with the request.

Returns:



27
28
29
30
31
32
33
# File 'lib/deepgram/read.rb', line 27

def analyze(text:, **kwargs)
  res = request(:post, **kwargs) do |request|
    request.body = JSON.generate(text: text)
  end

  Response.new(status: res.status, body: res.body, headers: res.headers)
end