Class: Trufina

Inherits:
Object
  • Object
show all
Defined in:
lib/trufina.rb,
lib/config.rb,
lib/elements.rb,
lib/requests.rb,
lib/responses.rb,
lib/exceptions.rb

Overview

This file defines all Trufina Exceptions

Defined Under Namespace

Modules: AllowCreationFromHash, Elements, Exceptions, Requests, Responses Classes: Config, Response

Class Method Summary collapse

Class Method Details

.access_request(auth = {}, data = {}) ⇒ Object

Given either an auth hash containing a PUR and a PRT (e.g. from an InfoResponse or LoginInfoResponse) or a suitable Trufina::*Response object directly (i.e. we can just pass the results of a Trufina.login_info_request directly for auth), as well as a data hash containing any data fields we wish to request about the specified user, sends a request for data off to Trufina. Trufina will respond immediately with a status of “pending” for the newly requested information, will notify the user via email that we’re requesting new info, and finally will notify us via an AccessNotification if/when the user grants us access to the additional data.



75
76
77
78
79
# File 'lib/trufina.rb', line 75

def access_request(auth = {}, data = {})
  auth = {:pur => auth.pur, :prt => auth.prt} unless auth.is_a?(Hash)
  xml = Requests::AccessRequest.new( auth.merge(:data => data) ).render
  sendToTrufina(xml)
end

.handle_access_notification(raw_xml) ⇒ Object

This should be exposed to the internet to receive Trufina’s postback after a user follows the login_url and completes a profile

Receives the access notification, and automatically sends a request for the actual information.



50
51
52
# File 'lib/trufina.rb', line 50

def handle_access_notification(raw_xml)
  info_request( parseFromTrufina(raw_xml).tnid )
end

.info_request(tnid) ⇒ Object

Given a TNID, send info_request



55
56
57
58
# File 'lib/trufina.rb', line 55

def info_request(tnid)
  xml = Requests::InfoRequest.new(:tnid => tnid).render
  sendToTrufina(xml)
end

.login_info_request(tlid) ⇒ Object

Given a TLID, send login_info_request



61
62
63
64
# File 'lib/trufina.rb', line 61

def (tlid)
  xml = Requests::LoginInfoRequest.new(:tlid => tlid).render
  sendToTrufina(xml)
end

.login_request(prt, opts = {}) ⇒ Object

Creates and sends a login request for the specified PRT

Examples:

Trufina.(Time.now)
Trufina.(Time.now, :requested => [:phone], :seed => {:name => {:first => 'Foo', :last => 'Bar'}})

Options:

* requested -- Hash of requested info to be returned once the user is done with Trufina
* seed  -- Hash of seed data used to prefill the user's forms at Trufina's website


21
22
23
24
25
# File 'lib/trufina.rb', line 21

def (prt, opts = {})
  opts[:requested] ||= {:name => [:first, :last]}
  xml = Requests::LoginRequest.new(:prt => prt, :data => opts[:requested], :seed => remove_empties_from_hash(opts[:seed] || [])).render
  sendToTrufina(xml)
end

.login_url(prt, opts = {}) ⇒ Object

Given a PRT, send the login request an return the redirect URL

Sends login request to get a PLID from Trufina, then uses that to build a redirect URL specific to this user.

Once user completes filling out their information and makes it available to us, Trufina will ping us with an access_notification to let us know it’s there and we should ask for it.

Options:

* demo  -- Boolean value. If true, and Trufina::Config.staging? is true, returns demo URL
* requested -- Hash of requested info to be returned once the user is done with Trufina
* seed  -- Hash of seed data used to prefill the user's forms at Trufina's website


40
41
42
43
# File 'lib/trufina.rb', line 40

def (prt, opts = {})
  plid = (prt, :requested => opts.delete(:requested), :seed => opts.delete(:seed)).plid
  ( plid, opts.delete(:demo) )
end

.schemaObject

Retreive Trufina’s XSD Schema



82
83
84
# File 'lib/trufina.rb', line 82

def schema
  @@schema ||= XML::Schema.from_string(open("http://www.trufina.com/api/truapi.xsd").read)
end