voice-notes-ruby 0.1.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 5e5fda5d02e233e1e380c996612f95f2bd966ec00153843161968baea4811fa7
4
+ data.tar.gz: 790e5006c44571f29242e77ad0d48a6da76e31089c26a24d87052f9f4b007526
5
+ SHA512:
6
+ metadata.gz: a2b9da816d90eda694ab8203f401c1738e755d6185bf4fa372b9601a84dabc2f98bd093b60ecff29c475ee173402d662a588edfa10b1723c31a2b7e039493fe8
7
+ data.tar.gz: 2b5297aea223626b1a1d2bb1e7ec179d01babc1ccb5d67491114b15676a6b6bbbc2dc6d3cbd0ad8983d5a6d1646588f0315dedaea85ecdd3f3ef45cbc15bfd4e
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,39 @@
1
+ AllCops:
2
+ NewCops: enable
3
+ TargetRubyVersion: 3.2
4
+ SuggestExtensions: false
5
+ Exclude:
6
+ - 'bin/*'
7
+ - 'vendor/**/*'
8
+
9
+ Style/StringLiterals:
10
+ EnforcedStyle: double_quotes
11
+
12
+ Style/StringLiteralsInInterpolation:
13
+ EnforcedStyle: double_quotes
14
+
15
+ Style/Documentation:
16
+ Enabled: false
17
+
18
+ Metrics/BlockLength:
19
+ Exclude:
20
+ - 'spec/**/*'
21
+ - '*.gemspec'
22
+
23
+ Metrics/MethodLength:
24
+ Max: 20
25
+
26
+ Layout/LineLength:
27
+ Max: 120
28
+
29
+ Metrics/AbcSize:
30
+ Max: 25
31
+
32
+ Metrics/CyclomaticComplexity:
33
+ Max: 12
34
+
35
+ Gemspec/DevelopmentDependencies:
36
+ Enabled: false
37
+
38
+ Gemspec/RequiredRubyVersion:
39
+ Enabled: false
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 3.3.5
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2024 Voice Notes
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,108 @@
1
+ # Voice Notes Ruby
2
+
3
+ Ruby client for the Voice Notes API.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'voice-notes-ruby'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ ```bash
16
+ bundle install
17
+ ```
18
+
19
+ Or install it yourself as:
20
+
21
+ ```bash
22
+ gem install voice-notes-ruby
23
+ ```
24
+
25
+ ## Configuration
26
+
27
+ ```ruby
28
+ VoiceNotes.configure do |config|
29
+ config.api_key = "your_access_token"
30
+ config.base_url = "https://voice-notes.online" # optional, this is the default
31
+ config.timeout = 30 # optional, in seconds
32
+ end
33
+ ```
34
+
35
+ Or set via environment variables:
36
+
37
+ ```bash
38
+ export VOICE_NOTES_API_KEY="your_access_token"
39
+ ```
40
+
41
+ ## Usage
42
+
43
+ ### Authentication
44
+
45
+ ```ruby
46
+ require "voice_notes"
47
+
48
+ client = VoiceNotes.client
49
+
50
+ # Login with email and password
51
+ response = client.auth.login(email: "user@example.com", password: "password123")
52
+ access_token = response["access_token"]
53
+ refresh_token = response["refresh_token"]
54
+
55
+ # Set the access token for subsequent requests
56
+ client.access_token = access_token
57
+
58
+ # Get current user info
59
+ me = client.auth.me
60
+ puts me["data"]["attributes"]["email"]
61
+
62
+ # Refresh access token when expired
63
+ new_tokens = client.auth.refresh(refresh_token: refresh_token)
64
+ client.access_token = new_tokens["access_token"]
65
+
66
+ # Logout
67
+ client.auth.logout
68
+ ```
69
+
70
+ ### Notes
71
+
72
+ ```ruby
73
+ # Retrieve a note by its short ID
74
+ note = client.notes.find("abc123")
75
+
76
+ puts note["data"]["attributes"]["site_url"]
77
+ puts note["data"]["attributes"]["recording_url"]
78
+ ```
79
+
80
+ ### Error Handling
81
+
82
+ ```ruby
83
+ begin
84
+ note = client.notes.find("nonexistent")
85
+ rescue VoiceNotes::NotFoundError
86
+ puts "Note not found"
87
+ rescue VoiceNotes::AuthenticationError
88
+ puts "Invalid or expired token"
89
+ rescue VoiceNotes::AuthorizationError
90
+ puts "Access forbidden"
91
+ rescue VoiceNotes::ValidationError => e
92
+ puts "Validation error: #{e.message}"
93
+ rescue VoiceNotes::RateLimitError
94
+ puts "Rate limit exceeded, try again later"
95
+ rescue VoiceNotes::ServerError
96
+ puts "Server error, try again later"
97
+ end
98
+ ```
99
+
100
+ ## Development
101
+
102
+ 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.
103
+
104
+ To install this gem onto your local machine, run `bundle exec rake install`.
105
+
106
+ ## License
107
+
108
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+ require "rubocop/rake_task"
6
+
7
+ RSpec::Core::RakeTask.new(:spec)
8
+ RuboCop::RakeTask.new
9
+
10
+ task default: %i[spec rubocop]
@@ -0,0 +1,109 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "net/http"
4
+ require "json"
5
+ require "uri"
6
+
7
+ module VoiceNotes
8
+ class Client
9
+ attr_accessor :access_token
10
+
11
+ def initialize(access_token: nil, base_url: nil)
12
+ @access_token = access_token || VoiceNotes.configuration&.api_key
13
+ @base_url = base_url || VoiceNotes.configuration&.base_url
14
+ end
15
+
16
+ def auth
17
+ @auth ||= Resources::Auth.new(self)
18
+ end
19
+
20
+ def notes
21
+ @notes ||= Resources::Notes.new(self)
22
+ end
23
+
24
+ def get(path, params = {})
25
+ request(:get, path, params)
26
+ end
27
+
28
+ def post(path, body = {})
29
+ request(:post, path, body)
30
+ end
31
+
32
+ def put(path, body = {})
33
+ request(:put, path, body)
34
+ end
35
+
36
+ def delete(path)
37
+ request(:delete, path)
38
+ end
39
+
40
+ private
41
+
42
+ attr_reader :base_url
43
+
44
+ def request(method, path, data = {})
45
+ uri = URI.join(base_url, path)
46
+
47
+ uri.query = URI.encode_www_form(data) if method == :get && !data.empty?
48
+
49
+ http = Net::HTTP.new(uri.host, uri.port)
50
+ http.use_ssl = uri.scheme == "https"
51
+ http.read_timeout = VoiceNotes.configuration&.timeout || 30
52
+
53
+ request = build_request(method, uri, data)
54
+ response = http.request(request)
55
+
56
+ handle_response(response)
57
+ end
58
+
59
+ def build_request(method, uri, data)
60
+ request_class = {
61
+ get: Net::HTTP::Get,
62
+ post: Net::HTTP::Post,
63
+ put: Net::HTTP::Put,
64
+ delete: Net::HTTP::Delete
65
+ }.fetch(method)
66
+
67
+ request = request_class.new(uri)
68
+ request["Authorization"] = "Bearer #{access_token}" if access_token
69
+ request["Content-Type"] = "application/json"
70
+ request["Accept"] = "application/vnd.api+json"
71
+
72
+ request.body = JSON.generate(data) if %i[post put].include?(method) && !data.empty?
73
+
74
+ request
75
+ end
76
+
77
+ def handle_response(response)
78
+ case response.code.to_i
79
+ when 200..299
80
+ JSON.parse(response.body) unless response.body.nil? || response.body.empty?
81
+ when 401
82
+ raise AuthenticationError, "Invalid or expired token"
83
+ when 403
84
+ raise AuthorizationError, "Access forbidden"
85
+ when 404
86
+ raise NotFoundError, "Resource not found"
87
+ when 422
88
+ raise ValidationError, parse_error_message(response)
89
+ when 429
90
+ raise RateLimitError, "Rate limit exceeded"
91
+ when 500..599
92
+ raise ServerError, "Server error: #{response.code}"
93
+ else
94
+ raise Error, "Unexpected response: #{response.code}"
95
+ end
96
+ end
97
+
98
+ def parse_error_message(response)
99
+ body = JSON.parse(response.body)
100
+ if body["errors"]&.first
101
+ body["errors"].first["detail"] || body["errors"].first["title"]
102
+ else
103
+ body["error"] || body["message"] || "Validation failed"
104
+ end
105
+ rescue JSON::ParserError
106
+ "Validation failed"
107
+ end
108
+ end
109
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module VoiceNotes
4
+ class Configuration
5
+ attr_accessor :api_key, :base_url, :timeout
6
+
7
+ def initialize
8
+ @api_key = ENV.fetch("VOICE_NOTES_API_KEY", nil)
9
+ @base_url = ENV.fetch("VOICE_NOTES_BASE_URL", "https://voice-notes.online")
10
+ @timeout = 30
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module VoiceNotes
4
+ class Error < StandardError; end
5
+ class AuthenticationError < Error; end
6
+ class AuthorizationError < Error; end
7
+ class NotFoundError < Error; end
8
+ class ValidationError < Error; end
9
+ class RateLimitError < Error; end
10
+ class ServerError < Error; end
11
+ end
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ module VoiceNotes
4
+ module Resources
5
+ class Auth < Base
6
+ # Login with email and password
7
+ # @param email [String] User's email
8
+ # @param password [String] User's password
9
+ # @return [Hash] Response containing access_token and refresh_token
10
+ def login(email:, password:)
11
+ post("/api/v1/auth/login", {
12
+ email: email,
13
+ password: password,
14
+ grant_type: "password"
15
+ })
16
+ end
17
+
18
+ # Refresh access token using refresh token
19
+ # @param refresh_token [String] The refresh token
20
+ # @return [Hash] Response containing new access_token and refresh_token
21
+ def refresh(refresh_token:)
22
+ post("/api/v1/auth/login", {
23
+ grant_type: "refresh_token",
24
+ refresh_token: refresh_token
25
+ })
26
+ end
27
+
28
+ # Logout and invalidate the current session
29
+ # @return [Hash, nil] Response from server
30
+ def logout
31
+ delete("/api/v1/auth/logout")
32
+ end
33
+
34
+ # Get current authenticated user
35
+ # @return [Hash] User data in JSON:API format
36
+ def me
37
+ get("/api/v1/me")
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ module VoiceNotes
4
+ module Resources
5
+ class Base
6
+ attr_reader :client
7
+
8
+ def initialize(client)
9
+ @client = client
10
+ end
11
+
12
+ private
13
+
14
+ def get(path, params = {})
15
+ client.get(path, params)
16
+ end
17
+
18
+ def post(path, body = {})
19
+ client.post(path, body)
20
+ end
21
+
22
+ def put(path, body = {})
23
+ client.put(path, body)
24
+ end
25
+
26
+ def delete(path)
27
+ client.delete(path)
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module VoiceNotes
4
+ module Resources
5
+ class Notes < Base
6
+ # Retrieve a voice note by its short ID
7
+ # @param id [String] The Base58 short ID of the note
8
+ # @return [Hash] Note data in JSON:API format
9
+ def find(id)
10
+ get("/api/v1/notes/#{id}")
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module VoiceNotes
4
+ VERSION = "0.1.0"
5
+ end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "voice_notes/version"
4
+ require_relative "voice_notes/configuration"
5
+ require_relative "voice_notes/error"
6
+ require_relative "voice_notes/client"
7
+ require_relative "voice_notes/resources/base"
8
+ require_relative "voice_notes/resources/auth"
9
+ require_relative "voice_notes/resources/notes"
10
+
11
+ module VoiceNotes
12
+ class << self
13
+ attr_accessor :configuration
14
+ end
15
+
16
+ def self.configure
17
+ self.configuration ||= Configuration.new
18
+ yield(configuration)
19
+ end
20
+
21
+ def self.client
22
+ @client ||= Client.new
23
+ end
24
+
25
+ def self.reset!
26
+ @client = nil
27
+ @configuration = nil
28
+ end
29
+ end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/voice_notes/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "voice-notes-ruby"
7
+ spec.version = VoiceNotes::VERSION
8
+ spec.authors = ["Voice Notes"]
9
+ spec.email = ["support@voice-notes.online"]
10
+
11
+ spec.summary = "Ruby client for the Voice Notes API"
12
+ spec.description = "Official Ruby client library for interacting with the Voice Notes API"
13
+ spec.homepage = "https://github.com/voice-notes-online/voice-notes-ruby"
14
+ spec.license = "MIT"
15
+ spec.required_ruby_version = ">= 3.0.0"
16
+
17
+ spec.metadata["homepage_uri"] = spec.homepage
18
+ spec.metadata["source_code_uri"] = spec.homepage
19
+ spec.metadata["changelog_uri"] = "#{spec.homepage}/blob/master/CHANGELOG.md"
20
+ spec.metadata["rubygems_mfa_required"] = "true"
21
+
22
+ spec.files = Dir.chdir(__dir__) do
23
+ `git ls-files -z`.split("\x0").reject do |f|
24
+ (File.expand_path(f) == __FILE__) ||
25
+ f.start_with?(*%w[bin/ test/ spec/ features/ .git .github appveyor Gemfile])
26
+ end
27
+ end
28
+ spec.bindir = "exe"
29
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
30
+ spec.require_paths = ["lib"]
31
+
32
+ spec.add_development_dependency "bundler", "~> 2.0"
33
+ spec.add_development_dependency "rake", "~> 13.0"
34
+ spec.add_development_dependency "rspec", "~> 3.0"
35
+ spec.add_development_dependency "rubocop", "~> 1.21"
36
+ spec.add_development_dependency "webmock", "~> 3.18"
37
+ end
metadata ADDED
@@ -0,0 +1,132 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: voice-notes-ruby
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Voice Notes
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2025-11-28 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '13.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '13.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rubocop
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.21'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.21'
69
+ - !ruby/object:Gem::Dependency
70
+ name: webmock
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.18'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.18'
83
+ description: Official Ruby client library for interacting with the Voice Notes API
84
+ email:
85
+ - support@voice-notes.online
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".rspec"
91
+ - ".rubocop.yml"
92
+ - ".ruby-version"
93
+ - LICENSE.txt
94
+ - README.md
95
+ - Rakefile
96
+ - lib/voice_notes.rb
97
+ - lib/voice_notes/client.rb
98
+ - lib/voice_notes/configuration.rb
99
+ - lib/voice_notes/error.rb
100
+ - lib/voice_notes/resources/auth.rb
101
+ - lib/voice_notes/resources/base.rb
102
+ - lib/voice_notes/resources/notes.rb
103
+ - lib/voice_notes/version.rb
104
+ - voice-notes-ruby.gemspec
105
+ homepage: https://github.com/voice-notes-online/voice-notes-ruby
106
+ licenses:
107
+ - MIT
108
+ metadata:
109
+ homepage_uri: https://github.com/voice-notes-online/voice-notes-ruby
110
+ source_code_uri: https://github.com/voice-notes-online/voice-notes-ruby
111
+ changelog_uri: https://github.com/voice-notes-online/voice-notes-ruby/blob/master/CHANGELOG.md
112
+ rubygems_mfa_required: 'true'
113
+ post_install_message:
114
+ rdoc_options: []
115
+ require_paths:
116
+ - lib
117
+ required_ruby_version: !ruby/object:Gem::Requirement
118
+ requirements:
119
+ - - ">="
120
+ - !ruby/object:Gem::Version
121
+ version: 3.0.0
122
+ required_rubygems_version: !ruby/object:Gem::Requirement
123
+ requirements:
124
+ - - ">="
125
+ - !ruby/object:Gem::Version
126
+ version: '0'
127
+ requirements: []
128
+ rubygems_version: 3.5.16
129
+ signing_key:
130
+ specification_version: 4
131
+ summary: Ruby client for the Voice Notes API
132
+ test_files: []