Class: Deepgram::Base
- Inherits:
-
Object
- Object
- Deepgram::Base
- Includes:
- ResponseHandler
- Defined in:
- lib/deepgram/base.rb
Overview
The Base class initializes the Faraday connection to interact with the Deepgram API and provides a generic request method for its subclasses.
Direct Known Subclasses
Listen::Client, Management::Client, Read::Client, Speak::Client
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Base
constructor
Initializes a Faraday connection to the Deepgram API.
-
#request(method, path = nil, **kwargs) {|request| ... } ⇒ Faraday::Response
Sends an HTTP request to the specified path using the initialized Faraday connection.
Methods included from ResponseHandler
Constructor Details
#initialize(options = {}) ⇒ Base
Initializes a Faraday connection to the Deepgram API. The API endpoint and authorization token are set via environment variables, with defaults provided.
16 17 18 19 20 |
# File 'lib/deepgram/base.rb', line 16 def initialize( = {}) @connection = Faraday.new(url: ENV.fetch('DEEPGRAM_URL', 'https://api.deepgram.com')) @connection.headers['Authorization'] = "Token #{ENV.fetch('DEEPGRAM_API_KEY', 'api-key')}" @options = end |
Instance Method Details
#request(method, path = nil, **kwargs) {|request| ... } ⇒ Faraday::Response
Sends an HTTP request to the specified path using the initialized Faraday connection. This method is designed to be flexible, allowing any HTTP method to be used.
30 31 32 33 34 35 36 37 |
# File 'lib/deepgram/base.rb', line 30 def request(method, path = nil, **kwargs) res = @connection.send(method, path, **kwargs) do |request| yield(request) if block_given? request.params.merge!(kwargs) end handle_response(res) end |