yun-logistics 1.0.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 +7 -0
- data/.gitignore +9 -0
- data/CODE_OF_CONDUCT.md +49 -0
- data/Gemfile +5 -0
- data/LICENSE.txt +21 -0
- data/README.md +41 -0
- data/Rakefile +2 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/yun/logistics.rb +21 -0
- data/lib/yun/logistics/ems/address.rb +47 -0
- data/lib/yun/logistics/ems/base.rb +259 -0
- data/lib/yun/logistics/ems/label.rb +27 -0
- data/lib/yun/logistics/ems/rate.rb +24 -0
- data/lib/yun/logistics/ems/ship.rb +63 -0
- data/lib/yun/logistics/ems/track.rb +28 -0
- data/lib/yun/logistics/version.rb +5 -0
- data/yun-logistics.gemspec +50 -0
- metadata +132 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: a0e62dbd70306272d5fab20c8dbf401dff10e11d
|
4
|
+
data.tar.gz: ed6d58dae312b9d637ddd60af90cc6b7dff5ec2f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 2c09eb7c910b96b76c635c2986b6ff5bbff327384f7a581250f505f682c9779ae0bf9888aa3cd32441df3852f6ccac402fb9de94d41004c190f64f90e7c994e8
|
7
|
+
data.tar.gz: 1a94b922ed04e3d2a220295e75de5b4fab10a1ae3533b0aa7d818e120e8ccac9c3b330ec06f298d92e7441477db5f80fdab6c94d522806b63af0bc2a8e8e3cf0
|
data/.gitignore
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# Contributor Code of Conduct
|
2
|
+
|
3
|
+
As contributors and maintainers of this project, and in the interest of
|
4
|
+
fostering an open and welcoming community, we pledge to respect all people who
|
5
|
+
contribute through reporting issues, posting feature requests, updating
|
6
|
+
documentation, submitting pull requests or patches, and other activities.
|
7
|
+
|
8
|
+
We are committed to making participation in this project a harassment-free
|
9
|
+
experience for everyone, regardless of level of experience, gender, gender
|
10
|
+
identity and expression, sexual orientation, disability, personal appearance,
|
11
|
+
body size, race, ethnicity, age, religion, or nationality.
|
12
|
+
|
13
|
+
Examples of unacceptable behavior by participants include:
|
14
|
+
|
15
|
+
* The use of sexualized language or imagery
|
16
|
+
* Personal attacks
|
17
|
+
* Trolling or insulting/derogatory comments
|
18
|
+
* Public or private harassment
|
19
|
+
* Publishing other's private information, such as physical or electronic
|
20
|
+
addresses, without explicit permission
|
21
|
+
* Other unethical or unprofessional conduct
|
22
|
+
|
23
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
24
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
25
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
26
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
27
|
+
threatening, offensive, or harmful.
|
28
|
+
|
29
|
+
By adopting this Code of Conduct, project maintainers commit themselves to
|
30
|
+
fairly and consistently applying these principles to every aspect of managing
|
31
|
+
this project. Project maintainers who do not follow or enforce the Code of
|
32
|
+
Conduct may be permanently removed from the project team.
|
33
|
+
|
34
|
+
This code of conduct applies both within project spaces and in public spaces
|
35
|
+
when an individual is representing the project or its community.
|
36
|
+
|
37
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
38
|
+
reported by contacting a project maintainer at liyongkuan@yundianjia.com. All
|
39
|
+
complaints will be reviewed and investigated and will result in a response that
|
40
|
+
is deemed necessary and appropriate to the circumstances. Maintainers are
|
41
|
+
obligated to maintain confidentiality with regard to the reporter of an
|
42
|
+
incident.
|
43
|
+
|
44
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
45
|
+
version 1.3.0, available at
|
46
|
+
[http://contributor-covenant.org/version/1/3/0/][version]
|
47
|
+
|
48
|
+
[homepage]: http://contributor-covenant.org
|
49
|
+
[version]: http://contributor-covenant.org/version/1/3/0/
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 liyongkuan
|
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
|
+
# Yun::Logistics
|
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/yun/logistics`. 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 'yun-logistics'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install yun-logistics
|
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. 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]/yun-logistics. 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 "yun/logistics"
|
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
@@ -0,0 +1,21 @@
|
|
1
|
+
require "yun/logistics/version"
|
2
|
+
|
3
|
+
# require "yun/logistics/ems/base"
|
4
|
+
# require "yun/logistics/ems/address"
|
5
|
+
# require "yun/logistics/ems/label"
|
6
|
+
# require "yun/logistics/ems/rate"
|
7
|
+
# require "yun/logistics/ems/ship"
|
8
|
+
# require "yun/logistics/ems/track"
|
9
|
+
|
10
|
+
module Yun
|
11
|
+
module Logistics
|
12
|
+
# Your code goes here...
|
13
|
+
# directory_path = 'yun/logistics'
|
14
|
+
#
|
15
|
+
# autoload :Base, "#{directory_path}/base"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
|
20
|
+
Gem.find_files('yun/logistics/*.rb').each { |path| require path }
|
21
|
+
Gem.find_files('yun/logistics/ems/*.rb').each { |path| require path }
|
@@ -0,0 +1,47 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
require 'yun/logistics/ems/base'
|
3
|
+
|
4
|
+
# 地址服务
|
5
|
+
module Yun
|
6
|
+
module Logistics
|
7
|
+
module Ems
|
8
|
+
class Address < Ems::Base
|
9
|
+
# 类方法
|
10
|
+
class << self
|
11
|
+
|
12
|
+
# 提供国内、国外标准地名或编码的查询
|
13
|
+
|
14
|
+
# 获取国内省级行政区划
|
15
|
+
# url: http://shipping2.ems.com.cn/partner/api/public/p/area/cn/province/list
|
16
|
+
# example: http://shipping2.ems.com.cn/partner/api/public/p/area/cn/province/list
|
17
|
+
# http_method: GET
|
18
|
+
def query_province_list_server(params = {}, options = {})
|
19
|
+
url = "http://shipping2.ems.com.cn/partner/api/public/p/area/cn/province/list"
|
20
|
+
get(get_host({host: url}), params, options)
|
21
|
+
end
|
22
|
+
|
23
|
+
# 获取省份内城市行政区划
|
24
|
+
# url: http://shipping2.ems.com.cn/partner/api/public/p/area/cn/city/list/{no}
|
25
|
+
# example: http://shipping2.ems.com.cn/partner/api/public/p/area/cn/city/list/130000
|
26
|
+
# http_method: GET
|
27
|
+
def query_cite_list_server(params = {}, options = {})
|
28
|
+
url = "http://shipping2.ems.com.cn/partner/api/public/p/area/cn/city/list/#{params[:no]}"
|
29
|
+
get(get_host({host: url}), params, options)
|
30
|
+
end
|
31
|
+
|
32
|
+
# 获取城市下辖区县列表
|
33
|
+
# url: http://shipping2.ems.com.cn/partner/api/public/p/area/cn/county/list/{no}
|
34
|
+
# example: http://shipping2.ems.com.cn/partner/api/public/area/p/cn/county/list/130100
|
35
|
+
# http_method: GET
|
36
|
+
def query_county_list_server(params = {}, options = {})
|
37
|
+
url = "http://shipping2.ems.com.cn/partner/api/public/p/area/cn/county/list/#{params[:no]}"
|
38
|
+
get(get_host({host: url}), params, options)
|
39
|
+
end
|
40
|
+
|
41
|
+
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,259 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
|
3
|
+
require 'rest-client'
|
4
|
+
require 'hashie'
|
5
|
+
require 'public_suffix'
|
6
|
+
|
7
|
+
module Yun
|
8
|
+
module Logistics
|
9
|
+
|
10
|
+
module Ems
|
11
|
+
|
12
|
+
# 状态码
|
13
|
+
module Code
|
14
|
+
################################################################################
|
15
|
+
#
|
16
|
+
# 20000 成功
|
17
|
+
#
|
18
|
+
################################################################################
|
19
|
+
|
20
|
+
SUCCESS = '20000'
|
21
|
+
|
22
|
+
################################################################################
|
23
|
+
#
|
24
|
+
# 3xxxx 数据相关
|
25
|
+
#
|
26
|
+
################################################################################
|
27
|
+
|
28
|
+
# 用户绑定第三方账户
|
29
|
+
|
30
|
+
# 第三方账户已绑定其它用户
|
31
|
+
PROVIDER_BIND_ANOTHER_USER = '30010'
|
32
|
+
|
33
|
+
################################################################################
|
34
|
+
#
|
35
|
+
# 4xxxx 业务相关
|
36
|
+
#
|
37
|
+
################################################################################
|
38
|
+
|
39
|
+
# 非法请求
|
40
|
+
INVALID_REQUEST = '40300'
|
41
|
+
|
42
|
+
# 终端密钥错误
|
43
|
+
INVALID_TERMINAL_SESSION_KEY = '40301'
|
44
|
+
|
45
|
+
# 用户密钥错误
|
46
|
+
INVALID_USER_SESSION_KEY = '40302'
|
47
|
+
|
48
|
+
# 超出请求限制数
|
49
|
+
EXCEED_REQUEST_LIMIT = '40303'
|
50
|
+
|
51
|
+
# 版本号不适配
|
52
|
+
NOT_COMPATIBLE_REVISION = '40304'
|
53
|
+
|
54
|
+
################################################################################
|
55
|
+
#
|
56
|
+
# 5xxxx 系统相关
|
57
|
+
#
|
58
|
+
################################################################################
|
59
|
+
|
60
|
+
# 未知错误(通常在捕捉异常后使用)
|
61
|
+
ERROR = '50000'
|
62
|
+
|
63
|
+
# 请求参数缺失
|
64
|
+
# Todo: 移动到数据相关
|
65
|
+
MISS_REQUEST_PARAMS = '50001'
|
66
|
+
|
67
|
+
# 数据处理错误
|
68
|
+
# Todo: 移动到数据相关
|
69
|
+
DATA_PROCESS_ERROR = '51000'
|
70
|
+
|
71
|
+
# 数据缺失错误
|
72
|
+
# Todo: 移动到数据相关
|
73
|
+
DATA_MISS_ERROR = '51001'
|
74
|
+
end
|
75
|
+
|
76
|
+
# 接口基础类
|
77
|
+
class Base
|
78
|
+
|
79
|
+
# 接口地址
|
80
|
+
@@host = 'http://shipping2.ems.com.cn/partner/api/public/p/'
|
81
|
+
|
82
|
+
# 获得接口路径
|
83
|
+
#
|
84
|
+
# @example BrowseHistories => browse_histories
|
85
|
+
#
|
86
|
+
# @return [String] 返回
|
87
|
+
#
|
88
|
+
def self.path
|
89
|
+
self.name.underscore.split('/').last
|
90
|
+
end
|
91
|
+
|
92
|
+
# 获得host类变量
|
93
|
+
#
|
94
|
+
# @return [String] 返回
|
95
|
+
#
|
96
|
+
def self.host
|
97
|
+
@@host
|
98
|
+
end
|
99
|
+
|
100
|
+
# 设置host类变量
|
101
|
+
#
|
102
|
+
# @param options [Hash] 选项,其中包含接口地址
|
103
|
+
#
|
104
|
+
# @return [String] 返回
|
105
|
+
#
|
106
|
+
def self.get_host(options = nil)
|
107
|
+
unless options.nil? && options[:host].nil
|
108
|
+
return options[:host]
|
109
|
+
end
|
110
|
+
|
111
|
+
host
|
112
|
+
end
|
113
|
+
|
114
|
+
# 设置host类变量
|
115
|
+
#
|
116
|
+
# @param value [String] 接口地址
|
117
|
+
#
|
118
|
+
# @return [String] 返回
|
119
|
+
#
|
120
|
+
def self.host=(value)
|
121
|
+
@@host = value
|
122
|
+
end
|
123
|
+
|
124
|
+
# 获取 platform 变量
|
125
|
+
#
|
126
|
+
# @return [String] 返回
|
127
|
+
#
|
128
|
+
def self.platform
|
129
|
+
@@platform
|
130
|
+
end
|
131
|
+
|
132
|
+
#
|
133
|
+
# 设置 platform 变量
|
134
|
+
#
|
135
|
+
# @param value [String] 接口地址
|
136
|
+
#
|
137
|
+
# @return [String] 返回
|
138
|
+
#
|
139
|
+
def self.platform=(value)
|
140
|
+
@@platform = value
|
141
|
+
end
|
142
|
+
|
143
|
+
# 发送 get 请求
|
144
|
+
#
|
145
|
+
# @param @see #self.request
|
146
|
+
#
|
147
|
+
# @return [Hash] 响应
|
148
|
+
#
|
149
|
+
def self.get(url, params = {}, options = {})
|
150
|
+
request(:get, url, params, options)
|
151
|
+
end
|
152
|
+
|
153
|
+
#
|
154
|
+
# 发送 post 请求
|
155
|
+
#
|
156
|
+
# @param @see #self.request
|
157
|
+
#
|
158
|
+
# @return [Hash] 响应
|
159
|
+
#
|
160
|
+
def self.post(url, params = {}, options = {})
|
161
|
+
request(:post, url, params, options)
|
162
|
+
end
|
163
|
+
|
164
|
+
#
|
165
|
+
# 发送 delete 请求
|
166
|
+
#
|
167
|
+
# @param @see #self.request
|
168
|
+
#
|
169
|
+
# @return [Hash] 响应
|
170
|
+
#
|
171
|
+
def self.delete(url, params = {}, options = {})
|
172
|
+
request(:delete, url, params, options)
|
173
|
+
end
|
174
|
+
|
175
|
+
#
|
176
|
+
# 发请求处理
|
177
|
+
#
|
178
|
+
# @param method [Symbol] 方法 eg. :get/:post/:put/:delete
|
179
|
+
# @param url [String] 请求地址(包括 host version path)
|
180
|
+
# @param params [Hash, nil] 请求参数
|
181
|
+
# @param options [Hash, nil] 可选参数 eg. format: :json
|
182
|
+
#
|
183
|
+
# @return [Hash] 响应
|
184
|
+
|
185
|
+
def self.request(method, url, params = {}, options = {})
|
186
|
+
response ||= set_response
|
187
|
+
|
188
|
+
if method.nil?
|
189
|
+
return set_response(Code::INVALID_REQUEST, '请求方式缺失')
|
190
|
+
end
|
191
|
+
|
192
|
+
if url.nil?
|
193
|
+
return set_response(Code::DATA_MISS_ERROR, '请求地址缺失')
|
194
|
+
end
|
195
|
+
|
196
|
+
#params = "<?xml version='1.0' encoding='UTF-8'?> <orders xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'> <order> <orderid>CSDN1111</orderid> <!--客户订单号 --> <operationtype>3</operationtype> <producttype>3</producttype> <customercode>1111</customercode> <!--客户代码 --> <vipcode>00000000000001</vipcode> <!--大客户代码 --> <clcttype>1</clcttype> <!--揽收类型 上门或者自送 --> <pod>false</pod> <!--电子签收 --> <untread>Returned</untread> <!--退回 --> <volweight>123</volweight> <!--体积重量 --> <startdate>2011-03-01T22:22:22</startdate> <!--起始预约时间 --> <enddate>2011-03-11T02:22:11</enddate> <!--起始预约时间 --> <sku1>客户自定义信息1</sku1> <sku2>客户自定义信息2</sku2> <sender> <!--寄件人地址,英文--> <name>Wang Lin</name> <postcode>100055</postcode> <phone>2131231</phone> <mobile>1123333333313</mobile> <country>CN</country> <province>441402</province> <city>441402</city> <county>441402</county> <company>Teamsun</company> <street>Lotus Street</street> <email>mail@team.com</email> </sender> <receiver> <name>Michael K Bristow2</name> <postcode>3043</postcode> <phone>111111</phone> <mobile>212-222-0111</mobile> <country>AU</country> <province>VIC</province> <city> Roeland Park</city> <county></county> <street>123123123</street> <street_extra_1>baigong</street_extra_1> <street_extra_2>xiaobushijia</street_extra_2> </receiver> <collect> <!--揽收地址,中文--> <name>王大琳</name> <postcode>100067</postcode> <phone>123456-908-098</phone> <mobile>1233333333333</mobile> <country>CN</country> <province>441402</province> <city>441402</city> <county>441402</county> <company/> <street>莲花池东路126号</street> <email>bin@team.com</email> </collect> <!--退货地址--> <retreat> <name></name> <postcode>3043</postcode> <phone></phone> <mobile></mobile> <!-- 退回国家 --> <country>AUSTRALIA</country> <province>VIC</province> <city>Tullamarine</city> <county></county> <street>StarTrack International,38 Annandale Road</street> </retreat> <items> <item> <cnname>电脑22</cnname> <enname>Kansas </enname> <count>2</count> <unit>xxx</unit> <weight>0.1</weight> <delcarevalue>20.34</delcarevalue> <origin>CN</origin> <description>orderid</description> <sellurl>http://www.baidu.com</sellurl> </item> </items> <remark /> </order> </orders>"
|
197
|
+
puts "请求方法:#{method.to_s.upcase}"
|
198
|
+
puts "请求地址:#{url}"
|
199
|
+
puts "请求参数:#{params}"
|
200
|
+
puts "请求可选参数:#{options}"
|
201
|
+
|
202
|
+
start_time = Time.now
|
203
|
+
|
204
|
+
puts "请求开始时间:#{start_time.strftime('%Y-%m-%d %H:%M:%S')}"
|
205
|
+
|
206
|
+
headers = {
|
207
|
+
content_type: 'application/xml; charset=UTF-8' || options[:content_type],
|
208
|
+
version: 'international_eub_us_1.1' || options[:version],
|
209
|
+
authenticate: options[:authenticate]
|
210
|
+
}
|
211
|
+
# headers = {
|
212
|
+
# content_type: 'application/xml; charset=utf-8',
|
213
|
+
# version: 'international_eub_us_1.1',
|
214
|
+
# authenticate: 'kjds_c7c5062a7d843d468276caa44b14bfd5'
|
215
|
+
# }
|
216
|
+
|
217
|
+
begin
|
218
|
+
|
219
|
+
response = RestClient::Request.execute(
|
220
|
+
{
|
221
|
+
method: method,
|
222
|
+
url: url,
|
223
|
+
payload: params,
|
224
|
+
headers: headers
|
225
|
+
}
|
226
|
+
)
|
227
|
+
|
228
|
+
rescue RestClient::ExceptionWithResponse => err
|
229
|
+
err.response
|
230
|
+
puts "请求失败原因:"
|
231
|
+
puts err.response
|
232
|
+
|
233
|
+
response = set_response(Code::ERROR, '系统繁忙,请稍后重试')
|
234
|
+
end
|
235
|
+
|
236
|
+
end_time = Time.now
|
237
|
+
|
238
|
+
puts "请求结束时间:#{end_time.strftime('%Y-%m-%d %H:%M:%S')}"
|
239
|
+
puts "请求耗时:#{end_time - start_time}秒\n"
|
240
|
+
|
241
|
+
response
|
242
|
+
|
243
|
+
end
|
244
|
+
|
245
|
+
|
246
|
+
#
|
247
|
+
# 设置响应的函数
|
248
|
+
#
|
249
|
+
def self.set_response(code = Code::SUCCESS, message = '')
|
250
|
+
Hashie::Mash.new({
|
251
|
+
status: {code: code, message: message}
|
252
|
+
})
|
253
|
+
end
|
254
|
+
|
255
|
+
|
256
|
+
end
|
257
|
+
end
|
258
|
+
end
|
259
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
|
3
|
+
# 标签服务
|
4
|
+
module Yun
|
5
|
+
module Logistics
|
6
|
+
module Ems
|
7
|
+
class Label < Base
|
8
|
+
|
9
|
+
# 类方法
|
10
|
+
class << self
|
11
|
+
|
12
|
+
# 批量获取标签服务(可以使用返回值中的URL进行标签下载)
|
13
|
+
# url: http://shipping2.ems.com.cn/partner/api/public/p/print/downloadLabels
|
14
|
+
# http_method: POST
|
15
|
+
def get_label_list(params = {}, options = {})
|
16
|
+
|
17
|
+
url = 'http://shipping2.ems.com.cn/partner/api/public/p/print/downloadLabels'
|
18
|
+
post(get_host({host: url}), params, options)
|
19
|
+
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
|
3
|
+
# 费率服务
|
4
|
+
module Yun
|
5
|
+
module Logistics
|
6
|
+
module Ems
|
7
|
+
class Rate < Base
|
8
|
+
|
9
|
+
# 类方法
|
10
|
+
class << self
|
11
|
+
|
12
|
+
# 费率服务(提供运单费率的估算服务)
|
13
|
+
# url: http://shipping2.ems.com.cn/partner/api/public/p/rate/epacket/
|
14
|
+
# http_method: POST
|
15
|
+
def query_order_message_server(params = {}, options = {})
|
16
|
+
url = "http://shipping2.ems.com.cn/partner/api/public/p/rate/epacket/"
|
17
|
+
get(get_host({host: url}), params, options)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
#发运服务
|
3
|
+
module Yun
|
4
|
+
module Logistics
|
5
|
+
module Ems
|
6
|
+
class Ship < Base
|
7
|
+
# 类方法
|
8
|
+
class << self
|
9
|
+
|
10
|
+
# 运单信息接受服务(发送运单信息到ems)
|
11
|
+
#
|
12
|
+
# url: 'http://shipping2.ems.com.cn/partner/api/public/p/order/'
|
13
|
+
#
|
14
|
+
# http_method : POST
|
15
|
+
#
|
16
|
+
def send_order_message(params = {}, options = {})
|
17
|
+
url = 'http://shipping2.ems.com.cn/partner/api/public/p/order/'
|
18
|
+
post(get_host({host: url}), params, options)
|
19
|
+
end
|
20
|
+
|
21
|
+
# 运单信息验证服务(出现问题后,使用此服务排查原因)
|
22
|
+
#
|
23
|
+
# url: http://shipping2.ems.com.cn/partner/api/public/p/validate
|
24
|
+
#
|
25
|
+
# http_method: POST
|
26
|
+
#
|
27
|
+
def validate_order_server(params = {}, options = {})
|
28
|
+
url = 'http://shipping2.ems.com.cn/partner/api/public/p/validate/'
|
29
|
+
post(get_host({host: url}), params, options)
|
30
|
+
end
|
31
|
+
|
32
|
+
# 运单信息取消服务(该服务用于将运单信息标记为无效)
|
33
|
+
#
|
34
|
+
# url: http://shipping2.ems.com.cn/partner/api/public/p/order/{mail_num}
|
35
|
+
#
|
36
|
+
# http_method: DELETE
|
37
|
+
#
|
38
|
+
def cancel_order_server(params = {}, options = {})
|
39
|
+
url = "http://shipping2.ems.com.cn/partner/api/public/p/order/#{params[:mail_num]}"
|
40
|
+
delete(get_host({host: url}), params, options)
|
41
|
+
end
|
42
|
+
|
43
|
+
# 运单信息查询服务(在order节点下增加元素<actualfee/>,<actualweight/>表示实收资费、实收重量)
|
44
|
+
#
|
45
|
+
# url: http://shipping2.ems.com.cn/partner/api/public/p/order/{mail_num}
|
46
|
+
#
|
47
|
+
# http_method: GET
|
48
|
+
#
|
49
|
+
def query_order_server(params ={}, options = {})
|
50
|
+
url = "http://shipping2.ems.com.cn/partner/api/public/p/order/#{params[:mail_num]}"
|
51
|
+
get(get_host({host: url}), params, options)
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
|
56
|
+
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
|
61
|
+
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
|
3
|
+
# 跟踪信息服务
|
4
|
+
module Yun
|
5
|
+
module Logistics
|
6
|
+
module Ems
|
7
|
+
class Track < Base
|
8
|
+
# 类方法
|
9
|
+
class << self
|
10
|
+
# 跟踪信息服务(实时跟踪信息的查询)
|
11
|
+
# url: http://shipping2.ems.com.cn/partner/api/public/p/track/query/{cn|en}/{mail_num}
|
12
|
+
# des: {en|cn}表示选用en或cn任意值,en为英文信息,cn为中文信息。
|
13
|
+
# http_method: GET
|
14
|
+
def track_order_message_server(params = {}, options = {})
|
15
|
+
langue = params[:langue] || 'en'
|
16
|
+
url = "http://shipping2.ems.com.cn/partner/api/public/p/track/query/#{langue}/#{params[:mail_num]}"
|
17
|
+
get(get_host({host: url}), params, options)
|
18
|
+
end
|
19
|
+
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'yun/logistics/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "yun-logistics"
|
8
|
+
spec.version = Yun::Logistics::VERSION
|
9
|
+
spec.authors = ["liyongkuan"]
|
10
|
+
spec.email = ["lykperson@163.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{logistics interface.}
|
13
|
+
spec.description = %q{logistics interface.}
|
14
|
+
spec.homepage = "https://github.com/liyongkuan"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
# Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
|
18
|
+
# delete this section to allow pushing this gem to any host.
|
19
|
+
if spec.respond_to?(:metadata)
|
20
|
+
spec.metadata['allowed_push_host'] = "https://rubygems.org"
|
21
|
+
else
|
22
|
+
raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
|
23
|
+
end
|
24
|
+
|
25
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
26
|
+
#spec.files = Dir['lib/yun/**/*']
|
27
|
+
spec.bindir = "exe"
|
28
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
29
|
+
spec.require_paths = ["lib"]
|
30
|
+
|
31
|
+
# Development dependency
|
32
|
+
spec.add_development_dependency "bundler", "~> 1.11"
|
33
|
+
spec.add_development_dependency "rake", "~> 10.5"
|
34
|
+
|
35
|
+
# Runtime dependency
|
36
|
+
#spec.add_runtime_dependency 'rest-client', '1.8.0'
|
37
|
+
spec.add_runtime_dependency 'rest-client'
|
38
|
+
|
39
|
+
# parser domain
|
40
|
+
#spec.add_runtime_dependency 'public_suffix', '1.5.3'
|
41
|
+
spec.add_runtime_dependency 'public_suffix'
|
42
|
+
|
43
|
+
# hash extend
|
44
|
+
#spec.add_runtime_dependency 'hashie', '3.4.3'
|
45
|
+
spec.add_runtime_dependency 'hashie'
|
46
|
+
|
47
|
+
# Required ruby version
|
48
|
+
spec.required_ruby_version = '2.3.0'
|
49
|
+
|
50
|
+
end
|
metadata
ADDED
@@ -0,0 +1,132 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: yun-logistics
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- liyongkuan
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-05-13 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.11'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.11'
|
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.5'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.5'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rest-client
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: public_suffix
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: hashie
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
description: logistics interface.
|
84
|
+
email:
|
85
|
+
- lykperson@163.com
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- ".gitignore"
|
91
|
+
- CODE_OF_CONDUCT.md
|
92
|
+
- Gemfile
|
93
|
+
- LICENSE.txt
|
94
|
+
- README.md
|
95
|
+
- Rakefile
|
96
|
+
- bin/console
|
97
|
+
- bin/setup
|
98
|
+
- lib/yun/logistics.rb
|
99
|
+
- lib/yun/logistics/ems/address.rb
|
100
|
+
- lib/yun/logistics/ems/base.rb
|
101
|
+
- lib/yun/logistics/ems/label.rb
|
102
|
+
- lib/yun/logistics/ems/rate.rb
|
103
|
+
- lib/yun/logistics/ems/ship.rb
|
104
|
+
- lib/yun/logistics/ems/track.rb
|
105
|
+
- lib/yun/logistics/version.rb
|
106
|
+
- yun-logistics.gemspec
|
107
|
+
homepage: https://github.com/liyongkuan
|
108
|
+
licenses:
|
109
|
+
- MIT
|
110
|
+
metadata:
|
111
|
+
allowed_push_host: https://rubygems.org
|
112
|
+
post_install_message:
|
113
|
+
rdoc_options: []
|
114
|
+
require_paths:
|
115
|
+
- lib
|
116
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
117
|
+
requirements:
|
118
|
+
- - '='
|
119
|
+
- !ruby/object:Gem::Version
|
120
|
+
version: 2.3.0
|
121
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
122
|
+
requirements:
|
123
|
+
- - ">="
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '0'
|
126
|
+
requirements: []
|
127
|
+
rubyforge_project:
|
128
|
+
rubygems_version: 2.5.1
|
129
|
+
signing_key:
|
130
|
+
specification_version: 4
|
131
|
+
summary: logistics interface.
|
132
|
+
test_files: []
|