forked from adriand/gavel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gavel.rb
70 lines (64 loc) · 7.28 KB
/
gavel.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
require 'sinatra'
require 'net/http'
require 'uri'
require 'pry'
get '/' do
haml :index
end
get '/settings' do
haml :settings
end
get '/confirm' do
haml :confirm
end
post '/submit-complaint' do
# Check the README for details on how the city wants its form fields submitted.
post_params = {
"__VIEWSTATE" => 'dDwxNzUyNDY0MDEzO3Q8O2w8aTwzPjs+O2w8dDw7bDxpPDU+O2k8MTE+O2k8MTM+Oz47bDx0PDtsPGk8MD47aTwyPjs+O2w8dDxwPGw8VGV4dDs+O2w8XDxkaXYgY2xhc3M9InN1Ym5hdiJcPg0KICBcPHVsXD4NCiAgICBcPGxpXD4NCiAgICAgIFw8YSBocmVmPSIvQ2l0eURlcGFydG1lbnRzL0NvbW11bml0eVNlcnZpY2UvIlw+DQogICAgICAgIFw8c3Ryb25nXD5Db21tdW5pdHkgU2VydmljZXNcPC9zdHJvbmdcPg0KICAgICAgXDwvYVw+DQogICAgXDwvbGlcPg0KICAgIFw8dWxcPg0KICAgIFw8L3VsXD4NCiAgICBcPGxpXD4NCiAgICAgIFw8YSBocmVmPSIvQ2l0eURlcGFydG1lbnRzL0NvbnRhY3RVcy8iXD4NCiAgICAgICAgXDxzdHJvbmdcPkNvbnRhY3QgVXNcPC9zdHJvbmdcPg0KICAgICAgXDwvYVw+DQogICAgXDwvbGlcPg0KICAgIFw8dWxcPg0KICAgIFw8L3VsXD4NCiAgICBcPGxpXD4NCiAgICAgIFw8YSBocmVmPSIvQ2l0eURlcGFydG1lbnRzL0NvcnBvcmF0ZVNlcnZpY2VzLyJcPg0KICAgICAgICBcPHN0cm9uZ1w+Q29ycG9yYX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47Pj47Oz47Pj47Pj47Pj47Pj47bDxfeHBjTWV0YURhdGE7Pj5OwHs/MekAhEgMO/LfVIAa/1s7iw==',
"idSearchString" => "",
"COHShell:_ctl0:qQ_FNAME" => params[:first_name],
"COHShell:_ctl0:qQ_ADDRESS" => params[:address],
"COHShell:_ctl0:qQ_LNAME" => params[:last_name],
"COHShell:_ctl0:qQ_PCODE" => params[:postal_code],
"COHShell:_ctl0:qQ_HOMEPHONE" => params[:primary_phone],
"COHShell:_ctl0:qQ_CITY_CONTACT" => params[:city],
"COHShell:_ctl0:qQ_WORKNUMBER" => params[:secondary_phone],
"COHShell:_ctl0:qQ_EMAIL" => params[:email],
"COHShell:_ctl0:qQ_VADDRESS" => params[:complaintStreetAddress],
"COHShell:_ctl0:qQ_CITY" => params[:complaintCity],
"COHShell:_ctl0:qQ_VFNAME" => "",
"COHShell:_ctl0:qQ_VLNAME" => "",
"COHShell:_ctl0:qQ_COMPOLD" => "",
"COHShell:_ctl0:qQ_COMP" => params[:complaintComplaint],
"COHShell:_ctl0:qQ_OCOMP" => "",
"COHShell:_ctl0:qQ_COMMENTS" => params[:complaintComments],
"COHShell:_ctl0:Button1" => "Submit Form"
}
begin
uri = URI.parse("http://www.hamilton.ca/Hamilton.Portal/Templates/COHShell.aspx?NRMODE=Published&NRORIGINALURL=%2fCityDepartments%2fCorporateServices%2fITS%2fForms%2bin%2bDevelopment%2fMunicipal%2bLaw%2bEnforcement%2bOnline%2bComplaint%2bForm%2ehtm&NRNODEGUID=%7b4319AA7C-7E5E-4D65-9F46-CCBEC9AB86E0%7d&NRCACHEHINT=Guest")
http = Net::HTTP.new(uri.host, uri.port)
request = Net::HTTP::Post.new(uri.request_uri)
request.set_form_data(post_params)
response = http.request(request)
if response.code == "200"
parse_success_response(response)
else
"Error"
end
rescue StandardError, Timeout::Error => e
"Error"
end
end
def parse_success_response(response)
# the success page uses javascript to hide the main form and show the success form (thank you, diff!)
if response.body =~ /document\.getElementById\('mainform'\)\.style\.display = 'none';/
"Success"
else
"There was a problem submitting your complaint on the City's website."
end
end