Created
June 11, 2014 16:24
-
-
Save seanrclayton/4ec0cfb46a0bb16223a9 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
require 'rest_client' | |
require 'digest/sha1' | |
require 'base64' | |
require 'xmlsimple' | |
##time | |
time = Time.new | |
month = time.month | |
day = time.day | |
hour = time.hour | |
minute = time.min | |
second = time.sec | |
if day.length < 2 | |
day = "0#{day}" | |
end | |
if month.length < 2 | |
month = "0#{month}" | |
end | |
if hour.length < 2 | |
hour = "0#{hour}" | |
end | |
if minute.length < 2 | |
minute = "0#{minute}" | |
end | |
if second.length < 2 | |
second = "0#{second}" | |
end | |
##end time | |
userkey = "ZX+wTKV08HbFGTMmPZYP" | |
secretkey = "0TVQ/gWUFmR4H56nUmzLdMcbI/HNwbLXtDgEJlEp" | |
timestamp= "#{time.year}" + "0#{time.month}" + "#{time.day}" + "#{time.hour}" + "#{time.min}" + "#{time.sec}" | |
#*****************info for header******************************* | |
useragent = "Volusion" | |
data_to_sign = userkey + useragent + timestamp+ secretkey | |
hash = Base64.encode64(Digest::SHA1.digest(data_to_sign)) | |
signature = userkey + ":" + timestamp + ":" + hash | |
#*********end info for header ***************** | |
##-------------function to read from file and write to new file if it exists in rackspace-------- | |
file = File.open("descrep.txt", "r") | |
contents = file.read | |
fixedcontents =contents.split "," | |
fixedcontents.each do |x| | |
url = "https://api.emailsrvr.com/v0/customers?startswith=#{x}" | |
res = RestClient.get(url, headers={'User-Agent' => 'Volusion','X-Api-Signature' => signature}) | |
#xml parse | |
parsed = XmlSimple.xml_in(res) | |
#end xml parse | |
fname = "returned_from_descrep.txt" | |
somefile = File.open(fname, 'a') | |
somefile.puts parsed | |
if x.length > 1 | |
sleep (1) | |
else | |
somefile.close | |
end | |
endclass | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment