uqam_grade_notification 0.1.1 → 0.2.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: d776bac3ff844092ffe619f32226988cc2389c39
4
- data.tar.gz: eb0ea4227c447a377303dd19ca56f54e0279221e
3
+ metadata.gz: d9e1f1a5c003b5f71c81c10f79096dabb6448898
4
+ data.tar.gz: c9885635447fe35996a2a55689a72fdab0400ef2
5
5
  SHA512:
6
- metadata.gz: f105722f235b52a46aed418790c4330929010cccdf3ca7d381c8f3c6f2f9c5c5c3cadf5666cd3bd656a7367913b40c27ad3dd81856e0ed54d3dda01db121806c
7
- data.tar.gz: e1a9eb0dd54b96b08c1d30df5a96f3efd5f6464310a319266351a726bd85b4b0cd4a98f4a71f948349fafc19093054047e559b0d9c4eae9ec2f435cd48abcf1e
6
+ metadata.gz: 0d0bce3c4ebe50f302b5672cb766bd2b1823c1fb5adf3c6b6b0899948ee65ba3631b4bb372d960abf5d8a49081a275176dc0ae011a8b10549ee4061883a6a1ca
7
+ data.tar.gz: 6c8041bc2a95ee3304b302ac549c95872814a7936b3bfa739f44229bf06c48fac92dc85a55af848f53e4e23f49a116f8e48872a0235c2d5be03b73b1e00dd947
data/.gitignore CHANGED
@@ -7,3 +7,4 @@
7
7
  /pkg/
8
8
  /spec/reports/
9
9
  /tmp/
10
+ .ruby-version
@@ -1,5 +1,37 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require 'uqam_grade_notification'
4
+ require 'optparse'
4
5
 
5
- UqamGradeNotification.perform
6
+ options = {}
7
+ OptionParser.new do |opts|
8
+ opts.banner = "Usage: uqam_grade_notification [options]"
9
+
10
+ opts.on("-v", "--version", "Show version") do
11
+ p UqamGradeNotification::VERSION
12
+ exit
13
+ end
14
+
15
+ opts.on("-c", "--configure", "Set configuration options") do
16
+ p "Configuring Uqam Grade Notification"
17
+ UqamGradeNotification.configuration_cli
18
+ exit
19
+ end
20
+
21
+ opts.on("-h", "--help", "Show this message") do
22
+ p "Configuration is saved in #{UqamGradeNotification::APP_DIR}"
23
+ puts opts
24
+ exit
25
+ end
26
+ end.parse!
27
+
28
+ configuration =
29
+ if File.exist?(UqamGradeNotification::CONFIG_FILE)
30
+ JSON.parse(File.open(UqamGradeNotification::CONFIG_FILE).read)
31
+ else
32
+ configuration_cli
33
+ end
34
+
35
+ student = UqamGradeNotification::Student.new(configuration)
36
+ notifier = UqamGradeNotification::Notifier.new(configuration)
37
+ UqamGradeNotification.new(student, notifier).notify_of_changes
@@ -0,0 +1,36 @@
1
+ module UqamGradeNotification
2
+ class Client
3
+ attr_reader :student, :notifier, :storage
4
+
5
+ def initialize(student, notifier, storage)
6
+ @student = student
7
+ @notifier = notifier
8
+ @storage = storage
9
+ end
10
+
11
+ def notify_of_changes
12
+ current_grades = student.grades.to_json
13
+ if grades_have_changed?
14
+ p "Grades have not changed since last checked."
15
+ else
16
+ message = "Your grades have been updated!"
17
+ p message
18
+ save_student_grades
19
+ notifier.sms(message)
20
+ end
21
+ end
22
+
23
+ def grades_have_changed?
24
+ md5 = Digest::MD5.new
25
+ md5.hexdigest(student.grades.to_json) == md5.hexdigest(student_last_grades.to_json)
26
+ end
27
+
28
+ def student_last_grades
29
+ @last_grades ||= storage.last_grades(student)
30
+ end
31
+
32
+ def save_student_grades
33
+ storage.save_grades(student)
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,35 @@
1
+ module UqamGradeNotification
2
+ class Storage
3
+ extend Forwardable
4
+ def_delegators :@storage, :last_grades, :save_grades
5
+
6
+ def initialize(storage=LocalStorage.new)
7
+ @storage = storage
8
+ end
9
+
10
+ class LocalStorage
11
+ attr_reader :base_path
12
+ def initialize(base_path=UqamGradeNotification::APP_DIR)
13
+ @base_path = base_path
14
+ end
15
+
16
+ def last_grades(student)
17
+ if File.exist?(grade_file(student))
18
+ JSON.parse File.open(grade_file(student), "rb").read
19
+ else
20
+ ""
21
+ end
22
+ end
23
+
24
+ def save_grades(student)
25
+ File.write(grade_file(student), student.grades.to_json)
26
+ end
27
+
28
+ private
29
+
30
+ def grade_file(student)
31
+ "#{base_path}/#{student.code}_grades.json"
32
+ end
33
+ end
34
+ end
35
+ end
@@ -33,6 +33,7 @@ module UqamGradeNotification
33
33
  Faraday.new(url: "https://portailetudiant.uqam.ca") do |c|
34
34
  c.request :json
35
35
  c.response :json, content_type: /\bjson$/
36
+ c.use Faraday::Response::RaiseError
36
37
  c.use :cookie_jar
37
38
  c.adapter :net_http
38
39
  end
@@ -1,3 +1,3 @@
1
1
  module UqamGradeNotification
2
- VERSION = "0.1.1"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -5,67 +5,42 @@ require 'digest'
5
5
  require 'uqam_grade_notification/version'
6
6
  require 'uqam_grade_notification/student'
7
7
  require 'uqam_grade_notification/notifier'
8
+ require 'uqam_grade_notification/client'
9
+ require 'uqam_grade_notification/storage'
8
10
 
9
11
  module UqamGradeNotification
10
12
  APP_DIR = "#{ENV["HOME"]}/.uqam_grade_notification"
11
- USER_FILE = "#{APP_DIR}/user.json"
12
- GRADES_FILE = "#{APP_DIR}/grades.json"
13
+ CONFIG_FILE = "#{APP_DIR}/user.json"
13
14
 
14
- def self.perform
15
- current_grades = student.grades.to_json
16
- if grades_are_equals?(current_grades)
17
- p "Grades have not changed since last checked."
18
- else
19
- message = "Your grades have been updated!"
20
- p message
21
- File.write(GRADES_FILE, current_grades)
22
- Notifier.new(user_info).sms(message)
15
+ class << self
16
+ def new(student, notifier, storage=UqamGradeNotification::Storage.new)
17
+ Client.new(student, notifier, storage)
23
18
  end
24
- end
25
-
26
- def self.student
27
- UqamGradeNotification::Student.new(user_info)
28
- end
29
19
 
30
- def self.grades_are_equals?(grades)
31
- md5 = Digest::MD5.new
32
- md5.hexdigest(grades) == md5.hexdigest(last_grades)
33
- end
34
-
35
- def self.last_grades
36
- @last_grades ||=
37
- if File.exist?(GRADES_FILE)
38
- File.open(GRADES_FILE, "rb").read
39
- else
40
- ""
20
+ def configuration_cli
21
+ unless Dir.exists?(APP_DIR)
22
+ p "Running first time setup."
23
+ Dir.mkdir(APP_DIR)
41
24
  end
42
- end
43
25
 
44
- def self.user_info
45
- @user_info ||=
46
- if File.exist?(USER_FILE)
47
- JSON.parse(File.open(USER_FILE).read)
48
- else
49
- setup_user_data
50
- end
51
- end
52
-
53
- def self.setup_user_data
54
- unless Dir.exists?(APP_DIR)
55
- p "Running first time setup."
56
- Dir.mkdir(APP_DIR)
26
+ cli = HighLine.new
27
+ code = cli.ask("Code Permanent")
28
+ password = cli.ask("NIP")
29
+ phone = cli.ask("Phone Number")
30
+ twilio_account_id = cli.ask("Twilio Account ID")
31
+ twilio_token = cli.ask("Twilio Token")
32
+ twilio_phone = cli.ask("Twilio Phone Number")
33
+
34
+ info = { "code" => code,
35
+ "password" => password,
36
+ "phone" => phone,
37
+ "twilio_account_id" => twilio_account_id,
38
+ "twilio_token" => twilio_token,
39
+ "twilio_phone" => twilio_phone
40
+ }
41
+
42
+ File.write(CONFIG_FILE, info.to_json)
43
+ info
57
44
  end
58
-
59
- cli = HighLine.new
60
- code = cli.ask("Code Permanent")
61
- password = cli.ask("NIP")
62
- phone = cli.ask("Phone Number")
63
- twilio_account_id = cli.ask("Twilio Account ID")
64
- twilio_token = cli.ask("Twilio Token")
65
- twilio_phone = cli.ask("Twilio Phone Number")
66
-
67
- info = {"code" => code, "password" => password, "phone" => phone, "twilio_account_id" => twilio_account_id, "twilio_token" => twilio_token, "twilio_phone" => twilio_phone}
68
- File.write(USER_FILE, info.to_json)
69
- info
70
45
  end
71
46
  end
metadata CHANGED
@@ -1,125 +1,125 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: uqam_grade_notification
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexandre Croteau-Pothier
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-01-10 00:00:00.000000000 Z
11
+ date: 2016-01-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: '1.9'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ~>
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.9'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ~>
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
33
  version: '10.0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ~>
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '10.0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: nokogiri
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - '>='
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - '>='
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: faraday
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - '>='
59
+ - - ">="
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - '>='
66
+ - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: faraday_middleware
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - '>='
73
+ - - ">="
74
74
  - !ruby/object:Gem::Version
75
75
  version: '0'
76
76
  type: :runtime
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - '>='
80
+ - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: faraday-cookie_jar
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - '>='
87
+ - - ">="
88
88
  - !ruby/object:Gem::Version
89
89
  version: '0'
90
90
  type: :runtime
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - '>='
94
+ - - ">="
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: highline
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
- - - '>='
101
+ - - ">="
102
102
  - !ruby/object:Gem::Version
103
103
  version: '0'
104
104
  type: :runtime
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
- - - '>='
108
+ - - ">="
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
111
  - !ruby/object:Gem::Dependency
112
112
  name: twilio-ruby
113
113
  requirement: !ruby/object:Gem::Requirement
114
114
  requirements:
115
- - - '>='
115
+ - - ">="
116
116
  - !ruby/object:Gem::Version
117
117
  version: '0'
118
118
  type: :runtime
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
- - - '>='
122
+ - - ">="
123
123
  - !ruby/object:Gem::Version
124
124
  version: '0'
125
125
  description:
@@ -130,9 +130,9 @@ executables:
130
130
  extensions: []
131
131
  extra_rdoc_files: []
132
132
  files:
133
- - .gitignore
134
- - .rspec
135
- - .travis.yml
133
+ - ".gitignore"
134
+ - ".rspec"
135
+ - ".travis.yml"
136
136
  - Gemfile
137
137
  - LICENSE.txt
138
138
  - README.md
@@ -141,7 +141,9 @@ files:
141
141
  - bin/setup
142
142
  - exe/uqam_grade_notification
143
143
  - lib/uqam_grade_notification.rb
144
+ - lib/uqam_grade_notification/client.rb
144
145
  - lib/uqam_grade_notification/notifier.rb
146
+ - lib/uqam_grade_notification/storage.rb
145
147
  - lib/uqam_grade_notification/student.rb
146
148
  - lib/uqam_grade_notification/version.rb
147
149
  - uqam_grade_notification.gemspec
@@ -156,17 +158,17 @@ require_paths:
156
158
  - lib/uqam_grade_notification
157
159
  required_ruby_version: !ruby/object:Gem::Requirement
158
160
  requirements:
159
- - - '>='
161
+ - - ">="
160
162
  - !ruby/object:Gem::Version
161
163
  version: '0'
162
164
  required_rubygems_version: !ruby/object:Gem::Requirement
163
165
  requirements:
164
- - - '>='
166
+ - - ">="
165
167
  - !ruby/object:Gem::Version
166
168
  version: '0'
167
169
  requirements: []
168
170
  rubyforge_project:
169
- rubygems_version: 2.0.14
171
+ rubygems_version: 2.4.7
170
172
  signing_key:
171
173
  specification_version: 4
172
174
  summary: Sends notification when notes are added.