Class: Deepgram::Read::Response

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

Overview

The Response class encapsulates the response from the Deepgram Read API, providing methods to access various parts of the response data.

Instance Method Summary collapse

Constructor Details

#initialize(status:, body:, headers:) ⇒ Response

Initializes a new Response object with the given status, body, and headers.

Parameters:

  • status (Integer)

    The HTTP status code of the response.

  • body (String)

    The body of the response, expected to be in JSON format.

  • headers (Hash)

    The HTTP headers of the response.



44
45
46
47
48
# File 'lib/deepgram/read.rb', line 44

def initialize(status:, body:, headers:)
  @status = status
  @body = body
  @headers = headers
end

Instance Method Details

#intentsArray?

Extracts and returns the intents segments from the response data.

Returns:

  • (Array, nil)

    The intents segments, if present.



88
89
90
# File 'lib/deepgram/read.rb', line 88

def intents
  raw.dig('results', 'intents', 'segments')
end

#metadataHash?

Extracts and returns the metadata from the response data.

Returns:

  • (Hash, nil)

    The metadata from the response, if present.



60
61
62
# File 'lib/deepgram/read.rb', line 60

def 
  raw['metadata']
end

#rawHash

Parses the response body as JSON and returns the raw data.

Returns:

  • (Hash)

    The parsed JSON from the response body.



53
54
55
# File 'lib/deepgram/read.rb', line 53

def raw
  JSON.parse(@body)
end

#sentimentsArray?

Extracts and returns the sentiments segments from the response data.

Returns:

  • (Array, nil)

    The sentiments segments, if present.



81
82
83
# File 'lib/deepgram/read.rb', line 81

def sentiments
  raw.dig('results', 'sentiments', 'segments')
end

#summaryString?

Extracts and returns the summary text from the response data.

Returns:

  • (String, nil)

    The summarized text, if present.



67
68
69
# File 'lib/deepgram/read.rb', line 67

def summary
  raw.dig('results', 'summary', 'text')
end

#topicsArray?

Extracts and returns the topics segments from the response data.

Returns:

  • (Array, nil)

    The topics segments, if present.



74
75
76
# File 'lib/deepgram/read.rb', line 74

def topics
  raw.dig('results', 'topics', 'segments')
end