elevenlabs-ruby 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c1ac9c2ee9225938c2f79819099697b8b56cd660396d3f61e4fdd731f10362d3
4
- data.tar.gz: 3857319b7947d80d2d8abc275d8b05ae9725b26d4670910b9464e2a080d10ac1
3
+ metadata.gz: f09441bd076023311ab4c534b879e7d15863cf3f3d8592aff670912142e9f990
4
+ data.tar.gz: d11560b31848bfbd4ecfd95204ef611d8bedcb984c075a5f05791027b933a93f
5
5
  SHA512:
6
- metadata.gz: a11e27bb12a99872a6eac9a805827f888ba74dffba9ca100257ec603b6ff5d841daeac6569e0e7d7534d076c3c228d71bf18d0d134e0574bc55e16409e84b61e
7
- data.tar.gz: ed4ca2da916b9c80971f9d0327acaffab7763c629dedefdaf762028f36527e1c1da8a706a331bee6aab0b82c683a7785ded301b2dbbd9648605e0bb47bbf7b3f
6
+ metadata.gz: 2db2ab4a2d79872f997f96ec6ba130e4304d41879302ba39b22364fa021ecb8264ca89081817432f36eaccf98376abc87c8f0472c6bc366ef5281715010f39dc
7
+ data.tar.gz: ebd6cf20635c4c3bd0b1eb4f7292c2ead619589136984eb4990fe0e83b41bb12db364219cdbaabf861ddd60c1c72bc7db050d0d24ca1696cd96fa0ec0141be70
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in replicate-ruby.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+
10
+ gem "minitest", "~> 5.0"
11
+
12
+ gem "rubocop", "~> 1.21"
data/Gemfile.lock ADDED
@@ -0,0 +1,77 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ elevenlabs-ruby (0.2.0)
5
+ addressable
6
+ faraday (>= 2.0)
7
+ faraday-multipart
8
+ faraday-retry
9
+
10
+ GEM
11
+ remote: https://rubygems.org/
12
+ specs:
13
+ addressable (2.8.4)
14
+ public_suffix (>= 2.0.2, < 6.0)
15
+ ast (2.4.2)
16
+ byebug (11.1.3)
17
+ coderay (1.1.3)
18
+ crack (0.4.5)
19
+ rexml
20
+ faraday (2.7.4)
21
+ faraday-net_http (>= 2.0, < 3.1)
22
+ ruby2_keywords (>= 0.0.4)
23
+ faraday-multipart (1.0.4)
24
+ multipart-post (~> 2)
25
+ faraday-net_http (3.0.2)
26
+ faraday-retry (2.1.0)
27
+ faraday (~> 2.0)
28
+ hashdiff (1.0.1)
29
+ json (2.6.3)
30
+ method_source (1.0.0)
31
+ minitest (5.18.0)
32
+ multipart-post (2.3.0)
33
+ parallel (1.23.0)
34
+ parser (3.2.2.1)
35
+ ast (~> 2.4.1)
36
+ pry (0.14.2)
37
+ coderay (~> 1.1)
38
+ method_source (~> 1.0)
39
+ public_suffix (5.0.1)
40
+ rainbow (3.1.1)
41
+ rake (13.0.6)
42
+ regexp_parser (2.8.0)
43
+ rexml (3.2.5)
44
+ rubocop (1.51.0)
45
+ json (~> 2.3)
46
+ parallel (~> 1.10)
47
+ parser (>= 3.2.0.0)
48
+ rainbow (>= 2.2.2, < 4.0)
49
+ regexp_parser (>= 1.8, < 3.0)
50
+ rexml (>= 3.2.5, < 4.0)
51
+ rubocop-ast (>= 1.28.0, < 2.0)
52
+ ruby-progressbar (~> 1.7)
53
+ unicode-display_width (>= 2.4.0, < 3.0)
54
+ rubocop-ast (1.28.1)
55
+ parser (>= 3.2.1.0)
56
+ ruby-progressbar (1.13.0)
57
+ ruby2_keywords (0.0.5)
58
+ unicode-display_width (2.4.2)
59
+ webmock (3.18.1)
60
+ addressable (>= 2.8.0)
61
+ crack (>= 0.3.2)
62
+ hashdiff (>= 0.4.0, < 2.0.0)
63
+
64
+ PLATFORMS
65
+ arm64-darwin-22
66
+
67
+ DEPENDENCIES
68
+ byebug
69
+ elevenlabs-ruby!
70
+ minitest (~> 5.0)
71
+ pry
72
+ rake (~> 13.0)
73
+ rubocop (~> 1.21)
74
+ webmock
75
+
76
+ BUNDLED WITH
77
+ 2.4.10
data/README.md ADDED
@@ -0,0 +1,34 @@
1
+ # ElevenLabs Ruby client
2
+
3
+ This is a Ruby client for the [ElevenLabs](https://elevenlabs.io/) API.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'elevenlabs-ruby'
11
+ ```
12
+
13
+ ## Usage
14
+
15
+ Grab your token from your ElevenLabs account and authenticate by configuring `api_token`:
16
+
17
+ ```ruby
18
+ ElevenLabs.configure do |config|
19
+ config.api_key = "your_api_token"
20
+ end
21
+ ```
22
+
23
+ Checkout their [API docs](https://api.elevenlabs.io/docs) for available endpoints.
24
+
25
+ ```ruby
26
+ client = ElevenLabs::Client.new(api_key: 'xxxxxxxxxx')
27
+ voices = client.get('voices')
28
+ voice_id = voices['voices'].first['voice_id']
29
+ speech = client.post("text-to-speech/#{voice_id}", { text: 'your text' }) # returns a binary string
30
+ ```
31
+
32
+ ## Development
33
+
34
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "eleven_labs/configurable"
4
+ require "eleven_labs/connection"
5
+
6
+ module ElevenLabs
7
+ class Client
8
+ include ElevenLabs::Configurable
9
+ include ElevenLabs::Connection
10
+
11
+ def initialize(options = {})
12
+ # Use options passed in, but fall back to module defaults
13
+ ElevenLabs::Configurable.keys.each do |key|
14
+ value = options.key?(key) ? options[key] : ElevenLabs.instance_variable_get(:"@#{key}")
15
+ instance_variable_set(:"@#{key}", value)
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ElevenLabs
4
+ module Configurable
5
+ attr_accessor :api_key
6
+ attr_writer :api_endpoint
7
+
8
+ class << self
9
+ # List of configurable keys for {Datatrans::Client}
10
+ # @return [Array] of option keys
11
+ def keys
12
+ @keys ||= %i[api_key api_endpoint]
13
+ end
14
+ end
15
+
16
+ # Set configuration options using a block
17
+ def configure
18
+ yield self
19
+ end
20
+
21
+ # API endpoint methods
22
+ def api_endpoint
23
+ @api_endpoint ||= "https://api.elevenlabs.io/v1"
24
+ end
25
+
26
+ private
27
+
28
+ def options
29
+ Hash[ElevenLabs::Configurable.keys.map { |key| [key, send(key)] }]
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,114 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "faraday"
4
+ require "faraday/net_http"
5
+ require "faraday/retry"
6
+ require "addressable/uri"
7
+
8
+ module ElevenLabs
9
+ # Network layer for API clients.
10
+ module Connection
11
+ DEFAULT_MEDIA_TYPE = "application/json"
12
+ USER_AGENT = "ElevenLabs Ruby Gem"
13
+
14
+ # Header keys that can be passed in options hash to {#get},{#head}
15
+ CONVENIENCE_HEADERS = Set.new(%i[accept content_type])
16
+
17
+ # Make a HTTP GET request
18
+ #
19
+ # @param url [String] The path, relative to {#api_endpoint}
20
+ # @param options [Hash] Query and header params for request
21
+ # @return [Sawyer::Resource]
22
+ def get(url, options = {})
23
+ request :get, url, options
24
+ end
25
+
26
+ # Make a HTTP POST request
27
+ #
28
+ # @param url [String] The path, relative to {#api_endpoint}
29
+ # @param options [Hash] Body and header params for request
30
+ # @return [Sawyer::Resource]
31
+ def post(url, options = {})
32
+ request :post, url, options.to_json
33
+ end
34
+
35
+ # Make a HTTP PUT request
36
+ #
37
+ # @param url [String] The path, relative to {#api_endpoint}
38
+ # @param options [Hash] Body and header params for request
39
+ # @return [Sawyer::Resource]
40
+ def put(url, options = {})
41
+ request :put, url, options.to_json
42
+ end
43
+
44
+ # Make a HTTP PATCH request
45
+ #
46
+ # @param url [String] The path, relative to {#api_endpoint}
47
+ # @param options [Hash] Body and header params for request
48
+ # @return [Sawyer::Resource]
49
+ def patch(url, options = {})
50
+ request :patch, url, options.to_json
51
+ end
52
+
53
+ # Make a HTTP DELETE request
54
+ #
55
+ # @param url [String] The path, relative to {#api_endpoint}
56
+ # @param options [Hash] Query and header params for request
57
+ # @return [Sawyer::Resource]
58
+ def delete(url, options = {})
59
+ request :delete, url, options
60
+ end
61
+
62
+ # Make a HTTP HEAD request
63
+ #
64
+ # @param url [String] The path, relative to {#api_endpoint}
65
+ # @param options [Hash] Query and header params for request
66
+ # @return [Sawyer::Resource]
67
+ def head(url, options = {})
68
+ request :head, url, options
69
+ end
70
+
71
+ # Hypermedia agent for the datatrans API
72
+ #
73
+ # @return [Sawyer::Agent]
74
+ def agent
75
+ @agent ||= Faraday.new(url: endpoint) do |conn|
76
+ conn.request :retry
77
+ conn.headers['XI-API-KEY'] = api_key
78
+ conn.headers["Content-Type"] = DEFAULT_MEDIA_TYPE
79
+ conn.headers["Accept"] = DEFAULT_MEDIA_TYPE
80
+
81
+ conn.adapter :net_http
82
+ end
83
+ end
84
+
85
+ # Response for last HTTP request
86
+ #
87
+ # @return [Sawyer::Response]
88
+ def last_response
89
+ @last_response if defined? @last_response
90
+ end
91
+
92
+ protected
93
+
94
+ def endpoint
95
+ api_endpoint
96
+ end
97
+
98
+ private
99
+
100
+ def request(method, path, data)
101
+ @last_response = agent.send(method, Addressable::URI.parse(path.to_s).normalize.to_s, data)
102
+ case @last_response.status
103
+ when 400
104
+ raise Error, "#{@last_response.status} #{@last_response.reason_phrase}: #{JSON.parse(@last_response.body)}"
105
+ else
106
+ begin
107
+ JSON.parse(@last_response.body)
108
+ rescue JSON::ParserError, TypeError => _e
109
+ @last_response.body
110
+ end
111
+ end
112
+ end
113
+ end
114
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ElevenLabs
4
+ VERSION = "0.2.0"
5
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "eleven_labs/client"
4
+
5
+ module ElevenLabs
6
+ class Error < StandardError; end
7
+
8
+ class << self
9
+ include ElevenLabs::Configurable
10
+
11
+ def client
12
+ return @client if defined?(@client)
13
+ @client = ElevenLabs::Client.new(options)
14
+ end
15
+ end
16
+ end
@@ -0,0 +1 @@
1
+ require_relative "../eleven_labs"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: elevenlabs-ruby
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
  - Dreaming Tulpa
@@ -114,7 +114,16 @@ email:
114
114
  executables: []
115
115
  extensions: []
116
116
  extra_rdoc_files: []
117
- files: []
117
+ files:
118
+ - Gemfile
119
+ - Gemfile.lock
120
+ - README.md
121
+ - lib/eleven_labs.rb
122
+ - lib/eleven_labs/client.rb
123
+ - lib/eleven_labs/configurable.rb
124
+ - lib/eleven_labs/connection.rb
125
+ - lib/eleven_labs/version.rb
126
+ - lib/elevenlabs/ruby.rb
118
127
  homepage: https://github.com/dreamingtulpa/elevenlabs-ruby
119
128
  licenses: []
120
129
  metadata: