xdelivery 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +8 -0
- data/.travis.yml +7 -0
- data/Gemfile +9 -0
- data/Gemfile.lock +51 -0
- data/LICENSE.txt +21 -0
- data/README.md +39 -0
- data/Rakefile +10 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/xdelivery/api/base.rb +55 -0
- data/lib/xdelivery/api/orders.rb +41 -0
- data/lib/xdelivery/api/ping.rb +9 -0
- data/lib/xdelivery/api/response/base.rb +22 -0
- data/lib/xdelivery/api/response/orders.rb +22 -0
- data/lib/xdelivery/api/response/ping.rb +9 -0
- data/lib/xdelivery/client.rb +22 -0
- data/lib/xdelivery/version.rb +3 -0
- data/lib/xdelivery.rb +17 -0
- data/xdelivery-ruby.gemspec +30 -0
- metadata +119 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 66f01b9efe9c8a673995a602bbf6d56fdd69e878
|
4
|
+
data.tar.gz: 0bb3faef10eef81dc89a5e66623728688fe48acd
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d7b68cef150265c95b7e1709a8d6cc791a797e6a310be3753cacf02006a75df300e4af3bbe0a703aab79f078c0a3aa087c07e21ed0c39cca2bfbfd07dae4a99a
|
7
|
+
data.tar.gz: 54ac80927b4fbf936213eb9e1c42116e50fb3414822f7b358a05df0c210b135509df35c3470acf8c3f638f580274ffefb67b2a9e57296ae28e14c891d25e2fea
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
xdelivery (0.1.0)
|
5
|
+
rest-client
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
addressable (2.5.2)
|
11
|
+
public_suffix (>= 2.0.2, < 4.0)
|
12
|
+
crack (0.4.3)
|
13
|
+
safe_yaml (~> 1.0.0)
|
14
|
+
domain_name (0.5.20180417)
|
15
|
+
unf (>= 0.0.5, < 1.0.0)
|
16
|
+
hashdiff (0.3.7)
|
17
|
+
http-cookie (1.0.3)
|
18
|
+
domain_name (~> 0.5)
|
19
|
+
mime-types (3.2.2)
|
20
|
+
mime-types-data (~> 3.2015)
|
21
|
+
mime-types-data (3.2018.0812)
|
22
|
+
minitest (5.11.3)
|
23
|
+
netrc (0.11.0)
|
24
|
+
public_suffix (3.0.3)
|
25
|
+
rake (10.5.0)
|
26
|
+
rest-client (2.0.2)
|
27
|
+
http-cookie (>= 1.0.2, < 2.0)
|
28
|
+
mime-types (>= 1.16, < 4.0)
|
29
|
+
netrc (~> 0.8)
|
30
|
+
safe_yaml (1.0.4)
|
31
|
+
unf (0.1.4)
|
32
|
+
unf_ext
|
33
|
+
unf_ext (0.0.7.5)
|
34
|
+
webmock (3.4.2)
|
35
|
+
addressable (>= 2.3.6)
|
36
|
+
crack (>= 0.3.2)
|
37
|
+
hashdiff
|
38
|
+
|
39
|
+
PLATFORMS
|
40
|
+
ruby
|
41
|
+
|
42
|
+
DEPENDENCIES
|
43
|
+
bundler (~> 1.16)
|
44
|
+
minitest (~> 5.0)
|
45
|
+
rake (~> 10.0)
|
46
|
+
rest-client
|
47
|
+
webmock
|
48
|
+
xdelivery!
|
49
|
+
|
50
|
+
BUNDLED WITH
|
51
|
+
1.16.4
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2018 eddie
|
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,39 @@
|
|
1
|
+
# Xdelivery::Ruby
|
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/xdelivery/ruby`. 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 'xdelivery-ruby'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install xdelivery-ruby
|
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. Then, run `rake test` to run the tests. 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]/xdelivery-ruby.
|
36
|
+
|
37
|
+
## License
|
38
|
+
|
39
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "xdelivery/ruby"
|
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(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'uri'
|
2
|
+
require 'rest-client'
|
3
|
+
|
4
|
+
module Xdelivery
|
5
|
+
module API
|
6
|
+
class Base
|
7
|
+
attr_accessor :merchant_no, :access_key
|
8
|
+
|
9
|
+
BASE_URL = 'https://api.xdelivery.io'
|
10
|
+
|
11
|
+
def initialize(merchant_no='', access_key='')
|
12
|
+
self.merchant_no = merchant_no
|
13
|
+
self.access_key = access_key
|
14
|
+
end
|
15
|
+
|
16
|
+
protected
|
17
|
+
|
18
|
+
def post(path)
|
19
|
+
RestClient.post(uri(path).to_s, post_data)
|
20
|
+
rescue RestClient::ExceptionWithResponse => e
|
21
|
+
e.response
|
22
|
+
end
|
23
|
+
|
24
|
+
def get(path)
|
25
|
+
RestClient.get(uri(path).to_s)
|
26
|
+
rescue RestClient::ExceptionWithResponse => e
|
27
|
+
e.response
|
28
|
+
end
|
29
|
+
|
30
|
+
# [GET] query string params
|
31
|
+
def params
|
32
|
+
{}
|
33
|
+
end
|
34
|
+
|
35
|
+
# [POST]
|
36
|
+
def post_data
|
37
|
+
{}
|
38
|
+
end
|
39
|
+
|
40
|
+
private
|
41
|
+
|
42
|
+
def uri(path)
|
43
|
+
uri = URI.parse("#{BASE_URL}#{path}").tap { |u| u.query = query_auth_params }
|
44
|
+
end
|
45
|
+
|
46
|
+
def query_auth_params
|
47
|
+
URI.encode_www_form(auth_params.merge(params))
|
48
|
+
end
|
49
|
+
|
50
|
+
def auth_params
|
51
|
+
{ merchant_no: merchant_no, access_key: access_key }
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module Xdelivery
|
2
|
+
module API
|
3
|
+
class Orders < Base
|
4
|
+
include Enumerable
|
5
|
+
|
6
|
+
attr_accessor :orders
|
7
|
+
|
8
|
+
COLUMNS = [
|
9
|
+
:order_id, :provider, :recipient, :mobile, :email, :store_id, :store_name, :address,
|
10
|
+
:items, :warehouse_items, :total_order_amount, :cash_on_delivery, :order_created_at,
|
11
|
+
:note, :callback_url, :ref_id, :tag
|
12
|
+
]
|
13
|
+
|
14
|
+
def add(params)
|
15
|
+
self.orders ||= []
|
16
|
+
params.delete_if { |k, v| COLUMNS.include?(k) == false }
|
17
|
+
orders.push(params)
|
18
|
+
params
|
19
|
+
end
|
20
|
+
|
21
|
+
def [](index)
|
22
|
+
orders[index]
|
23
|
+
end
|
24
|
+
|
25
|
+
def count
|
26
|
+
orders.count
|
27
|
+
end
|
28
|
+
|
29
|
+
def create!
|
30
|
+
response = post('/orders/batch')
|
31
|
+
Response::Orders.new(response)
|
32
|
+
end
|
33
|
+
|
34
|
+
protected
|
35
|
+
|
36
|
+
def post_data
|
37
|
+
{ import: { orders: orders } }
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module Xdelivery
|
2
|
+
module API
|
3
|
+
module Response
|
4
|
+
class Base
|
5
|
+
attr_accessor :response, :data
|
6
|
+
|
7
|
+
def initialize(response)
|
8
|
+
self.response = response
|
9
|
+
self.data = JSON.parse(response.body)
|
10
|
+
end
|
11
|
+
|
12
|
+
def auth?
|
13
|
+
response.code == 200
|
14
|
+
end
|
15
|
+
|
16
|
+
def status?
|
17
|
+
data['status'] == true
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module Xdelivery
|
2
|
+
module API
|
3
|
+
module Response
|
4
|
+
class Orders < Base
|
5
|
+
|
6
|
+
class Order < OpenStruct
|
7
|
+
def valid?
|
8
|
+
valid == true || errors.empty?
|
9
|
+
end
|
10
|
+
|
11
|
+
def errors
|
12
|
+
super || []
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def orders
|
17
|
+
data['orders'].map { |order| Order.new(order) }
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module Xdelivery
|
2
|
+
class Client
|
3
|
+
|
4
|
+
attr_accessor :merchant_no, :access_key
|
5
|
+
|
6
|
+
def initialize(merchant_no, access_key)
|
7
|
+
self.merchant_no = merchant_no
|
8
|
+
self.access_key = access_key
|
9
|
+
end
|
10
|
+
|
11
|
+
def create_orders!
|
12
|
+
api = API::Orders.new(merchant_no, access_key)
|
13
|
+
yield(api)
|
14
|
+
api.create!
|
15
|
+
end
|
16
|
+
|
17
|
+
def ping!
|
18
|
+
api = API::Ping.new(merchant_no, access_key)
|
19
|
+
api.ping!
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
data/lib/xdelivery.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'rest-client'
|
3
|
+
require "xdelivery/version"
|
4
|
+
require "xdelivery/client"
|
5
|
+
require "xdelivery/api/base"
|
6
|
+
require "xdelivery/api/orders"
|
7
|
+
require "xdelivery/api/ping"
|
8
|
+
require "xdelivery/api/response/base"
|
9
|
+
require "xdelivery/api/response/orders"
|
10
|
+
require "xdelivery/api/response/ping"
|
11
|
+
|
12
|
+
|
13
|
+
module Xdelivery
|
14
|
+
def url
|
15
|
+
API::Base::BASE_URL
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "xdelivery/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "xdelivery"
|
8
|
+
spec.version = Xdelivery::VERSION
|
9
|
+
spec.authors = ["eddie"]
|
10
|
+
spec.email = ["eddie@super-landing.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{火箭快遞 API 串接}
|
13
|
+
spec.description = %q{}
|
14
|
+
spec.homepage = "https://github.com/superlanding/xdelivery-ruby"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
# Specify which files should be added to the gem when it is released.
|
18
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
19
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
20
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
21
|
+
end
|
22
|
+
spec.bindir = "exe"
|
23
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
24
|
+
spec.require_paths = ["lib"]
|
25
|
+
|
26
|
+
spec.add_development_dependency "bundler", "~> 1.16"
|
27
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
28
|
+
spec.add_development_dependency "minitest", "~> 5.0"
|
29
|
+
spec.add_dependency "rest-client"
|
30
|
+
end
|
metadata
ADDED
@@ -0,0 +1,119 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: xdelivery
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- eddie
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-11-16 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.16'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.16'
|
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.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: minitest
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '5.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '5.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rest-client
|
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: ''
|
70
|
+
email:
|
71
|
+
- eddie@super-landing.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- ".travis.yml"
|
78
|
+
- Gemfile
|
79
|
+
- Gemfile.lock
|
80
|
+
- LICENSE.txt
|
81
|
+
- README.md
|
82
|
+
- Rakefile
|
83
|
+
- bin/console
|
84
|
+
- bin/setup
|
85
|
+
- lib/xdelivery.rb
|
86
|
+
- lib/xdelivery/api/base.rb
|
87
|
+
- lib/xdelivery/api/orders.rb
|
88
|
+
- lib/xdelivery/api/ping.rb
|
89
|
+
- lib/xdelivery/api/response/base.rb
|
90
|
+
- lib/xdelivery/api/response/orders.rb
|
91
|
+
- lib/xdelivery/api/response/ping.rb
|
92
|
+
- lib/xdelivery/client.rb
|
93
|
+
- lib/xdelivery/version.rb
|
94
|
+
- xdelivery-ruby.gemspec
|
95
|
+
homepage: https://github.com/superlanding/xdelivery-ruby
|
96
|
+
licenses:
|
97
|
+
- MIT
|
98
|
+
metadata: {}
|
99
|
+
post_install_message:
|
100
|
+
rdoc_options: []
|
101
|
+
require_paths:
|
102
|
+
- lib
|
103
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
104
|
+
requirements:
|
105
|
+
- - ">="
|
106
|
+
- !ruby/object:Gem::Version
|
107
|
+
version: '0'
|
108
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
109
|
+
requirements:
|
110
|
+
- - ">="
|
111
|
+
- !ruby/object:Gem::Version
|
112
|
+
version: '0'
|
113
|
+
requirements: []
|
114
|
+
rubyforge_project:
|
115
|
+
rubygems_version: 2.4.8
|
116
|
+
signing_key:
|
117
|
+
specification_version: 4
|
118
|
+
summary: "火箭快遞 API 串接"
|
119
|
+
test_files: []
|