Class: AssemblyAI::FilesClient
- Inherits:
-
Object
- Object
- AssemblyAI::FilesClient
- 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:) ⇒ FilesClient 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:) ⇒ FilesClient
14 15 16 17 |
# File 'lib/assemblyai/files/client.rb', line 14 def initialize(request_client:) # @type [RequestClient] @request_client = request_client end |
Instance Attribute Details
#request_client ⇒ Object (readonly)
Returns the value of attribute request_client.
10 11 12 |
# File 'lib/assemblyai/files/client.rb', line 10 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.
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/assemblyai/files/client.rb', line 24 def upload(file:, request_options: nil) 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 |