class WWPassConnection
Public Class Methods
new(cert_file, key_file, cafile, timeout = 10, spfe_addr = 'https://spfe.wwpass.com')
click to toggle source
# File lib/wwpass-ruby-sdk/wwpass_connection.rb, line 7 def initialize(cert_file, key_file, cafile, timeout = 10, spfe_addr = 'https://spfe.wwpass.com') @resource = RestClient::Resource.new( spfe_addr, :ssl_client_cert => OpenSSL::X509::Certificate.new(File.read(cert_file)), :ssl_client_key => OpenSSL::PKey::RSA.new(File.read(key_file)), :ssl_ca_file => cafile, :verify_ssl => OpenSSL::SSL::VERIFY_PEER, :timeout => timeout ) end
Public Instance Methods
get_name()
click to toggle source
# File lib/wwpass-ruby-sdk/wwpass_connection.rb, line 18 def get_name ticket = get_ticket('', 0) pos = ticket.index(':') if pos != nil ticket[0, pos] else raise WWPassException.new 'SPFE return ticket without a colon' end end
get_puid(ticket, auth_type = '')
click to toggle source
# File lib/wwpass-ruby-sdk/wwpass_connection.rb, line 32 def get_puid(ticket, auth_type = '') make_request('GET', 'puid', :params => {:ticket => ticket, :auth_type => auth_type}) end
get_ticket(auth_type = '', ttl=120)
click to toggle source
# File lib/wwpass-ruby-sdk/wwpass_connection.rb, line 28 def get_ticket(auth_type = '', ttl=120) make_request('GET', 'get', :params => {:ttl => ttl, :auth_type => auth_type}) end
lock(ticket, lock_timeout, lockid)
click to toggle source
# File lib/wwpass-ruby-sdk/wwpass_connection.rb, line 56 def lock(ticket, lock_timeout, lockid) make_request('GET','lock',:params => {:ticket => ticket, :lockid => lockid, :to => lock_timeout}) end
put_ticket(ticket, ttl = 120, auth_type = '')
click to toggle source
# File lib/wwpass-ruby-sdk/wwpass_connection.rb, line 36 def put_ticket(ticket, ttl = 120, auth_type = '') make_request('GET','put', :params => {:ticket => ticket, :ttl => ttl, :auth_type => auth_type}) end
read_data(ticket, container = '')
click to toggle source
# File lib/wwpass-ruby-sdk/wwpass_connection.rb, line 40 def read_data(ticket, container = '') make_request('GET','read', :params => {:ticket => ticket, :container => container}) end
read_data_and_lock(ticket, lock_timeout, container = '')
click to toggle source
# File lib/wwpass-ruby-sdk/wwpass_connection.rb, line 44 def read_data_and_lock(ticket, lock_timeout, container = '') make_request('GET','read', :params => {:ticket => ticket, :container => container, :lock => '1', :to => lock_timeout}) end
unlock(ticket, lockid)
click to toggle source
# File lib/wwpass-ruby-sdk/wwpass_connection.rb, line 60 def unlock(ticket, lockid) make_request('GET','unlock', :params => {:ticket => ticket, :lockid => lockid}) end
write_data(ticket, data, container = '')
click to toggle source
# File lib/wwpass-ruby-sdk/wwpass_connection.rb, line 48 def write_data(ticket, data, container = '') make_request('POST','write', {:ticket => ticket, :data => data, :container => container}, 1) end
write_data_and_unlock(ticket, data, container = '')
click to toggle source
# File lib/wwpass-ruby-sdk/wwpass_connection.rb, line 52 def write_data_and_unlock(ticket, data, container = '') make_request('POST','write', {:ticket => ticket, :data => data, :container => container, :unlock => '1'}, 1) end
Private Instance Methods
make_request(method, command, params = {}, attempts = 3)
click to toggle source
# File lib/wwpass-ruby-sdk/wwpass_connection.rb, line 67 def make_request(method, command, params = {}, attempts = 3) case when method == 'GET' response = JSON @resource[command + '.json'].get(params) when method == 'POST' response = JSON @resource[command + '.json'].post(params) end if response['result'] if response['encoding'] == 'plain' response['data'] else Base64.decode64 response['data'] end else #exception if attempts > 1 attempts = attempts - 1 make_request(method, command, params, attempts) else raise WWPassException.new 'SPFE return error: ', response['data'] end end end