Skip to content

Instantly share code, notes, and snippets.

@gaurish
Created November 20, 2014 22:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gaurish/c12c3236100d8877f56d to your computer and use it in GitHub Desktop.
Save gaurish/c12c3236100d8877f56d to your computer and use it in GitHub Desktop.
require 'net/http'
require 'json'
require 'rack'
URL="http//staging.punchh.com"
def params(match_data)
json = JSON.parse(match_data[2].gsub("=>", ":").gsub('nil', '"NULL"'))
Rack::Utils.build_query json.to_h
end
log_regex = Regexp.compile(/\A"(\S+)"\s+Parameters:\s+(.+)\z/)
data_file = File.new('missing_records_cap_21nov_v2.txt', 'r')
i = 0
data_file.each_line do |line|
match_data = log_regex.match line.strip.chomp
next if match_data.nil?
request = Net::HTTP::Post.new(match_data[1])
request.add_field "Content-Type",'application/x-www-form-urlencoded'
# request.add_field "HTTP_AUTHORIZATION", token_goes_here
# request.add_field "punchh-app-key", punchh_app_key_goes_here
request.body = params(match_data)
uri = URI.parse(URL)
http = Net::HTTP.new(uri.host, uri.port)
puts "#{i}. #{match_data[1]} -- #{params(match_data)}"
#http.request(request)
i+=1
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment