Class: Deepgram::Speak::Response

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

Overview

The Response class encapsulates the response from the Deepgram Speak 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 contain the speech file or request details.

  • headers (Hash)

    The HTTP headers of the response.



62
63
64
65
66
# File 'lib/deepgram/speak.rb', line 62

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

Instance Method Details

#fileString

Returns the body of the response, which contains the speech file in asynchronous requests.

Returns:

  • (String)

    The body of the response.



85
86
87
# File 'lib/deepgram/speak.rb', line 85

def file
  @body
end

#rawHash

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

Returns:

  • (Hash)

    The parsed JSON from the response body.



71
72
73
# File 'lib/deepgram/speak.rb', line 71

def raw
  JSON.parse(@body)
end

#request_idString?

Extracts and returns the request ID from the response data.

Returns:

  • (String, nil)

    The request ID, if present.



78
79
80
# File 'lib/deepgram/speak.rb', line 78

def request_id
  raw['request_id']
end