ubcbooker 0.2.3 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 053f9ad2f8d23269ce39d0c7e6cf53b51774d810
4
- data.tar.gz: 79624f9a62de98c504efc5a53b96ee94da8ab41d
3
+ metadata.gz: d1e73b63f6a87178f231f0c23da7c8cccc7b2037
4
+ data.tar.gz: c1d507e4562bf8ce1da4dac8c09c5363a6c7d947
5
5
  SHA512:
6
- metadata.gz: 8464319a1fbebeb17ae4c7e66ff9335cf2a3125bd5cfe81b8aec9eacafd93b40d8b14813dbec3258bce30601eb3f0d0984b8fe77dfdc202dacb206edd4bdcca6
7
- data.tar.gz: 5990bc3fdb45c82be09c794b712e199701a8a13d427281b480c6ba94c2ba889c8cccd6d609dfdd1dba5e8787fdcbea232dbb823bcdfab5c3a1e2f9747c053ec5
6
+ metadata.gz: 3b840fbd221115e669777f7dd264bcf8ae2db82c492ba2711be026d2cbfc0aa650f1a6d4a9ba9742a216a7945ebd930075b4fb1ad2d563b1cd7ba75cc9018c23
7
+ data.tar.gz: 1f5a9abbdc2cd2a1ec6747d207207a8f318e142bc37abc3f959a5f4efef67c7ebfb667a342e4620b443e1e1460dc66d4c6441427beab508d82e606b52cce701c
data/README.md CHANGED
@@ -49,7 +49,7 @@ ex. Book a room in CS from 11am to 1pm on March 5th with the name 'Study Group'
49
49
  $> ubcbooker -b cs -n 'Study Group' -d 03/05 -t 11:00-13:00
50
50
  ```
51
51
 
52
- Currently this app supports project rooms in cs (Commputer Science). Run `ubcbooker -l` to check the latest supported departments.
52
+ Currently this app supports project rooms in cs (Computer Science). Run `ubcbooker -l` to check the latest supported departments.
53
53
 
54
54
  Feel free to send a PR that supports your department's rooms.
55
55
 
@@ -67,4 +67,4 @@ The gem is available as open source under the terms of the [MIT License](https:/
67
67
 
68
68
  ## Code of Conduct
69
69
 
70
- Everyone interacting in the Ubcbooker project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/jumbosushi/ubcbooker/blob/master/CODE_OF_CONDUCT.md).
70
+ Everyone interacting in the Ubcbooker project’s codebase, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/jumbosushi/ubcbooker/blob/master/CODE_OF_CONDUCT.md).
@@ -7,6 +7,17 @@ require "obscenity"
7
7
  require "io/console" # For handling password
8
8
  require "optparse"
9
9
  require "yaml"
10
+ require "keyring"
11
+ # Keyring dependencies
12
+ # Keyring gem is currently unable to correcly detect the following downlaod
13
+ # https://github.com/jheiss/keyring/blob/master/ext/mkrf_conf.rb#L26
14
+ # http://en.wikibooks.org/wiki/Ruby_Programming/RubyGems#How_to_install_different_versions_of_gems_depending_on_which_version_of_ruby_the_installee_is_using
15
+ case Gem::Platform.local.os
16
+ when "linux"
17
+ require "gir_ffi-gnome_keyring"
18
+ when "darwin"
19
+ require "ruby-keychain"
20
+ end
10
21
 
11
22
  module Ubcbooker
12
23
  BOOKING_URL = {
@@ -130,11 +130,13 @@ module Ubcbooker
130
130
  ]
131
131
 
132
132
  @options = get_options
133
- @config.ask if !@config.defined?
133
+ if !@config.defined? || @config.is_windows?
134
+ @config.ask
135
+ end
134
136
 
135
137
  @client = get_scraper(@options[:department],
136
- @config.account["username"],
137
- @config.account["password"])
138
+ @config.get_username,
139
+ @config.get_password)
138
140
  begin
139
141
  room_id = @client.book(@options)
140
142
  puts "Success! #{room_id} is booked".green
@@ -2,13 +2,15 @@ module Ubcbooker
2
2
  class Config
3
3
  attr_accessor :account
4
4
 
5
+ # We use system keyring for storing cwl credentials
6
+ # https://askubuntu.com/questions/32164/what-does-a-keyring-do
7
+ #
8
+ # since the keyring gem doesn't suppot Windows, we ask for cred each time
9
+ # if the user is on OSX or Linux, username and password will be stored in keyring
5
10
  def initialize
6
- @config_path = get_config_path
7
- if !File.exist?(@config_path)
8
- create_config_file(@config_path)
9
- end
10
-
11
- @account = YAML.load_file(@config_path)
11
+ @keyring = Keyring.new
12
+ @win_username = ""
13
+ @win_password = ""
12
14
  end
13
15
 
14
16
  def ask
@@ -17,24 +19,20 @@ module Ubcbooker
17
19
  print "Your CWL password: "
18
20
  # Hide the password input
19
21
  password = STDIN.noecho(&:gets).chomp
20
- write(username, password)
22
+ save_credentials(username, password)
21
23
  puts
22
24
  end
23
25
 
24
- def create_config_file(config_path)
25
- File.open(config_path, "w") do |f|
26
- f.write("---\nusername: sample\npassword: sample")
26
+ def save_credentials(username, password)
27
+ if is_windows?
28
+ @win_username = username
29
+ @win_pasword = password
30
+ else
31
+ @keyring.set_password("ubcbooker", "username", username)
32
+ @keyring.set_password("ubcbooker", "password", password)
27
33
  end
28
34
  end
29
35
 
30
- def write(username, password)
31
- @account["username"] = username
32
- @account["password"] = password
33
- new_yml = YAML.dump(@account)
34
- open(@config_path, "w") { |f| f.write(new_yml) }
35
- @account = YAML.load_file(@config_path)
36
- end
37
-
38
36
  def print_supported_departments
39
37
  puts "Supported department options in #{Ubcbooker::VERSION}:"
40
38
  BOOKING_URL.keys.each do |d|
@@ -42,18 +40,41 @@ module Ubcbooker
42
40
  end
43
41
  end
44
42
 
45
- def get_config_path
46
- if ENV['RACK_ENV'] == 'test'
47
- File.expand_path("../config.yml", __FILE__)
43
+ # True if user is on windows platform
44
+ def is_windows?
45
+ return Gem.win_platform?
46
+ end
47
+
48
+ # Delete stored user credentials
49
+ # Used in specs
50
+ def delete_credentials
51
+ if is_windows?
52
+ @win_username = ""
53
+ @win_password = ""
54
+ else
55
+ @keyring.delete_password("ubcbooker", "username")
56
+ @keyring.delete_password("ubcbooker", "password")
57
+ end
58
+ end
59
+
60
+ def get_username
61
+ if is_windows?
62
+ return @win_username
63
+ else
64
+ return @keyring.get_password("ubcbooker", "username")
65
+ end
66
+ end
67
+
68
+ def get_password
69
+ if is_windows?
70
+ return @win_pasword
48
71
  else
49
- File.expand_path("../../../spec/config.yml", __FILE__)
72
+ return @keyring.get_password("ubcbooker", "password")
50
73
  end
51
74
  end
52
75
 
53
76
  def defined?
54
- return File.exist?(@config_path) &&
55
- @account["username"] != "sample" &&
56
- @account["password"] != "sample"
77
+ return !!(get_username && get_password)
57
78
  end
58
79
  end
59
80
  end
@@ -1,3 +1,3 @@
1
1
  module Ubcbooker
2
- VERSION = "0.2.3"
2
+ VERSION = "1.0.0"
3
3
  end
@@ -24,6 +24,9 @@ Gem::Specification.new do |spec|
24
24
  spec.add_dependency "typhoeus", "~> 1.1"
25
25
  spec.add_dependency "obscenity", "~> 1.0.2"
26
26
  spec.add_dependency "tty-spinner", "~> 0.7.0"
27
+ spec.add_dependency "keyring", "~> 0.4.1"
28
+ spec.add_dependency "gir_ffi-gnome_keyring", "~> 0.0.3"
29
+ spec.add_dependency "ruby-keychain", "~> 0.3.2"
27
30
 
28
31
  spec.add_development_dependency "rake", "~> 10.0"
29
32
  spec.add_development_dependency "rspec", "~> 3.0"
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.3
4
+ version: 1.0.0
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-18 00:00:00.000000000 Z
11
+ date: 2018-03-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mechanize
@@ -80,6 +80,48 @@ dependencies:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
82
  version: 0.7.0
83
+ - !ruby/object:Gem::Dependency
84
+ name: keyring
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 0.4.1
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 0.4.1
97
+ - !ruby/object:Gem::Dependency
98
+ name: gir_ffi-gnome_keyring
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: 0.0.3
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: 0.0.3
111
+ - !ruby/object:Gem::Dependency
112
+ name: ruby-keychain
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: 0.3.2
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: 0.3.2
83
125
  - !ruby/object:Gem::Dependency
84
126
  name: rake
85
127
  requirement: !ruby/object:Gem::Requirement
@@ -175,7 +217,6 @@ files:
175
217
  - lib/ubcbooker/color.rb
176
218
  - lib/ubcbooker/config.rb
177
219
  - lib/ubcbooker/error.rb
178
- - lib/ubcbooker/sample.yml
179
220
  - lib/ubcbooker/scrapers/base_scraper.rb
180
221
  - lib/ubcbooker/scrapers/cs.rb
181
222
  - lib/ubcbooker/scrapers/scraper.rb
@@ -1,3 +0,0 @@
1
- ---
2
- username: sample
3
- password: sample