|
| 1 | +# frozen_string_literal: true |
| 2 | + |
| 3 | +require_relative "../../requests" |
| 4 | +require_relative "types/transcript_list" |
| 5 | +require "async" |
| 6 | + |
| 7 | +module AssemblyAI |
| 8 | + # :nodoc: |
| 9 | + class TranscriptsClient |
| 10 | + # Retrieve a list of transcripts you created, this is used for pagination to easily retrieve the next page of transcripts |
| 11 | + # |
| 12 | + # @param url [String] The URL to retrieve the transcript list from |
| 13 | + # @param request_options [RequestOptions] |
| 14 | + # @return [Transcripts::TranscriptList] |
| 15 | + # |
| 16 | + # @example Retrieve the next page of results |
| 17 | + # client = AssemblyAI::Client.new(api_key: "YOUR_API_KEY") |
| 18 | + # transcript_list = client.transcripts.list(limit: 1) |
| 19 | + # client.transcripts.list_by_url(url: transcript_list.page_details.next_url) |
| 20 | + def list_by_url(url: nil, request_options: nil) |
| 21 | + url = "/v2/transcript" if url.nil? |
| 22 | + response = @request_client.conn.get(url) do |req| |
| 23 | + req.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil? |
| 24 | + req.headers["Authorization"] = request_options.api_key unless request_options&.api_key.nil? |
| 25 | + req.headers = { **req.headers, **(request_options&.additional_headers || {}) }.compact |
| 26 | + end |
| 27 | + Transcripts::TranscriptList.from_json(json_object: response.body) |
| 28 | + end |
| 29 | + end |
| 30 | + |
| 31 | + # :nodoc: |
| 32 | + class AsyncTranscriptsClient |
| 33 | + # Retrieve a list of transcripts you created |
| 34 | + # |
| 35 | + # @param url [String] The URL to retrieve the transcript list from |
| 36 | + # @param request_options [RequestOptions] |
| 37 | + # @return [Transcripts::TranscriptList] |
| 38 | + # |
| 39 | + # @example Retrieve the next page of results |
| 40 | + # client = AssemblyAI::AsyncClient.new(api_key: "YOUR_API_KEY") |
| 41 | + # Sync do |
| 42 | + # transcript_list = client.transcripts.list(limit: 1).wait |
| 43 | + # client.transcripts.list_by_url(url: transcript_list.page_details.next_url) |
| 44 | + # end |
| 45 | + def list_by_url(url: nil, request_options: nil) |
| 46 | + Async do |
| 47 | + url = "/v2/transcript" if url.nil? |
| 48 | + response = @request_client.conn.get(url) do |req| |
| 49 | + req.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil? |
| 50 | + req.headers["Authorization"] = request_options.api_key unless request_options&.api_key.nil? |
| 51 | + req.headers = { **req.headers, **(request_options&.additional_headers || {}) }.compact |
| 52 | + end |
| 53 | + Transcripts::TranscriptList.from_json(json_object: response.body) |
| 54 | + end |
| 55 | + end |
| 56 | + end |
| 57 | +end |
0 commit comments