module Tidas::Client
Private Class Methods
activate(id)
click to toggle source
# File lib/tidas/client.rb, line 74 def self.activate(id) body = {tidas_id: id} wrapped_post('identities/activate', body) end
api_key()
click to toggle source
# File lib/tidas/client.rb, line 22 def self.api_key Configuration.api_key end
application()
click to toggle source
# File lib/tidas/client.rb, line 26 def self.application Configuration.application end
client()
click to toggle source
# File lib/tidas/client.rb, line 11 def self.client unless server && api_key && application raise(ConfigurationError,"Tidas not configured: see readme for help") end @client ||= Faraday.new(url:server) end
deactivate(id)
click to toggle source
# File lib/tidas/client.rb, line 69 def self.deactivate(id) body = {tidas_id: id} wrapped_post('identities/deactivate', body) end
enroll(data, id, overwrite)
click to toggle source
# File lib/tidas/client.rb, line 46 def self.enroll(data, id, overwrite) body = {} body[:enrollment_data] = data body[:tidas_id] = id if !id.to_s.empty? body[:overwrite] = true if overwrite wrapped_post('identities/enroll', body) end
get(url, extra_params = nil)
click to toggle source
# File lib/tidas/client.rb, line 105 def self.get(url, extra_params = nil) resp = client.get do |req| req.url url req.params['api_key'] = api_key req.params['application'] = application if extra_params != nil extra_params.each do |param, value| req.params[param] = value end end req.options[:timeout] = timeout end resp end
get_identity(id)
click to toggle source
# File lib/tidas/client.rb, line 42 def self.get_identity(id) wrapped_get("identities/index", {tidas_id: id}) end
index_identities()
click to toggle source
# File lib/tidas/client.rb, line 38 def self.index_identities wrapped_get("identities/index") end
ping()
click to toggle source
# File lib/tidas/client.rb, line 34 def self.ping wrapped_get('ping') end
post(url, body)
click to toggle source
# File lib/tidas/client.rb, line 123 def self.post(url, body) resp = client.post do |req| req.url url req.headers['Content-Type'] = 'application/json' req.params['api_key'] = api_key req.options[:timeout] = timeout body[:application] = application req.body = body.to_json end resp end
server()
click to toggle source
# File lib/tidas/client.rb, line 18 def self.server Configuration.server end
timeout()
click to toggle source
# File lib/tidas/client.rb, line 30 def self.timeout Configuration.timeout.to_i end
validate(data, id = nil)
click to toggle source
# File lib/tidas/client.rb, line 55 def self.validate(data, id = nil) begin tidas_data = Utilities::Unpacker.init_with_blob(data) rescue StandardError, NoMethodError raise(ParameterError,"Invalid data for request") end body = {} body[:validation_data] = tidas_data.to_s body[:tidas_id] = id if !id.to_s.empty? wrapped_post('identities/validate', body, tidas_data.parse[:data_to_sign]) end
wrapped_get(url, extra_params = nil)
click to toggle source
# File lib/tidas/client.rb, line 79 def self.wrapped_get(url, extra_params = nil) begin resp = get(url, extra_params) rescue Faraday::TimeoutError return TimeoutError rescue Faraday::ConnectionFailed return ConnectionError end return Utilities::ResponsePackager.package_response(resp) end
wrapped_post(url, body, data = nil)
click to toggle source
# File lib/tidas/client.rb, line 90 def self.wrapped_post(url, body, data = nil) begin resp = post(url,body) if data return Utilities::ResponsePackager.package_response(resp, data) else return Utilities::ResponsePackager.package_response(resp) end rescue Faraday::TimeoutError return TimeoutError rescue Faraday::ConnectionFailed return ConnectionError end end