-
Notifications
You must be signed in to change notification settings - Fork 1
/
module
102 lines (83 loc) · 2.04 KB
/
module
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
require 'rubygems'
require 'mechanize'
require 'open-uri'
class Bot
def initialize
@agent = Mechanize.new
@agent.get(CAMPGROUND_URL)
end
def fetch_site!
enter_search_criteria
click_first_available_site
click_book_these_dates
enter_login_credentials
enter_site_details
proceed_to_checkout
# enter_billing_information
end
def print_links
@agent.page.links.each do |link|
puts link.href
end
end
def print_forms
@agent.page.forms[0].fields.each_with_index do |field, index|
puts "#{index}: #{field.name}"
end
end
def print_body
puts @agent.page.body
end
private
def change_value(field_num, new_value)
@agent.page.forms[0].fields[field_num].value = new_value
end
def submit_form(num)
@agent.page.forms[num].submit
end
def check_box(name)
@agent.page.forms[0].checkbox_with(:name => name).check
end
def enter_search_criteria
change_value(6, SITES)
change_value(20, ARRIVAL)
change_value(21, NIGHTS)
change_value(23, '2003') # '2003' => tent
change_value(9, 6) # 6 => max occupants
submit_form(0)
end
def click_first_available_site
@agent.page.link_with(:dom_class => 'book now').click
end
def click_book_these_dates
submit_form(0)
end
def enter_login_credentials
change_value(0, EMAIL)
change_value(1, PASSWORD)
submit_form(0)
end
def enter_site_details
change_value(19, 108060) # 108060 => tent
change_value(4, 6) # 6 => max occupants
change_value(5, 2) # 3 => max vehicles
check_box('agreementAccepted')
submit_form(0)
end
def proceed_to_checkout
submit_form(1)
end
def enter_billing_information
change_value(20, CARD_TYPE)
change_value(5, CARD_NO)
change_value(6, SECURITY_CODE)
change_value(7, EXPIRATION_MONTH)
change_value(8, EXPIRATION_YEAR)
change_value(9, FIRST_NAME)
change_value(10, LAST_NAME)
check_box('acknowlegeAccepted')
submit_form(0)
end
end
cyber_raccoon = Bot.new
cyber_raccoon.fetch_site!