cmcc_hxy 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 4879e5457c9bd318bd044320337b2e599d068396b2c2de9e66e81a363fea8f2c
4
+ data.tar.gz: bd2be5d426bd5c5915525a882b624cae452222ca1fd57afcfe5249d0feabfc72
5
+ SHA512:
6
+ metadata.gz: 9e4bb8c7be39b0674a2a6fda52d6acbba92bcab6480592b3c125b807edbb7cda7137ff1f9d046d4a914d385c1895038250edc4e8a7ae7d458a7e8bebb7152e4e
7
+ data.tar.gz: 6af462f9f9be97e5d4df965f2d7fcec20c6df9ee0a9e70548c43ac1389f5a545f74b1c7a1eee4f8ef3a82d176e8407346806da2c8519effb5d50071a06985f7e
data/.gitignore ADDED
@@ -0,0 +1,8 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.5.1
5
+ before_install: gem install bundler -v 1.16.2
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in cmcc_hxy.gemspec
6
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,38 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ cmcc_hxy (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ domain_name (0.5.20180417)
10
+ unf (>= 0.0.5, < 1.0.0)
11
+ http-cookie (1.0.3)
12
+ domain_name (~> 0.5)
13
+ mime-types (3.2.2)
14
+ mime-types-data (~> 3.2015)
15
+ mime-types-data (3.2018.0812)
16
+ minitest (5.11.3)
17
+ netrc (0.11.0)
18
+ rake (10.5.0)
19
+ rest-client (2.0.2)
20
+ http-cookie (>= 1.0.2, < 2.0)
21
+ mime-types (>= 1.16, < 4.0)
22
+ netrc (~> 0.8)
23
+ unf (0.1.4)
24
+ unf_ext
25
+ unf_ext (0.0.7.5)
26
+
27
+ PLATFORMS
28
+ ruby
29
+
30
+ DEPENDENCIES
31
+ bundler (~> 1.16)
32
+ cmcc_hxy!
33
+ minitest (~> 5.0)
34
+ rake (~> 10.0)
35
+ rest-client (~> 2.0.2)
36
+
37
+ BUNDLED WITH
38
+ 1.16.2
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 lumuy
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,23 @@
1
+ # CmccHxy
2
+
3
+ CMCC he xiao yuan API
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'cmcc_hxy'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install cmcc_hxy
20
+
21
+ ## License
22
+
23
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList["test/**/*_test.rb"]
8
+ end
9
+
10
+ task :default => :test
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "cmcc_hxy"
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(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/cmcc_hxy.gemspec ADDED
@@ -0,0 +1,31 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "cmcc_hxy/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "cmcc_hxy"
8
+ spec.version = CmccHxy::VERSION
9
+ spec.authors = ["lumuy"]
10
+ spec.email = ["dxgnaw@gmail.com"]
11
+
12
+ spec.summary = %q{CMCC hxy.}
13
+ spec.description = %q{CMCC hexiaoyuan API.}
14
+ spec.homepage = "https://github.com/Lumuy/cmcc_hxy.git"
15
+ spec.license = "MIT"
16
+
17
+
18
+ # Specify which files should be added to the gem when it is released.
19
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
20
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
21
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
22
+ end
23
+ spec.bindir = "exe"
24
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
25
+ spec.require_paths = ["lib"]
26
+
27
+ spec.add_development_dependency "bundler", "~> 1.16"
28
+ spec.add_development_dependency "rake", "~> 10.0"
29
+ spec.add_development_dependency "minitest", "~> 5.0"
30
+ spec.add_development_dependency "rest-client", "~> 2.0.2"
31
+ end
@@ -0,0 +1,97 @@
1
+ require 'json'
2
+ require 'rest-client'
3
+ require 'cmcc_hxy/error'
4
+
5
+ class CmccHxy::Client
6
+ def initialize(token)
7
+ @token = token
8
+ end
9
+
10
+ def get_users
11
+ chk_oauth
12
+ end
13
+
14
+ def get_order(user_id)
15
+ qry_order(user_id)
16
+ end
17
+
18
+ # 第三方应用获取accessToken后调用CHK_OAUTH接口,获取用户信息
19
+ # http://IP:PORT/typtOauth/typt/chk_oauth?data={accesstoken:"sdfsdf"}
20
+ #
21
+ # 请求:
22
+ # 参数名称 Json参数对 类型 是否比需 描述
23
+ # --------------------------------------------------------------------------------------------
24
+ # data =>
25
+ # accesstoken String 是 登录时有开放平台提供
26
+ #
27
+ # 响应:(查询结果json数组)
28
+ # 参数名称 类型 是否必需 描述
29
+ # --------------------------------------------------------------------------------------------
30
+ # ID String 是 用户ID
31
+ # NAME String 是 用户姓名,如果是用户手机号则中间4位由*代替
32
+ # MOBILE String 是 用户手机号
33
+ # ROLE String 是 1:学生 2:家长 3:老师 4:管理员
34
+ # STUNUM String 是 学号
35
+ # CLASSID String 是 班级ID
36
+ # GRADEID String 是 年级ID
37
+ # SCHOOLID String 是 学校ID
38
+ # COUNTYID String 是 区县ID
39
+ # CITYID String 是 地市ID
40
+ # ONLY_ID String 是 对应启迪用户ID
41
+ def chk_oauth
42
+ params = {
43
+ data: "{accesstoken: #{@token}}"
44
+ }
45
+ request("#{CmccHxy.config.hxy_host}/typtOauth/typt/chk_oauth", {params: params})
46
+ end
47
+
48
+ # 第三方应用调用此接口查询业务的开通情况.第三方应用只能查询到有关自己的业务开通情况。
49
+ # http://IP:PORT/typtOauth/typt/qry_order?data={accesstoken:"sdfsdf",userid: "12321"}
50
+ #
51
+ # 请求:
52
+ # 参数名称 类型 是否比需 描述
53
+ # --------------------------------------------------------------------------------------------
54
+ # accesstoken String 是
55
+ # userid String 是
56
+ #
57
+ # 响应:
58
+ # 参数名称 类型 是否必需 描述
59
+ # --------------------------------------------------------------------------------------------
60
+ # userid String 是
61
+ # apps =>
62
+ # appid int 应用ID
63
+ # appname String 应用名称
64
+ # applifecycle int 0体验期 1正式期
65
+ # servicesid String 业务ID
66
+ # servicename String 业务名称
67
+ # fee Float 费用
68
+ # feetype int 0:一次性 1:包月 2:包年
69
+ # createtime String 订购时间
70
+ # begintime String 订购时间
71
+ # endtime String 订购时间
72
+ def qry_order(uid)
73
+ params = {
74
+ data: "{accesstoken:#{@token}, userid:#{uid}}"
75
+ }
76
+ request("#{CmccHxy.config.hxy_host}/typtOauth/typt/qry_order", {params: params})
77
+ end
78
+
79
+ private
80
+
81
+ def request(url, params)
82
+ begin
83
+ response = RestClient.get(url, params)
84
+ result = JSON.parse(response)
85
+ rescue JSON::ParserError
86
+ raise CmccHxy::Error.new("移动和校园 JSON 解析出错")
87
+ rescue RestClient::ExceptionWithResponse => e
88
+ raise CmccHxy::Error.new("移动和校园请求出错 #{e.response.code}")
89
+ end
90
+
91
+ if response.code == 200 && result.is_a?(Hash) && result.key?('error_code')
92
+ raise CmccHxy::Error.new(result.fetch('error_msg'))
93
+ end
94
+
95
+ result
96
+ end
97
+ end
@@ -0,0 +1,9 @@
1
+ module CmccHxy
2
+ class Config
3
+ attr_accessor :hxy_host
4
+
5
+ def initialize
6
+ @hxy_host = "http://223.86.3.124:8081"
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,2 @@
1
+ class CmccHxy::Error < StandardError
2
+ end
@@ -0,0 +1,3 @@
1
+ module CmccHxy
2
+ VERSION = "0.1.0".freeze
3
+ end
data/lib/cmcc_hxy.rb ADDED
@@ -0,0 +1,11 @@
1
+ require "cmcc_hxy/client"
2
+ require "cmcc_hxy/config"
3
+ require "cmcc_hxy/version"
4
+
5
+ module CmccHxy
6
+ class << self
7
+ attr_accessor :config
8
+ end
9
+
10
+ self.config ||= Config.new
11
+ end
metadata ADDED
@@ -0,0 +1,115 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cmcc_hxy
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - lumuy
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-10-15 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.16'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.16'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '5.0'
48
+ type: :development
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: rest-client
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 2.0.2
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 2.0.2
69
+ description: CMCC hexiaoyuan API.
70
+ email:
71
+ - dxgnaw@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".travis.yml"
78
+ - Gemfile
79
+ - Gemfile.lock
80
+ - LICENSE.txt
81
+ - README.md
82
+ - Rakefile
83
+ - bin/console
84
+ - bin/setup
85
+ - cmcc_hxy.gemspec
86
+ - lib/cmcc_hxy.rb
87
+ - lib/cmcc_hxy/client.rb
88
+ - lib/cmcc_hxy/config.rb
89
+ - lib/cmcc_hxy/error.rb
90
+ - lib/cmcc_hxy/version.rb
91
+ homepage: https://github.com/Lumuy/cmcc_hxy.git
92
+ licenses:
93
+ - MIT
94
+ metadata: {}
95
+ post_install_message:
96
+ rdoc_options: []
97
+ require_paths:
98
+ - lib
99
+ required_ruby_version: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ required_rubygems_version: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - ">="
107
+ - !ruby/object:Gem::Version
108
+ version: '0'
109
+ requirements: []
110
+ rubyforge_project:
111
+ rubygems_version: 2.7.6
112
+ signing_key:
113
+ specification_version: 4
114
+ summary: CMCC hxy.
115
+ test_files: []