Any ideas?
Here is the code which is from 'http://www.expendablewords.com/2008/09/01/automatic-my-coke-rewards-code-entry/'
require 'xmlrpc/client'
require 'logger'
class McrSender
@@SERVICE_URL = "https://secure.mycokerewards.com/xmlrpc"
def initialize(codeFile, logFile, readCount, username, password)
@codeFile = codeFile
@logFile = logFile
@readCount = readCount
@username = username
@password = password
@logger = Logger.new(@logFile)
end
def send_codes
i = 1
# read file into an array
lines = File.readlines(@codeFile)
lineCount = lines.length
if(lineCount > 0 and lines[0].strip.length > 0)
# login
if(login == true)
@logger.info "Successfully logged in."
puts lineCount
# process items and remove them from the array
i = 0
while (i < @readCount && i < lineCount)
code = lines[0].chomp
send_code(code)
lines.delete_at(0)
i += 1
end
# write array back to file
File.open(@codeFile, "w") do |file|
file.puts(lines.join())
end
else
@logger.error "Could not login with username '#{@username}' and password '#{@password}'."
end
else
@logger.info "No codes found in code file (or the first line is empty). Exiting."
end
end
private
def send_code(code)
args = {'emailAddress' => @username, 'password' => @password, 'screenName' => ' ', 'capCode' => code, 'VERSION' => '3.0'}
service = XMLRPC::Client.new2(@@SERVICE_URL)
result = service.call('points.enterCode', args)
if(result[0]['ENTER_CODE_RESULT'] == "true")
earned = result[0]['POINTS_EARNED']
@logger.info "Successfully entered code '#{code}' Points earned '#{earned}'. "
else
message = result[0]['MESSAGES']
@logger.error "Error entering code '#{code}'. Error message: '#{message}'."
end
end
def login
args = {'emailAddress' => @username, 'password' => @password, 'screenName' => ' ', 'VERSION' => '3.0'}
service = XMLRPC::Client.new2(@@SERVICE_URL)
result = service.call('points.pointsBalance', args)
result[0]['LOGIN_RESULT'] == "true"
end
end
sender = McrSender.new("codes.txt", "log.txt", 10, "YOUR_EMAIL", "YOUR_PASSWORD")
sender.send_codes

New Topic/Question
Reply




MultiQuote


|