cfan122 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +63 -0
- data/LICENSE +21 -0
- data/LICENSE.txt +21 -0
- data/README.md +41 -0
- data/Rakefile +10 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/cfan122.gemspec +34 -0
- data/lib/cfan122/config.rb +22 -0
- data/lib/cfan122/http_config.rb +24 -0
- data/lib/cfan122/operation.rb +64 -0
- data/lib/cfan122/operation_methods.rb +43 -0
- data/lib/cfan122/operations/exam_agency.rb +29 -0
- data/lib/cfan122/operations/exam_location.rb +31 -0
- data/lib/cfan122/operations/exam_plan_detail.rb +38 -0
- data/lib/cfan122/operations/exam_plan_list.rb +37 -0
- data/lib/cfan122/operations/exam_plan_result.rb +32 -0
- data/lib/cfan122/operations/exam_subject.rb +29 -0
- data/lib/cfan122/version.rb +3 -0
- data/lib/cfan122/yaml_generator.rb +44 -0
- data/lib/cfan122.rb +86 -0
- metadata +193 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: ae3d5085db3051dcd6b3a7f77126e45a365dc9b2
|
4
|
+
data.tar.gz: b4ee644e156a86ff31a38eadaa17f6bb97994b10
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 0dce9d547ae566f84d0fe15e294adb0f62e4f6d615eae5c17528dae7b864c8402ae37cc2d571425dcb752d86aa6fa092219d8036428c2dc90e0bab08d559f71a
|
7
|
+
data.tar.gz: 72304dda3868547b978ce7aa5dd0fd29e31920bc52318c7ee3bb268e0e0a1548cfd05e162ed2b016bfe8abac277196a02203f08c9a715f0f087a72563fcf8a51
|
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at dean.wang@tbwa.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
cfan122 (0.1.0)
|
5
|
+
activesupport (~> 5.0)
|
6
|
+
httparty (~> 0.14)
|
7
|
+
jsonpath (~> 0.5.8)
|
8
|
+
|
9
|
+
GEM
|
10
|
+
remote: https://rubygems.org/
|
11
|
+
specs:
|
12
|
+
activesupport (5.0.0.1)
|
13
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
14
|
+
i18n (~> 0.7)
|
15
|
+
minitest (~> 5.1)
|
16
|
+
tzinfo (~> 1.1)
|
17
|
+
addressable (2.5.0)
|
18
|
+
public_suffix (~> 2.0, >= 2.0.2)
|
19
|
+
awesome_print (1.7.0)
|
20
|
+
coderay (1.1.1)
|
21
|
+
concurrent-ruby (1.0.2)
|
22
|
+
crack (0.4.3)
|
23
|
+
safe_yaml (~> 1.0.0)
|
24
|
+
hashdiff (0.3.0)
|
25
|
+
httparty (0.14.0)
|
26
|
+
multi_xml (>= 0.5.2)
|
27
|
+
i18n (0.7.0)
|
28
|
+
jsonpath (0.5.8)
|
29
|
+
multi_json
|
30
|
+
method_source (0.8.2)
|
31
|
+
minitest (5.9.1)
|
32
|
+
multi_json (1.12.1)
|
33
|
+
multi_xml (0.5.5)
|
34
|
+
pry (0.10.4)
|
35
|
+
coderay (~> 1.1.0)
|
36
|
+
method_source (~> 0.8.1)
|
37
|
+
slop (~> 3.4)
|
38
|
+
public_suffix (2.0.4)
|
39
|
+
rake (10.5.0)
|
40
|
+
safe_yaml (1.0.4)
|
41
|
+
slop (3.6.0)
|
42
|
+
thread_safe (0.3.5)
|
43
|
+
tzinfo (1.2.2)
|
44
|
+
thread_safe (~> 0.1)
|
45
|
+
webmock (2.1.0)
|
46
|
+
addressable (>= 2.3.6)
|
47
|
+
crack (>= 0.3.2)
|
48
|
+
hashdiff
|
49
|
+
|
50
|
+
PLATFORMS
|
51
|
+
ruby
|
52
|
+
|
53
|
+
DEPENDENCIES
|
54
|
+
awesome_print
|
55
|
+
bundler (~> 1.13)
|
56
|
+
cfan122!
|
57
|
+
minitest (~> 5.0)
|
58
|
+
pry
|
59
|
+
rake (~> 10.0)
|
60
|
+
webmock
|
61
|
+
|
62
|
+
BUNDLED WITH
|
63
|
+
1.13.6
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2016
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 Dean Wang
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
# Cfan122
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/cfan122`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'cfan122'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install cfan122
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
TODO: Write usage instructions here
|
26
|
+
|
27
|
+
## Development
|
28
|
+
|
29
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
30
|
+
|
31
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/cfan122. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
36
|
+
|
37
|
+
|
38
|
+
## License
|
39
|
+
|
40
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
41
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "cfan122"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
data/cfan122.gemspec
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'cfan122/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "cfan122"
|
8
|
+
spec.version = Cfan122::VERSION
|
9
|
+
spec.authors = ["cfanbase"]
|
10
|
+
spec.email = ["cfanbase@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = "A library for retrieving exam information from http://www.122.gov.cn"
|
13
|
+
spec.description = spec.summary
|
14
|
+
spec.homepage = "https://github.com/cfanbase/cfan122"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
18
|
+
f.match(%r{^(test|spec|features)/})
|
19
|
+
end
|
20
|
+
spec.bindir = "exe"
|
21
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
|
+
spec.require_paths = ["lib"]
|
23
|
+
|
24
|
+
spec.add_runtime_dependency "jsonpath", "~> 0.5.8"
|
25
|
+
spec.add_runtime_dependency "httparty", "~> 0.14"
|
26
|
+
spec.add_runtime_dependency "activesupport", "~> 5.0"
|
27
|
+
|
28
|
+
spec.add_development_dependency "bundler", "~> 1.13"
|
29
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
30
|
+
spec.add_development_dependency "minitest", "~> 5.0"
|
31
|
+
spec.add_development_dependency "awesome_print"
|
32
|
+
spec.add_development_dependency "webmock"
|
33
|
+
spec.add_development_dependency "pry"
|
34
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Cfan122
|
4
|
+
|
5
|
+
class Config
|
6
|
+
include Singleton
|
7
|
+
|
8
|
+
attr_accessor :domain, :timeout, :username, :password, :debug
|
9
|
+
|
10
|
+
def initialize
|
11
|
+
reset
|
12
|
+
end
|
13
|
+
|
14
|
+
def reset
|
15
|
+
@domain ||= 'http://www.122.gov.cn'
|
16
|
+
@username = nil
|
17
|
+
@password = nil
|
18
|
+
@debug = false
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Cfan122
|
4
|
+
|
5
|
+
module HttpConfig
|
6
|
+
extend ActiveSupport::Concern
|
7
|
+
|
8
|
+
included do
|
9
|
+
include HTTParty
|
10
|
+
debug_output $stdout
|
11
|
+
headers({
|
12
|
+
"Accept-Encoding" => 'gzip',
|
13
|
+
"Accept" => 'application/json',
|
14
|
+
'Content-Type' => 'application/x-www-form-urlencoded; charset=UTF-8',
|
15
|
+
"User-Agent" => "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/32.0.1700.107 Safari/537.36"
|
16
|
+
})
|
17
|
+
|
18
|
+
def set_base_uri province
|
19
|
+
self.class.base_uri Config.instance.domain.dup.gsub('www', province.to_s)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Cfan122
|
4
|
+
|
5
|
+
class Operation
|
6
|
+
attr_reader :options, :request, :response
|
7
|
+
|
8
|
+
def initialize options = {}
|
9
|
+
@options = options
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.execute options = {}
|
13
|
+
self.new(options).execute
|
14
|
+
end
|
15
|
+
|
16
|
+
def execute
|
17
|
+
@request = self.class::Request.new(options)
|
18
|
+
@response = self.class::Response.new(@request)
|
19
|
+
@response.body
|
20
|
+
end
|
21
|
+
|
22
|
+
class Request
|
23
|
+
attr_accessor :body, :response, :impersonation_user
|
24
|
+
|
25
|
+
def initialize params = {}
|
26
|
+
reset
|
27
|
+
self.attributes = params
|
28
|
+
set_base_uri province
|
29
|
+
end
|
30
|
+
|
31
|
+
def reset
|
32
|
+
end
|
33
|
+
|
34
|
+
def execute
|
35
|
+
raise NotImplemented
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
class ResponseError < StandardError
|
40
|
+
attr_reader :response_code
|
41
|
+
|
42
|
+
def initialize message, response_code
|
43
|
+
super message
|
44
|
+
@response_code = response_code
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
class Response
|
49
|
+
attr_reader :request, :response, :operation
|
50
|
+
|
51
|
+
def initialize operation
|
52
|
+
@operation = operation
|
53
|
+
@response = operation.execute
|
54
|
+
@request = response.request
|
55
|
+
raise ResponseError.new('Request Error!', response.code) if response.code != 200
|
56
|
+
end
|
57
|
+
|
58
|
+
def to_json
|
59
|
+
JSON.parse(response.body)
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Cfan122
|
4
|
+
|
5
|
+
module OperationMethods
|
6
|
+
extend ActiveSupport::Concern
|
7
|
+
|
8
|
+
included do
|
9
|
+
|
10
|
+
def attributes
|
11
|
+
attrs = self.class.const_defined?('PARAMS') ? (self.class.attrs + self.class::PARAMS) : self.class.attrs
|
12
|
+
attrs.map{|key| [key, public_send("#{key}")]}.to_h
|
13
|
+
end
|
14
|
+
|
15
|
+
def attributes=(hash)
|
16
|
+
hash.each{|key, value| public_send("#{key}=", value) if self.class.method_defined? "#{key}=" }
|
17
|
+
end
|
18
|
+
|
19
|
+
def to_params options = {}
|
20
|
+
options = options.select{|k, v| self.class::PARAMS.include?(k) } if self.class.const_defined?('PARAMS')
|
21
|
+
options.map{|k, v| ["#{k}", v] }.to_h
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.attrs
|
25
|
+
[:province, :city, :subject, :type, :location, :page]
|
26
|
+
end
|
27
|
+
|
28
|
+
attr_accessor *attrs
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def set_default
|
33
|
+
@province ||= :ln
|
34
|
+
@subject ||= 3
|
35
|
+
@type ||= 'C1'
|
36
|
+
@city ||= '辽B'
|
37
|
+
@location ||= '21020103'
|
38
|
+
@page ||= 0
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Cfan122
|
4
|
+
|
5
|
+
class ExamAgency < Operation
|
6
|
+
class Request < Operation::Request
|
7
|
+
include HttpConfig
|
8
|
+
include OperationMethods
|
9
|
+
|
10
|
+
def execute params = {}
|
11
|
+
options = attributes.merge(params)
|
12
|
+
self.class.post('/m/syscode/gxfzjg', body: to_params(options))
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
def reset
|
17
|
+
set_default
|
18
|
+
self.attributes = {kvmode: 0}
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
class Response < Operation::Response
|
23
|
+
def body
|
24
|
+
to_json['data']
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Cfan122
|
4
|
+
|
5
|
+
class ExamLocation < Operation
|
6
|
+
class Request < Operation::Request
|
7
|
+
PARAMS = [:fzjg, :kskm]
|
8
|
+
attr_accessor *PARAMS
|
9
|
+
include HttpConfig
|
10
|
+
include OperationMethods
|
11
|
+
|
12
|
+
def execute params = {}
|
13
|
+
options = attributes.merge(params)
|
14
|
+
self.class.post('/m/examplan/initKsdd', body: to_params(options))
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
def reset
|
19
|
+
set_default
|
20
|
+
self.attributes = {fzjg: city, kskm: subject}
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
class Response < Operation::Response
|
25
|
+
def body
|
26
|
+
to_json['data']
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Cfan122
|
4
|
+
|
5
|
+
class ExamPlanDetail < Operation
|
6
|
+
class Request < Operation::Request
|
7
|
+
PARAMS = [:startTime, :endTime, :fzjg, :kscx, :ksdd, :kskm, :zt]
|
8
|
+
attr_accessor *PARAMS
|
9
|
+
include HttpConfig
|
10
|
+
include OperationMethods
|
11
|
+
|
12
|
+
def execute params = {}
|
13
|
+
options = attributes.merge(params)
|
14
|
+
self.class.post('/m/examplan/getExamPlanDetail', body: to_params(options))
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
def reset
|
19
|
+
set_default
|
20
|
+
self.attributes = {
|
21
|
+
startTime: Date.today,
|
22
|
+
endTime: Date.today + 1.year,
|
23
|
+
fzjg: city, kscx: type,
|
24
|
+
ksdd: location, kskm: subject,
|
25
|
+
zt: 2
|
26
|
+
}
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
class Response < Operation::Response
|
32
|
+
def body
|
33
|
+
to_json['data'][0]
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Cfan122
|
4
|
+
|
5
|
+
class ExamPlanList < Operation
|
6
|
+
class Request < Operation::Request
|
7
|
+
PARAMS = [:startTime, :endTime, :fzjg, :kscx, :ksdd, :kskm, :page, :zt]
|
8
|
+
attr_accessor *PARAMS
|
9
|
+
include HttpConfig
|
10
|
+
include OperationMethods
|
11
|
+
|
12
|
+
def execute params = {}
|
13
|
+
options = attributes.merge(params)
|
14
|
+
self.class.post('/m/examplan/getExamPlan', body: to_params(options))
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
def reset
|
19
|
+
set_default
|
20
|
+
self.attributes = {
|
21
|
+
startTime: Date.today,
|
22
|
+
endTime: Date.today + 1.year,
|
23
|
+
fzjg: city, kscx: type,
|
24
|
+
ksdd: location, kskm: subject,
|
25
|
+
page: page, zt: 2
|
26
|
+
}
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
class Response < Operation::Response
|
31
|
+
def body
|
32
|
+
to_json['data'][0]
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Cfan122
|
4
|
+
|
5
|
+
class ExamPlanResult < Operation
|
6
|
+
class Request < Operation::Request
|
7
|
+
PARAMS = [:xh, :page, :size]
|
8
|
+
attr_accessor *PARAMS
|
9
|
+
include HttpConfig
|
10
|
+
include OperationMethods
|
11
|
+
|
12
|
+
def execute params = {}
|
13
|
+
options = attributes.merge(params)
|
14
|
+
self.class.post('/m/examplan/getStudentInfo', body: to_params(options))
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
def reset
|
19
|
+
set_default
|
20
|
+
self.attributes = {page: 1, size: 99999}
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
class Response < Operation::Response
|
25
|
+
|
26
|
+
def body
|
27
|
+
to_json['data']
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Cfan122
|
4
|
+
|
5
|
+
class ExamSubject < Operation
|
6
|
+
class Request < Operation::Request
|
7
|
+
include HttpConfig
|
8
|
+
include OperationMethods
|
9
|
+
|
10
|
+
def execute params = {}
|
11
|
+
options = attributes.merge(params)
|
12
|
+
self.class.post('/m/examplan/initKskm', body: to_params(options))
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
def reset
|
17
|
+
set_default
|
18
|
+
self.attributes = {kvmode: 0}
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
class Response < Operation::Response
|
23
|
+
def body
|
24
|
+
to_json['data']
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'yaml'
|
3
|
+
|
4
|
+
module Cfan122
|
5
|
+
|
6
|
+
class YamlGenerator
|
7
|
+
attr_reader :path, :text
|
8
|
+
|
9
|
+
def initialize params = {}
|
10
|
+
@file_name, @key, @text = params[:name], params[:key], params[:text]
|
11
|
+
@path = "./lib/#{self.class.name.split("::")[0]}/meta/#{@file_name}.yml"
|
12
|
+
end
|
13
|
+
|
14
|
+
def open
|
15
|
+
YAML.load_file(path) if File.exist?(path)
|
16
|
+
end
|
17
|
+
|
18
|
+
def save
|
19
|
+
data = open || {}
|
20
|
+
data[@key] = @text
|
21
|
+
File.open(path, "w"){|file| file.write(data.to_yaml) }
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.generate_exam_info province = :ln, type = 'C1', subject = 3
|
25
|
+
self.generate_exam_subject province, type, subject
|
26
|
+
self.generate_exam_agency province, type, subject
|
27
|
+
self.generate_exam_location province, type, subject
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.generate_exam_subject province = :ln, type = 'C1', subject = 3
|
31
|
+
YamlGenerator.new(name: province, key: "exam_subject_#{type}_#{subject}", text: ExamSubject.execute({province: province, type: type, subject: subject})).save
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.generate_exam_agency province = :ln, type = 'C1', subject = 3
|
35
|
+
YamlGenerator.new(name: province, key: "exam_agency_#{type}_#{subject}", text: ExamAgency.execute({province: province, type: type, subject: subject})).save
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.generate_exam_location province = :ln, type = 'C1', subject = 3
|
39
|
+
YamlGenerator.new(name: province, key: "exam_location_#{type}_#{subject}", text: ExamLocation.execute({province: province, type: type, subject: subject})).save
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
data/lib/cfan122.rb
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "active_support"
|
4
|
+
require "active_support/core_ext"
|
5
|
+
require "httparty"
|
6
|
+
require "jsonpath"
|
7
|
+
|
8
|
+
require "cfan122/config"
|
9
|
+
require "cfan122/http_config"
|
10
|
+
require "cfan122/operation"
|
11
|
+
require "cfan122/operation_methods"
|
12
|
+
require "cfan122/operations/exam_location"
|
13
|
+
require "cfan122/operations/exam_subject"
|
14
|
+
require "cfan122/operations/exam_agency"
|
15
|
+
require "cfan122/operations/exam_plan_list"
|
16
|
+
require "cfan122/operations/exam_plan_detail"
|
17
|
+
require "cfan122/operations/exam_plan_result"
|
18
|
+
require "cfan122/yaml_generator"
|
19
|
+
require "cfan122/version"
|
20
|
+
|
21
|
+
|
22
|
+
module Cfan122
|
23
|
+
|
24
|
+
class << self
|
25
|
+
def configure
|
26
|
+
config = Config.instance
|
27
|
+
block_given? ? yield(config) : config
|
28
|
+
end
|
29
|
+
|
30
|
+
alias :config :configure
|
31
|
+
end
|
32
|
+
|
33
|
+
|
34
|
+
def self.reload!
|
35
|
+
Reloader.new(self).reload
|
36
|
+
end
|
37
|
+
|
38
|
+
class Reloader
|
39
|
+
def initialize(top)
|
40
|
+
@top = top
|
41
|
+
end
|
42
|
+
|
43
|
+
def reload
|
44
|
+
cleanup
|
45
|
+
load_all
|
46
|
+
end
|
47
|
+
|
48
|
+
private
|
49
|
+
|
50
|
+
# @return [Array<String>] array of all files that were loaded to memory
|
51
|
+
# under the lib/my_gem_name folder.
|
52
|
+
# This code makes assumption #1 above.
|
53
|
+
def loaded_files
|
54
|
+
$LOADED_FEATURES.select{|x| x.starts_with?(__FILE__.chomp('.rb'))}
|
55
|
+
end
|
56
|
+
|
57
|
+
# @return [Array<Module>] Recursively find all modules and classes
|
58
|
+
# under the MyGemName namespace.
|
59
|
+
# This code makes assumption number #2 above.
|
60
|
+
def all_project_objects(current = @top)
|
61
|
+
return [] unless current.is_a?(Module) and current.to_s.split('::').first == @top.to_s
|
62
|
+
[current] + current.constants.flat_map{|x| all_project_objects(current.const_get(x))}
|
63
|
+
end
|
64
|
+
|
65
|
+
# @return [Hash] of the format {Module => true} containing all modules
|
66
|
+
# and classes under the MyGemName namespace
|
67
|
+
def all_project_objects_lookup
|
68
|
+
@_all_project_objects_lookup ||= Hash[all_project_objects.map{|x| [x, true]}]
|
69
|
+
end
|
70
|
+
|
71
|
+
# Recursively removes all constant entries of modules and classes under
|
72
|
+
# the MyGemName namespace
|
73
|
+
def cleanup(parent = Object, current = @top)
|
74
|
+
return unless all_project_objects_lookup[current]
|
75
|
+
current.constants.each {|const| cleanup current, current.const_get(const)}
|
76
|
+
parent.send(:remove_const, current.to_s.split('::').last.to_sym)
|
77
|
+
end
|
78
|
+
|
79
|
+
# Re-load all files that were previously reloaded
|
80
|
+
def load_all
|
81
|
+
loaded_files.each{|x| load x}
|
82
|
+
true
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
end
|
metadata
ADDED
@@ -0,0 +1,193 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: cfan122
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- cfanbase
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-11-11 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: jsonpath
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.5.8
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.5.8
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: httparty
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0.14'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0.14'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: activesupport
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '5.0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '5.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: bundler
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.13'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.13'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rake
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '10.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '10.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: minitest
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '5.0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '5.0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: awesome_print
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: webmock
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
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
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: pry
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
description: A library for retrieving exam information from http://www.122.gov.cn
|
140
|
+
email:
|
141
|
+
- cfanbase@gmail.com
|
142
|
+
executables: []
|
143
|
+
extensions: []
|
144
|
+
extra_rdoc_files: []
|
145
|
+
files:
|
146
|
+
- CODE_OF_CONDUCT.md
|
147
|
+
- Gemfile
|
148
|
+
- Gemfile.lock
|
149
|
+
- LICENSE
|
150
|
+
- LICENSE.txt
|
151
|
+
- README.md
|
152
|
+
- Rakefile
|
153
|
+
- bin/console
|
154
|
+
- bin/setup
|
155
|
+
- cfan122.gemspec
|
156
|
+
- lib/cfan122.rb
|
157
|
+
- lib/cfan122/config.rb
|
158
|
+
- lib/cfan122/http_config.rb
|
159
|
+
- lib/cfan122/operation.rb
|
160
|
+
- lib/cfan122/operation_methods.rb
|
161
|
+
- lib/cfan122/operations/exam_agency.rb
|
162
|
+
- lib/cfan122/operations/exam_location.rb
|
163
|
+
- lib/cfan122/operations/exam_plan_detail.rb
|
164
|
+
- lib/cfan122/operations/exam_plan_list.rb
|
165
|
+
- lib/cfan122/operations/exam_plan_result.rb
|
166
|
+
- lib/cfan122/operations/exam_subject.rb
|
167
|
+
- lib/cfan122/version.rb
|
168
|
+
- lib/cfan122/yaml_generator.rb
|
169
|
+
homepage: https://github.com/cfanbase/cfan122
|
170
|
+
licenses:
|
171
|
+
- MIT
|
172
|
+
metadata: {}
|
173
|
+
post_install_message:
|
174
|
+
rdoc_options: []
|
175
|
+
require_paths:
|
176
|
+
- lib
|
177
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
178
|
+
requirements:
|
179
|
+
- - ">="
|
180
|
+
- !ruby/object:Gem::Version
|
181
|
+
version: '0'
|
182
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
183
|
+
requirements:
|
184
|
+
- - ">="
|
185
|
+
- !ruby/object:Gem::Version
|
186
|
+
version: '0'
|
187
|
+
requirements: []
|
188
|
+
rubyforge_project:
|
189
|
+
rubygems_version: 2.4.5.1
|
190
|
+
signing_key:
|
191
|
+
specification_version: 4
|
192
|
+
summary: A library for retrieving exam information from http://www.122.gov.cn
|
193
|
+
test_files: []
|