Created
July 16, 2009 21:37
-
-
Save jamster/148709 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| #!/usr/bin/env ruby | |
| # Author => Jason Amster | |
| # Email => jayamster@gmail.com | |
| # Time.now => Thu Jul 16 17:33:50 -0400 2009 | |
| # Purpose => To get those friggin error codes off of Authorize.net and into somthing i can actually use | |
| require 'rubygems' | |
| require "activesupport" | |
| require 'hpricot' | |
| require 'open-uri' | |
| def fetch_and_html_and_parse_to_arry(url='http://developer.authorize.net/guides/SIM/Transaction_Response/Response_Reason_Codes_and_Response_Reason_Text.htm') | |
| puts url | |
| html = open(url).read | |
| doc = Hpricot html | |
| elements = doc/"tr" | |
| output = [] | |
| elements.each do |e| | |
| tds = e/'td' | |
| row = tds.map do |td| | |
| el = td/'p/' | |
| el.to_s.strip | |
| end.inject([]){|arr, el| arr << el; arr} | |
| output << row unless row[0] == 'RESPONSE CODE' | |
| end | |
| output | |
| end | |
| def sanitize_anchor_links(yaml_string) | |
| yaml_string.gsub(/<a name=\"[0-9]\"><\/a>/, '') | |
| end | |
| def save_results(array, file_name='authnet_codes.yml') | |
| text = sanitize_anchor_links(array.to_yaml) | |
| f = File.new(File.dirname(__FILE__)+"/#{file_name}" , 'w') | |
| f.write(text) | |
| f.close | |
| end | |
| save_results(fetch_and_html_and_parse_to_arry) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment