netcity 0.3.5 → 0.4.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/Gemfile +0 -2
- data/README.md +15 -1
- data/lib/netcity.rb +4 -75
- data/lib/netcity/data.rb +18 -2
- data/lib/netcity/errors.rb +5 -11
- data/lib/netcity/netcity.rb +85 -0
- data/lib/netcity/version.rb +3 -0
- data/netcity.gemspec +13 -4
- metadata +4 -4
- data/bin/test +0 -15
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 24de9d2d19d1e4fbb099524730790458a61d98f2dc75fc139c74b6c86b636b05
|
|
4
|
+
data.tar.gz: 1fbf557670cebc5faa508d18fde393c26b95c2ae3fcd5dcce1b4c8fb8011b3b2
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 73002751295a82ab78a9f4af076f2b33fc9307b6af3aff75b4708b604cce17e8d44f54091e6f6f0b35b1bdf3e6c74d4bc01b252402c38feea7953b0a90e94361
|
|
7
|
+
data.tar.gz: 1713737e21a113d0f0068f0205d3d71df483e719e982e34cdd73904e7df35a27263a0f5abb39d704480c4812f773cb6d384231ee8eaaa3879f97d4439ac23617
|
data/Gemfile
CHANGED
data/README.md
CHANGED
|
@@ -1,7 +1,21 @@
|
|
|
1
1
|
# netcity
|
|
2
2
|
|
|
3
|
-
[](https://travis-ci.com/tulen34/netcity)
|
|
4
3
|
[](https://badge.fury.io/rb/netcity)
|
|
4
|
+

|
|
5
5
|
[](https://github.com/tulen34/netcity/blob/main/LICENSE)
|
|
6
6
|
|
|
7
7
|
**API** клиент для "Сетевого города". Он позволяет легко взаимодействовать с **электронным дневником**.
|
|
8
|
+
|
|
9
|
+
### Установка
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
gem install netcity
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
### :warning: Внимание
|
|
16
|
+
|
|
17
|
+
Клиент разрабатывался изначально для **Волгоградской области**, поэтому, возможно, у вас он может **не работать**
|
|
18
|
+
|
|
19
|
+
### :love_letter: Благодарность
|
|
20
|
+
|
|
21
|
+
Меня вдохновил **[проект другого человека](https://github.com/nm17/netschoolapi)**. Я лишь **адаптировал** его под свой регион и на любимом языке.
|
data/lib/netcity.rb
CHANGED
|
@@ -1,75 +1,4 @@
|
|
|
1
|
-
require
|
|
2
|
-
require
|
|
3
|
-
|
|
4
|
-
require
|
|
5
|
-
require "netcity/errors.rb"
|
|
6
|
-
|
|
7
|
-
class NetCity
|
|
8
|
-
attr_accessor :client, :user_name, :password, :school_address
|
|
9
|
-
|
|
10
|
-
def initialize(base_url, state, province, city, func, school,
|
|
11
|
-
user_name, password)
|
|
12
|
-
@client = HTTP["user-agent": "netcity/#{VERSION}", referer: base_url]
|
|
13
|
-
.persistent(base_url)
|
|
14
|
-
|
|
15
|
-
@user_name = user_name
|
|
16
|
-
@password = password
|
|
17
|
-
@school_address = SchoolAddress.new(state, province, city, func, school)
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
def login
|
|
21
|
-
form = JSON.parse(@client.get("/webapi/prepareloginform"))
|
|
22
|
-
.keep_if { |k| %w(cid sid pid cn sft scid).include?(k) }
|
|
23
|
-
|
|
24
|
-
queue = form.keys[...-1].each_index
|
|
25
|
-
.zip(@school_address.members)
|
|
26
|
-
|
|
27
|
-
queue.each do |index, member|
|
|
28
|
-
concrete_form = JSON.parse(@client.get("/webapi/loginform", params: {
|
|
29
|
-
lastname: form.keys[index]
|
|
30
|
-
}.merge(form)))
|
|
31
|
-
|
|
32
|
-
match = concrete_form["items"].find do |item|
|
|
33
|
-
item["name"] == @school_address[member]
|
|
34
|
-
end or raise LoginFormError.new(member, @school_address[member])
|
|
35
|
-
|
|
36
|
-
form.update(form.keys[index + 1] => match["id"])
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
data = {}.tap do |h|
|
|
40
|
-
responce = @client.post("/webapi/auth/getdata")
|
|
41
|
-
@client = @client.cookies(responce.cookies)
|
|
42
|
-
h.update(JSON.parse(responce))
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
encoded_password = Digest::MD5.new.tap do |md5|
|
|
46
|
-
md5 << data.delete("salt") << Digest::MD5.hexdigest(@password)
|
|
47
|
-
end.hexdigest
|
|
48
|
-
|
|
49
|
-
info = {}.tap do |h|
|
|
50
|
-
responce = @client.post("/webapi/login", form: {
|
|
51
|
-
logintype: 1,
|
|
52
|
-
un: @user_name,
|
|
53
|
-
pw: encoded_password[...@password.size],
|
|
54
|
-
pw2: encoded_password
|
|
55
|
-
}.merge(form, data))
|
|
56
|
-
|
|
57
|
-
@client = @client.cookies(responce.cookies)
|
|
58
|
-
h.update(JSON.parse(responce))
|
|
59
|
-
end
|
|
60
|
-
|
|
61
|
-
raise Error, info["message"] unless info.include?("at")
|
|
62
|
-
@client = @client.headers(at: info["at"])
|
|
63
|
-
|
|
64
|
-
students, id = JSON.parse(@client.get("/webapi/student/diary/init"))
|
|
65
|
-
.values_at("students", "currentStudentId")
|
|
66
|
-
|
|
67
|
-
@student_id = students[id]["studentId"]
|
|
68
|
-
@year_id = JSON.parse(@client.get("/webapi/context"))["schoolYearId"]
|
|
69
|
-
end
|
|
70
|
-
|
|
71
|
-
def logout
|
|
72
|
-
@client.post("/webapi/auth/logout")
|
|
73
|
-
nil
|
|
74
|
-
end
|
|
75
|
-
end
|
|
1
|
+
require 'netcity/netcity'
|
|
2
|
+
require 'netcity/data'
|
|
3
|
+
require 'netcity/errors'
|
|
4
|
+
require 'netcity/version'
|
data/lib/netcity/data.rb
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
class NetCity
|
|
2
|
-
VERSION = "0.3.5"
|
|
3
|
-
|
|
4
2
|
SchoolAddress = Struct.new(:state, :province, :city, :func, :school)
|
|
3
|
+
|
|
4
|
+
class Context
|
|
5
|
+
attr_reader :full_name, :user_id, :year_id
|
|
6
|
+
|
|
7
|
+
def initialize(data)
|
|
8
|
+
@full_name = data['user']['name']
|
|
9
|
+
@user_id = data['user']['id']
|
|
10
|
+
@year_id = data['schoolYearId']
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
class Diary
|
|
15
|
+
attr_reader :week_start, :week_end, :schedule
|
|
16
|
+
|
|
17
|
+
def initilaize(data)
|
|
18
|
+
|
|
19
|
+
end
|
|
20
|
+
end
|
|
5
21
|
end
|
data/lib/netcity/errors.rb
CHANGED
|
@@ -5,15 +5,15 @@ class NetCity
|
|
|
5
5
|
def initialize(member, value)
|
|
6
6
|
@member = case member
|
|
7
7
|
when :state
|
|
8
|
-
|
|
8
|
+
'Регион'
|
|
9
9
|
when :province
|
|
10
|
-
|
|
10
|
+
'Городской округ / Муниципальный район'
|
|
11
11
|
when :city
|
|
12
|
-
|
|
12
|
+
'Населённый пункт'
|
|
13
13
|
when :func
|
|
14
|
-
|
|
14
|
+
'Тип ОО'
|
|
15
15
|
when :school
|
|
16
|
-
|
|
16
|
+
'Образовательная организация'
|
|
17
17
|
end
|
|
18
18
|
|
|
19
19
|
@value = value
|
|
@@ -23,10 +23,4 @@ class NetCity
|
|
|
23
23
|
"Отсутствует #{@member} со значением #{@value}"
|
|
24
24
|
end
|
|
25
25
|
end
|
|
26
|
-
|
|
27
|
-
class LoginDataError < Error
|
|
28
|
-
def to_s
|
|
29
|
-
"Неправильный логин или пароль"
|
|
30
|
-
end
|
|
31
|
-
end
|
|
32
26
|
end
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
require 'http'
|
|
2
|
+
require 'digest'
|
|
3
|
+
|
|
4
|
+
class NetCity
|
|
5
|
+
attr_accessor :client, :user_name, :password, :school_address
|
|
6
|
+
attr_reader :context
|
|
7
|
+
|
|
8
|
+
def initialize(base_url,
|
|
9
|
+
state, province, city, func, school,
|
|
10
|
+
user_name, password)
|
|
11
|
+
@client = HTTP["user-agent": "netcity/#{VERSION}", referer: base_url]
|
|
12
|
+
.persistent(base_url)
|
|
13
|
+
|
|
14
|
+
@user_name = user_name
|
|
15
|
+
@password = password
|
|
16
|
+
@school_address = SchoolAddress.new(state, province, city, func, school)
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def diary(options = {})
|
|
20
|
+
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def session
|
|
24
|
+
login
|
|
25
|
+
yield self
|
|
26
|
+
ensure
|
|
27
|
+
logout
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def login
|
|
31
|
+
form = JSON.parse(@client.get('/webapi/prepareloginform')).keep_if do |k|
|
|
32
|
+
%w[cid sid pid cn sft scid].include?(k)
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
queue = form
|
|
36
|
+
.keys[...-1]
|
|
37
|
+
.each_index
|
|
38
|
+
.zip(@school_address.members)
|
|
39
|
+
|
|
40
|
+
queue.each do |i, member|
|
|
41
|
+
current_form = JSON.parse(@client.get('/webapi/loginform', params: {
|
|
42
|
+
lastname: form.keys[i]
|
|
43
|
+
}.merge(form)))
|
|
44
|
+
|
|
45
|
+
match = current_form['items'].find do |item|
|
|
46
|
+
item['name'] == @school_address[member]
|
|
47
|
+
end or raise LoginFormError.new(member, @school_address[member])
|
|
48
|
+
|
|
49
|
+
form.update(form.keys[i + 1] => match['id'])
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
data = {}.tap do |h|
|
|
53
|
+
responce = @client.post('/webapi/auth/getdata')
|
|
54
|
+
@client = @client.cookies(responce.cookies)
|
|
55
|
+
h.update(JSON.parse(responce))
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
md5 = Digest::MD5.new.tap do |md5|
|
|
59
|
+
md5 << data.delete("salt") << Digest::MD5.hexdigest(@password)
|
|
60
|
+
end.hexdigest
|
|
61
|
+
|
|
62
|
+
info = {}.tap do |h|
|
|
63
|
+
responce = @client.post('/webapi/login', form: {
|
|
64
|
+
logintype: 1,
|
|
65
|
+
un: @user_name,
|
|
66
|
+
pw: md5[...@password.size],
|
|
67
|
+
pw2: md5
|
|
68
|
+
}.merge(form, data))
|
|
69
|
+
|
|
70
|
+
@client = @client.cookies(responce.cookies)
|
|
71
|
+
h.update(JSON.parse(responce))
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
raise Error, info['message'] unless info.include?('at')
|
|
75
|
+
@client = @client.headers(at: info['at'])
|
|
76
|
+
|
|
77
|
+
@context = Context.new(JSON.parse(@client.get('/webapi/context')))
|
|
78
|
+
nil
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
def logout
|
|
82
|
+
@client.post('/webapi/auth/logout')
|
|
83
|
+
nil
|
|
84
|
+
end
|
|
85
|
+
end
|
data/netcity.gemspec
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
require_relative "lib/netcity/data.rb"
|
|
1
|
+
require_relative "lib/netcity/version.rb"
|
|
3
2
|
|
|
4
3
|
Gem::Specification.new do |s|
|
|
5
4
|
s.name = "netcity"
|
|
@@ -17,8 +16,18 @@ Gem::Specification.new do |s|
|
|
|
17
16
|
s.metadata = {
|
|
18
17
|
"source_code_uri" => "https://github.com/tulen34/netcity"
|
|
19
18
|
}
|
|
20
|
-
|
|
21
|
-
|
|
19
|
+
s.files = [
|
|
20
|
+
"bin/netcity",
|
|
21
|
+
"lib/netcity.rb",
|
|
22
|
+
"lib/netcity/netcity.rb",
|
|
23
|
+
"lib/netcity/version.rb",
|
|
24
|
+
"lib/netcity/data.rb",
|
|
25
|
+
"lib/netcity/errors.rb",
|
|
26
|
+
"Gemfile",
|
|
27
|
+
"LICENSE",
|
|
28
|
+
"netcity.gemspec",
|
|
29
|
+
"README.md",
|
|
30
|
+
]
|
|
22
31
|
s.executables = s.files.grep(/^bin\/.+/) { |f| File.basename(f) }
|
|
23
32
|
|
|
24
33
|
s.required_ruby_version = Gem::Requirement.new(">= 2.7.0")
|
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.4.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-08 00:00:00.000000000 Z
|
|
12
12
|
dependencies: []
|
|
13
13
|
description: |
|
|
14
14
|
API клиент для "Сетевого города". Он позволяет легко взаимодействовать с
|
|
@@ -16,7 +16,6 @@ description: |
|
|
|
16
16
|
email: pulsar04040@gmail.com
|
|
17
17
|
executables:
|
|
18
18
|
- netcity
|
|
19
|
-
- test
|
|
20
19
|
extensions: []
|
|
21
20
|
extra_rdoc_files: []
|
|
22
21
|
files:
|
|
@@ -24,10 +23,11 @@ files:
|
|
|
24
23
|
- LICENSE
|
|
25
24
|
- README.md
|
|
26
25
|
- bin/netcity
|
|
27
|
-
- bin/test
|
|
28
26
|
- lib/netcity.rb
|
|
29
27
|
- lib/netcity/data.rb
|
|
30
28
|
- lib/netcity/errors.rb
|
|
29
|
+
- lib/netcity/netcity.rb
|
|
30
|
+
- lib/netcity/version.rb
|
|
31
31
|
- netcity.gemspec
|
|
32
32
|
homepage: https://rubygems.org/gems/netcity
|
|
33
33
|
licenses:
|
data/bin/test
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/ruby
|
|
2
|
-
|
|
3
|
-
require "netcity"
|
|
4
|
-
|
|
5
|
-
client = NetCity.new("https://sgo.volganet.ru",
|
|
6
|
-
"Волгоградская обл",
|
|
7
|
-
"Городской округ Волжский",
|
|
8
|
-
"Волжский, г.",
|
|
9
|
-
"Общеобразовательная",
|
|
10
|
-
"МОУ СШ № 28",
|
|
11
|
-
"Глушонков",
|
|
12
|
-
"22081979As")
|
|
13
|
-
client.login
|
|
14
|
-
pp client
|
|
15
|
-
client.logout
|