Class: Happyscribe::Transcript
- Inherits:
-
Object
- Object
- Happyscribe::Transcript
- Defined in:
- lib/happyscribe.rb
Overview
Your code goes here…
Instance Method Summary collapse
- #create(url, title = "", language = "fr-FR") ⇒ Object
- #create_export(id, format = "txt", timestamps = false, speakers = false, comments = false, highlights = false) ⇒ Object
- #export_in_txt(export_id) ⇒ Object
-
#initialize(key) ⇒ Transcript
constructor
A new instance of Transcript.
- #list ⇒ Object
- #retrieve(id) ⇒ Object
- #retrieve_export(export_id) ⇒ Object
Constructor Details
#initialize(key) ⇒ Transcript
Returns a new instance of Transcript.
11 12 13 14 15 |
# File 'lib/happyscribe.rb', line 11 def initialize(key) @api_key = key @base = "https://www.happyscribe.co/api/v1" @auth = "Bearer #{@api_key}" end |
Instance Method Details
#create(url, title = "", language = "fr-FR") ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/happyscribe.rb', line 16 def create(url,title="",language="fr-FR") endpoint = "#{@base}/transcriptions" uri = URI.parse(endpoint) request = Net::HTTP::Post.new(uri) request.content_type = "application/json" request["Authorization"] = @auth request.body = JSON.dump({ "transcription" => { "name" => (title=="" ? SecureRandom.alphanumeric : title ), "language" => language, "tmp_url" => url } }) = { use_ssl: uri.scheme == "https", } response = Net::HTTP.start(uri.hostname, uri.port, ) do |http| http.request(request) end return JSON.parse response.body end |
#create_export(id, format = "txt", timestamps = false, speakers = false, comments = false, highlights = false) ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/happyscribe.rb', line 70 def create_export(id,format="txt",=false,speakers=false,comments=false,highlights=false) uri = URI.parse("#{@base}/exports") request = Net::HTTP::Post.new(uri) request.content_type = "application/json" request["Authorization"] = @auth request.body = JSON.dump({ "export" => { "format" => format, "show_timestamps" => , "show_speakers" => speakers, "show_comments" => comments, "show_highlights" => highlights, "transcription_ids" => [ id ] } }) = { use_ssl: uri.scheme == "https", } response = Net::HTTP.start(uri.hostname, uri.port, ) do |http| http.request(request) end return JSON.parse response.body end |
#export_in_txt(export_id) ⇒ Object
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/happyscribe.rb', line 112 def export_in_txt(export_id) export = create_export(export_id,"txt")["id"] sleep(5) while true retrieved = retrieve_export(export) if(retrieved["state"]=="ready") break else sleep(2) end end txt = URI.parse(retrieved["download_link"]).open.read.force_encoding("utf-8") return txt end |
#list ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/happyscribe.rb', line 40 def list endpoint = "#{@base}/transcriptions" uri = URI.parse(endpoint) request = Net::HTTP::Get.new(uri) request["Authorization"] = @auth = { use_ssl: uri.scheme == "https", } response = Net::HTTP.start(uri.hostname, uri.port, ) do |http| http.request(request) end return JSON.parse response.body end |
#retrieve(id) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/happyscribe.rb', line 55 def retrieve(id) endpoint = "#{@base}/transcriptions/#{id}" uri = URI.parse(endpoint) request = Net::HTTP::Get.new(uri) request["Authorization"] = @auth = { use_ssl: uri.scheme == "https", } response = Net::HTTP.start(uri.hostname, uri.port, ) do |http| http.request(request) end return JSON.parse(response.body) end |
#retrieve_export(export_id) ⇒ Object
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/happyscribe.rb', line 97 def retrieve_export(export_id) endpoint = "#{@base}/exports/#{export_id}" uri = URI.parse(endpoint) request = Net::HTTP::Get.new(uri) request["Authorization"] = @auth = { use_ssl: uri.scheme == "https", } response = Net::HTTP.start(uri.hostname, uri.port, ) do |http| http.request(request) end return JSON.parse response.body end |