Class: WWPassConnection

Inherits:
Object
  • Object
show all
Defined in:
lib/wwpass-ruby-sdk/wwpass_connection.rb

Instance Method Summary collapse

Constructor Details

#initialize(cert_file, key_file, cafile, timeout = 10, spfe_addr = 'https://spfe.wwpass.com') ⇒ WWPassConnection

Returns a new instance of WWPassConnection.



7
8
9
10
11
12
13
14
15
16
# 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

Instance Method Details

#get_nameObject



18
19
20
21
22
23
24
25
26
# 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 = '') ⇒ Object



32
33
34
# 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) ⇒ Object



28
29
30
# 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) ⇒ Object



56
57
58
# 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 = '') ⇒ Object



36
37
38
# 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 = '') ⇒ Object



40
41
42
# 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 = '') ⇒ Object



44
45
46
# 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) ⇒ Object



60
61
62
# 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 = '') ⇒ Object



48
49
50
# 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 = '') ⇒ Object



52
53
54
# 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