juhe_ruby 0.1.0 → 0.1.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2185e8396199bc6c7b44f83fb063409ed1aa756f
4
- data.tar.gz: f9e4e0d00869542fd2d6d3d6444a19e66fbd7d18
3
+ metadata.gz: ab8d5593b355fbba7ab5d9a2a26ac23199b9e34a
4
+ data.tar.gz: e9ff9f82e954b653585c808eb882b99b2fbc5ca5
5
5
  SHA512:
6
- metadata.gz: 6ed4d548601732ff04aaa48a5457b74b1032a0efdc58ff620847623b6ac88de6472e811280cda9a0c466bd5e8eb296a905a513671844a3cfa16da9c3dbc545b5
7
- data.tar.gz: 0e8b31e90f5204a053eedb47408b995d1a90ad407bf26778a9cdd4551609d0bb655574fac4e4b280ae45f5d0e5450c79ef5702ffc3999ce303a1073976866bd9
6
+ metadata.gz: d8349e9e0a4bf123edf3b8a82f17e47a6fee50d8cfc36f8410d3619c9c59d8fb05e1b3e509e6753d0c3c146d1da88b3b0544ecbdf6c9fbfe0ed52cd7fe0fcd8b
7
+ data.tar.gz: bffbaf6ae92cf3fd84a38d87088f14f83e2c2249e893cb3ea597ccd2c17636f2b73768f08b592aac0a4898a638d5adf134ec2c097c13e42df86e0507df03ebdb
data/README.md CHANGED
@@ -3,6 +3,8 @@
3
3
 
4
4
  [聚合](http://www.juhe.cn/)ruby api,目前完成了以下功能:
5
5
 
6
+ - 身份证实名认证
7
+ - 身份证查询
6
8
  - 常用快递查询
7
9
  - 电影票房
8
10
 
@@ -15,24 +17,81 @@ gem 'juhe_ruby'
15
17
 
16
18
  然后执行:
17
19
  ```ruby
18
- $ bundle
20
+ $ bundle install
19
21
  ```
20
22
  或者自行安装:
21
23
  ```ruby
22
24
  $ gem install juhe_ruby
23
25
  ```
24
26
  ## 用法
27
+ 先创建文件`config/initializers/juhe_ruby_config.rb`设置各接口的app_key
28
+ ```ruby
29
+ Juhe::IdVerify.app_key = "54be350eb2fdefe5a9a087bf6669cc68"
30
+ Juhe::IdCard.app_key = "54be350eb2fdefe5a9a087bf6669cc68"
31
+ Juhe::Express.app_key = "d85fa433fb8f30419dc1b3697b035b3d"
32
+ Juhe::Boxoffice.app_key = "d85fa433fd8430419dc1b3697b035b3d"
33
+ ```
34
+
35
+ ### 身份证实名认证
36
+ 如果事先设置了app_key,就直接进行查询认证:
37
+ ```ruby
38
+ Juhe::IdVerify.search("32010819820114203X","王大锤")
39
+ ```
40
+ 或者直接将app_key作为参数:
41
+ ```ruby
42
+ Juhe::IdVerify.search("32010819820114203X","王大锤", app_key: "54be350eb2fdefe5a9a087bf6669cc68")
43
+ ```
44
+ 应答后返回的json格式,如果请求失败会抛出异常:
45
+ ```ruby
46
+ {
47
+ "realname": "董好帅", # 真实姓名
48
+ "idcard": "330329199001020012", # 身份证号码
49
+ "res": 1 # 1:匹配 2:不匹配
50
+ }
51
+ ```
52
+ 获取应答结果的方式:
53
+ ```ruby
54
+ result=Juhe::IdVerify.search("32010819820114203X","王大锤")
55
+ if(result["res"] == 0)
56
+ puts "实名认证匹配通过"
57
+ else if(result["res"] == 1)
58
+ puts "实名认证匹配未通过"
59
+ end
60
+ ```
61
+ ### 身份证查询
62
+ 如果事先设置了app_key,就直接进行查询认证:
63
+ ```ruby
64
+ Juhe::IdCard.search("32010819820114203X")
65
+ ```
66
+ 或者直接将app_key作为参数:
67
+ ```ruby
68
+ Juhe::IdCard.search("32010819820114203X", app_key: "54be350eb2fdefe5a9a087bf6669cc68")
69
+ ```
70
+
71
+ 应答后返回的json格式,如果请求失败会抛出异常:
72
+ ```ruby
73
+ {
74
+ "area":"浙江省温州市平阳县",
75
+ "sex":"男",
76
+ "birthday":"1989年03月08日"
77
+ }
78
+ ```
79
+ 获取应答结果的方式:
80
+ ```ruby
81
+ result=Juhe::IdCard.search("32010819820114203X")
82
+ pust(result["area"])
83
+ ```
84
+
25
85
 
26
86
  ### 常用快递查询
27
87
  目前支持的快递公司,`%w[顺丰 申通 圆通 韵达 天天 EMS 中通 汇通]`详细的请在[聚合页面](http://www.juhe.cn/docs/api/id/43/aid/103)上查看。
28
88
  api在第一次查询时也会调用快递公司查询接口。
29
89
 
30
- 具体用法设置app_key,然后进行查询:
90
+ 如果事先设置了app_key,就直接进行查询认证:
31
91
  ```ruby
32
- Juhe::Express.app_key = "d85fa433fb8f30419dc1b3697b035b3d" # 注册时,聚合提供的app_key
33
92
  Juhe::Express.search("顺丰", "575677355677")
34
93
  ```
35
- 或者直接将app_key作为参数:
94
+ 或者直接将app_key作为参数:
36
95
  ```ruby
37
96
  Juhe::Express.search("顺丰", "575677355677", app_key: "d85fa433fb8f30419dc1b3697b035b3d")
38
97
  ```
@@ -88,7 +147,6 @@ Juhe::Express.search("顺丰", "575677355677", app_key: "d85fa433fb8f30419dc1b36
88
147
  ```
89
148
  程序第一次运行会获取快递公司列表,如果想手动刷新快递公司信息:
90
149
  ```ruby
91
- Juhe::Express.app_key = "d85fa433fb8f30419dc1b3697b035b3d"
92
150
  Juhe::Express.refresh_companies
93
151
  # or
94
152
  Juhe::Express.refresh_companies(app_key: "d85fa433fb8f30419dc1b3697b035b3d")
@@ -99,7 +157,6 @@ Juhe::Express.refresh_companies(app_key: "d85fa433fb8f30419dc1b3697b035b3d")
99
157
  票房榜的区域,CN-内地,US-北美,HK-香港。
100
158
  示例:
101
159
  ```ruby
102
- Juhe::Boxoffice.app_key = "d85fa433fd8430419dc1b3697b035b3d"
103
160
  Juhe::Boxoffice.latest("HK") # 香港最新票房榜
104
161
  # 或者app_key直接作为参数
105
162
  Juhe::Boxoffice.latest("HK", app_key: "d85fa433fd8430419dc1b3697b035b3d") # 香港最新票房榜
@@ -183,7 +240,6 @@ Juhe::Boxoffice.latest("HK", app_key: "d85fa433fd8430419dc1b3697b035b3d") # 香
183
240
  #### 网票票房
184
241
  示例:
185
242
  ```ruby
186
- Juhe::Boxoffice.app_key = "d85fa433fd8430419dc1b3697b035b3d"
187
243
  Juhe::Boxoffice.wp # 网票票房
188
244
  # 或者app_key直接作为参数
189
245
  Juhe::Boxoffice.wp(app_key: "d85fa433fd8430419dc1b3697b035b3d") # 网票票房
@@ -192,14 +248,14 @@ Juhe::Boxoffice.wp(app_key: "d85fa433fd8430419dc1b3697b035b3d") # 网票票房
192
248
  ```ruby
193
249
  [
194
250
  {
195
- "name": "惊天危机(数字)", /*影片名称*/
196
- "totals": "2262", /*总场次*/
197
- "statistics": "1111", /*统计场次*/
198
- "averaging": "27", /*场均*/
199
- "attendance": "15%", /*上座率*/
200
- "people": "29999", /*人次*/
201
- "fare": "39", /*票价(元)*/
202
- "boxoffice": "1164731" /*票房(元)*/
251
+ "name": "惊天危机(数字)", # 影片名称
252
+ "totals": "2262", # 总场次
253
+ "statistics": "1111", # 统计场次
254
+ "averaging": "27", # 场均
255
+ "attendance": "15%", # 上座率
256
+ "people": "29999", # 人次
257
+ "fare": "39", # 票价(元)
258
+ "boxoffice": "1164731" # 票房(元)
203
259
  },
204
260
  {
205
261
  "name": "大明猩(数字3D)",
@@ -0,0 +1,21 @@
1
+ require "open-uri"
2
+ require "json"
3
+
4
+ module Juhe
5
+ module IdVerify
6
+
7
+ def self.search(cardno, name, options=nil)
8
+ app_key = (options[:app_key] if options) || Juhe::IdVerify.app_key
9
+
10
+ url = BASE_URL +
11
+ "/index?key=" + app_key +
12
+ "&idcard=" + cardno +
13
+ "&realname=" + URI::encode(name)
14
+
15
+ result = JSON.parse(open(url).read)
16
+ raise result["reason"] if result["error_code"] != 0
17
+ result["result"]
18
+ end
19
+
20
+ end
21
+ end
@@ -0,0 +1,20 @@
1
+ require "open-uri"
2
+ require "json"
3
+
4
+ module Juhe
5
+ module IdCard
6
+
7
+ def self.search(cardno, options=nil)
8
+ app_key = (options[:app_key] if options) || Juhe::IdCard.app_key
9
+
10
+ url = BASE_URL +
11
+ "/index?key=" + app_key +
12
+ "&cardno=" + cardno
13
+
14
+ result = JSON.parse(open(url).read)
15
+ raise result["reason"] if result["resultcode"] != "200"
16
+ result["result"]
17
+ end
18
+
19
+ end
20
+ end
@@ -1,3 +1,3 @@
1
1
  module JuheRuby
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
@@ -0,0 +1,25 @@
1
+ require "test_helper"
2
+
3
+ class Juhe::IdCardTest < Minitest::Test
4
+ def setup
5
+ Juhe::IdCard.app_key = "54be350eb2fdefe5a9a087bf6669cc68"
6
+ end
7
+
8
+ def test_app_key
9
+ Juhe::IdCard.app_key = "123456"
10
+ assert_equal(Juhe::IdCard.app_key, "123456")
11
+ end
12
+
13
+ def test_search_without_app_key
14
+ assert_equal(Juhe::IdCard.search("310108198701142032")["area"], "上海市闸北区")
15
+ end
16
+
17
+ # def test_search_with_app_key
18
+ # Juhe::IdCard.app_key = ""
19
+ # result = Juhe::IdCard.search(
20
+ # "310108198701142032",
21
+ # app_key: "54be350eb2fdefe5a9a087bf6669cc68"
22
+ # )
23
+ # assert_equal(result["area"], "上海市闸北区")
24
+ # end
25
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: juhe_ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - linuxnerd
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-12-14 00:00:00.000000000 Z
11
+ date: 2016-12-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -54,9 +54,12 @@ files:
54
54
  - lib/juhe_ruby.rb
55
55
  - lib/juhe_ruby/boxoffice.rb
56
56
  - lib/juhe_ruby/express.rb
57
+ - lib/juhe_ruby/id_verify.rb
58
+ - lib/juhe_ruby/idcard.rb
57
59
  - lib/juhe_ruby/version.rb
58
60
  - test/boxoffice/boxoffice_test.rb
59
61
  - test/express/express_test.rb
62
+ - test/idcard/idcard_test.rb
60
63
  - test/test_helper.rb
61
64
  homepage: https://github.com/linuxnerd/juhe_ruby
62
65
  licenses:
@@ -86,4 +89,5 @@ summary: '"聚合ruby api"'
86
89
  test_files:
87
90
  - test/boxoffice/boxoffice_test.rb
88
91
  - test/express/express_test.rb
92
+ - test/idcard/idcard_test.rb
89
93
  - test/test_helper.rb