Skip to content

Instantly share code, notes, and snippets.

@ornerymoose
Last active May 23, 2017 22:18
Show Gist options
  • Save ornerymoose/6cd7633acbeb2364c81c8d7e8c3c867a to your computer and use it in GitHub Desktop.
Save ornerymoose/6cd7633acbeb2364c81c8d7e8c3c867a to your computer and use it in GitHub Desktop.
class CustomersController < ApplicationController
include CustomersHelper
def lookup_phone
customer_phone = Customer.lookup_phone(params[:PhoneNumber])
if customer_phone == []
customer_phone += @match_not_found
else
customer_phone = Customer.lookup_phone(params[:PhoneNumber]).each {|c| [c.match_found = true, c.transfer_flag = false, c.reset_url = Customer.obtain_url(c)]}
end
customer_phone.to_json(:methods => [:transfer_flag, :match_found, :reset_url])
reset_device(customer_phone)
end
def lookup_account_id
customer_account_id = Customer.lookup_account_id(params[:AccountID])
if customer_account_id == []
customer_account_id += @match_not_found
else
customer_account_id = Customer.lookup_account_id(params[:AccountID]).each {|c| [c.match_found = true, c.transfer_flag = false, c.reset_url = Customer.obtain_url(c)]}
end
customer_account_id.to_json(:methods => [:transfer_flag, :match_found, :reset_url])
reset_device(customer_account_id)
end
end
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