class Weimark::Client
Constants
- WEIMARK_URL
Attributes
agents_email[R]
email[R]
password[R]
url[R]
Public Class Methods
new(options = {})
click to toggle source
# File lib/weimark/client.rb, line 11 def initialize(options = {}) @url = options[:url] || WEIMARK_URL @email = options[:email] || ENV['WEIMARK_EMAIL'] @password = options[:password] || ENV['WEIMARK_PASSWORD'] @agents_email = options[:agents_email] || ENV['AGENTS_EMAIL'] end
Public Instance Methods
get(application_id)
click to toggle source
# File lib/weimark/client.rb, line 18 def get(application_id) request( http_method: :post, endpoint: url, body: { request: xml_request( action: "GetApplication", agents_email: agents_email, body: { applicationid: application_id } ) } ) end
post(application_attributes = {})
click to toggle source
Sample application_attributes: {fname: 'JONATHAN', lname: 'CONSUMER', dob: '01/05/1987', gender: 'male', ssn: '485774859', streetnumber: '236', streetname: 'BIRCH', streettype: 'S', city: 'BURBANK', country: 'USA', suite: '1TEST', zip: '91502'}
# File lib/weimark/client.rb, line 36 def post(application_attributes = {}) request( http_method: :post, endpoint: url, body: { request: xml_request( action: "NewApplication", agents_email: agents_email, body: { applicant: application_attributes } ) } ) end
Private Instance Methods
request(http_method:, endpoint:, body: {})
click to toggle source
# File lib/weimark/client.rb, line 54 def request(http_method:, endpoint:, body: {}) response = Weimark::Response.new(HTTParty.public_send(http_method, endpoint, body: body)) end
xml_request(action:, agents_email:, body: {})
click to toggle source
# File lib/weimark/client.rb, line 58 def xml_request(action:, agents_email:, body: {}) Nokogiri::XML::Builder.new do |xml| xml.root { xml.action action xml.email email xml.password password xml.agents_email agents_email xml.request { body.each do |k, v| if v.is_a?(Hash) xml.send(k) { v.each { |k, v| xml.send(k, v) } } else xml.send(k, v) end end } } end.to_xml.gsub("root", "xml") end