deepgram 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f5fc13bf4ebba6ff0f05315233f883576d9b0529548f75f9d07be96ae54ee7d4
4
- data.tar.gz: cf5f6cf578576aa73ad5381d0df8319542706a0748228c858d22d3eff64df414
3
+ metadata.gz: 817aa3c44284b3c8bb2811a28f35b5fbf5d8f79e61b0c4ee3ff451fc3b9f50a0
4
+ data.tar.gz: cc596493ee0d80717af4d7cbb7f3f3c5420948c53eb0b2838cb50405986673a1
5
5
  SHA512:
6
- metadata.gz: 1df3f021dc572844968d36222605bc2faa83b6dfb55c5a869ca44124085a97131f018ca000f982e2f093639bae0700ea10f6aefa6a03d161ccba36b2e3a6f738
7
- data.tar.gz: ee8b6b2180cfeee3b5ecbe4c0c34aa4f81a5fb8e2dc0b44c680b12360be8357eabc8f138a7d9440f1d26a333ab8ef8d4317bd49f1b8ee30eb37ddfdfa5713f25
6
+ metadata.gz: 168c3ddaeafbfb84ff9d6355580b30a08a7dc1c19a954b5e622cb9d2ca238e3cda7bbebebd6a0c8ff12c32946739bdd452c957b842f08202c17ade88eb8a137b
7
+ data.tar.gz: ad459d45e906b0c855d9c73bf1f8a23c7e338040ac3fa0bb189801f78cc8d80e71216417b05981a0382c7ab300bbbabc810fde598778e80b803ffdd9739a0901
data/.rubocop.yml ADDED
@@ -0,0 +1,21 @@
1
+ AllCops:
2
+ NewCops: disable
3
+
4
+ Style/HashSyntax:
5
+ Enabled: false
6
+
7
+ Metrics/BlockLength:
8
+ Exclude:
9
+ # config files where we expect long blocks
10
+ - 'Gemfile'
11
+ - 'Guardfile'
12
+ - '*.gemspec'
13
+
14
+ # spec files that might have a big describe
15
+ - 'spec/**/*.rb'
16
+
17
+
18
+ Metrics/AbcSize:
19
+ Exclude:
20
+ # spec files, especially matchers, can get complicated and that's OK
21
+ - 'lib/deepgram/response_handler.rb'
data/Guardfile ADDED
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ guard :rspec, cmd: 'bundle exec rspec' do
4
+ require 'guard/rspec/dsl'
5
+ dsl = Guard::RSpec::Dsl.new(self)
6
+
7
+ # RSpec files
8
+ rspec = dsl.rspec
9
+ watch(rspec.spec_helper) { rspec.spec_dir }
10
+ watch(rspec.spec_support) { rspec.spec_dir }
11
+ watch(rspec.spec_files)
12
+
13
+ # Ruby files
14
+ ruby = dsl.ruby
15
+ dsl.watch_spec_files_for(ruby.lib_files)
16
+ end
17
+
18
+ guard :rubocop, cli: ['--autocorrect'] do
19
+ watch(/.+\.rb$/)
20
+ watch(%r{(?:.+/)?\.rubocop(?:_todo)?\.yml$}) { |m| File.dirname(m[0]) }
21
+ end
data/README.md CHANGED
@@ -1,39 +1,87 @@
1
- # Deepgram
1
+ # Deepgram Ruby Client
2
2
 
3
- TODO: Delete this and the text below, and describe your gem
3
+ The Deepgram Ruby Client is a comprehensive library for interacting with the Deepgram API, allowing developers to easily integrate Deepgram's powerful speech recognition and processing capabilities into Ruby applications. This client covers various functionalities, including file transcription, real-time audio processing, and management of Deepgram projects and resources.
4
4
 
5
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/deepgram`. To experiment with that code, run `bin/console` for an interactive prompt.
5
+ ## Features
6
+
7
+ - **Transcription**: Transcribe audio files or live audio streams with support for various audio formats.
8
+ - **Text-to-Speech**: Convert text into natural-sounding speech, with support for asynchronous operations and callbacks.
9
+ - **Project Management**: Manage Deepgram projects, including project creation, deletion, and updates.
10
+ - **API Key Management**: Create, list, and delete API keys associated with your Deepgram projects.
11
+ - **Member Management**: Manage project members, their roles, and permissions.
12
+ - **Usage and Metrics**: Access detailed usage metrics and balance information for your Deepgram projects.
6
13
 
7
14
  ## Installation
8
15
 
9
- TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
16
+ Add this line to your application's Gemfile:
17
+
18
+ ```ruby
19
+ gem 'deepgram'
20
+ ```
10
21
 
11
- Install the gem and add to the application's Gemfile by executing:
22
+ And then execute:
12
23
 
13
- $ bundle add UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
24
+ ```bash
25
+ bundle install
26
+ ```
14
27
 
15
- If bundler is not being used to manage dependencies, install the gem by executing:
28
+ Or install it yourself as:
16
29
 
17
- $ gem install UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
30
+ ```bash
31
+ gem install deepgram
32
+ ```
18
33
 
19
34
  ## Usage
20
35
 
21
- TODO: Write usage instructions here
36
+ ### Initialization
22
37
 
23
- ## Development
38
+ ```ruby
39
+ require 'deepgram'
40
+
41
+ # Initialize the client for different functionalities
42
+ read_client = Deepgram::Client.read
43
+ speak_client = Deepgram::Client.speak
44
+ listen_client = Deepgram::Client.listen
45
+ management_client = Deepgram::Client.management
46
+ on_prem_client = Deepgram::Client.on_prem
47
+ ```
48
+
49
+ ### Transcribing Audio Files
50
+
51
+ ```ruby
52
+ response = listen_client.transcribe_file(path: 'path/to/your/audio_file.wav')
53
+ puts response.transcript
54
+ ```
24
55
 
25
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
56
+ ### Converting Text to Speech
57
+
58
+ ```ruby
59
+ response = speak_client.speak(text: 'Hello, world!')
60
+ # Save the speech file or process further
61
+ ```
62
+
63
+ ### Managing Projects
64
+
65
+ ```ruby
66
+ # List all projects
67
+ projects = management_client.projects
68
+
69
+ # Create a new API key for a project
70
+ key_response = management_client.create_key(project_id: 'your_project_id', comment: 'New key', scopes: ['full_access'])
71
+ ```
72
+
73
+ ## Development
26
74
 
27
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
75
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
28
76
 
29
77
  ## Contributing
30
78
 
31
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/deepgram. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/deepgram/blob/main/CODE_OF_CONDUCT.md).
79
+ Bug reports and pull requests are welcome on GitHub at [your-github-repo-link]. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](CODE_OF_CONDUCT.md).
32
80
 
33
81
  ## License
34
82
 
35
- The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
83
+ The gem is available as open source under the terms of the [MIT License](LICENSE.txt).
36
84
 
37
85
  ## Code of Conduct
38
86
 
39
- Everyone interacting in the Deepgram project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/deepgram/blob/main/CODE_OF_CONDUCT.md).
87
+ Everyone interacting in the DeepgramRubyClient project's codebases, issue trackers, chat rooms, and mailing lists is expected to follow the [code of conduct](CODE_OF_CONDUCT.md).
data/Rakefile CHANGED
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "bundler/gem_tasks"
4
- require "rspec/core/rake_task"
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
5
 
6
6
  RSpec::Core::RakeTask.new(:spec)
7
7
 
data/harvard.wav ADDED
@@ -0,0 +1 @@
1
+ {"metadata":{"transaction_key":"deprecated","request_id":"c214e86e-bf04-4942-bd89-0794deae057f","sha256":"971b4163670445c415c6b0fb6813c38093409ecac2f6b4d429ae3574d24ad470","created":"2024-03-19T13:58:17.216Z","duration":18.356188,"channels":1,"models":["1ed36bac-f71c-4f3f-a31f-02fd6525c489"],"model_info":{"1ed36bac-f71c-4f3f-a31f-02fd6525c489":{"name":"general","version":"2024-01-26.8851","arch":"base"}}},"results":{"channels":[{"alternatives":[{"transcript":"the stale smell of old beer lingers it takes heat to bring out the odor a cold dip restores health and zest a salt pickle tastes fine with ham a tacos all pasteur are my favorite a zest food is the hot cross bun","confidence":0.99121094,"words":[{"word":"the","start":1.318125,"end":1.6376704,"confidence":0.9946289},{"word":"stale","start":1.6376704,"end":2.1169887,"confidence":0.54296875},{"word":"smell","start":2.1169887,"end":2.3566477,"confidence":0.99853516},{"word":"of","start":2.3566477,"end":2.5963068,"confidence":0.99853516},{"word":"old","start":2.5963068,"end":2.8359659,"confidence":0.9824219},{"word":"beer","start":2.8359659,"end":3.1555114,"confidence":0.984375},{"word":"lingers","start":3.1555114,"end":3.554943,"confidence":0.99853516},{"word":"it","start":4.3538065,"end":4.6733522,"confidence":0.9980469},{"word":"takes","start":4.6733522,"end":4.913011,"confidence":0.99902344},{"word":"heat","start":4.913011,"end":5.232557,"confidence":1.0},{"word":"to","start":5.232557,"end":5.392329,"confidence":0.9980469},{"word":"bring","start":5.392329,"end":5.6319885,"confidence":0.9951172},{"word":"out","start":5.6319885,"end":5.7917614,"confidence":0.9868164},{"word":"the","start":5.7917614,"end":6.03142,"confidence":0.9970703},{"word":"odor","start":6.03142,"end":6.2710795,"confidence":0.99365234},{"word":"a","start":7.084627,"end":7.322388,"confidence":0.9658203},{"word":"cold","start":7.322388,"end":7.639403,"confidence":0.96191406},{"word":"dip","start":7.639403,"end":8.139402,"confidence":0.9916992},{"word":"restores","start":8.273433,"end":8.511194,"confidence":0.9946289},{"word":"health","start":8.511194,"end":8.828209,"confidence":0.9951172},{"word":"and","start":8.828209,"end":9.06597,"confidence":0.7734375},{"word":"zest","start":9.06597,"end":9.382985,"confidence":0.99853516},{"word":"a","start":9.937761,"end":10.254776,"confidence":0.9785156},{"word":"salt","start":10.254776,"end":10.571791,"confidence":0.9941406},{"word":"pickle","start":10.571791,"end":11.047314,"confidence":0.8808594},{"word":"tastes","start":11.047314,"end":11.364328,"confidence":0.6015625},{"word":"fine","start":11.364328,"end":11.602089,"confidence":0.9902344},{"word":"with","start":11.602089,"end":11.760597,"confidence":0.99609375},{"word":"ham","start":11.760597,"end":11.998358,"confidence":0.99658203},{"word":"a","start":12.315372,"end":12.361188,"confidence":0.99316406},{"word":"tacos","start":12.719988,"end":12.9591875,"confidence":0.71191406},{"word":"all","start":13.038921,"end":13.278121,"confidence":0.3178711},{"word":"pasteur","start":13.278121,"end":13.676788,"confidence":0.953125},{"word":"are","start":13.676788,"end":13.915988,"confidence":0.9995117},{"word":"my","start":13.915988,"end":14.075455,"confidence":0.9951172},{"word":"favorite","start":14.075455,"end":14.474121,"confidence":0.9951172},{"word":"a","start":15.111988,"end":15.351188,"confidence":0.9916992},{"word":"zest","start":15.351188,"end":15.829588,"confidence":0.99853516},{"word":"food","start":15.829588,"end":16.228254,"confidence":0.9941406},{"word":"is","start":16.228254,"end":16.467455,"confidence":0.9995117},{"word":"the","start":16.467455,"end":16.62692,"confidence":0.9975586},{"word":"hot","start":16.62692,"end":16.945854,"confidence":0.9995117},{"word":"cross","start":16.945854,"end":17.264788,"confidence":0.8491211},{"word":"bun","start":17.264788,"end":17.503988,"confidence":0.9604492}]}]}]}}
data/lib/deepgram/base.rb CHANGED
@@ -1,11 +1,45 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'deepgram/response_handler'
4
+
3
5
  module Deepgram
6
+ # The Base class initializes the Faraday connection to interact with the Deepgram API
7
+ # and provides a generic request method for its subclasses.
4
8
  class Base
9
+ include ResponseHandler
10
+
11
+ # Initializes a Faraday connection to the Deepgram API.
12
+ # The API endpoint and authorization token are set via environment variables,
13
+ # with defaults provided.
14
+ #
15
+ # @param options [Hash] Optional parameters for future extensions.
5
16
  def initialize(options = {})
6
- @connection = Faraday.new(url: ENV.fetch('DEEPGRAM_URL', 'https://api.deepgram.com/v1'))
7
- @connection.headers['Authorization'] = "Token #{ENV.fetch('DEEPGRAM_API_KEY')}"
17
+ @connection = Faraday.new(url: ENV.fetch('DEEPGRAM_URL', 'https://api.deepgram.com'))
18
+ @connection.headers['Authorization'] = "Token #{ENV.fetch('DEEPGRAM_API_KEY', 'api-key')}"
8
19
  @options = options
9
20
  end
21
+
22
+ # Sends an HTTP request to the specified path using the initialized Faraday connection.
23
+ # This method is designed to be flexible, allowing any HTTP method to be used.
24
+ #
25
+ # @param method [Symbol] The HTTP method to use (:get, :post, etc.).
26
+ # @param path [String, nil] The path to append to the base API URL (optional).
27
+ # @param kwargs [Hash] Additional keyword arguments to include in the request.
28
+ # @yieldparam request [Faraday::Request] The request object, allowing for further customization.
29
+ # @return [Faraday::Response] The response from the Faraday connection.
30
+ def request(method, path = nil, **kwargs)
31
+ res = @connection.send(method, path, **kwargs) do |request|
32
+ yield(request) if block_given?
33
+ request.params.merge!(kwargs)
34
+ end
35
+
36
+ handle_response(res)
37
+ end
38
+
39
+ private
40
+
41
+ # Accessor for the Faraday connection instance
42
+ # @return [Faraday::Connection] The Faraday connection used to interact with the API.
43
+ attr_reader :connection
10
44
  end
11
45
  end
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Deepgram
4
+ # The Client module serves as a factory for creating instances of various
5
+ # specialized client classes within the Deepgram module. Each client class
6
+ # is tailored to interact with a specific part of the Deepgram API.
7
+ module Client
8
+ # Creates a new instance of the Read::Client class.
9
+ #
10
+ # @return [Deepgram::Read::Client] A client for interacting with the Deepgram Read API.
11
+ def self.read
12
+ Read::Client.new
13
+ end
14
+
15
+ # Creates a new instance of the Speak::Client class.
16
+ #
17
+ # @return [Deepgram::Speak::Client] A client for interacting with the Deepgram Speak API.
18
+ def self.speak
19
+ Speak::Client.new
20
+ end
21
+
22
+ # Creates a new instance of the Listen::Client class.
23
+ #
24
+ # @return [Deepgram::Listen::Client] A client for interacting with the Deepgram Listen API.
25
+ def self.listen
26
+ Listen::Client.new
27
+ end
28
+
29
+ # Creates a new instance of the Management::Client class.
30
+ #
31
+ # @return [Deepgram::Management::Client] A client for managing resources within the Deepgram platform.
32
+ def self.management
33
+ Management::Client.new
34
+ end
35
+
36
+ # Creates a new instance of the OnPrem::Client class.
37
+ #
38
+ # @return [Deepgram::OnPrem::Client] A client for managing on-premise deployments within the Deepgram platform.
39
+ def self.on_prem
40
+ OnPrem::Client.new
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,64 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Deepgram
4
+ # Base class for all Deepgram API exceptions.
5
+ class Exception < StandardError
6
+ attr_reader :error_data
7
+
8
+ # Initializes a new instance of the Exception class.
9
+ #
10
+ # @param message [String] The error message.
11
+ # @param error_data [Hash] Additional error data (e.g., headers, error codes).
12
+ def initialize(message, error_data = {})
13
+ super(message)
14
+ @error_data = error_data
15
+ end
16
+ end
17
+
18
+ # Base class for HTTP errors returned by the Deepgram API.
19
+ class HTTPError < Exception
20
+ # Returns the headers associated with the HTTP error.
21
+ #
22
+ # @return [Hash] The headers.
23
+ def headers
24
+ error_data[:headers]
25
+ end
26
+
27
+ # Returns the HTTP status code associated with the error.
28
+ #
29
+ # @return [Integer] The HTTP status code.
30
+ def http_code
31
+ error_data[:code]
32
+ end
33
+ end
34
+
35
+ # Exception raised when there are insufficient credits to perform a transcription.
36
+ class InsufficientCredits < HTTPError; end
37
+
38
+ # Exception raised when the rate limit for API requests has been exceeded.
39
+ class RateLimitExceeded < HTTPError; end
40
+
41
+ # Exception raised when the API request is invalid or malformed.
42
+ class BadRequest < HTTPError; end
43
+
44
+ # Exception raised when the API request is not authenticated or authorized.
45
+ class Unauthorized < HTTPError; end
46
+
47
+ # Exception raised when the API request is not permitted or forbidden.
48
+ class Forbidden < HTTPError; end
49
+
50
+ # Exception raised when the requested resource is not found.
51
+ class NotFound < HTTPError; end
52
+
53
+ # Exception raised when there is an internal server error on the Deepgram API side.
54
+ class InternalServerError < HTTPError; end
55
+
56
+ # Exception raised when there is a bad gateway error on the Deepgram API side.
57
+ class BadGateway < HTTPError; end
58
+
59
+ # Exception raised when the Deepgram API service is temporarily unavailable.
60
+ class ServiceUnavailable < HTTPError; end
61
+
62
+ # Exception raised when there is a gateway timeout error on the Deepgram API side.
63
+ class GatewayTimeout < HTTPError; end
64
+ end
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'pathname'
4
+
5
+ module Deepgram
6
+ # The Fixtures module provides utility methods for loading fixture files
7
+ # used for testing purposes.
8
+ module Fixtures
9
+ # Returns the root directory path where the fixture files are located.
10
+ #
11
+ # @return [Pathname] The root directory path.
12
+ def self.root
13
+ @root ||= Pathname.new(__dir__).join('..', '..', 'spec', 'fixtures')
14
+ end
15
+
16
+ # Loads the content of a fixture file as a string.
17
+ #
18
+ # @param file_name [String] The name of the fixture file to load.
19
+ #
20
+ # @return [String] The content of the loaded file.
21
+ def self.load_file(file_name)
22
+ file_path = root.join(file_name)
23
+ File.read(file_path)
24
+ end
25
+
26
+ # Loads the content of a JSON fixture file and parses it as a Ruby object.
27
+ #
28
+ # @param file_name [String] The name of the JSON fixture file to load.
29
+ #
30
+ # @return [Object] The parsed Ruby object from the JSON file.
31
+ def self.load_json(file_name)
32
+ JSON.parse(load_file(file_name))
33
+ end
34
+
35
+ # Loads the content of a YAML fixture file and parses it as a Ruby object.
36
+ #
37
+ # @param file_name [String] The name of the YAML fixture file to load.
38
+ #
39
+ # @return [Object] The parsed Ruby object from the YAML file.
40
+ def self.load_yaml(file_name)
41
+ YAML.safe_load(load_file(file_name), permitted_classes: [])
42
+ end
43
+ end
44
+ end
@@ -2,39 +2,125 @@
2
2
 
3
3
  module Deepgram
4
4
  module Listen
5
+ # The Client class within the Listen module extends the Base class
6
+ # to handle operations specific to the Deepgram 'Listen' API endpoint.
5
7
  class Client < Base
8
+ # Initializes the Client object for the Deepgram 'Listen' service,
9
+ # setting up the necessary API endpoint and request headers for JSON.
6
10
  def initialize
7
11
  super
8
- @connection.path_prefix = 'listen'
12
+ @connection.path_prefix = 'v1/listen'
9
13
  @connection.headers['Content-Type'] = 'application/json'
10
14
  @connection.headers['Accept'] = 'application/json'
11
15
  end
12
16
 
17
+ # Transcribes audio content from a file.
18
+ #
19
+ # @param path [String] The local file system path to the audio file to be transcribed.
20
+ # @param audio_format [String] The MIME type of the audio file (defaults to 'audio/wav').
21
+ # @param kwargs [Hash] Additional keyword arguments for the request.
22
+ # @return [Deepgram::Listen::Response] The response object containing transcription results.
13
23
  def transcribe_file(path:, audio_format: 'audio/wav', **kwargs)
14
24
  validate_file_path(path)
15
- @connection.post do |request|
25
+
26
+ request(:post, **kwargs) do |request|
16
27
  request.headers['Content-Type'] = audio_format
17
- request.params.merge!(kwargs)
18
28
  request.body = File.binread(path)
19
29
  end
20
30
  end
21
31
 
32
+ # Transcribes audio content from a URL.
33
+ #
34
+ # @param url [String] The URL of the audio file to be transcribed.
35
+ # @param kwargs [Hash] Additional keyword arguments for the request.
36
+ # @return [Deepgram::Listen::Response] The response object containing transcription results.
22
37
  def transcribe_url(url:, **kwargs)
23
38
  validate_url(url)
24
- @connection.post do |request|
25
- request.params.merge!(kwargs)
39
+
40
+ request(:post, **kwargs) do |request|
26
41
  request.body = JSON.generate(url: url)
27
42
  end
28
43
  end
29
44
 
30
45
  private
31
46
 
47
+ # Validates the file path to ensure the file exists.
48
+ #
49
+ # @param path [String] The file path to validate.
50
+ # @raise [ArgumentError] If the file path does not exist.
32
51
  def validate_file_path(path)
33
52
  raise ArgumentError, "Invalid file path: #{path}" unless File.exist?(path)
34
53
  end
35
54
 
55
+ # Validates the URL to ensure it is properly formatted.
56
+ #
57
+ # @param url [String] The URL to validate.
58
+ # @raise [ArgumentError] If the URL is not properly formatted.
36
59
  def validate_url(url)
37
- raise ArgumentError, "Invalid URL: #{url}" unless url.match?(%r{\A#{URI::DEFAULT_PARSER.make_regexp}\z})
60
+ raise ArgumentError, "Invalid URL: #{url}" unless url.match?(/\A#{URI::DEFAULT_PARSER.make_regexp}\z/)
61
+ end
62
+
63
+ # Overrides the request method from the Base class to wrap the response
64
+ # in a Deepgram::Listen::Response object.
65
+ #
66
+ # @param (see Base#request)
67
+ # @return [Deepgram::Listen::Response] The wrapped response object.
68
+ def request(method, path = nil, **kwargs)
69
+ res = super(method, path, **kwargs)
70
+
71
+ Response.new(status: res.status, body: res.body, headers: res.headers)
72
+ end
73
+ end
74
+
75
+ # The Response class encapsulates the response from the Deepgram Listen API,
76
+ # providing methods to access various parts of the response data.
77
+ class Response
78
+ attr_reader :status, :body, :headers
79
+
80
+ # Initializes a new Response object with the given status, body, and headers.
81
+ #
82
+ # @param status [Integer] The HTTP status code of the response.
83
+ # @param body [String] The body of the response, expected to be in JSON format.
84
+ # @param headers [Hash] The HTTP headers of the response.
85
+ def initialize(status:, body:, headers:)
86
+ @status = status
87
+ @body = body
88
+ @headers = headers
89
+ end
90
+
91
+ # Extracts and returns the metadata from the response data.
92
+ #
93
+ # @return [Hash, nil] The metadata from the response, if present.
94
+ def metadata
95
+ raw['metadata']
96
+ end
97
+
98
+ # Extracts and returns the transcript text from the first channel and alternative in the response data.
99
+ #
100
+ # @return [String, nil] The transcript text, if present.
101
+ def transcript
102
+ raw.dig('results', 'channels', 0, 'alternatives', 0, 'transcript')
103
+ end
104
+
105
+ # Extracts and returns the words array from the first channel and alternative in the response data.
106
+ #
107
+ # @return [Array, nil] The words array, if present.
108
+ def words
109
+ raw.dig('results', 'channels', 0, 'alternatives', 0, 'words')
110
+ end
111
+
112
+ # Extracts and returns the confidence score from the first channel and alternative in the response data.
113
+ #
114
+ # @return [Float, nil] The confidence score, if present.
115
+ def confidence
116
+ raw.dig('results', 'channels', 0, 'alternatives', 0, 'confidence')
117
+ end
118
+
119
+ # Parses the response body as JSON and returns the raw data.
120
+ #
121
+ # @return [Hash] The parsed JSON from the response body.
122
+ def raw
123
+ JSON.parse(@body)
38
124
  end
39
125
  end
40
126
  end
@@ -0,0 +1,273 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Deepgram
4
+ module Management
5
+ # Client class for interacting with Deepgram's Management API,
6
+ # allowing management of projects, keys, members, and more.
7
+ class Client < Base
8
+ # Sets up the API endpoint and headers for JSON content type.
9
+ def initialize
10
+ super
11
+ @connection.path_prefix = 'v1/projects'
12
+ @connection.headers['Content-Type'] = 'application/json'
13
+ end
14
+
15
+ # Projects
16
+
17
+ # Retrieves all projects.
18
+ # @return [Deepgram::Management::Response] The response object containing projects data.
19
+ def projects
20
+ request(:get)
21
+ end
22
+
23
+ # Retrieves a specific project by ID.
24
+ # @param id [String] The project ID.
25
+ # @param kwargs [Hash] Additional keyword arguments for the request.
26
+ # @return [Deepgram::Management::Response] The response object containing the project data.
27
+ def get_project(id, **kwargs)
28
+ request(:get, id, **kwargs)
29
+ end
30
+
31
+ # Updates the name of a specific project.
32
+ # @param id [String] The project ID.
33
+ # @param name [String] The new name for the project.
34
+ # @return [Deepgram::Management::Response] The response object containing the updated project data.
35
+ def update_project(id, name:)
36
+ request(:patch, id) do |request|
37
+ request.body = JSON.generate(name: name)
38
+ end
39
+ end
40
+
41
+ # Deletes a specific project.
42
+ # @param id [String] The project ID.
43
+ # @return [nil] Indicates the project has been successfully deleted.
44
+ def delete_project(id)
45
+ request(:delete, id)
46
+ end
47
+
48
+ # Keys
49
+
50
+ # Lists all keys for a project.
51
+ # @param project_id [String] The project ID.
52
+ # @return [Deepgram::Management::Response] The response object containing keys data.
53
+ def keys(project_id:)
54
+ request(:get, "#{project_id}/keys")
55
+ end
56
+
57
+ # Retrieves a specific key by key ID for a project.
58
+ # @param key_id [String] The key ID.
59
+ # @param project_id [String] The project ID.
60
+ # @param kwargs [Hash] Additional keyword arguments for the request.
61
+ # @return [Deepgram::Management::Response] The response object containing the key data.
62
+ def get_key(key_id, project_id:, **kwargs)
63
+ request(:get, "#{project_id}/keys/#{key_id}", **kwargs)
64
+ end
65
+
66
+ # Creates a new key for a project.
67
+ # @param project_id [String] The project ID.
68
+ # @param comment [String] Comment or description for the key.
69
+ # @param scopes [Array] Scopes or permissions assigned to the key.
70
+ # @param kwargs [Hash] Additional keyword arguments for the request.
71
+ # @return [Deepgram::Management::Response] The response object containing the new key data.
72
+ def create_key(project_id:, comment:, scopes:, **kwargs)
73
+ request(:post, "#{project_id}/keys", **kwargs) do |request|
74
+ request.body = JSON.generate(comment: comment, scopes: scopes)
75
+ end
76
+ end
77
+
78
+ # Deletes a specific key for a project.
79
+ # @param key_id [String] The key ID.
80
+ # @param project_id [String] The project ID.
81
+ # @return [nil] Indicates the key has been successfully deleted.
82
+ def delete_key(key_id, project_id:)
83
+ request(:delete, "#{project_id}/keys/#{key_id}")
84
+ end
85
+
86
+ # Members
87
+
88
+ # Lists all members of a project.
89
+ # @param project_id [String] The project ID.
90
+ # @return [Deepgram::Management::Response] The response object containing members data.
91
+ def members(project_id:)
92
+ request(:get, "#{project_id}/members")
93
+ end
94
+
95
+ # Removes a specific member from a project.
96
+ # @param member_id [String] The member ID.
97
+ # @param project_id [String] The project ID.
98
+ # @return [nil] Indicates the member has been successfully removed.
99
+ def remove_member(member_id, project_id:)
100
+ request(:delete, "#{project_id}/members/#{member_id}")
101
+ end
102
+
103
+ # Retrieves scopes for a specific member of a project.
104
+ # @param project_id [String] The project ID.
105
+ # @param member_id [String] The member ID.
106
+ # @return [Deepgram::Management::Response] The response object containing member's scopes data.
107
+ def member_scopes(project_id:, member_id:)
108
+ request(:get, "#{project_id}/members/#{member_id}/scopes")
109
+ end
110
+
111
+ # Updates the scopes for a specific member of a project.
112
+ # @param scope [Array] The new scopes for the member.
113
+ # @param project_id [String] The project ID.
114
+ # @param member_id [String] The member ID.
115
+ # @return [Deepgram::Management::Response] The response object indicating the update was successful.
116
+ def update_scope(scope, project_id:, member_id:)
117
+ request(:put, "#{project_id}/members/#{member_id}/scopes") do |request|
118
+ request.body = JSON.generate(scope: scope)
119
+ end
120
+ end
121
+
122
+ # Invitations
123
+
124
+ # Lists all invites for a project.
125
+ # @param project_id [String] The project ID.
126
+ # @return [Deepgram::Management::Response] The response object containing invites data.
127
+ def invites(project_id:)
128
+ request(:get, "#{project_id}/invites")
129
+ end
130
+
131
+ # Sends an invite to join a project.
132
+ # @param email [String] The email address of the invitee.
133
+ # @param project_id [String] The project ID.
134
+ # @param scope [Array] The scopes assigned to the invitee upon acceptance.
135
+ # @return [Deepgram::Management::Response] The response object indicating the invite was sent.
136
+ def send_invite(email:, project_id:, scope:)
137
+ request(:post, "#{project_id}/invites") do |request|
138
+ request.body = JSON.generate(email: email, scope: scope)
139
+ end
140
+ end
141
+
142
+ # Deletes an invite for a project.
143
+ # @param email [String] The email address of the invitee.
144
+ # @param project_id [String] The project ID.
145
+ # @return [nil] Indicates the invite has been successfully deleted.
146
+ def delete_invite(email, project_id:)
147
+ request(:delete, "#{project_id}/invites/#{email}")
148
+ end
149
+
150
+ # Allows a member to leave a project.
151
+ # @param project_id [String] The project ID.
152
+ # @return [nil] Indicates the member has left the project.
153
+ def leave_project(project_id:)
154
+ request(:delete, "#{project_id}/leave")
155
+ end
156
+
157
+ # Requests
158
+
159
+ # Lists all requests for a project.
160
+ # @param project_id [String] The project ID.
161
+ # @param kwargs [Hash] Additional keyword arguments for the request.
162
+ # @return [Deepgram::Management::Response] The response object containing requests data.
163
+ def requests(project_id:, **kwargs)
164
+ request(:get, "#{project_id}/requests", **kwargs)
165
+ end
166
+
167
+ # Retrieves a specific request for a project.
168
+ # @param request_id [String] The request ID.
169
+ # @param project_id [String] The project ID.
170
+ # @return [Deepgram::Management::Response] The response object containing the request data.
171
+ def get_request(request_id, project_id:)
172
+ request(:get, "#{project_id}/requests/#{request_id}")
173
+ end
174
+
175
+ # Usage
176
+
177
+ # Retrieves usage information for a project.
178
+ # @param project_id [String] The project ID.
179
+ # @param kwargs [Hash] Additional keyword arguments for the request.
180
+ # @return [Deepgram::Management::Response] The response object containing usage data.
181
+ def usage(project_id:, **kwargs)
182
+ request(:get, "#{project_id}/usage", **kwargs)
183
+ end
184
+
185
+ # Retrieves the available fields for usage data for a project.
186
+ # @param project_id [String] The project ID.
187
+ # @param kwargs [Hash] Additional keyword arguments for the request.
188
+ # @return [Deepgram::Management::Response] The response object containing fields data.
189
+ def fields(project_id:, **kwargs)
190
+ request(:get, "#{project_id}/usage/fields", **kwargs)
191
+ end
192
+
193
+ # Balances
194
+
195
+ # Lists all balances for a project.
196
+ # @param project_id [String] The project ID.
197
+ # @return [Deepgram::Management::Response] The response object containing balances data.
198
+ def balances(project_id:)
199
+ request(:get, "#{project_id}/balances")
200
+ end
201
+
202
+ # Retrieves a specific balance for a project.
203
+ # @param balance_id [String] The balance ID.
204
+ # @param project_id [String] The project ID.
205
+ # @return [Deepgram::Management::Response] The response object containing the balance data.
206
+ def balance(balance_id, project_id:)
207
+ request(:get, "#{project_id}/balances/#{balance_id}")
208
+ end
209
+
210
+ private
211
+
212
+ # Extends the Base class's request method to wrap the response in a Management::Response object.
213
+ # @param method [Symbol] The HTTP method.
214
+ # @param path [String] The endpoint path.
215
+ # @param kwargs [Hash] Additional keyword arguments for the request.
216
+ # @return [Deepgram::Management::Response] The wrapped response object.
217
+ def request(method, path = nil, **kwargs)
218
+ res = super(method, path, **kwargs)
219
+
220
+ Response.new(status: res.status, body: res.body, headers: res.headers)
221
+ end
222
+ end
223
+
224
+ # Encapsulates the response from the Management API, providing methods to access various response data.
225
+ class Response
226
+ def initialize(status:, body:, headers:)
227
+ @status = status
228
+ @body = body
229
+ @headers = headers
230
+ end
231
+
232
+ # Parses the response body as JSON and returns the raw data.
233
+ def raw
234
+ JSON.parse(@body)
235
+ end
236
+
237
+ # Methods for accessing specific parts of the response data, such as projects, keys, members, etc.
238
+ # Each method parses the raw JSON data and returns the relevant section, e.g., `raw['projects']` for `projects`.
239
+
240
+ def projects
241
+ raw['projects']
242
+ end
243
+
244
+ def keys
245
+ raw['api_keys']
246
+ end
247
+
248
+ def members
249
+ raw['members']
250
+ end
251
+
252
+ def scopes
253
+ raw['scopes']
254
+ end
255
+
256
+ def invites
257
+ raw['invites']
258
+ end
259
+
260
+ def requests
261
+ raw['requests']
262
+ end
263
+
264
+ def balances
265
+ raw['balances']
266
+ end
267
+
268
+ def distribution_credentials
269
+ raw['distribution_credentials']
270
+ end
271
+ end
272
+ end
273
+ end
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Deepgram
4
+ module OnPrem
5
+ # The Client class within the OnPrem module extends the Management::Client class
6
+ # to handle operations specific to on-premise deployments within the Deepgram platform.
7
+ class Client < Management::Client
8
+ # Retrieves a list of credentials for a given project.
9
+ #
10
+ # @param project_id [String] The unique identifier for the project.
11
+ # @return [Array] A list of credentials associated with the specified project.
12
+ def credentials(project_id:)
13
+ request(:get, "#{project_id}/onprem/distribution/credentials")
14
+ end
15
+
16
+ # Retrieves a specific credential by its ID within a given project.
17
+ #
18
+ # @param id [String] The unique identifier for the credential.
19
+ # @param project_id [String] The unique identifier for the project.
20
+ # @return [Hash] The details of the specified credential.
21
+ def get_credential(id, project_id:)
22
+ request(:get, "#{project_id}/onprem/distribution/credentials/#{id}")
23
+ end
24
+
25
+ # Creates a new credential within a project with the specified details.
26
+ #
27
+ # @param comments [String] Descriptive comments about the credential.
28
+ # @param scopes [Array] The scopes or permissions assigned to the credential.
29
+ # @param provider [String] The provider or platform for which the credential is valid.
30
+ # @param project_id [String] The unique identifier for the project.
31
+ # @return [Hash] The details of the newly created credential.
32
+ def create_credential(comments:, scopes:, provider:, project_id:)
33
+ request(:post, "#{project_id}/onprem/distribution/credentials") do |request|
34
+ request.body = JSON.generate(comments: comments, scopes: scopes, provider: provider)
35
+ end
36
+ end
37
+
38
+ # Deletes a specific credential by its ID from a given project.
39
+ #
40
+ # @param id [String] The unique identifier for the credential to be deleted.
41
+ # @param project_id [String] The unique identifier for the project.
42
+ # @return [nil] Indicates the credential has been successfully deleted.
43
+ def delete_credential(id, project_id:)
44
+ request(:delete, "#{project_id}/onprem/distribution/credentials/#{id}")
45
+ end
46
+ end
47
+ end
48
+ end
data/lib/deepgram/read.rb CHANGED
@@ -1,48 +1,92 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'deepgram/fixtures'
4
+
3
5
  module Deepgram
4
6
  module Read
7
+ # The Client class extends the Base class to handle read operations
8
+ # specific to the Deepgram 'Read' API endpoint.
5
9
  class Client < Base
10
+ # Initializes a Client object for the Deepgram 'Read' service.
11
+ # Sets the default language and appropriate headers for JSON requests.
12
+ #
13
+ # @param language [String] The default language to use for analysis (defaults to 'en').
6
14
  def initialize(language = 'en')
7
- super
8
-
15
+ super()
9
16
  @connection.path_prefix = 'v1/read'
10
17
  @connection.params[:language] = language
11
18
  @connection.headers['Content-Type'] = 'application/json'
12
19
  end
13
20
 
14
- def summarize(text:, **kwargs)
15
- post(text, **kwargs) do |params|
16
- params[:summarize] = true
21
+ # Sends a POST request to analyze text using the Deepgram Read API.
22
+ # Returns a Response object containing the analysis results.
23
+ #
24
+ # @param text [String] The text to be analyzed.
25
+ # @param kwargs [Hash] Additional keyword arguments to be sent with the request.
26
+ # @return [Deepgram::Read::Response] The response object containing analysis results.
27
+ def analyze(text:, **kwargs)
28
+ res = request(:post, **kwargs) do |request|
29
+ request.body = JSON.generate(text: text)
17
30
  end
31
+
32
+ Response.new(status: res.status, body: res.body, headers: res.headers)
18
33
  end
34
+ end
19
35
 
20
- def topics(text:, **kwargs)
21
- post(text, **kwargs) do |params|
22
- params[:topics] = true
23
- end
36
+ # The Response class encapsulates the response from the Deepgram Read API,
37
+ # providing methods to access various parts of the response data.
38
+ class Response
39
+ # Initializes a new Response object with the given status, body, and headers.
40
+ #
41
+ # @param status [Integer] The HTTP status code of the response.
42
+ # @param body [String] The body of the response, expected to be in JSON format.
43
+ # @param headers [Hash] The HTTP headers of the response.
44
+ def initialize(status:, body:, headers:)
45
+ @status = status
46
+ @body = body
47
+ @headers = headers
24
48
  end
25
49
 
26
- def sentiment(text:, **kwargs)
27
- post(text, **kwargs) do |params|
28
- params[:sentiment] = true
29
- end
50
+ # Parses the response body as JSON and returns the raw data.
51
+ #
52
+ # @return [Hash] The parsed JSON from the response body.
53
+ def raw
54
+ JSON.parse(@body)
30
55
  end
31
56
 
32
- def intents(text:, **kwargs)
33
- post(text, **kwargs) do |params|
34
- params[:intents] = true
35
- end
57
+ # Extracts and returns the metadata from the response data.
58
+ #
59
+ # @return [Hash, nil] The metadata from the response, if present.
60
+ def metadata
61
+ raw['metadata']
36
62
  end
37
63
 
38
- private
64
+ # Extracts and returns the summary text from the response data.
65
+ #
66
+ # @return [String, nil] The summarized text, if present.
67
+ def summary
68
+ raw.dig('results', 'summary', 'text')
69
+ end
39
70
 
40
- def post(text, **kwargs)
41
- @connection.post do |request|
42
- request.body = JSON.generate(text: text)
43
- request.params.merge!(kwargs)
44
- yield request.params if block_given?
45
- end
71
+ # Extracts and returns the topics segments from the response data.
72
+ #
73
+ # @return [Array, nil] The topics segments, if present.
74
+ def topics
75
+ raw.dig('results', 'topics', 'segments')
76
+ end
77
+
78
+ # Extracts and returns the sentiments segments from the response data.
79
+ #
80
+ # @return [Array, nil] The sentiments segments, if present.
81
+ def sentiments
82
+ raw.dig('results', 'sentiments', 'segments')
83
+ end
84
+
85
+ # Extracts and returns the intents segments from the response data.
86
+ #
87
+ # @return [Array, nil] The intents segments, if present.
88
+ def intents
89
+ raw.dig('results', 'intents', 'segments')
46
90
  end
47
91
  end
48
92
  end
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'exception'
4
+
5
+ module Deepgram
6
+ # The ResponseHandler module provides a method for handling responses
7
+ # from the Deepgram API and raising appropriate exceptions based on
8
+ # the HTTP status code.
9
+ module ResponseHandler
10
+ # Handles the response from the Deepgram API.
11
+ #
12
+ # @param res [Faraday::Response] The response object from the API request.
13
+ #
14
+ # @raise [Deepgram::BadRequestError] If the response has a 400 status code.
15
+ # @raise [Deepgram::UnauthorizedError] If the response has a 401 status code.
16
+ # @raise [Deepgram::ForbiddenError] If the response has a 403 status code.
17
+ # @raise [Deepgram::NotFoundError] If the response has a 404 status code.
18
+ # @raise [Deepgram::RateLimitExceededError] If the response has a 429 status code.
19
+ # @raise [Deepgram::InternalServerErrorError] If the response has a 500 status code.
20
+ # @raise [Deepgram::BadGatewayError] If the response has a 502 status code.
21
+ # @raise [Deepgram::ServiceUnavailableError] If the response has a 503 status code.
22
+ #
23
+ # @return [Faraday::Response] The response object if the status code is between 200 and 226.
24
+ def handle_response(res) # rubocop:disable Metrics/MethodLength, Metrics/CyclomaticComplexity
25
+ case res.status
26
+ when 200..226 then res
27
+ when 400 then raise Deepgram::BadRequest.new(res.body, code: res.status, headers: res.headers)
28
+ when 401 then raise Deepgram::Unauthorized.new(res.body, code: res.status, headers: res.headers)
29
+ when 403 then raise Deepgram::Forbidden.new(res.body, code: res.status, headers: res.headers)
30
+ when 404 then raise Deepgram::NotFound.new(res.body, code: res.status, headers: res.headers)
31
+ when 429 then raise Deepgram::RateLimitExceeded.new(res.body, code: res.status, headers: res.headers)
32
+ when 500 then raise Deepgram::InternalServerError.new(res.body, code: res.status, headers: res.headers)
33
+ when 502 then raise Deepgram::BadGateway.new(res.body, code: res.status, headers: res.headers)
34
+ when 503 then raise Deepgram::ServiceUnavailable.new(res.body, code: res.status, headers: res.headers)
35
+ end
36
+ end
37
+ end
38
+ end
@@ -2,28 +2,89 @@
2
2
 
3
3
  module Deepgram
4
4
  module Speak
5
+ # The Client class within the Speak module extends the Base class
6
+ # to handle operations specific to the Deepgram 'Speak' API endpoint.
5
7
  class Client < Base
8
+ # Initializes the Client object for the Deepgram 'Speak' service,
9
+ # setting up the necessary API endpoint and request headers for JSON.
6
10
  def initialize
7
11
  super
8
-
9
12
  @connection.path_prefix = 'v1/speak'
10
13
  @connection.headers['Content-Type'] = 'application/json'
11
14
  end
12
15
 
16
+ # Sends a synchronous request to convert text to speech.
17
+ #
18
+ # @param text [String] The text to be converted to speech.
19
+ # @param kwargs [Hash] Additional keyword arguments for the request.
20
+ # @return [Deepgram::Speak::Response] The response object containing the speech file.
13
21
  def speak(text:, **kwargs)
14
- @connection.post do |request|
15
- request.params.merge!(kwargs)
22
+ request(:post, **kwargs) do |request|
16
23
  request.body = JSON.generate(text: text)
17
24
  end
18
25
  end
19
26
 
27
+ # Sends an asynchronous request to convert text to speech, with the results
28
+ # sent to a specified callback URL.
29
+ #
30
+ # @param text [String] The text to be converted to speech.
31
+ # @param callback_url [String] The URL to which the response will be sent upon completion.
32
+ # @param kwargs [Hash] Additional keyword arguments for the request.
33
+ # @return [Deepgram::Speak::Response] The response object containing the speech file or request details.
20
34
  def speak_async(text:, callback_url:, **kwargs)
21
- @connection.post do |request|
22
- request.params.merge!(kwargs)
23
- request.params[:callback] = callback_url
35
+ request(:post, callback_url: callback_url, **kwargs) do |request|
24
36
  request.body = JSON.generate(text: text)
25
37
  end
26
38
  end
39
+
40
+ private
41
+
42
+ # Overrides the request method from the Base class to wrap the response
43
+ # in a Deepgram::Speak::Response object.
44
+ #
45
+ # @param (see Base#request)
46
+ # @return [Deepgram::Speak::Response] The wrapped response object.
47
+ def request(method, path = nil, **kwargs)
48
+ res = super(method, path, **kwargs)
49
+
50
+ Response.new(status: res.status, body: res.body, headers: res.headers)
51
+ end
52
+ end
53
+
54
+ # The Response class encapsulates the response from the Deepgram Speak API,
55
+ # providing methods to access various parts of the response data.
56
+ class Response
57
+ # Initializes a new Response object with the given status, body, and headers.
58
+ #
59
+ # @param status [Integer] The HTTP status code of the response.
60
+ # @param body [String] The body of the response, expected to contain the speech file or request details.
61
+ # @param headers [Hash] The HTTP headers of the response.
62
+ def initialize(status:, body:, headers:)
63
+ @status = status
64
+ @body = body
65
+ @headers = headers
66
+ end
67
+
68
+ # Parses the response body as JSON and returns the raw data.
69
+ #
70
+ # @return [Hash] The parsed JSON from the response body.
71
+ def raw
72
+ JSON.parse(@body)
73
+ end
74
+
75
+ # Extracts and returns the request ID from the response data.
76
+ #
77
+ # @return [String, nil] The request ID, if present.
78
+ def request_id
79
+ raw['request_id']
80
+ end
81
+
82
+ # Returns the body of the response, which contains the speech file in asynchronous requests.
83
+ #
84
+ # @return [String] The body of the response.
85
+ def file
86
+ @body
87
+ end
27
88
  end
28
89
  end
29
90
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Deepgram
4
- VERSION = "0.1.0"
4
+ VERSION = '0.2.0'
5
5
  end
data/lib/deepgram.rb CHANGED
@@ -1,13 +1,29 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # The Deepgram Ruby gem provides a simple and convenient way to interact
4
+ # with the Deepgram APIs for speech recognition, text-to-speech, and
5
+ # natural language processing tasks.
6
+ #
7
+ # This file serves as the main entry point for the gem and handles loading
8
+ # the necessary dependencies and modules.
9
+
3
10
  require 'faraday'
4
11
  require 'dotenv/load'
12
+
13
+ # Load version information
5
14
  require_relative 'deepgram/version'
15
+
16
+ # Load base classes and modules
6
17
  require_relative 'deepgram/base'
7
18
  require_relative 'deepgram/listen'
8
19
  require_relative 'deepgram/speak'
9
20
  require_relative 'deepgram/read'
21
+ require_relative 'deepgram/client'
22
+ require_relative 'deepgram/management'
23
+ require_relative 'deepgram/on_prem'
10
24
 
25
+ # The Deepgram module is the main namespace for the gem.
26
+ # It provides access to the various classes and modules
27
+ # for interacting with the Deepgram APIs.
11
28
  module Deepgram
12
- class Error < StandardError; end
13
29
  end
data/projects.json ADDED
@@ -0,0 +1,8 @@
1
+ {
2
+ "projects": [
3
+ {
4
+ "project_id": "ccb6b56a-332d-46dc-ba33-618fdb0dbf91",
5
+ "name": "rileyjhardy@gmail.com's Project"
6
+ }
7
+ ]
8
+ }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: deepgram
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Riley Hardy
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-03-19 00:00:00.000000000 Z
11
+ date: 2024-04-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -38,6 +38,76 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '3.1'
41
+ - !ruby/object:Gem::Dependency
42
+ name: guard
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '2.18'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '2.18'
55
+ - !ruby/object:Gem::Dependency
56
+ name: guard-rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '4.7'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '4.7'
69
+ - !ruby/object:Gem::Dependency
70
+ name: guard-rubocop
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.5'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.5'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '3.0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '3.0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rubocop
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '1.62'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '1.62'
41
111
  description: Ruby toolkit for Deepgram API https://www.deepgram.com
42
112
  email:
43
113
  - 54298858+rileyjhardy@users.noreply.github.com
@@ -46,18 +116,27 @@ extensions: []
46
116
  extra_rdoc_files: []
47
117
  files:
48
118
  - ".rspec"
119
+ - ".rubocop.yml"
49
120
  - CHANGELOG.md
50
121
  - CODE_OF_CONDUCT.md
122
+ - Guardfile
51
123
  - LICENSE.txt
52
124
  - README.md
53
125
  - Rakefile
126
+ - harvard.wav
54
127
  - lib/deepgram.rb
55
128
  - lib/deepgram/base.rb
129
+ - lib/deepgram/client.rb
130
+ - lib/deepgram/exception.rb
131
+ - lib/deepgram/fixtures.rb
56
132
  - lib/deepgram/listen.rb
133
+ - lib/deepgram/management.rb
134
+ - lib/deepgram/on_prem.rb
57
135
  - lib/deepgram/read.rb
136
+ - lib/deepgram/response_handler.rb
58
137
  - lib/deepgram/speak.rb
59
138
  - lib/deepgram/version.rb
60
- - sig/deepgram.rbs
139
+ - projects.json
61
140
  homepage: https://github.com/rileyjhardy/deepgram
62
141
  licenses:
63
142
  - MIT
@@ -70,7 +149,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
70
149
  requirements:
71
150
  - - ">="
72
151
  - !ruby/object:Gem::Version
73
- version: '0'
152
+ version: '2.7'
74
153
  required_rubygems_version: !ruby/object:Gem::Requirement
75
154
  requirements:
76
155
  - - ">="
data/sig/deepgram.rbs DELETED
@@ -1,4 +0,0 @@
1
- module Deepgram
2
- VERSION: String
3
- # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
- end