Class: Deepgram::Listen::Response
- Inherits:
-
Object
- Object
- Deepgram::Listen::Response
- Defined in:
- lib/deepgram/listen.rb
Overview
The Response class encapsulates the response from the Deepgram Listen API, providing methods to access various parts of the response data.
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
Instance Method Summary collapse
-
#confidence ⇒ Float?
Extracts and returns the confidence score from the first channel and alternative in the response data.
-
#initialize(status:, body:, headers:) ⇒ Response
constructor
Initializes a new Response object with the given status, body, and headers.
-
#metadata ⇒ Hash?
Extracts and returns the metadata from the response data.
-
#raw ⇒ Hash
Parses the response body as JSON and returns the raw data.
-
#transcript ⇒ String?
Extracts and returns the transcript text from the first channel and alternative in the response data.
-
#words ⇒ Array?
Extracts and returns the words array from the first channel and alternative in the response data.
Constructor Details
#initialize(status:, body:, headers:) ⇒ Response
Initializes a new Response object with the given status, body, and headers.
85 86 87 88 89 |
# File 'lib/deepgram/listen.rb', line 85 def initialize(status:, body:, headers:) @status = status @body = body @headers = headers end |
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
78 79 80 |
# File 'lib/deepgram/listen.rb', line 78 def body @body end |
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
78 79 80 |
# File 'lib/deepgram/listen.rb', line 78 def headers @headers end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
78 79 80 |
# File 'lib/deepgram/listen.rb', line 78 def status @status end |
Instance Method Details
#confidence ⇒ Float?
Extracts and returns the confidence score from the first channel and alternative in the response data.
115 116 117 |
# File 'lib/deepgram/listen.rb', line 115 def confidence raw.dig('results', 'channels', 0, 'alternatives', 0, 'confidence') end |
#metadata ⇒ Hash?
Extracts and returns the metadata from the response data.
94 95 96 |
# File 'lib/deepgram/listen.rb', line 94 def raw['metadata'] end |
#raw ⇒ Hash
Parses the response body as JSON and returns the raw data.
122 123 124 |
# File 'lib/deepgram/listen.rb', line 122 def raw JSON.parse(@body) end |
#transcript ⇒ String?
Extracts and returns the transcript text from the first channel and alternative in the response data.
101 102 103 |
# File 'lib/deepgram/listen.rb', line 101 def transcript raw.dig('results', 'channels', 0, 'alternatives', 0, 'transcript') end |
#words ⇒ Array?
Extracts and returns the words array from the first channel and alternative in the response data.
108 109 110 |
# File 'lib/deepgram/listen.rb', line 108 def words raw.dig('results', 'channels', 0, 'alternatives', 0, 'words') end |