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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7efe5f04f612bc16d7e09e65cb6f2fb167a276f4
4
- data.tar.gz: 3db3d59dfb27c9f4e02454df623567019b42db1d
3
+ metadata.gz: 4766f1efea1f0d704f6127b5ef27edc304dd70c4
4
+ data.tar.gz: 4df1c2a0657538575c8f5bb6a88c0e005043f8ec
5
5
  SHA512:
6
- metadata.gz: 9ab3b545c5e844313864761184e085ec9308ee388a5f6644e7e10bc57257c70ab3f07d82199fde37fe8fc26b0c693c3a983fcae23cbf4584b1e989daf18f671f
7
- data.tar.gz: 0af455ab11fa6bf67829b38a484782496113b883624ac6b403c77158ca6ef57f631e3c728f311f48af5a0c40f4efa2cd37b694bcd47f490287a6ff0a3f8c2d6c
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)上查询。api在第一次查询的时候也会调用支持快递公司查询借口。
25
+ 目前支持的快递公司,`%w[顺丰 申通 圆通 韵达 天天 EMS 中通 汇通]`详细的请在[聚合页面](http://www.juhe.cn/docs/api/id/43/aid/103)上查看。
26
+ api在第一次查询时也会调用快递公司查询接口。
26
27
 
27
- 具体用法为express_app_key一次赋值,多次查询:
28
+ 具体用法设置app_key,然后进行查询:
28
29
  ```ruby
29
- Juhe.express_app_key = "d85fa433fb8f30419dc1b3697b035b3d" # 注册时,聚合提供的app_key
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.express_app_key = "d85fa433fb8f30419dc1b3697b035b3d"
89
+ Juhe::Express.app_key = "d85fa433fb8f30419dc1b3697b035b3d"
89
90
  Juhe::Express.refresh_companies
90
91
  # or
91
92
  Juhe::Express.refresh_companies(app_key: "d85fa433fb8f30419dc1b3697b035b3d")
@@ -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.express_app_key
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.express_app_key
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"]
@@ -1,3 +1,3 @@
1
1
  module JuheRuby
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
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
- attr_accessor "#{$1.downcase}_app_key".to_sym
10
- end
11
- end
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.express_app_key = "d85fa433fd8f30419dc1b3697b035b3d"
5
+ Juhe::Express.app_key = "d85fa433fd8f30419dc1b3697b035b3d"
6
6
  end
7
7
 
8
8
  def test_app_key
9
- Juhe.express_app_key = "123456"
10
- assert_equal(Juhe.express_app_key, "123456")
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.express_app_key = ""
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::express_app_key = "wrong app key"
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: juhe_ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - linuxnerd