netcity 0.1.0 → 0.3.5
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 +7 -1
- data/bin/test +15 -0
- data/lib/netcity.rb +41 -42
- data/lib/netcity/data.rb +1 -1
- data/lib/netcity/errors.rb +16 -4
- data/netcity.gemspec +4 -1
- metadata +7 -4
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA256:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: e74345b40482be87c3f32bfe664bf3fd78011b07f9a13929284a280acb14b4d2
         | 
| 4 | 
            +
              data.tar.gz: abfcbee97e017fff139458d3ee8cb6fc906f121b93dd67bfce9cb20018ca5226
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 7493df8082793fc00598852edf70dc4fff77372179db218d36a481aeeb0247db621e825626fe05e97301ee1e6d7b17a4ac3ade38471a9114b3cb42496495ca85
         | 
| 7 | 
            +
              data.tar.gz: c5e0a9b422e8784328adc8340240ace60147f07fa25899b728589227572e7dcdb38b3c44ae96476805f05078ef753af745fcfb9c3d7f8e6fd83f88265fe8f297
         | 
    
        data/README.md
    CHANGED
    
    | @@ -1 +1,7 @@ | |
| 1 | 
            -
            # netcity
         | 
| 1 | 
            +
            # netcity
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            [](https://travis-ci.com/tulen34/netcity)
         | 
| 4 | 
            +
            [](https://badge.fury.io/rb/netcity)
         | 
| 5 | 
            +
            [](https://github.com/tulen34/netcity/blob/main/LICENSE)
         | 
| 6 | 
            +
             | 
| 7 | 
            +
            **API** клиент для "Сетевого города". Он позволяет легко взаимодействовать с **электронным дневником**.
         | 
    
        data/bin/test
    ADDED
    
    | @@ -0,0 +1,15 @@ | |
| 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
         | 
    
        data/lib/netcity.rb
    CHANGED
    
    | @@ -7,70 +7,69 @@ require "netcity/errors.rb" | |
| 7 7 | 
             
            class NetCity
         | 
| 8 8 | 
             
              attr_accessor :client, :user_name, :password, :school_address
         | 
| 9 9 |  | 
| 10 | 
            -
              def initialize(base_url,  | 
| 10 | 
            +
              def initialize(base_url, state, province, city, func, school, 
         | 
| 11 | 
            +
                             user_name, password)
         | 
| 11 12 | 
             
                @client = HTTP["user-agent": "netcity/#{VERSION}", referer: base_url]
         | 
| 12 13 | 
             
                  .persistent(base_url)
         | 
| 13 14 |  | 
| 14 15 | 
             
                @user_name      = user_name
         | 
| 15 16 | 
             
                @password       = password
         | 
| 16 | 
            -
                @school_address =  | 
| 17 | 
            +
                @school_address = SchoolAddress.new(state, province, city, func, school)
         | 
| 17 18 | 
             
              end
         | 
| 18 19 |  | 
| 19 20 | 
             
              def login
         | 
| 20 | 
            -
                 | 
| 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|
         | 
| 21 40 | 
             
                  responce = @client.post("/webapi/auth/getdata")
         | 
| 22 41 | 
             
                  @client  = @client.cookies(responce.cookies)
         | 
| 23 | 
            -
                   | 
| 42 | 
            +
                  h.update(JSON.parse(responce))
         | 
| 24 43 | 
             
                end
         | 
| 25 44 |  | 
| 26 45 | 
             
                encoded_password = Digest::MD5.new.tap do |md5|
         | 
| 27 46 | 
             
                  md5 << data.delete("salt") << Digest::MD5.hexdigest(@password)
         | 
| 28 47 | 
             
                end.hexdigest
         | 
| 29 48 |  | 
| 30 | 
            -
                 | 
| 31 | 
            -
             | 
| 32 | 
            -
             | 
| 33 | 
            -
             | 
| 34 | 
            -
             | 
| 35 | 
            -
             | 
| 36 | 
            -
             | 
| 37 | 
            -
                unless responce.include?("at")
         | 
| 38 | 
            -
                  if responce["message"].size == 29
         | 
| 39 | 
            -
                    raise LoginDataError
         | 
| 40 | 
            -
                  else
         | 
| 41 | 
            -
                    raise Error, responce["message"]
         | 
| 42 | 
            -
                  end
         | 
| 43 | 
            -
                end
         | 
| 44 | 
            -
                @client = @client.headers(at: responce["at"])
         | 
| 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))
         | 
| 45 56 |  | 
| 46 | 
            -
             | 
| 47 | 
            -
                   | 
| 48 | 
            -
                  logout
         | 
| 57 | 
            +
                  @client = @client.cookies(responce.cookies)
         | 
| 58 | 
            +
                  h.update(JSON.parse(responce))
         | 
| 49 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"]
         | 
| 50 69 | 
             
              end
         | 
| 51 70 |  | 
| 52 71 | 
             
              def logout
         | 
| 53 72 | 
             
                @client.post("/webapi/auth/logout")
         | 
| 54 73 | 
             
                nil
         | 
| 55 74 | 
             
              end
         | 
| 56 | 
            -
             | 
| 57 | 
            -
              private
         | 
| 58 | 
            -
             | 
| 59 | 
            -
              def login_form
         | 
| 60 | 
            -
                login_form = JSON.parse(@client.get("/webapi/prepareloginform"))
         | 
| 61 | 
            -
                  .keep_if { |key| key =~ /cid|sid|pid|cn|sft|scid/ }
         | 
| 62 | 
            -
             | 
| 63 | 
            -
                queue = login_form.keys[...-1].each_index.zip(@school_address.members)
         | 
| 64 | 
            -
                queue.each do |index, member|
         | 
| 65 | 
            -
                  params = login_form.merge(lastname: login_form.keys[index])
         | 
| 66 | 
            -
                  form   = JSON.parse(@client.get("/webapi/loginform", params: params))
         | 
| 67 | 
            -
             | 
| 68 | 
            -
                  match = form["items"].find do |item|
         | 
| 69 | 
            -
                    item["name"] == @school_address[member]
         | 
| 70 | 
            -
                  end or raise LoginFormError.new(member, @school_address[member])
         | 
| 71 | 
            -
             | 
| 72 | 
            -
                  login_form.update(login_form.keys[index + 1] => match["id"])
         | 
| 73 | 
            -
                end
         | 
| 74 | 
            -
                login_form
         | 
| 75 | 
            -
              end
         | 
| 76 75 | 
             
            end
         | 
    
        data/lib/netcity/data.rb
    CHANGED
    
    
    
        data/lib/netcity/errors.rb
    CHANGED
    
    | @@ -3,18 +3,30 @@ class NetCity | |
| 3 3 |  | 
| 4 4 | 
             
              class LoginFormError < Error
         | 
| 5 5 | 
             
                def initialize(member, value)
         | 
| 6 | 
            -
                  @member = member
         | 
| 7 | 
            -
             | 
| 6 | 
            +
                  @member = case member
         | 
| 7 | 
            +
                            when :state
         | 
| 8 | 
            +
                              "Регион"
         | 
| 9 | 
            +
                            when :province
         | 
| 10 | 
            +
                              "Городской округ / Муниципальный район"
         | 
| 11 | 
            +
                            when :city
         | 
| 12 | 
            +
                              "Населённый пункт"
         | 
| 13 | 
            +
                            when :func
         | 
| 14 | 
            +
                              "Тип ОО"
         | 
| 15 | 
            +
                            when :school
         | 
| 16 | 
            +
                              "Образовательная организация"
         | 
| 17 | 
            +
                            end
         | 
| 18 | 
            +
             | 
| 19 | 
            +
                  @value = value
         | 
| 8 20 | 
             
                end
         | 
| 9 21 |  | 
| 10 22 | 
             
                def to_s
         | 
| 11 | 
            -
                  " | 
| 23 | 
            +
                  "Отсутствует #{@member} со значением #{@value}"
         | 
| 12 24 | 
             
                end
         | 
| 13 25 | 
             
              end
         | 
| 14 26 |  | 
| 15 27 | 
             
              class LoginDataError < Error
         | 
| 16 28 | 
             
                def to_s
         | 
| 17 | 
            -
                  " | 
| 29 | 
            +
                  "Неправильный логин или пароль"
         | 
| 18 30 | 
             
                end
         | 
| 19 31 | 
             
              end
         | 
| 20 32 | 
             
            end
         | 
    
        data/netcity.gemspec
    CHANGED
    
    | @@ -12,8 +12,11 @@ Gem::Specification.new do |s| | |
| 12 12 | 
             
                API клиент для "Сетевого города". Он позволяет легко взаимодействовать с
         | 
| 13 13 | 
             
                электронным дневником.
         | 
| 14 14 | 
             
              EOF
         | 
| 15 | 
            -
              s.homepage    = "https:// | 
| 15 | 
            +
              s.homepage    = "https://rubygems.org/gems/netcity"
         | 
| 16 16 | 
             
              s.license     = "MIT"
         | 
| 17 | 
            +
              s.metadata    = {
         | 
| 18 | 
            +
                "source_code_uri" => "https://github.com/tulen34/netcity"
         | 
| 19 | 
            +
              }
         | 
| 17 20 |  | 
| 18 21 | 
             
              s.files       = Rake::FileList["**/*"].exclude(*File.read(".gitignore").split)
         | 
| 19 22 | 
             
              s.executables = s.files.grep(/^bin\/.+/) { |f| File.basename(f) }
         | 
    
        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.3.5
         | 
| 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- | 
| 11 | 
            +
            date: 2021-03-03 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies: []
         | 
| 13 13 | 
             
            description: |
         | 
| 14 14 | 
             
              API клиент для "Сетевого города". Он позволяет легко взаимодействовать с
         | 
| @@ -16,6 +16,7 @@ description: | | |
| 16 16 | 
             
            email: pulsar04040@gmail.com
         | 
| 17 17 | 
             
            executables:
         | 
| 18 18 | 
             
            - netcity
         | 
| 19 | 
            +
            - test
         | 
| 19 20 | 
             
            extensions: []
         | 
| 20 21 | 
             
            extra_rdoc_files: []
         | 
| 21 22 | 
             
            files:
         | 
| @@ -23,14 +24,16 @@ files: | |
| 23 24 | 
             
            - LICENSE
         | 
| 24 25 | 
             
            - README.md
         | 
| 25 26 | 
             
            - bin/netcity
         | 
| 27 | 
            +
            - bin/test
         | 
| 26 28 | 
             
            - lib/netcity.rb
         | 
| 27 29 | 
             
            - lib/netcity/data.rb
         | 
| 28 30 | 
             
            - lib/netcity/errors.rb
         | 
| 29 31 | 
             
            - netcity.gemspec
         | 
| 30 | 
            -
            homepage: https:// | 
| 32 | 
            +
            homepage: https://rubygems.org/gems/netcity
         | 
| 31 33 | 
             
            licenses:
         | 
| 32 34 | 
             
            - MIT
         | 
| 33 | 
            -
            metadata: | 
| 35 | 
            +
            metadata:
         | 
| 36 | 
            +
              source_code_uri: https://github.com/tulen34/netcity
         | 
| 34 37 | 
             
            post_install_message:
         | 
| 35 38 | 
             
            rdoc_options: []
         | 
| 36 39 | 
             
            require_paths:
         |