juhe_ruby 0.0.3 → 0.0.4
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 +5 -4
- data/lib/juhe_ruby/express.rb +2 -2
- data/lib/juhe_ruby/version.rb +1 -1
- data/lib/juhe_ruby.rb +8 -3
- data/test/express/express_test.rb +5 -5
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 4766f1efea1f0d704f6127b5ef27edc304dd70c4
|
|
4
|
+
data.tar.gz: 4df1c2a0657538575c8f5bb6a88c0e005043f8ec
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: a5133cf400b069475481dd69ee4c57619c42f80337ca2d17f3ecb8d22db1669a79849e3f7bdada954e86f1717d3ddd655ac314bec0a49dcb7ddf83637d8b18db
|
|
7
|
+
data.tar.gz: 5cd48fc50bd968876b5253c0c4bbea956f6acee4625d8edbde14ef67955d5906a055a5de37189858f0ab9a45ba1417d36c1c4bd1050ff073683f1d7afa4540bc
|
data/README.md
CHANGED
|
@@ -22,11 +22,12 @@ $ gem install juhe_ruby
|
|
|
22
22
|
## 用法
|
|
23
23
|
|
|
24
24
|
### 常用快递查询
|
|
25
|
-
目前支持的快递公司,`%w[顺丰 申通 圆通 韵达 天天 EMS 中通 汇通]`详细的请在[聚合页面](http://www.juhe.cn/docs/api/id/43/aid/103)
|
|
25
|
+
目前支持的快递公司,`%w[顺丰 申通 圆通 韵达 天天 EMS 中通 汇通]`详细的请在[聚合页面](http://www.juhe.cn/docs/api/id/43/aid/103)上查看。
|
|
26
|
+
api在第一次查询时也会调用快递公司查询接口。
|
|
26
27
|
|
|
27
|
-
|
|
28
|
+
具体用法设置app_key,然后进行查询:
|
|
28
29
|
```ruby
|
|
29
|
-
Juhe.
|
|
30
|
+
Juhe::Express.app_key = "d85fa433fb8f30419dc1b3697b035b3d" # 注册时,聚合提供的app_key
|
|
30
31
|
Juhe::Express.search("顺丰", "575677355677")
|
|
31
32
|
```
|
|
32
33
|
或者直接将app_key作为参数:
|
|
@@ -85,7 +86,7 @@ Juhe::Express.search("顺丰", "575677355677", app_key: "d85fa433fb8f30419dc1b36
|
|
|
85
86
|
```
|
|
86
87
|
程序第一次运行会获取快递公司列表,如果想手动刷新快递公司信息:
|
|
87
88
|
```ruby
|
|
88
|
-
Juhe.
|
|
89
|
+
Juhe::Express.app_key = "d85fa433fb8f30419dc1b3697b035b3d"
|
|
89
90
|
Juhe::Express.refresh_companies
|
|
90
91
|
# or
|
|
91
92
|
Juhe::Express.refresh_companies(app_key: "d85fa433fb8f30419dc1b3697b035b3d")
|
data/lib/juhe_ruby/express.rb
CHANGED
|
@@ -10,7 +10,7 @@ module Juhe
|
|
|
10
10
|
end
|
|
11
11
|
|
|
12
12
|
def self.search(company_name, number, options = nil)
|
|
13
|
-
app_key = (options[:app_key] if options) || Juhe.
|
|
13
|
+
app_key = (options[:app_key] if options) || Juhe::Express.app_key
|
|
14
14
|
url = BASE_URL \
|
|
15
15
|
+ "/index?key=" \
|
|
16
16
|
+ app_key \
|
|
@@ -31,7 +31,7 @@ module Juhe
|
|
|
31
31
|
end
|
|
32
32
|
|
|
33
33
|
def self.refresh_companies(options)
|
|
34
|
-
app_key = (options[:app_key] if options) || Juhe.
|
|
34
|
+
app_key = (options[:app_key] if options) || Juhe::Express.app_key
|
|
35
35
|
result = JSON.parse(open(BASE_URL+"/com?key="+app_key).read)
|
|
36
36
|
raise result["reason"] if result["resultcode"] != "200"
|
|
37
37
|
@companies = result["result"]
|
data/lib/juhe_ruby/version.rb
CHANGED
data/lib/juhe_ruby.rb
CHANGED
|
@@ -3,11 +3,16 @@ require "juhe_ruby/express"
|
|
|
3
3
|
|
|
4
4
|
module Juhe
|
|
5
5
|
class << self
|
|
6
|
+
# Array of module names
|
|
6
7
|
modules = Juhe.constants.map{ |el| Juhe.const_get(el) }.select{ |m| m.instance_of?(Module) }
|
|
7
8
|
modules.each do |mod|
|
|
8
9
|
if mod.to_s =~ /\AJuhe::(.*)/
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
mod.module_eval do
|
|
11
|
+
class << self
|
|
12
|
+
attr_accessor :app_key
|
|
13
|
+
end # class << self
|
|
14
|
+
end # module_evale
|
|
15
|
+
end # if
|
|
16
|
+
end # modules.each
|
|
12
17
|
end
|
|
13
18
|
end
|
|
@@ -2,12 +2,12 @@ require "test_helper"
|
|
|
2
2
|
|
|
3
3
|
class Juhe::ExpressTest < Test::Unit::TestCase
|
|
4
4
|
def setup
|
|
5
|
-
Juhe.
|
|
5
|
+
Juhe::Express.app_key = "d85fa433fd8f30419dc1b3697b035b3d"
|
|
6
6
|
end
|
|
7
7
|
|
|
8
8
|
def test_app_key
|
|
9
|
-
Juhe.
|
|
10
|
-
assert_equal(Juhe.
|
|
9
|
+
Juhe::Express.app_key = "123456"
|
|
10
|
+
assert_equal(Juhe::Express.app_key, "123456")
|
|
11
11
|
end
|
|
12
12
|
|
|
13
13
|
def test_company_of_name
|
|
@@ -19,7 +19,7 @@ class Juhe::ExpressTest < Test::Unit::TestCase
|
|
|
19
19
|
end
|
|
20
20
|
|
|
21
21
|
def test_search_with_app_key
|
|
22
|
-
Juhe.
|
|
22
|
+
Juhe::Express.app_key = ""
|
|
23
23
|
result = Juhe::Express.search(
|
|
24
24
|
"顺丰",
|
|
25
25
|
"575677355677",
|
|
@@ -30,7 +30,7 @@ class Juhe::ExpressTest < Test::Unit::TestCase
|
|
|
30
30
|
|
|
31
31
|
def test_only_the_first_company_query_uses_api
|
|
32
32
|
first_time = Juhe::Express.company_code_of("申通") # => "sto"
|
|
33
|
-
Juhe::
|
|
33
|
+
Juhe::Express.app_key = "wrong app key"
|
|
34
34
|
second_time = Juhe::Express.company_code_of("申通")
|
|
35
35
|
assert_equal(first_time, second_time)
|
|
36
36
|
end
|