Sha256: 94b243ec36a873a1ca3134f5886270e3a41969bbc68ea3cbafca491460e99da6
Contents?: true
Size: 1.15 KB
Versions: 1
Compression:
Stored size: 1.15 KB
Contents
module WatsonTtsAsrClient require 'net/http' require 'EVHttp/http_client' class AuthorizationClient def initialize(service_type, http_client = WatsonTtsAsrClient::HttpClient) @service_type = service_type @url_options = WatsonTtsAsrClient::WebsocketClient.default_options @http_client = http_client end def authorize return get_token if has_valid_token response = @http_client.get(construct_uri, @url_options[:credentials][@service_type][:username], @url_options[:credentials][@service_type][:password]) save_token(response.body) response.body end private def construct_uri token_uri = URI(@url_options[@service_type][0...@url_options[@service_type].index(/v1/)]) token_uri.scheme = "https" URI("#{@url_options[:authorization_url]}api/v1/token?url=#{token_uri.to_s}") end def has_valid_token false #WatsonApi.find(username: @username) #return token.timestamp < 1hr end def get_token #WatsonApi.find(username: @username) end def save_token(token) #WatsonApi.save(username: @username, token: token) end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
watson_tts_asr_client-0.1.0 | lib/authorization_client.rb |