Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix UserAgent conflict #49

Merged
merged 2 commits into from
Aug 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .fernignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ assemblyai.gemspec

lib/gemconfig.rb
lib/requests.rb
lib/user_agent.rb
lib/assemblyai.rb
lib/assemblyai/types/user_agent.rb

<!-- Manual customized files client -->
lib/assemblyai/files/client.rb
Expand Down
1 change: 1 addition & 0 deletions lib/assemblyai.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
require_relative "environment"
require_relative "types_export"
require_relative "requests"
require_relative "assemblyai/types/user_agent"
require_relative "assemblyai/files/client"
require_relative "assemblyai/transcripts/client"
require_relative "assemblyai/transcripts/polling_client"
Expand Down
6 changes: 3 additions & 3 deletions lib/user_agent.rb → lib/assemblyai/types/user_agent.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def add_item(key, user_agent_item)
# @param user_agent2 [AssemblyAI::UserAgent]
# @return [AssemblyAI::UserAgent]
def self.merge(user_agent1, user_agent2)
merged_user_agent = UserAgent.new
merged_user_agent = AssemblyAI::UserAgent.new

user_agent1&.user_agent_items&.each do |key, item|
merged_user_agent.add_item(key, item)
Expand Down Expand Up @@ -62,8 +62,8 @@ class DefaultUserAgent
attr_reader :user_agent

def initialize
@user_agent = UserAgent.new
@user_agent.add_item("sdk", UserAgentItem.new(name: "Ruby", version: AssemblyAI::Gemconfig::VERSION))
@user_agent = AssemblyAI::UserAgent.new
@user_agent.add_item("sdk", AssemblyAI::UserAgentItem.new(name: "Ruby", version: AssemblyAI::Gemconfig::VERSION))
end
end
end
2 changes: 1 addition & 1 deletion lib/gemconfig.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

module AssemblyAI
module Gemconfig
VERSION = "1.0.0"
VERSION = "1.0.1"
AUTHORS = ["AssemblyAI"].freeze
EMAIL = "[email protected]"
SUMMARY = "AssemblyAI Ruby SDK"
Expand Down
2 changes: 1 addition & 1 deletion lib/requests.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

require_relative "environment"
require_relative "user_agent"
require_relative "assemblyai/types/user_agent"
require_relative "gemconfig"
require "faraday"
require "faraday/retry"
Expand Down
1 change: 1 addition & 0 deletions lib/types_export.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,4 @@
require_relative "assemblyai/lemur/types/lemur_model"
require_relative "assemblyai/lemur/types/lemur_usage"
require_relative "assemblyai/types/error"
require_relative "assemblyai/types/user_agent"
22 changes: 12 additions & 10 deletions test/test_assemblyai.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,18 @@ def api_key
ENV.fetch("ASSEMBLYAI_API_KEY")
end

# @return [String] AssemblyAI Base URL
def base_url
ENV.key?("ASSEMBLYAI_BASE_URL") ? ENV.fetch("ASSEMBLYAI_BASE_URL") : AssemblyAI::Environment::DEFAULT
end

def client
AssemblyAI::Client.new(
api_key: api_key,
environment: base_url
)
end

# @return [String] Transcript ID
def transcript_id
ENV.fetch("TEST_TRANSCRIPT_ID")
Expand All @@ -22,20 +34,17 @@ def transcript_ids
end

def test_upload_file_with_file
client = AssemblyAI::Client.new(api_key: api_key)
file = File.new("./test/gore-short.wav")
uploaded_file = client.files.upload(file: file)
assert !uploaded_file.upload_url.nil?
end

def test_upload_file_with_path
client = AssemblyAI::Client.new(api_key: api_key)
uploaded_file = client.files.upload(file: "./test/gore-short.wav")
assert !uploaded_file.upload_url.nil?
end

def test_upload_file_with_base64_string
client = AssemblyAI::Client.new(api_key: api_key)
uploaded_file = client.files.upload(file: File.read("./test/gore-short.wav"))
assert !uploaded_file.upload_url.nil?
end
Expand All @@ -46,7 +55,6 @@ def test_init
end

def test_pagination
client = AssemblyAI::Client.new(api_key: api_key)
transcript_list = client.transcripts.list

count = 0
Expand All @@ -69,24 +77,19 @@ def test_pagination
end

def test_transcribe
client = AssemblyAI::Client.new(api_key: api_key)
transcript = client.transcripts.transcribe(audio_url: "https://storage.googleapis.com/aai-web-samples/espn-bears.m4a")
assert transcript.status == AssemblyAI::Transcripts::TranscriptStatus::COMPLETED
end

def test_submit
# Transcribe
client = AssemblyAI::Client.new(api_key: api_key)

transcript_submission = client.transcripts.submit(audio_url: "https://storage.googleapis.com/aai-web-samples/espn-bears.m4a")
assert !transcript_submission.id.nil?
gotten_transcript = client.transcripts.get(transcript_id: transcript_submission.id)
assert gotten_transcript.id == transcript_submission.id
end

def test_polling
client = AssemblyAI::Client.new(api_key: api_key)

transcript = client.transcripts.submit(audio_url: "https://storage.googleapis.com/aai-web-samples/espn-bears.m4a")
assert !transcript.id.nil?

Expand All @@ -95,7 +98,6 @@ def test_polling
end

def test_lemur
client = AssemblyAI::Client.new(api_key: api_key)
assert !client.lemur.summary(transcript_ids: transcript_ids).response.nil?

qa_response = client.lemur.question_answer(
Expand Down