Class: StrongKeyLite
- Inherits:
-
Object
- Object
- StrongKeyLite
- Includes:
- API
- Defined in:
- lib/skles.rb,
lib/skles_api.rb
Overview
Client for the StrongKey Lite Encryption System (SKLES) SOAP-based API. An instance of this API interfaces with your StrongKey Lite box to encrypt and decrypt credit card numbers into the vault.
Since many StrongKey Lite setups use different logins to perform different tasks (e.g., a more secure login/password is used to decrypt credit cards than to encrypt them), this class supports storing multiple sets of credentials, choosing them depending on the operation being performed.
Defined Under Namespace
Modules: API Classes: HTTPError, ResponseError, SOAPError
Instance Attribute Summary collapse
-
#domain_id ⇒ Object
The domain ID of the StrongKey service.
Class Method Summary collapse
-
.http_adapter=(adapter) ⇒ Object
Sets the HTTPI adapter to use for Savon.
Instance Method Summary collapse
-
#actions ⇒ Array<Symbol>
A list of actions that the API can perform.
-
#add_user(login, password, *actions_for_user) ⇒ Object
Adds a user by login and password.
-
#call(meth, options = {}) ⇒ Hash
Makes an API call and returns the result as a hash.
-
#initialize(service_url, domain_id, options = {}) {|http| ... } ⇒ StrongKeyLite
constructor
Creates a new client interface.
-
#set_user_for_actions(login, action, ...) ⇒ Object
(also: #set_user_for_action)
Tells the client to use this user for a list of actions.
Methods included from API
#decrypt, #delete, #encrypt, #ping, #search
Constructor Details
#initialize(service_url, domain_id, options = {}) {|http| ... } ⇒ StrongKeyLite
Creates a new client interface.
52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/skles.rb', line 52 def initialize(service_url, domain_id, ={}) @client = Savon::Client.new do |wsdl, http, wsse| wsdl.document = "#{service_url}/strongkeyliteWAR/EncryptionService?wsdl" yield http if block_given? end [:http].each { |key, val| @client.request.http.send :"#{key}=", val } if [:http].kind_of?(Hash) self.domain_id = domain_id @users = {} @users_for_action = {} add_user([:login], [:password], :all) if [:login] and [:password] end |
Instance Attribute Details
#domain_id ⇒ Object
The domain ID of the StrongKey service.
34 35 36 |
# File 'lib/skles.rb', line 34 def domain_id @domain_id end |
Class Method Details
.http_adapter=(adapter) ⇒ Object
Sets the HTTPI adapter to use for Savon. By default it’s @:net_http@.
143 144 145 |
# File 'lib/skles.rb', line 143 def self.http_adapter=(adapter) Savon.http_adapter = adapter end |
Instance Method Details
#actions ⇒ Array<Symbol>
Returns A list of actions that the API can perform.
111 112 113 |
# File 'lib/skles.rb', line 111 def actions @actions ||= @client.wsdl.soap_actions end |
#add_user(login, password) ⇒ Object #add_user(login, password, action, ...) ⇒ Object #add_user(login, password, : all) ⇒ Object
Adds a user by login and password. These users are used to perform API actions.
85 86 87 88 89 90 91 92 |
# File 'lib/skles.rb', line 85 def add_user(login, password, *actions_for_user) @users[login] = password if actions_for_user == [ :all ] then actions.each { |action| set_user_for_action(login, action) } else actions_for_user.each { |action| set_user_for_action(login, action) } end end |
#call(meth, options = {}) ⇒ Hash
Makes an API call and returns the result as a hash. This method is the basis of all the more high-level API methods.
125 126 127 128 129 130 131 132 133 134 135 136 137 |
# File 'lib/skles.rb', line 125 def call(meth, ={}) raise ArgumentError, "Unknown action #{meth.inspect}" unless actions.include?(meth) login = @users_for_action[meth] raise "No user has been assigned to action #{meth.inspect}" unless login password = @users[login] response = @client.request(:wsdl, meth) { |soap| soap.body = { did: domain_id, username: login, password: password }.merge() } raise SOAPError.new(response.soap_fault, response) if response.soap_fault? raise HTTPError.new(response.http_error, response) if response.http_error? return response.to_hash end |
#set_user_for_actions(login, action, ...) ⇒ Object Also known as: set_user_for_action
102 103 104 105 106 |
# File 'lib/skles.rb', line 102 def set_user_for_actions(login, *actions_for_user) actions.flatten! raise ArgumentError, "Unknown action(s): #{(actions_for_user - actions).join(',' )}" unless (actions_for_user - actions).empty? actions_for_user.each { |action| @users_for_action[action] = login } end |