Class: AssemblyAI::AsyncFilesClient
- Inherits:
-
Object
- Object
- AssemblyAI::AsyncFilesClient
- Defined in:
- lib/assemblyai/files/client.rb
Instance Attribute Summary collapse
-
#request_client ⇒ Object
readonly
Returns the value of attribute request_client.
Instance Method Summary collapse
- #initialize(request_client:) ⇒ AsyncFilesClient constructor
-
#upload(file:, request_options: nil) ⇒ Files::UploadedFile
Upload your media file directly to the AssemblyAI API if it isn’t accessible via a URL already.
Constructor Details
#initialize(request_client:) ⇒ AsyncFilesClient
65 66 67 68 |
# File 'lib/assemblyai/files/client.rb', line 65 def initialize(request_client:) # @type [AsyncRequestClient] @request_client = request_client end |
Instance Attribute Details
#request_client ⇒ Object (readonly)
Returns the value of attribute request_client.
61 62 63 |
# File 'lib/assemblyai/files/client.rb', line 61 def request_client @request_client end |
Instance Method Details
#upload(file:, request_options: nil) ⇒ Files::UploadedFile
Upload your media file directly to the AssemblyAI API if it isn’t accessible via a URL already.
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/assemblyai/files/client.rb', line 75 def upload(file:, request_options: nil) Async do response = @request_client.conn.post do |req| if file.is_a? String begin path = Pathname.new(file) rescue StandardError file_data = file end unless path.nil? if path.file? file_data = File.new(file) elsif path.directory? raise "file path has to be a path to file, but is a path to directory" else raise "file at path does not exist" end end else file_data = file end req..timeout = .timeout_in_seconds unless &.timeout_in_seconds.nil? req.headers["Authorization"] = .api_key unless &.api_key.nil? req.headers = { **req.headers, **(&.additional_headers || {}) }.compact req.headers["Content-Type"] = "application/octet-stream" if file.is_a? File req.headers["Content-Length"] = File.size(file_data.path).to_s else req.headers["Transfer-Encoding"] = "chunked" end req.body = file_data req.url "#{@request_client.get_url(request_options: )}/v2/upload" end Files::UploadedFile.from_json(json_object: response.body) end end |