class JumioRock::Client
Attributes
api_url[RW]
init_embed_url[RW]
init_redirect_url[RW]
multi_document_url[RW]
retrieval_url[RW]
Public Class Methods
jumio_js()
click to toggle source
# File lib/jumio_rock/client.rb, line 90 def self.jumio_js '<script type="text/javascript" src="https://netverify.com/widget/jumio-verify/2.0/iframe-script.js"> </script>' end
new()
click to toggle source
# File lib/jumio_rock/client.rb, line 6 def initialize @api_url = conf.api_url @init_embed_url = conf.init_embed_url @init_redirect_url = conf.init_redirect_url @multi_document_url = conf.multi_document_url @retrieval_url = conf.retrieval_url @initialization_type = nil end
Public Instance Methods
call_api(scan_reference, front_side_image_path, options = {})
click to toggle source
# File lib/jumio_rock/client.rb, line 15 def call_api(scan_reference, front_side_image_path, options = {}) body = PerformNetverifyParams.new(scan_reference, front_side_image_path) body = set_options body, options post(api_url, body.to_json) end
iframe(locale = "en")
click to toggle source
# File lib/jumio_rock/client.rb, line 62 def iframe(locale = "en") iframe_html(locale, js_type) end
iframe_html(locale = "en", type = "initVerify")
click to toggle source
# File lib/jumio_rock/client.rb, line 66 def iframe_html(locale = "en", type = "initVerify") <<-TEXT #{self.class.jumio_js} <script type="text/javascript"> /*<![CDATA[*/ #{js_request(locale, type)} /*]]>*/ </script> TEXT end
init_embed(scan_reference, success_url, error_url, options = {})
click to toggle source
# File lib/jumio_rock/client.rb, line 21 def init_embed(scan_reference, success_url, error_url, options = {}) @initialization_type = :embed body = EmbedNetverifyParams.new(scan_reference, success_url, error_url) body = set_options body, options response = post(init_embed_url, body.to_json) @authorization_token = response.authorizationToken response end
init_multidocument(document_type, merchant_scan_reference, customer_id, success_url, error_url, options = {})
click to toggle source
# File lib/jumio_rock/client.rb, line 37 def init_multidocument(document_type, merchant_scan_reference, customer_id, success_url, error_url, options = {}) @initialization_type = :multi body = MultiDocumentNetverifyParams.new(document_type, merchant_scan_reference, customer_id, success_url, error_url) body = set_options body, options response = post(multi_document_url, body.to_json) @authorization_token = response.authorizationToken response end
init_redirect(scan_reference, customer_id, options = {})
click to toggle source
# File lib/jumio_rock/client.rb, line 30 def init_redirect(scan_reference, customer_id, options = {}) @initialization_type = :redirect body = RedirectNetverifyParams.new(scan_reference, customer_id) body = set_options body, options post(init_redirect_url, body.to_json) end
js(locale = "en")
click to toggle source
# File lib/jumio_rock/client.rb, line 77 def js(locale = "en") js_request(locale, js_type) end
js_request(locale, type)
click to toggle source
# File lib/jumio_rock/client.rb, line 81 def js_request(locale, type) <<-TEXT JumioClient.setVars({ authorizationToken: \"#{authorization_token}\", locale: \"#{locale}\" }).#{type}(\"JUMIOIFRAME\"); TEXT end
retrieval_url_base(scan_reference)
click to toggle source
# File lib/jumio_rock/client.rb, line 58 def retrieval_url_base(scan_reference) File.join(retrieval_url, scan_reference.to_s) end
retrieve(scan_reference)
click to toggle source
# File lib/jumio_rock/client.rb, line 46 def retrieve(scan_reference) @initialization_type = :retrieve url = retrieval_url_base(scan_reference) get(url) end
retrieve_document_data(scan_reference)
click to toggle source
# File lib/jumio_rock/client.rb, line 52 def retrieve_document_data(scan_reference) @initialization_type = :retrieve_document_data url = File.join(retrieval_url_base(scan_reference), 'data/document') get(url) end
Private Instance Methods
conf()
click to toggle source
# File lib/jumio_rock/client.rb, line 129 def conf Configuration.configuration end
get(url)
click to toggle source
# File lib/jumio_rock/client.rb, line 118 def get(url) connection = Excon.new(url, user: conf.api_token, password: conf.api_secret) response = connection.request( method: 'GET', headers: headers ) OpenStruct.new JSON.parse(response.body) end
headers()
click to toggle source
# File lib/jumio_rock/client.rb, line 133 def headers { 'Accept' => 'application/json', 'Content-Type' => 'application/json', 'User-Agent' => "#{conf.company_name} #{conf.app_name}/#{conf.version}" } end
js_type()
click to toggle source
# File lib/jumio_rock/client.rb, line 96 def js_type raise "Client not initialized (init_embed or init_multidocument)" unless @initialization_type @initialization_type == :multi ? "initMDM" : "initVerify" end
post(url, body)
click to toggle source
# File lib/jumio_rock/client.rb, line 108 def post(url, body) connection = Excon.new(url, :user => conf.api_token, :password => conf.api_secret) response = connection.request( method: 'POST', headers: headers, body: body ) OpenStruct.new JSON.parse(response.body) end
set_options(body, options)
click to toggle source
# File lib/jumio_rock/client.rb, line 101 def set_options(body, options) options.each do |k, v| body.send("#{k}=", v) end body end