markify 0.1.0

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.
@@ -0,0 +1,101 @@
1
+ # encoding: utf-8
2
+ =begin
3
+ Copyright Daniel Meißner <meise+markify@3st.be>, 2013
4
+
5
+ This file is part of Markify.
6
+
7
+ Markify is free software: you can redistribute it and/or modify
8
+ it under the terms of the GNU General Public License as published by
9
+ the Free Software Foundation, either version 3 of the License, or
10
+ (at your option) any later version.
11
+
12
+ Markify is distributed in the hope that it will be useful,
13
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
+ GNU General Public License for more details.
16
+
17
+ You should have received a copy of the GNU General Public License
18
+ along with Markify. If not, see <http://www.gnu.org/licenses/>.
19
+ =end
20
+
21
+ module Markify::Settings
22
+
23
+ DEFAULT_CONFIG_PATH = Pathname(ENV['HOME'] + "/markify/config.yml")
24
+
25
+ attr_reader :config
26
+
27
+ def self.load!(file = nil)
28
+ config_file = file || DEFAULT_CONFIG_PATH
29
+
30
+ if config_file.exist?
31
+ config = YAML::load_file(config_file)
32
+ validate(config)
33
+ else
34
+ puts 'Config file does not exist. Please create it.'
35
+ puts " $ #{$0} --init"
36
+ exit
37
+ end
38
+ end
39
+
40
+ def self.create_example_config(file = nil)
41
+ config_file = file || DEFAULT_CONFIG_PATH
42
+
43
+ if config_file.exist?
44
+ puts "Configuration file #{config_file} already exists."
45
+ exit
46
+ else
47
+ Dir.mkdir(config_file.dirname) unless config_file.dirname.exist?
48
+
49
+ File.open(config_file, 'a+', 0600) do |file|
50
+ file.puts <<CONTENT
51
+ sis:
52
+ login_name: "foobaz2s"
53
+ login_password: "fnord2000"
54
+
55
+ xmpp:
56
+ bot_id: "bot@foo.baz.er"
57
+ bot_password: "möpmöp"
58
+
59
+ recipients: [bla@jabber.foo.baz, müp@möp.blap.ba]
60
+
61
+ general:
62
+ verbose: false
63
+ database_file: "#{ENV['HOME'] + '/markify/hashes.txt'}"
64
+ CONTENT
65
+ end
66
+
67
+ puts "#{config_file} created."
68
+
69
+ exit
70
+ end
71
+ end
72
+
73
+ def self.test_settings(config)
74
+ Markify::Scraper.new(config['sis']['login_name'], config['sis']['login_password']).test_login
75
+
76
+ begin
77
+ Markify::Bot.new(config['xmpp']['bot_id'],
78
+ config['xmpp']['bot_password']).send_message(config['xmpp']['recipients'],
79
+ "#{Markify::NAME} Test #{Time.now}")
80
+ rescue Jabber::ClientAuthenticationFailure
81
+ puts "XMPP: Bot authentication failed."
82
+ else
83
+ puts "XMPP: Bot works."
84
+ end
85
+ end
86
+
87
+ protected
88
+
89
+ def self.validate(config)
90
+ # convert recipients to an array
91
+ if config['xmpp']['recipients'].is_a?(String)
92
+ config['xmpp']['recipients'] = [ config['xmpp']['recipients'] ]
93
+ end
94
+
95
+ unless config['general']['database_file'].nil?
96
+ config['general']['database_file'] = Pathname(config['general']['database_file'])
97
+ end
98
+
99
+ config
100
+ end
101
+ end
@@ -0,0 +1,42 @@
1
+ # encoding: utf-8
2
+ =begin
3
+ Copyright Daniel Meißner <meise+markify@3st.be>, 2013
4
+
5
+ This file is part of Markify.
6
+
7
+ Markify is free software: you can redistribute it and/or modify
8
+ it under the terms of the GNU General Public License as published by
9
+ the Free Software Foundation, either version 3 of the License, or
10
+ (at your option) any later version.
11
+
12
+ Markify is distributed in the hope that it will be useful,
13
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
+ GNU General Public License for more details.
16
+
17
+ You should have received a copy of the GNU General Public License
18
+ along with Markify. If not, see <http://www.gnu.org/licenses/>.
19
+ =end
20
+
21
+ module Markify
22
+
23
+ VERSION = '0.1.0'
24
+ NAME = 'markify'
25
+
26
+ DESCRIPTION =<<DESCRIPTION
27
+ #{Markify::NAME.capitalize} is a ruby script to detect new marks in the
28
+ Studierendeninformationssystem (SIS) of the University of Applied Sciences
29
+ Bonn-Rhein-Sieg. If #{Markify::NAME} detects new marks, they will send you a xmpp
30
+ message for every change.
31
+ DESCRIPTION
32
+
33
+ LICENCE =<<LICENCE
34
+ #{Markify::NAME.capitalize} - v#{Markify::VERSION}
35
+ Released under the GNU GENERAL PUBLIC LICENSE Version 3. © Daniel Meißner, 2013
36
+ LICENCE
37
+
38
+ SUMMARY =<<SUMMARY
39
+ Mark notify script for the Studierendeninformationssystem (SIS) of the University of Applied Sciences Bonn-Rhein-Sieg.
40
+ SUMMARY
41
+
42
+ end
@@ -0,0 +1,31 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'markify/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = Markify::NAME.downcase
8
+ spec.version = Markify::VERSION
9
+ spec.authors = ["Daniel Meißner"]
10
+ spec.email = ["meise+markify@3st.be"]
11
+ spec.description = Markify::DESCRIPTION
12
+ spec.summary = Markify::SUMMARY
13
+ spec.homepage = "https://github.com/meise/markify"
14
+ spec.license = "GPL"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.required_ruby_version = '>= 1.9.3'
22
+
23
+ spec.add_dependency('xmpp4r', '~> 0.5')
24
+ spec.add_dependency('mechanize', '~> 2.5.1')
25
+
26
+ spec.add_development_dependency "bundler", "~> 1.3"
27
+ spec.add_development_dependency "rake"
28
+ spec.add_development_dependency "pry"
29
+ spec.add_development_dependency('rspec', '~> 2.11.0')
30
+ spec.add_development_dependency('simplecov')
31
+ end
@@ -0,0 +1,87 @@
1
+ # encoding: utf-8
2
+ =begin
3
+ Copyright Daniel Meißner <meise+markify@3st.be>, 2013
4
+
5
+ This file is part of Markify.
6
+
7
+ Markify is free software: you can redistribute it and/or modify
8
+ it under the terms of the GNU General Public License as published by
9
+ the Free Software Foundation, either version 3 of the License, or
10
+ (at your option) any later version.
11
+
12
+ Markify is distributed in the hope that it will be useful,
13
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
+ GNU General Public License for more details.
16
+
17
+ You should have received a copy of the GNU General Public License
18
+ along with Markify. If not, see <http://www.gnu.org/licenses/>.
19
+ =end
20
+
21
+ require 'spec_helper'
22
+
23
+ describe Markify::Database do
24
+ before(:each) do
25
+ File.open(Pathname('/tmp/markify_hashes.txt'), "a+") do |file|
26
+ file.puts <<HASHES
27
+ # markify hash database
28
+ 19189e4668008cd48265538054282379c38bc7422811e4402a7f1e693138a579
29
+ 0482652650dc959dbaa199f7f08d60b1184c4329a41152479ecec7835cd2c9c5
30
+ HASHES
31
+ end
32
+
33
+ @database = Markify::Database.new(Pathname('/tmp/markify_hashes.txt'))
34
+ end
35
+
36
+ after(:each) do
37
+ @database.file_path.delete
38
+ end
39
+
40
+ it "should set default database path" do
41
+ @database.file_path.should_not eq(nil)
42
+ end
43
+
44
+ it "should set database path" do
45
+ @database.file_path.should eq(Pathname('/tmp/markify_hashes.txt'))
46
+ end
47
+
48
+ describe "#check_for_new_marks" do
49
+ it "should return a array with only new marks" do
50
+ mark1 = Markify::Mark.new('Peter Lustig', '2342', '3.0', 'BE', '2', '23.02.1942')
51
+ mark2 = Markify::Mark.new('Peter Lustig', '4223', '1.7', 'BE', '3', '23.02.1923')
52
+ mark3 = Markify::Mark.new('Peter Lustig', '2323', '5.0', 'NB', '1', '24.09.1923')
53
+
54
+ @database.check_for_new_marks([mark1, mark2, mark3]).should eq([mark3])
55
+ end
56
+ end
57
+
58
+ describe "#checksums" do
59
+ it "should return all checksums in database" do
60
+ @database.checksums.should eq(['19189e4668008cd48265538054282379c38bc7422811e4402a7f1e693138a579',
61
+ '0482652650dc959dbaa199f7f08d60b1184c4329a41152479ecec7835cd2c9c5'])
62
+ end
63
+ end
64
+
65
+ describe "#read_checksums" do
66
+ it "should be protected" do
67
+ @database.protected_methods.include?(:read_checksum_file).should eq(true)
68
+ end
69
+
70
+ it "should hash file and return array for each line" do
71
+ @database.send(:read_checksum_file,
72
+ *Markify::Database.protected_methods).should eq(['# markify hash database',
73
+ '19189e4668008cd48265538054282379c38bc7422811e4402a7f1e693138a579',
74
+ '0482652650dc959dbaa199f7f08d60b1184c4329a41152479ecec7835cd2c9c5'])
75
+ end
76
+ end
77
+
78
+ describe "#create_checksum_file" do
79
+ it "should be protected" do
80
+ @database.protected_methods.include?(:create_checksum_file).should eq(true)
81
+ end
82
+
83
+ it "should create new hash database if no exist" do
84
+ # TODO
85
+ end
86
+ end
87
+ end
@@ -0,0 +1,68 @@
1
+ # encoding: utf-8
2
+ =begin
3
+ Copyright Daniel Meißner <meise+markify@3st.be>, 2013
4
+
5
+ This file is part of Markify.
6
+
7
+ Markify is free software: you can redistribute it and/or modify
8
+ it under the terms of the GNU General Public License as published by
9
+ the Free Software Foundation, either version 3 of the License, or
10
+ (at your option) any later version.
11
+
12
+ Markify is distributed in the hope that it will be useful,
13
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
+ GNU General Public License for more details.
16
+
17
+ You should have received a copy of the GNU General Public License
18
+ along with Markify. If not, see <http://www.gnu.org/licenses/>.
19
+ =end
20
+
21
+ require 'spec_helper'
22
+
23
+ describe Markify::Mark do
24
+ before do
25
+ @mark = Markify::Mark.new('Peter Lustig', '2342', '3.0', 'BE', '2', '23.02.1942')
26
+ end
27
+
28
+ it "should be a string" do
29
+ @mark.name.should == "Peter Lustig"
30
+ end
31
+
32
+ it "should be a integer" do
33
+ @mark.id.should == 2342
34
+ end
35
+
36
+ it "should be a float" do
37
+ @mark.mark.should == 3.0
38
+ end
39
+
40
+ it "should be a string" do
41
+ @mark.passed.should == "BE"
42
+ end
43
+
44
+ it "should be a date" do
45
+ @mark.date.should == Date.strptime("23.02.1942", '%d.%m.%Y')
46
+ end
47
+
48
+ it "should be a integer" do
49
+ @mark.try.should == 2
50
+ end
51
+
52
+ describe "#to_s" do
53
+ it "should return a string" do
54
+ @mark.to_s.is_a?(String).should == true
55
+ end
56
+ end
57
+
58
+ describe "#to_sha256" do
59
+ it "should return sha256 object" do
60
+ @mark.to_sha256.is_a?(Digest::SHA256).should == true
61
+ end
62
+
63
+ it "should be generate a hash with the right order" do
64
+ @hash = Digest::SHA256.new << "Peter Lustig2342#{Date.strptime("23.02.1942", '%d.%m.%Y')}3.02BE"
65
+ @mark.to_sha256.should eq(@hash)
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,39 @@
1
+ # encoding: UTF-8
2
+ =begin
3
+ Copyright Daniel Meißner <meise+markify@3st.be>, 2013
4
+
5
+ This file is part of Markify.
6
+
7
+ Markify is free software: you can redistribute it and/or modify
8
+ it under the terms of the GNU General Public License as published by
9
+ the Free Software Foundation, either version 3 of the License, or
10
+ (at your option) any later version.
11
+
12
+ Markify is distributed in the hope that it will be useful,
13
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
+ GNU General Public License for more details.
16
+
17
+ You should have received a copy of the GNU General Public License
18
+ along with Markify. If not, see <http://www.gnu.org/licenses/>.
19
+ =end
20
+
21
+ require 'simplecov'
22
+
23
+ SimpleCov.start do
24
+ add_filter "/spec/"
25
+ end
26
+
27
+ require 'pathname'
28
+ require 'rspec'
29
+ require 'markify'
30
+
31
+ RSpec.configure do |config|
32
+ config.treat_symbols_as_metadata_keys_with_true_values = true
33
+ config.run_all_when_everything_filtered = true
34
+ config.filter_run :focus
35
+
36
+ config.color_enabled = true
37
+
38
+ config.order = 'random'
39
+ end
metadata ADDED
@@ -0,0 +1,195 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: markify
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Daniel Meißner
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-04-29 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: xmpp4r
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '0.5'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '0.5'
30
+ - !ruby/object:Gem::Dependency
31
+ name: mechanize
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: 2.5.1
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: 2.5.1
46
+ - !ruby/object:Gem::Dependency
47
+ name: bundler
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: '1.3'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '1.3'
62
+ - !ruby/object:Gem::Dependency
63
+ name: rake
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: pry
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ - !ruby/object:Gem::Dependency
95
+ name: rspec
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ~>
100
+ - !ruby/object:Gem::Version
101
+ version: 2.11.0
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ~>
108
+ - !ruby/object:Gem::Version
109
+ version: 2.11.0
110
+ - !ruby/object:Gem::Dependency
111
+ name: simplecov
112
+ requirement: !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ! '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ! '>='
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ description: ! 'Markify is a ruby script to detect new marks in the
127
+
128
+ Studierendeninformationssystem (SIS) of the University of Applied Sciences
129
+
130
+ Bonn-Rhein-Sieg. If markify detects new marks, they will send you a xmpp
131
+
132
+ message for every change.
133
+
134
+ '
135
+ email:
136
+ - meise+markify@3st.be
137
+ executables:
138
+ - markify
139
+ extensions: []
140
+ extra_rdoc_files: []
141
+ files:
142
+ - .gitignore
143
+ - Gemfile
144
+ - Gemfile.lock
145
+ - LICENSE.txt
146
+ - README.md
147
+ - Rakefile
148
+ - bin/markify
149
+ - examples/config.yml.example
150
+ - examples/hashes.txt
151
+ - lib/markify.rb
152
+ - lib/markify/bot.rb
153
+ - lib/markify/database.rb
154
+ - lib/markify/mark.rb
155
+ - lib/markify/optparser.rb
156
+ - lib/markify/scraper.rb
157
+ - lib/markify/settings.rb
158
+ - lib/markify/version.rb
159
+ - markify.gemspec
160
+ - spec/markify/database_spec.rb
161
+ - spec/markify/mark_spec.rb
162
+ - spec/spec_helper.rb
163
+ homepage: https://github.com/meise/markify
164
+ licenses:
165
+ - GPL
166
+ post_install_message:
167
+ rdoc_options: []
168
+ require_paths:
169
+ - lib
170
+ required_ruby_version: !ruby/object:Gem::Requirement
171
+ none: false
172
+ requirements:
173
+ - - ! '>='
174
+ - !ruby/object:Gem::Version
175
+ version: 1.9.3
176
+ required_rubygems_version: !ruby/object:Gem::Requirement
177
+ none: false
178
+ requirements:
179
+ - - ! '>='
180
+ - !ruby/object:Gem::Version
181
+ version: '0'
182
+ segments:
183
+ - 0
184
+ hash: -198789376526089427
185
+ requirements: []
186
+ rubyforge_project:
187
+ rubygems_version: 1.8.23
188
+ signing_key:
189
+ specification_version: 3
190
+ summary: Mark notify script for the Studierendeninformationssystem (SIS) of the University
191
+ of Applied Sciences Bonn-Rhein-Sieg.
192
+ test_files:
193
+ - spec/markify/database_spec.rb
194
+ - spec/markify/mark_spec.rb
195
+ - spec/spec_helper.rb