yhd 1.0.0
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 +22 -0
- data/.rspec +1 -0
- data/.rubocop.yml +6 -0
- data/Gemfile +18 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +20 -0
- data/lib/yhd.rb +7 -0
- data/lib/yhd/api.rb +7 -0
- data/lib/yhd/client.rb +116 -0
- data/lib/yhd/orders.rb +30 -0
- data/lib/yhd/response/parse_json.rb +30 -0
- data/lib/yhd/version.rb +4 -0
- data/spec/fixtures/order_detail.json +65 -0
- data/spec/fixtures/order_details.json +124 -0
- data/spec/fixtures/orders.json +47 -0
- data/spec/spec_helper.rb +68 -0
- data/spec/yhd/client_spec.rb +41 -0
- data/spec/yhd/orders_spec.rb +29 -0
- data/yhd.gemspec +26 -0
- metadata +127 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: c4b35f1d4673f169540c6b41b34b033fbab8e93b
|
4
|
+
data.tar.gz: f8ec846a42b88a1d0b782397f9938eb7f4092117
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 3a5ac366ceab46c0399aafb2e53a0430a8aaea5b54017dc19c1cbc65c8a8a5e20846e5d78104b873061617be7765f7f5c91f2b179a3ccf83a66032be9ba61362
|
7
|
+
data.tar.gz: e614ebdb96734f03f02bd63b14c7893b30bad4dad733981df4afeabcfca2f3d0d4b8d115421ea3ff6f53170d6590607612e210d5cf7193a0e0bde66615826039
|
data/.gitignore
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
doc/
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
tmp
|
18
|
+
*.bundle
|
19
|
+
*.so
|
20
|
+
*.o
|
21
|
+
*.a
|
22
|
+
mkmf.log
|
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
-c
|
data/.rubocop.yml
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
source 'http://ruby.taobao.org'
|
2
|
+
|
3
|
+
gem 'yard'
|
4
|
+
|
5
|
+
group :development do
|
6
|
+
gem 'pry'
|
7
|
+
gem 'pry-rescue'
|
8
|
+
end
|
9
|
+
|
10
|
+
group :test do
|
11
|
+
gem 'rspec'
|
12
|
+
gem 'rubocop', require: false
|
13
|
+
gem 'simplecov', require: false
|
14
|
+
gem 'webmock'
|
15
|
+
end
|
16
|
+
|
17
|
+
# Specify your gem's dependencies in yhd.gemspec
|
18
|
+
gemspec
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 ryancheung
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# Yhd
|
2
|
+
|
3
|
+
Ruby SDK for open.yhd.com
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'yhd'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install yhd
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it ( https://github.com/ryancheung/yhd/fork )
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'bundler/gem_tasks'
|
2
|
+
|
3
|
+
require 'rspec/core/rake_task'
|
4
|
+
RSpec::Core::RakeTask.new(:spec)
|
5
|
+
|
6
|
+
task test: :spec
|
7
|
+
|
8
|
+
begin
|
9
|
+
require 'rubocop/rake_task'
|
10
|
+
RuboCop::RakeTask.new
|
11
|
+
rescue LoadError
|
12
|
+
task :rubocop do
|
13
|
+
$stderr.puts 'Rubocop is disabled'
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
require 'yard'
|
18
|
+
YARD::Rake::YardocTask.new
|
19
|
+
|
20
|
+
task default: [:spec, :rubocop]
|
data/lib/yhd.rb
ADDED
data/lib/yhd/api.rb
ADDED
data/lib/yhd/client.rb
ADDED
@@ -0,0 +1,116 @@
|
|
1
|
+
require 'yhd/version'
|
2
|
+
require 'faraday'
|
3
|
+
require 'yhd/response/parse_json'
|
4
|
+
require 'yhd/api'
|
5
|
+
|
6
|
+
module Yhd
|
7
|
+
# API Client
|
8
|
+
class Client
|
9
|
+
include Yhd::API
|
10
|
+
|
11
|
+
DEFAULT_ENDPOINT = "http://openapi.yhd.com"
|
12
|
+
DEFAULT_PATH = "/app/api/rest/router"
|
13
|
+
|
14
|
+
attr_reader :app_key, :app_secret, :session_key
|
15
|
+
|
16
|
+
# Initializes a new Client object
|
17
|
+
# @param options [Hash]
|
18
|
+
# @option options [String] :app_key Required.
|
19
|
+
# @option options [String] :app_secret Required.
|
20
|
+
# @option options [String] :session_key Required.
|
21
|
+
# @option options [String] :endpoint Optional. API endpoint
|
22
|
+
def initialize(options)
|
23
|
+
@app_key = options.fetch(:app_key)
|
24
|
+
@app_secret = options.fetch(:app_secret)
|
25
|
+
@session_key = options.fetch(:session_key)
|
26
|
+
@endpoint = options[:endpoint]
|
27
|
+
end
|
28
|
+
|
29
|
+
# @return [String]
|
30
|
+
def endpoint
|
31
|
+
@endpoint ||= DEFAULT_ENDPOINT
|
32
|
+
end
|
33
|
+
|
34
|
+
# @return [String]
|
35
|
+
def user_agent
|
36
|
+
"Yhd Ruby Gem #{Yhd::VERSION}"
|
37
|
+
end
|
38
|
+
|
39
|
+
# Connection options for faraday
|
40
|
+
#
|
41
|
+
# @return [Hash]
|
42
|
+
def connection_options
|
43
|
+
{
|
44
|
+
:builder => middleware,
|
45
|
+
:headers => {
|
46
|
+
:accept => 'application/json',
|
47
|
+
:user_agent => user_agent,
|
48
|
+
},
|
49
|
+
:request => {
|
50
|
+
:open_timeout => 10,
|
51
|
+
:timeout => 30,
|
52
|
+
}
|
53
|
+
}
|
54
|
+
end
|
55
|
+
|
56
|
+
# @return [Faraday::RackBuilder]
|
57
|
+
def middleware
|
58
|
+
Faraday::RackBuilder.new do |faraday|
|
59
|
+
# Checks for files in the payload, otherwise leaves everything untouched
|
60
|
+
faraday.request :multipart
|
61
|
+
# Encodes as "application/x-www-form-urlencoded" if not already encoded
|
62
|
+
faraday.request :url_encoded
|
63
|
+
# Parse JSON response bodies
|
64
|
+
faraday.response :parse_json
|
65
|
+
# Set default HTTP adapter
|
66
|
+
faraday.adapter :net_http
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
# Perform an HTTP GET request
|
71
|
+
def get(params = {})
|
72
|
+
request(:get, params)
|
73
|
+
end
|
74
|
+
|
75
|
+
# Perform an HTTP POST request
|
76
|
+
def post(params = {})
|
77
|
+
request(:post, params)
|
78
|
+
end
|
79
|
+
|
80
|
+
# Perform an HTTP PUT request
|
81
|
+
def put(params = {})
|
82
|
+
request(:put, params)
|
83
|
+
end
|
84
|
+
|
85
|
+
# Perform an HTTP DELETE request
|
86
|
+
def delete(params = {})
|
87
|
+
request(:delete, params)
|
88
|
+
end
|
89
|
+
|
90
|
+
private
|
91
|
+
|
92
|
+
def connection
|
93
|
+
@connection ||= Faraday.new(endpoint, connection_options)
|
94
|
+
end
|
95
|
+
|
96
|
+
def request(method, params = {}, path = DEFAULT_PATH, headers = {})
|
97
|
+
connection.send(method.to_sym, path, signed_params(default_params.merge(params))) { |request| request.headers.update(headers) }.env
|
98
|
+
end
|
99
|
+
|
100
|
+
def default_params
|
101
|
+
{ appKey: app_key, sessionKey: session_key, format: 'json', ver: '1.0', timestamp: Time.now.strftime("%Y-%m-%d %T") }
|
102
|
+
end
|
103
|
+
|
104
|
+
def signed_params(params)
|
105
|
+
canonical_string = params.map do |k, v|
|
106
|
+
"#{k}#{v}"
|
107
|
+
end.sort.join
|
108
|
+
|
109
|
+
sign_md5 = Digest::MD5.hexdigest("#{app_secret}#{canonical_string}#{app_secret}")
|
110
|
+
|
111
|
+
new_params = params.dup
|
112
|
+
new_params[:sign] = sign_md5
|
113
|
+
new_params
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
data/lib/yhd/orders.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
module Yhd
|
2
|
+
module Orders
|
3
|
+
# Get brief info list of order
|
4
|
+
# @param options [Hash]
|
5
|
+
# @option options [String] :orderStatusList Required. 订单状态(逗号分隔): ORDER_WAIT_PAY:已下单(货款未全收)、 ORDER_PAYED:已下单(货款已收)、 ORDER_WAIT_SEND:可以发货(已送仓库)、 ORDER_ON_SENDING:已出库(货在途)、 ORDER_RECEIVED:货物用户已收到、 ORDER_FINISH:订单完成、 ORDER_CANCEL:订单取消
|
6
|
+
# @option options [String] :dateType Optional. 日期类型(1:订单生成日期,2:订单付款日期,3:订单发货日期,4:订单收货日期,5:订单更新日期)
|
7
|
+
# @option options [Time,String] :startTime Required.
|
8
|
+
# @option options [Time,String] :endTime Required.
|
9
|
+
# @option options [Integer] :curPage Optional, defaults to 1. Current page
|
10
|
+
# @option options [Integer] :pageRows Optional, defaults to 50, max 100. Order count per page
|
11
|
+
def get_orders(options)
|
12
|
+
if Time === options[:startTime]
|
13
|
+
options[:startTime] = options[:startTime].strftime("%Y-%m-%d %T")
|
14
|
+
end
|
15
|
+
|
16
|
+
if Time === options[:endTime]
|
17
|
+
options[:endTime] = options[:endTime].strftime("%Y-%m-%d %T")
|
18
|
+
end
|
19
|
+
|
20
|
+
post({ method: 'yhd.orders.get' }.merge(options))
|
21
|
+
end
|
22
|
+
|
23
|
+
# Get detailed info of orders
|
24
|
+
# @param orderCodeList [String] Order codes seperated by comma
|
25
|
+
def get_detail_orders(orderCodeList)
|
26
|
+
post({ method: 'yhd.orders.detail.get' }.merge(orderCodeList: orderCodeList))
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
module Yhd
|
5
|
+
module Response
|
6
|
+
class ParseJson < Faraday::Response::Middleware
|
7
|
+
WHITESPACE_REGEX = /\A^\s*$\z/
|
8
|
+
|
9
|
+
def parse(body)
|
10
|
+
case body
|
11
|
+
when WHITESPACE_REGEX, nil
|
12
|
+
nil
|
13
|
+
else
|
14
|
+
JSON.parse(body, :symbolize_names => true)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def on_complete(response)
|
19
|
+
response.body = parse(response.body) if respond_to?(:parse) && !unparsable_status_codes.include?(response.status)
|
20
|
+
end
|
21
|
+
|
22
|
+
def unparsable_status_codes
|
23
|
+
#[204, 301, 302, 304]
|
24
|
+
[]
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
Faraday::Response.register_middleware :parse_json => Yhd::Response::ParseJson
|
data/lib/yhd/version.rb
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
{
|
2
|
+
"response": {
|
3
|
+
"orderInfo": {
|
4
|
+
"orderDetail": {
|
5
|
+
"orderId": 743264512493,
|
6
|
+
"orderCode": "743264512493",
|
7
|
+
"orderStatus": "ORDER_OUT_OF_WH",
|
8
|
+
"orderAmount": 1299.0,
|
9
|
+
"productAmount": 1299.0,
|
10
|
+
"realAmount": 1299.0,
|
11
|
+
"orderCreateTime": "2014-09-01 17:17:30",
|
12
|
+
"orderDeliveryFee": 0.0,
|
13
|
+
"orderNeedInvoice": 0,
|
14
|
+
"invoiceTitle": "",
|
15
|
+
"goodReceiverName": "田苗 郭月",
|
16
|
+
"goodReceiverAddress": "南洲大桥西桂林国奥城,郭月0773-32559688",
|
17
|
+
"goodReceiverProvince": "广西",
|
18
|
+
"goodReceiverCity": "桂林市",
|
19
|
+
"goodReceiverCounty": "叠彩区",
|
20
|
+
"goodReceiverPostCode": "541001",
|
21
|
+
"goodReceiverMoblie": "13910227020",
|
22
|
+
"deliveryDate": "2014-09-02 10:21:08",
|
23
|
+
"deliveryRemark": "请务必于9月4日送达",
|
24
|
+
"orderPaymentConfirmDate": "2014-09-02 00:58:02",
|
25
|
+
"payServiceType": 1,
|
26
|
+
"orderPromotionDiscount": 0.0,
|
27
|
+
"deliverySupplierId": 1756,
|
28
|
+
"merchantExpressNbr": "904513823026",
|
29
|
+
"updateTime": "2014-09-02 10:21:08",
|
30
|
+
"orderCouponDiscount": 0.0,
|
31
|
+
"orderPlatformDiscount": 0.0,
|
32
|
+
"endUserId": 157314493,
|
33
|
+
"warehouseId": 35318,
|
34
|
+
"businessType": 5,
|
35
|
+
"isDepositOrder": 0,
|
36
|
+
"isMobileOrder": 0
|
37
|
+
},
|
38
|
+
|
39
|
+
"orderItemList": {
|
40
|
+
"orderItem": [{
|
41
|
+
"id":887022884,
|
42
|
+
"orderId":743264512493,
|
43
|
+
"orderItemAmount":1299.0,
|
44
|
+
"orderItemNum":1,
|
45
|
+
"orderItemPrice":1299.0,
|
46
|
+
"productCName":"花里Huali 『波卡波卡』Marc Jacobs Dot小雏菊瓢虫波点女性香水永生花盒 - 花里花店",
|
47
|
+
"productId":29833702,
|
48
|
+
"originalPrice":1299.0,
|
49
|
+
"merchantId":129404,
|
50
|
+
"updateTime":"2014-09-01 17:17:30",
|
51
|
+
"outerId":"175",
|
52
|
+
"groupFlag":0,
|
53
|
+
"deliveryFeeAmount":0.0,
|
54
|
+
"promotionAmount":0.0,
|
55
|
+
"couponAmountMerchant":0.0,
|
56
|
+
"couponPlatformDiscount":0.0,
|
57
|
+
"subsidyAmount":0.0,
|
58
|
+
"productDeposit":0.0
|
59
|
+
}]
|
60
|
+
}
|
61
|
+
},
|
62
|
+
"totalCount": 1,
|
63
|
+
"errorCount": 0
|
64
|
+
}
|
65
|
+
}
|
@@ -0,0 +1,124 @@
|
|
1
|
+
{
|
2
|
+
"response":{
|
3
|
+
"orderInfoList":{
|
4
|
+
"orderInfo":[{
|
5
|
+
"orderDetail":{
|
6
|
+
"orderId":804704353190,
|
7
|
+
"orderCode":"804704353190",
|
8
|
+
"orderStatus":"ORDER_TRUNED_TO_DO",
|
9
|
+
"orderAmount":299.0,
|
10
|
+
"productAmount":299.0,
|
11
|
+
"realAmount":299.0,
|
12
|
+
"orderCreateTime":"2014-09-07 08:56:55",
|
13
|
+
"orderDeliveryFee":0.0,
|
14
|
+
"orderNeedInvoice":2,
|
15
|
+
"invoiceTitle":"个人(陈颖)",
|
16
|
+
"invoiceContent":"由商家直接开具",
|
17
|
+
"goodReceiverName":"陈颖",
|
18
|
+
"goodReceiverAddress":"上海市松江区荣乐中路80弄37号101室(高乐小区)",
|
19
|
+
"goodReceiverProvince":"上海",
|
20
|
+
"goodReceiverCity":"上海市",
|
21
|
+
"goodReceiverCounty":"松江区",
|
22
|
+
"goodReceiverPostCode":"201600",
|
23
|
+
"goodReceiverMoblie":"13564113652",
|
24
|
+
"deliveryRemark":"求婚用,请务必好好挑选和包装,谢谢!",
|
25
|
+
"orderPaymentConfirmDate":"2014-09-07 09:02:22",
|
26
|
+
"payServiceType":1,
|
27
|
+
"orderPromotionDiscount":0.0,
|
28
|
+
"merchantExpressNbr":"",
|
29
|
+
"updateTime":"2014-09-07 09:03:00",
|
30
|
+
"orderCouponDiscount":0.0,
|
31
|
+
"orderPlatformDiscount":0.0,
|
32
|
+
"endUserId":162523190,
|
33
|
+
"warehouseId":35318,
|
34
|
+
"businessType":5,
|
35
|
+
"isDepositOrder":0,
|
36
|
+
"isMobileOrder":0
|
37
|
+
},
|
38
|
+
|
39
|
+
"orderItemList":{
|
40
|
+
"orderItem":[{
|
41
|
+
"id":891475977,
|
42
|
+
"orderId":804704353190,
|
43
|
+
"orderItemAmount":299.0,
|
44
|
+
"orderItemNum":1,
|
45
|
+
"orderItemPrice":299.0,
|
46
|
+
"productCName":"花里Huali 『奥德赛』鲜花花盒 - 花里花店",
|
47
|
+
"productId":29833698,
|
48
|
+
"originalPrice":299.0,
|
49
|
+
"merchantId":129404,
|
50
|
+
"updateTime":"2014-09-07 08:56:54",
|
51
|
+
"outerId":"168",
|
52
|
+
"groupFlag":0,
|
53
|
+
"deliveryFeeAmount":0.0,
|
54
|
+
"promotionAmount":0.0,
|
55
|
+
"couponAmountMerchant":0.0,
|
56
|
+
"couponPlatformDiscount":0.0,
|
57
|
+
"subsidyAmount":0.0,
|
58
|
+
"productDeposit":0.0
|
59
|
+
}]
|
60
|
+
}
|
61
|
+
},
|
62
|
+
{
|
63
|
+
"orderDetail":{
|
64
|
+
"orderId":743264512493,
|
65
|
+
"orderCode":"743264512493",
|
66
|
+
"orderStatus":"ORDER_OUT_OF_WH",
|
67
|
+
"orderAmount":1299.0,
|
68
|
+
"productAmount":1299.0,
|
69
|
+
"realAmount":1299.0,
|
70
|
+
"orderCreateTime":"2014-09-01 17:17:30",
|
71
|
+
"orderDeliveryFee":0.0,
|
72
|
+
"orderNeedInvoice":0,
|
73
|
+
"invoiceTitle":"",
|
74
|
+
"goodReceiverName":"田苗 郭月",
|
75
|
+
"goodReceiverAddress":"南洲大桥西桂林国奥城,郭月0773-32559688",
|
76
|
+
"goodReceiverProvince":"广西",
|
77
|
+
"goodReceiverCity":"桂林市",
|
78
|
+
"goodReceiverCounty":"叠彩区",
|
79
|
+
"goodReceiverPostCode":"541001",
|
80
|
+
"goodReceiverMoblie":"13910227020",
|
81
|
+
"deliveryDate":"2014-09-02 10:21:08",
|
82
|
+
"deliveryRemark":"请务必于9月4日送达",
|
83
|
+
"orderPaymentConfirmDate":"2014-09-02 00:58:02",
|
84
|
+
"payServiceType":1,
|
85
|
+
"orderPromotionDiscount":0.0,
|
86
|
+
"deliverySupplierId":1756,
|
87
|
+
"merchantExpressNbr":"904513823026",
|
88
|
+
"updateTime":"2014-09-02 10:21:08",
|
89
|
+
"orderCouponDiscount":0.0,
|
90
|
+
"orderPlatformDiscount":0.0,
|
91
|
+
"endUserId":157314493,
|
92
|
+
"warehouseId":35318,
|
93
|
+
"businessType":5,
|
94
|
+
"isDepositOrder":0,
|
95
|
+
"isMobileOrder":0
|
96
|
+
},
|
97
|
+
|
98
|
+
"orderItemList":{
|
99
|
+
"orderItem":[{
|
100
|
+
"id":887022884,
|
101
|
+
"orderId":743264512493,
|
102
|
+
"orderItemAmount":1299.0,
|
103
|
+
"orderItemNum":1,
|
104
|
+
"orderItemPrice":1299.0,
|
105
|
+
"productCName":"花里Huali 『波卡波卡』Marc Jacobs Dot小雏菊瓢虫波点女性香水永生花盒 - 花里花店",
|
106
|
+
"productId":29833702,
|
107
|
+
"originalPrice":1299.0,
|
108
|
+
"merchantId":129404,
|
109
|
+
"updateTime":"2014-09-01 17:17:30",
|
110
|
+
"outerId":"175",
|
111
|
+
"groupFlag":0,
|
112
|
+
"deliveryFeeAmount":0.0,
|
113
|
+
"promotionAmount":0.0,
|
114
|
+
"couponAmountMerchant":0.0,
|
115
|
+
"couponPlatformDiscount":0.0,
|
116
|
+
"subsidyAmount":0.0,
|
117
|
+
"productDeposit":0.0}]
|
118
|
+
}
|
119
|
+
}]
|
120
|
+
},
|
121
|
+
"totalCount":2,
|
122
|
+
"errorCount":0
|
123
|
+
}
|
124
|
+
}
|
@@ -0,0 +1,47 @@
|
|
1
|
+
{
|
2
|
+
"response": {
|
3
|
+
"orderList": {
|
4
|
+
"order": [{
|
5
|
+
"orderId": "5626152549",
|
6
|
+
"orderCode": "130225Y3HJRL",
|
7
|
+
"orderStatus": "ORDER_WAIT_PAY",
|
8
|
+
"orderAmount": "123.0",
|
9
|
+
"productAmount": "112.0",
|
10
|
+
"orderCreateTime": "2013-11-12 22:37:45",
|
11
|
+
"orderDeliveryFee": "11.0",
|
12
|
+
"orderNeedInvoice": "0",
|
13
|
+
"updateTime": "2013-06-17 15:59:33",
|
14
|
+
"endUserId": "89267177",
|
15
|
+
"warehouseId": "14039"
|
16
|
+
},
|
17
|
+
{
|
18
|
+
"orderId": "5626152901",
|
19
|
+
"orderCode": "130226Y3HK3L",
|
20
|
+
"orderStatus": "ORDER_PAYED",
|
21
|
+
"orderAmount": "123.0",
|
22
|
+
"productAmount": "112.0",
|
23
|
+
"orderCreateTime": "2013-11-12 22:38:20",
|
24
|
+
"orderDeliveryFee": "11.0",
|
25
|
+
"orderNeedInvoice": "0",
|
26
|
+
"updateTime": "2013-06-17 15:59:33",
|
27
|
+
"endUserId": "89267177",
|
28
|
+
"warehouseId": "14039"
|
29
|
+
},
|
30
|
+
{
|
31
|
+
"orderId": "5626152972",
|
32
|
+
"orderCode": "130226Y3HK5T",
|
33
|
+
"orderStatus": "ORDER_TRUNED_TO_DO",
|
34
|
+
"orderAmount": "459.0",
|
35
|
+
"productAmount": "424.0",
|
36
|
+
"orderCreateTime": "2013-11-12 22:39:06",
|
37
|
+
"orderDeliveryFee": "35.0",
|
38
|
+
"orderNeedInvoice": "0",
|
39
|
+
"updateTime": "2013-12-10 16:23:23",
|
40
|
+
"endUserId": "89267177",
|
41
|
+
"warehouseId": "14039"
|
42
|
+
}]
|
43
|
+
},
|
44
|
+
"totalCount": "61",
|
45
|
+
"errorCount": "0"
|
46
|
+
}
|
47
|
+
}
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
require 'simplecov'
|
2
|
+
|
3
|
+
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
|
4
|
+
SimpleCov::Formatter::HTMLFormatter,
|
5
|
+
]
|
6
|
+
|
7
|
+
SimpleCov.start do
|
8
|
+
add_filter '/spec/'
|
9
|
+
minimum_coverage(99.35)
|
10
|
+
end
|
11
|
+
|
12
|
+
require 'yhd'
|
13
|
+
|
14
|
+
require 'rspec'
|
15
|
+
require 'rr'
|
16
|
+
require 'webmock/rspec'
|
17
|
+
|
18
|
+
WebMock.disable_net_connect!
|
19
|
+
|
20
|
+
RSpec.configure do |config|
|
21
|
+
config.expect_with :rspec do |c|
|
22
|
+
c.syntax = :should
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def api_url
|
27
|
+
Yhd::Client::DEFAULT_ENDPOINT + Yhd::Client::DEFAULT_PATH
|
28
|
+
end
|
29
|
+
|
30
|
+
def a_delete(api_method)
|
31
|
+
a_request(:delete, api_url).with(body: hash_including(method: api_method))
|
32
|
+
end
|
33
|
+
|
34
|
+
def a_get(api_method)
|
35
|
+
a_request(:get, api_url).with(query: hash_including(method: api_method))
|
36
|
+
end
|
37
|
+
|
38
|
+
def a_post(api_method)
|
39
|
+
a_request(:post, api_url).with(body: hash_including(method: api_method))
|
40
|
+
end
|
41
|
+
|
42
|
+
def a_put(api_method)
|
43
|
+
a_request(:put, api_url).with(body: hash_including(method: api_method))
|
44
|
+
end
|
45
|
+
|
46
|
+
def stub_delete
|
47
|
+
stub_request(:delete, api_url)
|
48
|
+
end
|
49
|
+
|
50
|
+
def stub_get
|
51
|
+
stub_request(:get, api_url)
|
52
|
+
end
|
53
|
+
|
54
|
+
def stub_post
|
55
|
+
stub_request(:post, api_url)
|
56
|
+
end
|
57
|
+
|
58
|
+
def stub_put
|
59
|
+
stub_request(:put, api_url)
|
60
|
+
end
|
61
|
+
|
62
|
+
def fixture_path
|
63
|
+
File.expand_path('../fixtures', __FILE__)
|
64
|
+
end
|
65
|
+
|
66
|
+
def fixture(file)
|
67
|
+
File.new(fixture_path + '/' + file)
|
68
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Yhd::Client do
|
4
|
+
let(:client) { Yhd::Client.new(app_key: 'app_key', app_secret: 'app_secret', session_key: 'session_key', endpoint: 'endpoint') }
|
5
|
+
|
6
|
+
describe '.new' do
|
7
|
+
it 'raises exception if any required option keys for api is missing' do
|
8
|
+
-> { Yhd::Client.new(app_key: 'app_key') }.should raise_exception
|
9
|
+
-> { Yhd::Client.new(app_key: 'app_key', app_secret: 'app_secret') }.should raise_exception
|
10
|
+
-> { Yhd::Client.new(session_key: 'session_key', app_secret: 'app_secret') }.should raise_exception
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
describe '#endpoint' do
|
15
|
+
it 'returns the endpoint provided in options hash' do
|
16
|
+
client.endpoint.should eq('endpoint')
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'returns the default endpoint' do
|
20
|
+
client = Yhd::Client.new(app_key: 'app_key', app_secret: 'app_secret', session_key: 'session_key')
|
21
|
+
client.endpoint.should eq(Yhd::Client::DEFAULT_ENDPOINT)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
describe '#connection' do
|
26
|
+
it 'looks like a faraday connection' do
|
27
|
+
client.send(:connection).should respond_to(:run_request)
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'memorizes the connection' do
|
31
|
+
c1, c2 = client.send(:connection), client.send(:connection)
|
32
|
+
c1.object_id.should eq(c2.object_id)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
describe '#signed_params' do
|
37
|
+
it 'returns a params hash with a sign key in it' do
|
38
|
+
client.send(:signed_params, { foo: '1', bar: '2', baz: '3' }).should include(:sign)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Yhd::Orders do
|
4
|
+
let(:client) { Yhd::Client.new(app_key: 'app_key', app_secret: 'app_secret', session_key: 'session_key') }
|
5
|
+
|
6
|
+
describe '#get_orders' do
|
7
|
+
before do
|
8
|
+
stub_post.with(body: %r{method=yhd.orders.get}).to_return(:body => fixture('orders.json'))
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'requests the correct resource on POST' do
|
12
|
+
client.get_orders(orderStatusList: 'ORDER_PAYED,ORDER_WAIT_SEND,ORDER_ON_SENDING,ORDER_RECEIVED,ORDER_FINISH,ORDER_CANCEL',
|
13
|
+
startTime: "2014-08-01 10:00:00",
|
14
|
+
endTime: "2014-08-10 10:00:00")
|
15
|
+
a_post('yhd.orders.get').should have_been_made
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe '#get_order_details' do
|
20
|
+
before do
|
21
|
+
stub_post.with(body: %r{method=yhd.orders.detail.get}).to_return(:body => fixture('order_details.json'))
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'requests the correct resource on POST' do
|
25
|
+
client.get_detail_orders(orderCodeList: "804704353190,743264512493")
|
26
|
+
a_post('yhd.orders.detail.get').should have_been_made
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
data/yhd.gemspec
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'yhd/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'yhd'
|
8
|
+
spec.version = Yhd::VERSION
|
9
|
+
spec.authors = ['ryancheung']
|
10
|
+
spec.email = ['ryancheung.go@gmail.com']
|
11
|
+
spec.summary = 'Ruby SDK for open.yhd.com'
|
12
|
+
spec.description = 'Ruby SDK for open.yhd.com'
|
13
|
+
spec.homepage = 'https://github.com/ryancheung/yhd'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(/^bin\//) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(/^(test|spec|features)/)
|
19
|
+
spec.require_paths = ['lib']
|
20
|
+
|
21
|
+
spec.add_development_dependency 'bundler', '~> 1.6'
|
22
|
+
spec.add_development_dependency 'rake'
|
23
|
+
|
24
|
+
spec.add_dependency 'descendants_tracker'
|
25
|
+
spec.add_dependency 'faraday'
|
26
|
+
end
|
metadata
ADDED
@@ -0,0 +1,127 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: yhd
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- ryancheung
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-09-08 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.6'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.6'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: descendants_tracker
|
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: faraday
|
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
|
+
description: Ruby SDK for open.yhd.com
|
70
|
+
email:
|
71
|
+
- ryancheung.go@gmail.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- ".rspec"
|
78
|
+
- ".rubocop.yml"
|
79
|
+
- Gemfile
|
80
|
+
- LICENSE.txt
|
81
|
+
- README.md
|
82
|
+
- Rakefile
|
83
|
+
- lib/yhd.rb
|
84
|
+
- lib/yhd/api.rb
|
85
|
+
- lib/yhd/client.rb
|
86
|
+
- lib/yhd/orders.rb
|
87
|
+
- lib/yhd/response/parse_json.rb
|
88
|
+
- lib/yhd/version.rb
|
89
|
+
- spec/fixtures/order_detail.json
|
90
|
+
- spec/fixtures/order_details.json
|
91
|
+
- spec/fixtures/orders.json
|
92
|
+
- spec/spec_helper.rb
|
93
|
+
- spec/yhd/client_spec.rb
|
94
|
+
- spec/yhd/orders_spec.rb
|
95
|
+
- yhd.gemspec
|
96
|
+
homepage: https://github.com/ryancheung/yhd
|
97
|
+
licenses:
|
98
|
+
- MIT
|
99
|
+
metadata: {}
|
100
|
+
post_install_message:
|
101
|
+
rdoc_options: []
|
102
|
+
require_paths:
|
103
|
+
- lib
|
104
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
105
|
+
requirements:
|
106
|
+
- - ">="
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
version: '0'
|
109
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
110
|
+
requirements:
|
111
|
+
- - ">="
|
112
|
+
- !ruby/object:Gem::Version
|
113
|
+
version: '0'
|
114
|
+
requirements: []
|
115
|
+
rubyforge_project:
|
116
|
+
rubygems_version: 2.2.2
|
117
|
+
signing_key:
|
118
|
+
specification_version: 4
|
119
|
+
summary: Ruby SDK for open.yhd.com
|
120
|
+
test_files:
|
121
|
+
- spec/fixtures/order_detail.json
|
122
|
+
- spec/fixtures/order_details.json
|
123
|
+
- spec/fixtures/orders.json
|
124
|
+
- spec/spec_helper.rb
|
125
|
+
- spec/yhd/client_spec.rb
|
126
|
+
- spec/yhd/orders_spec.rb
|
127
|
+
has_rdoc:
|