ege_parser 1.0.0 → 1.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6d97966c307a6afba2579d16a15671415ecbbd89
4
- data.tar.gz: 84bab26b2f56247818f316d2a5e71cf619821219
3
+ metadata.gz: 8c3d88a6d1218841609cc949cdb780de9c477267
4
+ data.tar.gz: 39b923161b41d0be14e6857929010d628258658f
5
5
  SHA512:
6
- metadata.gz: 0362644dc515fa306c2fafa13bcf52619911de8241fe03cd013723b8bf1483cbd49dab9f83ce85f57ff5be8761f37af2b91d34d06b28d68f3d46c3f8e0a51880
7
- data.tar.gz: d4901b1d2589058326759e1d314eeaffe39bfa0b851f73bdd7fd10524918d11dbb8821634ae36571549a29fb66318641237f388195c0e92e18068715b33e4e15
6
+ metadata.gz: 1d373c802c80d53a47f4783673a18f9d8bac3b47da6938da2574920b9bbc3bcef57e1c8f930c8e8ece8ac26aa577cdbb9644599a2437c502f8d1e062a2085401
7
+ data.tar.gz: e8a8a1e3976bb4f12be6ca26fd5459bb10ceaf7a4d48f7ab749b9ba7f998464ab2835962b0dc1887eb7f2874c762a17ca1d09f2e6c1fd208b66f728a7827b071
data/.coveralls.yml ADDED
@@ -0,0 +1,2 @@
1
+ service_name: travis-pro
2
+ repo_token: qkUyVDDryC8fvCC3byZLX1SzMEE7AzxgO
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.2
4
+ - 1.9.3
5
+ - 2.0.0
6
+ - ruby-head
data/Gemfile CHANGED
@@ -10,9 +10,9 @@ group :development do
10
10
  gem "rdoc", "~> 3.12"
11
11
  gem "bundler", "~> 1.0"
12
12
  gem "jeweler", "~> 2.0.1"
13
- gem "simplecov", ">= 0"
14
- gem "webmock"
13
+ gem "webmock"
15
14
  end
15
+ gem 'coveralls', require: false
16
16
 
17
17
  gem 'nokogiri'
18
18
  gem 'mechanize'
data/Gemfile.lock CHANGED
@@ -3,6 +3,12 @@ GEM
3
3
  specs:
4
4
  addressable (2.3.6)
5
5
  builder (3.2.2)
6
+ coveralls (0.7.0)
7
+ multi_json (~> 1.3)
8
+ rest-client
9
+ simplecov (>= 0.7)
10
+ term-ansicolor
11
+ thor
6
12
  crack (0.4.2)
7
13
  safe_yaml (~> 1.0.0)
8
14
  descendants_tracker (0.0.4)
@@ -72,6 +78,8 @@ GEM
72
78
  rake (10.3.2)
73
79
  rdoc (3.12.2)
74
80
  json (~> 1.4)
81
+ rest-client (1.6.7)
82
+ mime-types (>= 1.16)
75
83
  rspec (2.8.0)
76
84
  rspec-core (~> 2.8.0)
77
85
  rspec-expectations (~> 2.8.0)
@@ -86,8 +94,11 @@ GEM
86
94
  multi_json
87
95
  simplecov-html (~> 0.8.0)
88
96
  simplecov-html (0.8.0)
97
+ term-ansicolor (1.3.0)
98
+ tins (~> 1.0)
89
99
  thor (0.19.1)
90
100
  thread_safe (0.3.4)
101
+ tins (1.3.0)
91
102
  unf (0.1.4)
92
103
  unf_ext
93
104
  unf_ext (0.0.6)
@@ -101,11 +112,11 @@ PLATFORMS
101
112
 
102
113
  DEPENDENCIES
103
114
  bundler (~> 1.0)
115
+ coveralls
104
116
  foreman
105
117
  jeweler (~> 2.0.1)
106
118
  mechanize
107
119
  nokogiri
108
120
  rdoc (~> 3.12)
109
121
  rspec (~> 2.8.0)
110
- simplecov
111
122
  webmock
data/README.rdoc CHANGED
@@ -1,7 +1,12 @@
1
- = ege_parser
1
+ = ege_parser {<img src="https://coveralls.io/repos/manyrus/ege_gem/badge.png" alt="Coverage Status" />}[https://coveralls.io/r/manyrus/ege_gem] {<img src="https://travis-ci.org/manyrus/ege_gem.svg?branch=master" alt="Build Status" />}[https://travis-ci.org/manyrus/ege_gem]
2
2
 
3
- Description goes here.
3
+ See {example}[https://github.com/manyrus/ege_gem/blob/master/examples/2.rb]
4
4
 
5
+ == Installing
6
+ Simply add to your Gemfile this code:
7
+ gem 'ege_parser'
8
+ Or exec from console:
9
+ $ gem install ege_parser
5
10
  == Contributing to ege_parser
6
11
 
7
12
  * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.0
1
+ 1.1.0
data/ege_parser.gemspec CHANGED
@@ -2,11 +2,11 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: ege_parser 1.0.0 ruby lib
5
+ # stub: ege_parser 1.1.0 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "ege_parser"
9
- s.version = "1.0.0"
9
+ s.version = "1.1.0"
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
12
  s.require_paths = ["lib"]
@@ -19,8 +19,10 @@ Gem::Specification.new do |s|
19
19
  "README.rdoc"
20
20
  ]
21
21
  s.files = [
22
+ ".coveralls.yml",
22
23
  ".document",
23
24
  ".rspec",
25
+ ".travis.yml",
24
26
  "Gemfile",
25
27
  "Gemfile.lock",
26
28
  "LICENSE.txt",
@@ -48,6 +50,7 @@ Gem::Specification.new do |s|
48
50
  s.specification_version = 4
49
51
 
50
52
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
53
+ s.add_runtime_dependency(%q<coveralls>, [">= 0"])
51
54
  s.add_runtime_dependency(%q<nokogiri>, [">= 0"])
52
55
  s.add_runtime_dependency(%q<mechanize>, [">= 0"])
53
56
  s.add_runtime_dependency(%q<foreman>, [">= 0"])
@@ -55,9 +58,9 @@ Gem::Specification.new do |s|
55
58
  s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
56
59
  s.add_development_dependency(%q<bundler>, ["~> 1.0"])
57
60
  s.add_development_dependency(%q<jeweler>, ["~> 2.0.1"])
58
- s.add_development_dependency(%q<simplecov>, [">= 0"])
59
61
  s.add_development_dependency(%q<webmock>, [">= 0"])
60
62
  else
63
+ s.add_dependency(%q<coveralls>, [">= 0"])
61
64
  s.add_dependency(%q<nokogiri>, [">= 0"])
62
65
  s.add_dependency(%q<mechanize>, [">= 0"])
63
66
  s.add_dependency(%q<foreman>, [">= 0"])
@@ -65,10 +68,10 @@ Gem::Specification.new do |s|
65
68
  s.add_dependency(%q<rdoc>, ["~> 3.12"])
66
69
  s.add_dependency(%q<bundler>, ["~> 1.0"])
67
70
  s.add_dependency(%q<jeweler>, ["~> 2.0.1"])
68
- s.add_dependency(%q<simplecov>, [">= 0"])
69
71
  s.add_dependency(%q<webmock>, [">= 0"])
70
72
  end
71
73
  else
74
+ s.add_dependency(%q<coveralls>, [">= 0"])
72
75
  s.add_dependency(%q<nokogiri>, [">= 0"])
73
76
  s.add_dependency(%q<mechanize>, [">= 0"])
74
77
  s.add_dependency(%q<foreman>, [">= 0"])
@@ -76,7 +79,6 @@ Gem::Specification.new do |s|
76
79
  s.add_dependency(%q<rdoc>, ["~> 3.12"])
77
80
  s.add_dependency(%q<bundler>, ["~> 1.0"])
78
81
  s.add_dependency(%q<jeweler>, ["~> 2.0.1"])
79
- s.add_dependency(%q<simplecov>, [">= 0"])
80
82
  s.add_dependency(%q<webmock>, [">= 0"])
81
83
  end
82
84
  end
data/examples/2.rb CHANGED
@@ -1,4 +1,5 @@
1
- require_relative '../lib/ege_parser.rb'
1
+ require 'ege_parser'
2
+
2
3
  pupil = EgeParser::Pupil.new
3
4
 
4
5
  pupil.name = 'Никитос'
@@ -8,4 +9,8 @@ pupil.passport = '453312'
8
9
  pupil.region = '45'
9
10
 
10
11
  ege_parser = EgeParser::Parser.new
11
- p ege_parser.get_subjects pupil
12
+ begin
13
+ p ege_parser.get_subjects pupil #output as {'subject'=>'status', 'subject#2'=>'status2'}
14
+ rescue EgeParser::AuthError #see all errors in error.rb
15
+ p 'Auth error('
16
+ end
data/lib/ege_parser.rb CHANGED
@@ -8,70 +8,70 @@ require_relative 'pupil.rb'
8
8
 
9
9
  module EgeParser
10
10
 
11
- class Parser
12
-
13
- attr_writer :auth_agent
14
-
15
- def auth_agent
16
- @auth_agent ||= Mechanize.new
17
- @auth_agent.open_timeout=180
18
- @auth_agent.read_timeout=180
19
- @auth_agent
20
- end
21
-
22
- def get_subjects pupil
23
- page = auth_agent.post('http://check.ege.edu.ru/ru/index.php', {
24
- name: pupil.name,
25
- surname: pupil.surname,
26
- patronymic: pupil.patronymic,
27
- doc_number: pupil.passport,
28
- region: pupil.region,
29
- generate_captcha_val => ''
30
- })
31
-
32
- generate_subjects page
33
- end
34
-
35
- private
36
-
37
- def generate_captcha_val
38
- captcha_key = '-a-UHS2Wj8Cy8W4QB4cpZ8y_6XZNUWU'
39
- page = auth_agent.post('http://check.ege.edu.ru/common/Qaptcha.jquery.php', {
40
- action:'qaptcha',
41
- qaptcha_key:captcha_key
42
- })
43
- raise EgeParser::CaptchaError if JSON.parse(page.body)['error']
44
- captcha_key
45
- end
46
-
47
- def generate_subjects page
48
- Hash[find_elements(2, page).zip find_elements(5, page)]
49
- end
50
-
51
- def find_elements row, page
52
- result = []
53
- page.search("//table[contains(@class, 'appil_resultat')]/tbody/tr/td[#{row}]").to_a.map{|el|
54
- parsed = el_to_s(el)
55
- result << parsed if parsed != nil|| parsed != ''
56
- }
57
-
58
- check_for_errors page
59
-
60
- raise EgeParser::BadDataError if result.any?{|k| k.empty?} || result.empty?
61
-
62
- result
63
- end
64
-
65
- def check_for_errors page
66
- service_error = el_to_s(page.search('//h2'))
67
- raise EgeParser::ServiceError.new(service_error) unless service_error.empty?
68
-
69
- auth_error = el_to_s(page.search('//div[@id="show_div2"]/form'))
70
- raise EgeParser::AuthError.new unless auth_error.empty?
71
- end
72
-
73
- def el_to_s el
74
- el.to_s.gsub(/<\/?[^>]+>/, '').gsub(/\n|\t/,'').strip
75
- end
76
- end
11
+ class Parser
12
+
13
+ attr_writer :auth_agent
14
+
15
+ def auth_agent
16
+ @auth_agent ||= Mechanize.new
17
+ @auth_agent.open_timeout=180
18
+ @auth_agent.read_timeout=180
19
+ @auth_agent
20
+ end
21
+
22
+ def get_subjects pupil
23
+ page = auth_agent.post('http://check.ege.edu.ru/ru/index.php', {
24
+ name: pupil.name,
25
+ surname: pupil.surname,
26
+ patronymic: pupil.patronymic,
27
+ doc_number: pupil.passport,
28
+ region: pupil.region,
29
+ generate_captcha_val => ''
30
+ })
31
+
32
+ generate_subjects page
33
+ end
34
+
35
+ private
36
+
37
+ def generate_captcha_val
38
+ captcha_key = '-a-UHS2Wj8Cy8W4QB4cpZ8y_6XZNUWU'
39
+ page = auth_agent.post('http://check.ege.edu.ru/common/Qaptcha.jquery.php', {
40
+ action:'qaptcha',
41
+ qaptcha_key:captcha_key
42
+ })
43
+ raise EgeParser::CaptchaError if JSON.parse(page.body)['error']
44
+ captcha_key
45
+ end
46
+
47
+ def generate_subjects page
48
+ Hash[find_elements(2, page).zip find_elements(5, page)]
49
+ end
50
+
51
+ def find_elements row, page
52
+ result = []
53
+ page.search("//table[contains(@class, 'appil_resultat')]/tbody/tr/td[#{row}]").to_a.map{|el|
54
+ parsed = el_to_s(el)
55
+ result << parsed if parsed != nil|| parsed != ''
56
+ }
57
+
58
+ check_for_errors page
59
+
60
+ raise EgeParser::BadDataError if result.any?{|k| k.empty?} || result.empty?
61
+
62
+ result
63
+ end
64
+
65
+ def check_for_errors page
66
+ service_error = el_to_s(page.search('//h2'))
67
+ raise EgeParser::ServiceError.new(service_error) unless service_error.empty?
68
+
69
+ auth_error = el_to_s(page.search('//div[@id="show_div2"]/form'))
70
+ raise EgeParser::AuthError.new unless auth_error.empty?
71
+ end
72
+
73
+ def el_to_s el
74
+ el.to_s.gsub(/<\/?[^>]+>/, '').gsub(/\n|\t/,'').strip
75
+ end
76
+ end
77
77
  end
data/lib/error.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  module EgeParser
2
- class AuthError < StandardError; end
3
- class ParserError < StandardError; end
4
- class BadDataError < StandardError; end
5
- class ServiceError < StandardError; end
6
- class CaptchaError < StandardError; end
2
+ class AuthError < StandardError; end
3
+ class ParserError < StandardError; end
4
+ class BadDataError < StandardError; end
5
+ class ServiceError < StandardError; end
6
+ class CaptchaError < StandardError; end
7
7
  end
data/lib/pupil.rb CHANGED
@@ -1,11 +1,11 @@
1
1
  module EgeParser
2
2
 
3
- class Pupil
4
- attr_accessor :name,
5
- :surname,
6
- :patronymic,
7
- :passport,
8
- :region
9
- end
3
+ class Pupil
4
+ attr_accessor :name,
5
+ :surname,
6
+ :patronymic,
7
+ :passport,
8
+ :region
9
+ end
10
10
 
11
11
  end
@@ -1,70 +1,71 @@
1
+ # encoding: utf-8
1
2
  require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
3
 
3
4
  describe EgeParser::Parser, :fast do
4
- let(:pupil){
5
- pupil = EgeParser::Pupil.new
6
- pupil.name = 'Сергей'
7
- pupil.surname = 'Попов'
8
- pupil.patronymic = 'Олегович'
9
- pupil.passport = '741131'
10
- pupil.region = '29'
5
+ let(:pupil){
6
+ pupil = EgeParser::Pupil.new
7
+ pupil.name = 'Сер'
8
+ pupil.surname = 'ПоЛяков'
9
+ pupil.patronymic = 'Сергеевич'
10
+ pupil.passport = '342412'
11
+ pupil.region = '30'
11
12
 
12
- pupil
13
- }
13
+ pupil
14
+ }
14
15
 
15
- def stub_captcha(is_error=false)
16
- stub_request(:post, 'http://check.ege.edu.ru/common/Qaptcha.jquery.php').to_return(body:{error:is_error}.to_json)
17
- end
16
+ def stub_captcha(is_error = false)
17
+ stub_request(:post, 'http://check.ege.edu.ru/common/Qaptcha.jquery.php').to_return(body:{error:is_error}.to_json)
18
+ end
18
19
 
19
- def stub_result file_name
20
- stub_request(:post, "http://check.ege.edu.ru/ru/index.php")
21
- .to_return(
22
- :status => 200,
23
- :body => File.read(File.dirname(__FILE__) + "/templates/#{file_name}.html"),
24
- :headers => {'Content-Type'=>'text/html'}
25
- )
26
- end
20
+ def stub_result file_name
21
+ stub_request(:post, "http://check.ege.edu.ru/ru/index.php")
22
+ .to_return(
23
+ :status => 200,
24
+ :body => File.read(File.dirname(__FILE__) + "/templates/#{file_name}.html"),
25
+ :headers => {'Content-Type'=>'text/html'}
26
+ )
27
+ end
27
28
 
28
29
  describe '#get_subjects' do
29
- context 'when bad captcha' do
30
- it 'throw EgeParser::CaptchaError' do
31
- stub_captcha(is_error = true)
30
+ context 'when bad captcha' do
31
+ it 'throw EgeParser::CaptchaError' do
32
+ stub_captcha(true)
32
33
 
33
- expect{subject.get_subjects pupil}.to raise_error(EgeParser::CaptchaError)
34
- end
35
- end
34
+ expect{subject.get_subjects pupil}.to raise_error(EgeParser::CaptchaError)
35
+ end
36
+ end
36
37
 
37
- context 'when not authed' do
38
- it 'throw EgeParser::AuthError' do
39
- stub_captcha
40
- stub_result 'authed_error'
38
+ context 'when not authed' do
39
+ it 'throw EgeParser::AuthError' do
40
+ stub_captcha
41
+ stub_result 'authed_error'
41
42
 
42
- expect{subject.get_subjects pupil}.to raise_error(EgeParser::AuthError)
43
- end
44
- end
43
+ expect{subject.get_subjects pupil}.to raise_error(EgeParser::AuthError)
44
+ end
45
+ end
45
46
 
46
- context 'when some subject is empty' do
47
- it 'throw EgeParser::ParserError' do
48
- stub_captcha
49
- stub_result 'bad_data'
47
+ context 'when some subject is empty' do
48
+ it 'throw EgeParser::ParserError' do
49
+ stub_captcha
50
+ stub_result 'bad_data'
50
51
 
51
- expect{p subject.get_subjects pupil}.to raise_error(EgeParser::BadDataError)
52
- end
53
- end
52
+ expect{p subject.get_subjects pupil}.to raise_error(EgeParser::BadDataError)
53
+ end
54
+ end
54
55
 
55
- context 'all ok' do
56
- it 'parse all data and get result' do
57
- stub_captcha
58
- stub_result 'success'
56
+ context 'all ok' do
57
+ it 'parse all data and get result' do
58
+ stub_captcha
59
+ stub_result 'success'
59
60
 
60
- subject.get_subjects(pupil).should ==
61
- {'Русский язык' => 'Нет результата (обработка)',
62
- 'Математика' => 'Экзамен не проходил',
63
- 'Физика' => 'Экзамен не проходил',
64
- 'Информатика и ИКТ' => 'Экзамен не проходил'}
65
- end
66
- end
67
- end
61
+ subject.get_subjects(pupil).should ==
62
+ {'Русский язык' => 'Нет результата (обработка)',
63
+ 'Математика' => 'Экзамен не проходил',
64
+ 'Физика' => 'Экзамен не проходил',
65
+ 'Информатика и ИКТ' => 'Экзамен не проходил'}
66
+ end
67
+ end
68
+ end
68
69
  end
69
70
 
70
71
 
data/spec/spec_helper.rb CHANGED
@@ -1,6 +1,8 @@
1
1
  require 'simplecov'
2
2
  require 'webmock/rspec'
3
+ require 'coveralls'
3
4
 
5
+ Coveralls.wear!
4
6
  module SimpleCov::Configuration
5
7
  def clean_filters
6
8
  @filters = []
@@ -26,5 +28,5 @@ require 'ege_parser'
26
28
  Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
27
29
 
28
30
  RSpec.configure do |c|
29
- c.treat_symbols_as_metadata_keys_with_true_values = true
31
+ c.treat_symbols_as_metadata_keys_with_true_values = true
30
32
  end