ubcbooker 0.2.2 → 0.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/README.md +15 -2
- data/Rakefile +1 -0
- data/lib/ubcbooker/cli.rb +13 -22
- data/lib/ubcbooker/config.rb +22 -2
- data/lib/ubcbooker/error.rb +20 -0
- data/lib/ubcbooker/scrapers/cs.rb +10 -3
- data/lib/ubcbooker/version.rb +1 -1
- metadata +2 -4
- data/bin/setup +0 -8
- data/lib/ubcbooker/account.rb +0 -31
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 053f9ad2f8d23269ce39d0c7e6cf53b51774d810
|
4
|
+
data.tar.gz: 79624f9a62de98c504efc5a53b96ee94da8ab41d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8464319a1fbebeb17ae4c7e66ff9335cf2a3125bd5cfe81b8aec9eacafd93b40d8b14813dbec3258bce30601eb3f0d0984b8fe77dfdc202dacb206edd4bdcca6
|
7
|
+
data.tar.gz: 5990bc3fdb45c82be09c794b712e199701a8a13d427281b480c6ba94c2ba889c8cccd6d609dfdd1dba5e8787fdcbea232dbb823bcdfab5c3a1e2f9747c053ec5
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -2,6 +2,8 @@
|
|
2
2
|
|
3
3
|
CLI tool to book project rooms in UBC
|
4
4
|
|
5
|
+

|
6
|
+
|
5
7
|
## Installation
|
6
8
|
|
7
9
|
Install it as:
|
@@ -21,7 +23,17 @@ And then execute:
|
|
21
23
|
## Usage
|
22
24
|
|
23
25
|
```
|
24
|
-
|
26
|
+
# Book a room in CS with the name 'Study Group' from 11am to 1pm on March 5th
|
27
|
+
|
28
|
+
$ ubcbooker -b cs -n 'Study Group' -d 03/05 -t 11:00-13:00
|
29
|
+
```
|
30
|
+
|
31
|
+
When you first run the command it will ask for your CWL account auth info. This is saved locally within the gem as `config.yml`. You can look at [sample.yml](https://github.com/jumbosushi/ubcbooker/blob/master/lib/ubcbooker/sample.yml) to understand what it will look like.
|
32
|
+
|
33
|
+
Run `ubcbooker -u` to update the CWL auth info.
|
34
|
+
|
35
|
+
```
|
36
|
+
$ ubcbooker --help
|
25
37
|
|
26
38
|
Usage: ubcbooker [options]
|
27
39
|
-b, --building BUILDING Specify which department to book rooms from
|
@@ -37,7 +49,8 @@ ex. Book a room in CS from 11am to 1pm on March 5th with the name 'Study Group'
|
|
37
49
|
$> ubcbooker -b cs -n 'Study Group' -d 03/05 -t 11:00-13:00
|
38
50
|
```
|
39
51
|
|
40
|
-
Currently this app supports project rooms in cs (Commputer Science).
|
52
|
+
Currently this app supports project rooms in cs (Commputer Science). Run `ubcbooker -l` to check the latest supported departments.
|
53
|
+
|
41
54
|
Feel free to send a PR that supports your department's rooms.
|
42
55
|
|
43
56
|
## Development
|
data/Rakefile
CHANGED
data/lib/ubcbooker/cli.rb
CHANGED
@@ -7,16 +7,6 @@ module Ubcbooker
|
|
7
7
|
@options = nil
|
8
8
|
end
|
9
9
|
|
10
|
-
def ask_config
|
11
|
-
print "Your CWL username: "
|
12
|
-
username = gets.chomp
|
13
|
-
print "Your CWL password: "
|
14
|
-
# Hide the password input
|
15
|
-
password = STDIN.noecho(&:gets).chomp
|
16
|
-
@config.write(username, password)
|
17
|
-
puts
|
18
|
-
end
|
19
|
-
|
20
10
|
def parse_options
|
21
11
|
|
22
12
|
# This will hold the options we parse
|
@@ -47,9 +37,8 @@ module Ubcbooker
|
|
47
37
|
|
48
38
|
parser.on("-h", "--help", "Show this help message") do
|
49
39
|
puts parser
|
50
|
-
puts
|
51
|
-
|
52
|
-
puts " $>ubcbooker -b cs -n 'Study Group' -d 03/05 -t 11:00-13:00"
|
40
|
+
puts "\nex. Book a room in CS from 11am to 1pm on March 5th with the name 'Study Group'\n" <<
|
41
|
+
" $ ubcbooker -b cs -n 'Study Group' -d 03/05 -t 11:00-13:00"
|
53
42
|
exit(0)
|
54
43
|
end
|
55
44
|
|
@@ -75,7 +64,7 @@ module Ubcbooker
|
|
75
64
|
end
|
76
65
|
|
77
66
|
parser.on("-u", "--update", "Update username and password") do |v|
|
78
|
-
|
67
|
+
@config.ask
|
79
68
|
exit(0)
|
80
69
|
end
|
81
70
|
|
@@ -89,7 +78,7 @@ module Ubcbooker
|
|
89
78
|
spinner.success("Done!") # Stop animation
|
90
79
|
|
91
80
|
if CLI::Validator.is_required_missing(options)
|
92
|
-
raise
|
81
|
+
raise Ubcbooker::Error::MissingRequired
|
93
82
|
end
|
94
83
|
|
95
84
|
return options
|
@@ -101,15 +90,11 @@ module Ubcbooker
|
|
101
90
|
Ubcbooker::Error::UnsupportedTime,
|
102
91
|
Ubcbooker::Error::UnsupportedDate,
|
103
92
|
Ubcbooker::Error::ProfaneName,
|
93
|
+
Ubcbooker::Error::MissingRequired,
|
104
94
|
]
|
105
95
|
|
106
96
|
begin
|
107
97
|
return parse_options
|
108
|
-
rescue OptionParser::MissingArgument
|
109
|
-
puts "Error: Missing Option\n".red <<
|
110
|
-
"One or more of required option are missing values\n" <<
|
111
|
-
"Please check if options -b, -d, -n, and -t all have values passed"
|
112
|
-
exit(1)
|
113
98
|
rescue *option_errors => e
|
114
99
|
puts e.message
|
115
100
|
exit(1)
|
@@ -139,8 +124,13 @@ module Ubcbooker
|
|
139
124
|
end
|
140
125
|
|
141
126
|
def start
|
127
|
+
book_errors = [
|
128
|
+
Ubcbooker::Error::NoAvailableRoom,
|
129
|
+
Ubcbooker::Error::BookingFailed,
|
130
|
+
]
|
131
|
+
|
142
132
|
@options = get_options
|
143
|
-
|
133
|
+
@config.ask if !@config.defined?
|
144
134
|
|
145
135
|
@client = get_scraper(@options[:department],
|
146
136
|
@config.account["username"],
|
@@ -148,8 +138,9 @@ module Ubcbooker
|
|
148
138
|
begin
|
149
139
|
room_id = @client.book(@options)
|
150
140
|
puts "Success! #{room_id} is booked".green
|
151
|
-
rescue
|
141
|
+
rescue *book_errors => e
|
152
142
|
puts e.message
|
143
|
+
exit(1)
|
153
144
|
end
|
154
145
|
end
|
155
146
|
end
|
data/lib/ubcbooker/config.rb
CHANGED
@@ -3,7 +3,7 @@ module Ubcbooker
|
|
3
3
|
attr_accessor :account
|
4
4
|
|
5
5
|
def initialize
|
6
|
-
@config_path =
|
6
|
+
@config_path = get_config_path
|
7
7
|
if !File.exist?(@config_path)
|
8
8
|
create_config_file(@config_path)
|
9
9
|
end
|
@@ -11,6 +11,16 @@ module Ubcbooker
|
|
11
11
|
@account = YAML.load_file(@config_path)
|
12
12
|
end
|
13
13
|
|
14
|
+
def ask
|
15
|
+
print "Your CWL username: "
|
16
|
+
username = gets.chomp
|
17
|
+
print "Your CWL password: "
|
18
|
+
# Hide the password input
|
19
|
+
password = STDIN.noecho(&:gets).chomp
|
20
|
+
write(username, password)
|
21
|
+
puts
|
22
|
+
end
|
23
|
+
|
14
24
|
def create_config_file(config_path)
|
15
25
|
File.open(config_path, "w") do |f|
|
16
26
|
f.write("---\nusername: sample\npassword: sample")
|
@@ -32,8 +42,18 @@ module Ubcbooker
|
|
32
42
|
end
|
33
43
|
end
|
34
44
|
|
45
|
+
def get_config_path
|
46
|
+
if ENV['RACK_ENV'] == 'test'
|
47
|
+
File.expand_path("../config.yml", __FILE__)
|
48
|
+
else
|
49
|
+
File.expand_path("../../../spec/config.yml", __FILE__)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
35
53
|
def defined?
|
36
|
-
return @
|
54
|
+
return File.exist?(@config_path) &&
|
55
|
+
@account["username"] != "sample" &&
|
56
|
+
@account["password"] != "sample"
|
37
57
|
end
|
38
58
|
end
|
39
59
|
end
|
data/lib/ubcbooker/error.rb
CHANGED
@@ -35,6 +35,17 @@ module Ubcbooker
|
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
38
|
+
class MissingRequired < StandardError
|
39
|
+
attr_reader :message, :time
|
40
|
+
def initialize()
|
41
|
+
@message = "Error: Missing Option\n".red <<
|
42
|
+
"One or more of required option are missing values\n" <<
|
43
|
+
"Please check if options -b, -d, -n, and -t all have values passed"
|
44
|
+
super
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
|
38
49
|
class ProfaneName < StandardError
|
39
50
|
attr_reader :message, :name
|
40
51
|
def initialize(name = "unknown")
|
@@ -57,6 +68,15 @@ module Ubcbooker
|
|
57
68
|
end
|
58
69
|
end
|
59
70
|
|
71
|
+
class BookingFailed < StandardError
|
72
|
+
attr_reader :message
|
73
|
+
def initialize
|
74
|
+
@message = "\nBooking Failed :/\n".red <<
|
75
|
+
"Please raise an issue on GitHub"
|
76
|
+
super
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
60
80
|
class LoginFailed < StandardError
|
61
81
|
attr_reader :message
|
62
82
|
def initialize
|
@@ -46,8 +46,13 @@ module Ubcbooker
|
|
46
46
|
booking_form["field_date[und][0][value][time]"] = time_to_ampm(book_slot.min)
|
47
47
|
booking_form["field_date[und][0][value2][date]"] = book_date_str
|
48
48
|
booking_form["field_date[und][0][value2][time]"] = time_to_ampm(book_slot.max)
|
49
|
-
booking_form.submit
|
50
|
-
|
49
|
+
confirmation_page = booking_form.submit
|
50
|
+
if confirmation_page.search("div.alert-error").empty?
|
51
|
+
spinner.success("Done!")
|
52
|
+
else
|
53
|
+
spinner.fail("Booking rejected")
|
54
|
+
raise Ubcbooker::Error::BookingFailed.new
|
55
|
+
end
|
51
56
|
end
|
52
57
|
|
53
58
|
# Select the form otpion with right room id
|
@@ -115,7 +120,9 @@ module Ubcbooker
|
|
115
120
|
def is_slot_booked(slot_booked, book_slot)
|
116
121
|
booked = false
|
117
122
|
slot_booked.each do |s|
|
118
|
-
if s.include?(book_slot.min) ||
|
123
|
+
if (s.include?(book_slot.min) ||
|
124
|
+
s.include?(book_slot.max) ||
|
125
|
+
book_slot.include?(s))
|
119
126
|
booked = true
|
120
127
|
end
|
121
128
|
end
|
data/lib/ubcbooker/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ubcbooker
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Atsushi Yamamoto
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-03-
|
11
|
+
date: 2018-03-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mechanize
|
@@ -168,10 +168,8 @@ files:
|
|
168
168
|
- README.md
|
169
169
|
- Rakefile
|
170
170
|
- bin/console
|
171
|
-
- bin/setup
|
172
171
|
- bin/ubcbooker
|
173
172
|
- lib/ubcbooker.rb
|
174
|
-
- lib/ubcbooker/account.rb
|
175
173
|
- lib/ubcbooker/cli.rb
|
176
174
|
- lib/ubcbooker/cli_validator.rb
|
177
175
|
- lib/ubcbooker/color.rb
|
data/bin/setup
DELETED
data/lib/ubcbooker/account.rb
DELETED
@@ -1,31 +0,0 @@
|
|
1
|
-
module Ubcbooker
|
2
|
-
class Account
|
3
|
-
attr_accessor :username, :password
|
4
|
-
|
5
|
-
def initialize
|
6
|
-
@config_path = File.expand_path("../config.yml", __FILE__)
|
7
|
-
@account_info = YAML.load_file(@config_path)
|
8
|
-
@username = @account_info["username"]
|
9
|
-
@password = @account_info["password"]
|
10
|
-
end
|
11
|
-
|
12
|
-
def write(username, password)
|
13
|
-
@account["username"] = username
|
14
|
-
@account["password"] = password
|
15
|
-
new_yml = YAML.dump(@account)
|
16
|
-
open(@config_path, "w") { |f| f.write(new_yml) }
|
17
|
-
@account = YAML.load_file(@config_path)
|
18
|
-
end
|
19
|
-
|
20
|
-
def print_supported_departments
|
21
|
-
puts "Supported department options in #{Ubcbooker::VERSION}:"
|
22
|
-
BOOKING_URL.keys.each do |d|
|
23
|
-
puts " - #{d}"
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
def defined?
|
28
|
-
return @account["username"] != "hoge" && @account["password"] != "hoge"
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|