Class: TranscribeMe::API::Client
- Inherits:
-
Object
- Object
- TranscribeMe::API::Client
- Defined in:
- lib/transcribeme/api/client.rb
Overview
API Client with methods for interacting with the SOAP API
Constant Summary collapse
- WSDL =
'http://transcribeme-api.cloudapp.net/PortalAPI.svc?wsdl=wsdl0'
- ENDPOINT =
'http://transcribeme-api.cloudapp.net/PortalAPI.svc'
- NAMESPACE =
'http://TranscribeMe.API.Web'
Instance Attribute Summary collapse
-
#recordings ⇒ Object
readonly
Public: Returns the last list of recordings.
-
#savon ⇒ Object
readonly
Public: Returns the underlining Savon object.
-
#session_expiry_time ⇒ Object
readonly
Public: Returns the expiry time of the current session.
-
#session_id ⇒ Object
readonly
Public: Returns the session id of the current session.
Instance Method Summary collapse
-
#finalize_session ⇒ Object
Public: Calls the ‘FinalizeSession’ SOAP Action to close the session on the server.
-
#get_recording_info(recording_id) ⇒ Object
Public: Calls the ‘GetRecordingInfo’ SOAP Action.
-
#get_recordings ⇒ Object
Public: Calls the ‘GetCustomerRecordings’ SOAP Action.
-
#get_transcription(recording_id, format = :text) ⇒ Object
Public: Calls the ‘GetTranscription’ SOAP Action to allow for downloading of transcriptions.
-
#get_upload_url ⇒ Object
Public: Calls the ‘GetUploadUrl’ SOAP Action.
-
#initialize ⇒ Client
constructor
Public: Initializes the API Client class.
-
#initialize_session ⇒ Object
Public: Initializes a session on the API server and stores the expiry time and the session_id in instance variables.
-
#sign_in(username, password) ⇒ Object
Public: Calls the ‘SignIn’ SOAP action.
-
#transcribe_recording(recording_id) ⇒ Object
Public: Calls the ‘TranscribeRecording’ SOAP Action.
-
#transcribe_recording_using_promocode(recording_id, promocode) ⇒ Object
Public: Calls the ‘TranscribeRecordingWithPromoCode’ SOAP Action.
-
#upload(file_path, options = {}) ⇒ Object
Public: uploads to Azure Blob Storage and commits the upload to the TranscribeMe SOAP API.
Constructor Details
#initialize ⇒ Client
Public: Initializes the API Client class
23 24 25 26 27 |
# File 'lib/transcribeme/api/client.rb', line 23 def initialize # Note: Deliberately disabling the verbose Savon logging @savon = ::Savon.client(endpoint: ENDPOINT, namespace: NAMESPACE, soap_version: 1, wsdl: WSDL, log: false) end |
Instance Attribute Details
#recordings ⇒ Object (readonly)
Public: Returns the last list of recordings
15 16 17 |
# File 'lib/transcribeme/api/client.rb', line 15 def recordings @recordings end |
#savon ⇒ Object (readonly)
Public: Returns the underlining Savon object
13 14 15 |
# File 'lib/transcribeme/api/client.rb', line 13 def savon @savon end |
#session_expiry_time ⇒ Object (readonly)
Public: Returns the expiry time of the current session
11 12 13 |
# File 'lib/transcribeme/api/client.rb', line 11 def session_expiry_time @session_expiry_time end |
#session_id ⇒ Object (readonly)
Public: Returns the session id of the current session
9 10 11 |
# File 'lib/transcribeme/api/client.rb', line 9 def session_id @session_id end |
Instance Method Details
#finalize_session ⇒ Object
Public: Calls the ‘FinalizeSession’ SOAP Action to close the session on the server
Returns the SOAP response Hash
222 223 224 225 |
# File 'lib/transcribeme/api/client.rb', line 222 def finalize_session @savon.call :finalize_session, message: { 'wsdl:sessionID' => @session_id } end |
#get_recording_info(recording_id) ⇒ Object
Public: Calls the ‘GetRecordingInfo’ SOAP Action
recording_id - a String in GUID format
Returns the SOAP response Hash
182 183 184 185 186 187 |
# File 'lib/transcribeme/api/client.rb', line 182 def get_recording_info(recording_id) response = @savon.call :get_recording_info, message: { 'wsdl:sessionID' => @session_id, 'wsdl:recordingID' => recording_id } response.body[:get_recording_info_response][:get_recording_info_result] end |
#get_recordings ⇒ Object
Public: Calls the ‘GetCustomerRecordings’ SOAP Action
requires the user to be logged in
Returns an Array of recording objects
73 74 75 76 77 78 79 80 81 |
# File 'lib/transcribeme/api/client.rb', line 73 def get_recordings # raise 'Login first!' unless @customer_login_id response = @savon.call :get_customer_recordings, message: { 'wsdl:sessionID' => session_id } # Returns an array of instances of the Recording class @recordings = Recording.new_from_soap response.body[:get_customer_recordings_response][:get_customer_recordings_result][:recording_info] end |
#get_transcription(recording_id, format = :text) ⇒ Object
Public: Calls the ‘GetTranscription’ SOAP Action to allow for downloading of transcriptions
recording_id - a String in GUID format format - a Symbol - either :text, :rtf, :pdf, :html
Returns the file data in a String to write to a file (decoded from Base64.)
196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 |
# File 'lib/transcribeme/api/client.rb', line 196 def get_transcription(recording_id, format = :text) format_type = case format when :text "Text" else format.to_s.upcase end response = @savon.call :get_transcription, message: { 'wsdl:sessionID' => @session_id, 'wsdl:recId' => recording_id, 'wsdl:formattingType' => format_type } = response.body[:get_transcription_response][:error_message] raise if transcription = response.body[:get_transcription_response][:get_transcription_result] raise "Transcription unable to be downloaded" if transcription.nil? Base64.decode64(transcription) end |
#get_upload_url ⇒ Object
Public: Calls the ‘GetUploadUrl’ SOAP Action
Returns the upload url as a String
86 87 88 89 90 91 92 93 |
# File 'lib/transcribeme/api/client.rb', line 86 def get_upload_url # raise 'Login first!' unless @customer_login_id response = @savon.call :get_upload_url, message: { 'wsdl:sessionID' => @session_id } @upload_url = response.body[:get_upload_url_response][:get_upload_url_result] end |
#initialize_session ⇒ Object
Public: Initializes a session on the API server and stores the expiry time and the session_id in instance variables
Returns the session_id GUID
33 34 35 36 37 38 39 |
# File 'lib/transcribeme/api/client.rb', line 33 def initialize_session response = @savon.call :initialize_session # Without ActiveSupport # 1.hour.from_now is 3600 seconds from Time.now @session_expiry_time = Time.now + 3600 @session_id = response.body[:initialize_session_response][:initialize_session_result] end |
#sign_in(username, password) ⇒ Object
Public: Calls the ‘SignIn’ SOAP action
username - a String which corresponds to a TranscribeMe Portal
account username which can be any valid email address
password - a String which is the portal account password
Returns a GUID of the Customer ID
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/transcribeme/api/client.rb', line 48 def sign_in(username, password) # If #login_with is called before we have a session_id instance variable # then call initialize_session initialize_session unless session_valid? # Use Savon to call the 'SignIn' SOAP action response = @savon.call :sign_in, message: { 'wsdl:sessionID' => @session_id, 'wsdl:username' => username, 'wsdl:password' => password } = response.body[:sign_in_response][:error_message] raise if # Assign the customer_login_id variable to the string in the SOAP response @customer_login_id = response.body[:sign_in_response][:sign_in_result] end |
#transcribe_recording(recording_id) ⇒ Object
Public: Calls the ‘TranscribeRecording’ SOAP Action
recording_id - a String in GUID format
Returns the SOAP response Hash
150 151 152 153 154 155 156 157 158 |
# File 'lib/transcribeme/api/client.rb', line 150 def transcribe_recording(recording_id) # initialize_session unless @session.try :valid? response = @savon.call :transcribe_recording, message: { 'wsdl:sessionID' => @session_id, 'wsdl:recordingId' => recording_id } response.body[:transcribe_recording_response][:transcribe_recording_result] end |
#transcribe_recording_using_promocode(recording_id, promocode) ⇒ Object
Public: Calls the ‘TranscribeRecordingWithPromoCode’ SOAP Action
recording_id - a String in GUID format promocode - a String
Returns the SOAP response Hash
166 167 168 169 170 171 172 173 174 175 |
# File 'lib/transcribeme/api/client.rb', line 166 def transcribe_recording_using_promocode(recording_id, promocode) # initialize_session unless @session.try :valid? response = @savon.call :transcribe_using_promo_code, message: { 'wsdl:sessionID' => @session_id, 'wsdl:recordingId' => recording_id, 'wsdl:promoCode' => promocode } response.body[:transcribe_using_promo_code_response][:transcribe_using_promo_code_result] end |
#upload(file_path, options = {}) ⇒ Object
Public: uploads to Azure Blob Storage and commits the upload to the TranscribeMe SOAP API
file_path - a String with the path to the actual file options - a Hash with these keys:
:multiple_speakers - Boolean (default is true)
:duration - Float
:description - String
Returns the response as a Hash
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 |
# File 'lib/transcribeme/api/client.rb', line 105 def upload(file_path, = {}) # If not logged in, raise this exception raise 'Login first!' unless @customer_login_id # Extract options from the options hash multiple_speakers = [:multiple_speakers] || true description = [:description] file_name = File.basename(file_path) file_format = File.extname(file_path) file_size = File.stat(file_path).size # Use the duration if provided in the options hash duration = [:duration] || ::FFMPEG::Movie.new(file_path).duration # Use the last upload url, or grab a new one @upload_url ||= get_upload_url # Create a connection to the upload url connection = Excon.new(@upload_url) # Upload to connection.put(headers: { "x-ms-blob-type" => "BlockBlob", "x-ms-date" => Time.now.to_s, "Content-Length" => file_size}, body: File.read(file_path)) # Post to the response = @savon.call :commit_upload, message: { "wsdl:sessionID" => @session_id, "wsdl:url" => @upload_url, "wsdl:name" => file_name, "wsdl:description" => description, "wsdl:duration" => duration, "wsdl:source" => "Ruby API Client", "wsdl:format" => file_format, "wsdl:isMultipleSpeakers" => multiple_speakers } # Set the upload url to nil so that we don't reuse it @upload_url = nil response end |