netcity 0.4.0 → 0.6.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 +4 -4
- data/README.md +32 -6
- data/lib/netcity/data.rb +89 -10
- data/lib/netcity/netcity.rb +31 -19
- data/lib/netcity/version.rb +1 -1
- data/netcity.gemspec +2 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: acf2517bc6c976016890ba1caf76949805d6afec2aa413f3172ba9754cc5b081
|
4
|
+
data.tar.gz: 93806e656f0404d18f6dcea593c80b8de5b5cfe69960291036207a0f4883a31f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3631c97c268327d2ebef673a49808d7b74c9bed5dae476daaa44c99a527d4f3f1373f6f3f36a4c5b7a6482e438defd8fb7e5ea904a2b11d68d3a214888cba0a3
|
7
|
+
data.tar.gz: 137e08d1f8a1385f06ce3b3ae9be7195e65024be11c6ef0fd5205f159ed0c2e49b73024abf44b8b3cfb1a2ffd34aed4e7069040fdcc272eb6287ea64b71d8d5b
|
data/README.md
CHANGED
@@ -1,20 +1,46 @@
|
|
1
|
-
|
1
|
+
<center><h2>netcity</h2></center>
|
2
2
|
|
3
3
|
[](https://badge.fury.io/rb/netcity)
|
4
4
|

|
5
5
|
[](https://github.com/tulen34/netcity/blob/main/LICENSE)
|
6
6
|
|
7
|
-
**API** клиент для "Сетевого города". Он позволяет легко взаимодействовать с **электронным дневником**.
|
7
|
+
**API** клиент для "Сетевого города". Он позволяет легко взаимодействовать с **электронным дневником**. Клиент разрабатывался изначально для **Волгоградской области**, поэтому, возможно, у вас он **может не работать**.
|
8
8
|
|
9
|
-
### Установка
|
9
|
+
### :hammer_and_wrench: Установка
|
10
10
|
|
11
|
-
```
|
11
|
+
```sh
|
12
12
|
gem install netcity
|
13
13
|
```
|
14
14
|
|
15
|
-
|
15
|
+
Или добавьте в ваш Gemfile эту строку:
|
16
16
|
|
17
|
-
|
17
|
+
```ruby
|
18
|
+
gem "http"
|
19
|
+
```
|
20
|
+
|
21
|
+
### :book: Пример
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
require 'netcity'
|
25
|
+
|
26
|
+
client = NetCity.new('https://sgo.volganet.ru',
|
27
|
+
'Волгоградская обл',
|
28
|
+
'Городской округ Волжский',
|
29
|
+
'Волжский, г.',
|
30
|
+
'Общеобразовательная',
|
31
|
+
'МОУ СШ № 123',
|
32
|
+
'Иванов',
|
33
|
+
'123456789')
|
34
|
+
client.session do |session|
|
35
|
+
puts session.diary
|
36
|
+
end
|
37
|
+
```
|
38
|
+
|
39
|
+
### :footprints: Прогресс разработки
|
40
|
+
|
41
|
+
- [x] Авторизация
|
42
|
+
- [x] Получение дневника
|
43
|
+
- [ ] Получение доски объявлений
|
18
44
|
|
19
45
|
### :love_letter: Благодарность
|
20
46
|
|
data/lib/netcity/data.rb
CHANGED
@@ -1,21 +1,100 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'date'
|
3
|
+
|
1
4
|
class NetCity
|
2
|
-
SchoolAddress = Struct.new(:state,
|
5
|
+
SchoolAddress = Struct.new(:state,
|
6
|
+
:province,
|
7
|
+
:city,
|
8
|
+
:func,
|
9
|
+
:school)
|
10
|
+
|
11
|
+
LoginInfo = Struct.new(:school_address,
|
12
|
+
:user_name,
|
13
|
+
:password)
|
14
|
+
|
15
|
+
class Diary
|
16
|
+
include Enumerable
|
17
|
+
|
18
|
+
attr_reader :start, :end
|
19
|
+
|
20
|
+
def initialize(hash)
|
21
|
+
@start = hash['weekStart']
|
22
|
+
@end = hash['weekEnd']
|
23
|
+
@days = hash['weekDays'].map { |h| Day.new(h) }
|
24
|
+
end
|
3
25
|
|
4
|
-
|
5
|
-
|
26
|
+
def [](index)
|
27
|
+
@days[index]
|
28
|
+
end
|
6
29
|
|
7
|
-
def
|
8
|
-
@
|
9
|
-
@user_id = data['user']['id']
|
10
|
-
@year_id = data['schoolYearId']
|
30
|
+
def each(&block)
|
31
|
+
@days.each { |lesson| block.call(day) }
|
11
32
|
end
|
12
33
|
end
|
13
34
|
|
14
|
-
class
|
15
|
-
|
35
|
+
class Day
|
36
|
+
include Enumerable
|
37
|
+
|
38
|
+
attr_reader :date
|
39
|
+
|
40
|
+
def initialize(hash)
|
41
|
+
@date = hash['date']
|
42
|
+
@lessons = hash['lessons'].map { |h| Lesson.new(h) }
|
43
|
+
end
|
44
|
+
|
45
|
+
def [](index)
|
46
|
+
@lessons[index]
|
47
|
+
end
|
16
48
|
|
17
|
-
def
|
49
|
+
def each(&block)
|
50
|
+
@lessons.each { |lesson| block.call(lesson) }
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
Assignment = Struct.new(:id,
|
55
|
+
:type,
|
56
|
+
:name,
|
57
|
+
:mark,
|
58
|
+
:deadline)
|
59
|
+
|
60
|
+
class Lesson
|
61
|
+
include Enumerable
|
62
|
+
|
63
|
+
attr_reader :start, :end, :number, :name, :room
|
64
|
+
|
65
|
+
def initialize(hash)
|
66
|
+
@start = hash['startTime']
|
67
|
+
@end = hash['endTime']
|
68
|
+
@number = hash['number']
|
69
|
+
@name = hash['subjectName']
|
70
|
+
@room = hash['room']
|
71
|
+
return unless hash.include?('assignments')
|
72
|
+
|
73
|
+
@assignments = hash['assignments'].map do |h|
|
74
|
+
Assignment.new.tap do |a|
|
75
|
+
a.id = h['id']
|
76
|
+
a.type = h['typeId']
|
77
|
+
a.name = h['assignmentName']
|
78
|
+
a.mark = h['mark']['mark'] if h.include?('mark')
|
79
|
+
a.deadline = h['dueDate']
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
def [](index)
|
85
|
+
@assignments[index]
|
86
|
+
end
|
18
87
|
|
88
|
+
def each(&block)
|
89
|
+
@assignments.each { |assignment| block.call(assignment) }
|
19
90
|
end
|
20
91
|
end
|
21
92
|
end
|
93
|
+
|
94
|
+
module JSON
|
95
|
+
def parse_diary(source)
|
96
|
+
NetCity::Diary.new(JSON.parse(source))
|
97
|
+
end
|
98
|
+
|
99
|
+
module_function :parse_diary
|
100
|
+
end
|
data/lib/netcity/netcity.rb
CHANGED
@@ -1,23 +1,31 @@
|
|
1
1
|
require 'http'
|
2
|
+
require 'date'
|
2
3
|
require 'digest'
|
3
4
|
|
4
5
|
class NetCity
|
5
|
-
attr_accessor :client, :
|
6
|
-
attr_reader :context
|
6
|
+
attr_accessor :client, :login_info
|
7
7
|
|
8
8
|
def initialize(base_url,
|
9
9
|
state, province, city, func, school,
|
10
10
|
user_name, password)
|
11
|
-
@client = HTTP[
|
11
|
+
@client = HTTP['user-agent': "netcity/#{VERSION}", referer: base_url]
|
12
12
|
.persistent(base_url)
|
13
13
|
|
14
|
-
@
|
15
|
-
|
16
|
-
|
14
|
+
@login_info = LoginInfo.new.tap do |l|
|
15
|
+
l.user_name = user_name
|
16
|
+
l.password = password
|
17
|
+
l.school_address = SchoolAddress.new(state, province, city, func, school)
|
18
|
+
end
|
17
19
|
end
|
18
20
|
|
19
|
-
def diary(
|
20
|
-
|
21
|
+
def diary(week_start: Date.today - Date.today.wday + 1,
|
22
|
+
week_end: Date.today - Date.today.wday + 6)
|
23
|
+
JSON.parse_diary(@client.get('/webapi/student/diary', params: {
|
24
|
+
'studentId' => @user_id,
|
25
|
+
'weekStart' => week_start.to_s,
|
26
|
+
'weekEnd' => week_end.to_s,
|
27
|
+
'yearId' => @year_id
|
28
|
+
}))
|
21
29
|
end
|
22
30
|
|
23
31
|
def session
|
@@ -31,21 +39,23 @@ class NetCity
|
|
31
39
|
form = JSON.parse(@client.get('/webapi/prepareloginform')).keep_if do |k|
|
32
40
|
%w[cid sid pid cn sft scid].include?(k)
|
33
41
|
end
|
34
|
-
|
35
42
|
queue = form
|
36
43
|
.keys[...-1]
|
37
44
|
.each_index
|
38
|
-
.zip(@school_address.members)
|
45
|
+
.zip(@login_info.school_address.members)
|
39
46
|
|
40
47
|
queue.each do |i, member|
|
41
48
|
current_form = JSON.parse(@client.get('/webapi/loginform', params: {
|
42
|
-
lastname
|
49
|
+
'lastname' => form.keys[i]
|
43
50
|
}.merge(form)))
|
44
51
|
|
45
52
|
match = current_form['items'].find do |item|
|
46
|
-
item['name'] == @school_address[member]
|
47
|
-
end
|
53
|
+
item['name'] == @login_info.school_address[member]
|
54
|
+
end
|
48
55
|
|
56
|
+
if match.nil?
|
57
|
+
raise LoginFormError.new(member, @login_info.school_address[member])
|
58
|
+
end
|
49
59
|
form.update(form.keys[i + 1] => match['id'])
|
50
60
|
end
|
51
61
|
|
@@ -56,15 +66,15 @@ class NetCity
|
|
56
66
|
end
|
57
67
|
|
58
68
|
md5 = Digest::MD5.new.tap do |md5|
|
59
|
-
md5 << data.delete(
|
69
|
+
md5 << data.delete('salt') << Digest::MD5.hexdigest(@login_info.password)
|
60
70
|
end.hexdigest
|
61
71
|
|
62
72
|
info = {}.tap do |h|
|
63
73
|
responce = @client.post('/webapi/login', form: {
|
64
|
-
logintype
|
65
|
-
un
|
66
|
-
pw
|
67
|
-
pw2
|
74
|
+
'logintype' => 1,
|
75
|
+
'un' => @login_info.user_name,
|
76
|
+
'pw' => md5[...@login_info.password.size],
|
77
|
+
'pw2' => md5
|
68
78
|
}.merge(form, data))
|
69
79
|
|
70
80
|
@client = @client.cookies(responce.cookies)
|
@@ -74,7 +84,9 @@ class NetCity
|
|
74
84
|
raise Error, info['message'] unless info.include?('at')
|
75
85
|
@client = @client.headers(at: info['at'])
|
76
86
|
|
77
|
-
|
87
|
+
context = JSON.parse(@client.get('/webapi/context'))
|
88
|
+
@user_id = context['user']['id']
|
89
|
+
@year_id = context['schoolYearId']
|
78
90
|
nil
|
79
91
|
end
|
80
92
|
|
data/lib/netcity/version.rb
CHANGED
data/netcity.gemspec
CHANGED
@@ -26,9 +26,9 @@ Gem::Specification.new do |s|
|
|
26
26
|
"Gemfile",
|
27
27
|
"LICENSE",
|
28
28
|
"netcity.gemspec",
|
29
|
-
"README.md"
|
29
|
+
"README.md"
|
30
30
|
]
|
31
|
-
s.
|
31
|
+
s.executable = "netcity"
|
32
32
|
|
33
33
|
s.required_ruby_version = Gem::Requirement.new(">= 2.7.0")
|
34
34
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: netcity
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Glushonkov Ilya
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-03-
|
11
|
+
date: 2021-03-16 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: |
|
14
14
|
API клиент для "Сетевого города". Он позволяет легко взаимодействовать с
|