Created
May 8, 2011 11:50
-
-
Save anwajler/961321 to your computer and use it in GitHub Desktop.
Smartpay.pl handling
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
require 'net/http' | |
require 'net/https' | |
MESSAGES = { | |
# OK | |
"1001" => "kod zostal znaleziony i jest aktywny", | |
# INACTIVE | |
"2001" => "szukany kod nie zostal znaleziony", | |
"2002" => "kod zostal znaleziony, ale nie jest juz aktywny", | |
# ERROR | |
"3001" => "brakuje ktoregos z parametrow (password, service lub code)", | |
"3004" => "podany identyfikator (parametr 'service') jest nieprawidlowy", | |
"3005" => "ktorys z parametrow ma nieprawidlowy format", | |
"3006" => "bledna kombinacja hasla uzytkownika i identyfikatora (subprefixu)", | |
"5001" => "blad wewnetrzny po stronie serwera Smartpay" | |
} | |
host = 'www.smartpay.pl' | |
code = '' | |
service = '' | |
password = '' | |
rate = '' | |
just_check = 'true' | |
http = Net::HTTP.new(host, 443) | |
http.use_ssl = true | |
path = "/check/?service=#{service}&password=#{password}&code=#{code}&just_check=#{just_check}&rate=#{rate}" | |
# GET request -> so the host can set his cookies | |
resp, data = http.get(path, nil) | |
status, message = data.split("\n") | |
msg_id = message.split(":")[0] | |
case status | |
when "OK" | |
puts MESSAGES[msg_id] | |
when "INACTIVE" | |
puts MESSAGES[msg_id] | |
when "ERROR" | |
puts MESSAGES[msg_id] | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment