-
-
Save ryancurtin/adef1885c882fa50abb202acefc5cb93 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CustomersController < ApplicationController | |
include CustomersHelper | |
def lookup_phone | |
customer_data = Customer.customer_data_by_type('phone', params[:PhoneNumber]) | |
reset_device(customer_data) | |
Customer.customer_data_to_json(customer_data) | |
end | |
def lookup_account_id | |
customer_data = Customer.customer_data_by_type('account_id', params[:AccountID]) | |
reset_device(customer_data) | |
Customer.customer_data_to_json(customer_data) | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Customer < ActiveRecord::Base | |
def self.customer_data_by_type(type, param) | |
Customer.send("lookup_#{type}", param) | |
end | |
def self.customer_data_to_json(objects) | |
if objects.blank? | |
objects += @match_not_found | |
else | |
objects = objects.map{|c| [c.match_found = true, c.transfer_flag = false, c.reset_url = Customer.obtain_url(c)]} | |
end | |
objects.to_json(:methods => [:transfer_flag, :match_found, :reset_url]) | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module CustomersHelper | |
def reset_device(customer_data) | |
url_list = [] | |
customer_data.each_with_index do |e, index| | |
url_list << e.reset_url | |
end | |
responses = [] | |
url_list.each do |url| | |
responses << RestClient::Request.execute(method: :get, url: url) | |
end | |
@success = [] | |
@failing = [] | |
responses.zip(customer_data).each do |res, customer| | |
data = Hash.from_xml(res) | |
cust_string = "Account Code: #{customer['AccountCode']}, Serial Number: #{customer['sSerialNumber']}" | |
if (data['string']['xmlns'] == "http://localhost/CHRPPVWS/") | |
@success << cust_string | |
else | |
@failing << cust_string | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment