0 Replies - 2185 Views - Last Post: 03 May 2012 - 09:14 AM Rate Topic: -----

#1 c0moshack  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 1
  • Joined: 12-January 10

/xmlrpc/client.rb:549:in `do_rpc': HTTP-Error: 301 Moved Permanent

Posted 03 May 2012 - 09:14 AM

I am trying to use this ruby script to enter the hundreds of codes that I have, but it returns a "301 Moved Permanently" error. However, when I enter the xmlrpc url into the browser it returns a message saying the service is running.

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



Is This A Good Question/Topic? 1
  • +

Page 1 of 1