xdelivery 1.0.1 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/xdelivery/api/response/base.rb +24 -2
- data/lib/xdelivery/exceptions.rb +33 -0
- data/lib/xdelivery/version.rb +1 -1
- data/lib/xdelivery.rb +1 -0
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 355fb7f6c6cbc86ac8471c2b70f05dfefc87353cded96521b0b44bc5c538ee28
|
4
|
+
data.tar.gz: c001a8e1e7c561f4782420dca6c5de9c0b8d4db15012d5472751fb735ba83bde
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8070cce10383f1579f90b859fc9471ec1ae371def5a42b225a558783bd83b6ef568a4f9642f0c0460aefe7cd77d4de03b1653cd759b84b00a99e3cc1d2bfb0d4
|
7
|
+
data.tar.gz: 7bfe8c7d89ff4e0c20be5af13249e88837c5e405df8475ef7a40fefab4ef11b54a25fc29cc70ec308b695269a20278306bd42feb5da42f5831b16a25b9279aac
|
@@ -6,16 +6,38 @@ module Xdelivery
|
|
6
6
|
|
7
7
|
def initialize(response)
|
8
8
|
self.response = response
|
9
|
-
|
9
|
+
handle_error!
|
10
|
+
|
11
|
+
self.data = begin
|
12
|
+
JSON.parse(response.body)
|
13
|
+
rescue JSON::ParserError
|
14
|
+
raise Client::UnknownResponse, "#{code}, Response is not json."
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def code
|
19
|
+
response.code
|
10
20
|
end
|
11
21
|
|
12
22
|
def auth?
|
13
|
-
|
23
|
+
code == 200
|
14
24
|
end
|
15
25
|
|
16
26
|
def status?
|
17
27
|
data['status'] == true
|
18
28
|
end
|
29
|
+
|
30
|
+
protected
|
31
|
+
|
32
|
+
def handle_error!
|
33
|
+
if Client::EXCEPTION_STATUSES[code]
|
34
|
+
raise Exceptions::EXCEPTIONS_MAP[code]
|
35
|
+
end
|
36
|
+
|
37
|
+
unless Client::EXPECTED_STATUSES[code]
|
38
|
+
raise Client::UnknownResponse, "Unexpected response status code: #{code}."
|
39
|
+
end
|
40
|
+
end
|
19
41
|
end
|
20
42
|
end
|
21
43
|
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module Xdelivery
|
2
|
+
|
3
|
+
module Exceptions
|
4
|
+
|
5
|
+
EXCEPTIONS_MAP = {}
|
6
|
+
end
|
7
|
+
|
8
|
+
class Client
|
9
|
+
class UnknownResponse < StandardError; end
|
10
|
+
|
11
|
+
EXPECTED_STATUSES = {
|
12
|
+
200 => 'Ok' ,
|
13
|
+
401 => 'Unauthorized'
|
14
|
+
}
|
15
|
+
|
16
|
+
EXCEPTION_STATUSES = {
|
17
|
+
404 => 'Not Found',
|
18
|
+
500 => 'Internal Server Error',
|
19
|
+
502 => 'Bad Gateway',
|
20
|
+
503 => 'Service Unavailable',
|
21
|
+
504 => 'Gateway Timeout',
|
22
|
+
}
|
23
|
+
|
24
|
+
EXCEPTION_STATUSES.each_pair do |code, message|
|
25
|
+
klass = Class.new(StandardError) do
|
26
|
+
send(:define_method, :message) { "#{code}, #{message}" }
|
27
|
+
end
|
28
|
+
const_name = message.delete(',\.\-\'\"').split(' ').map(&:capitalize).join
|
29
|
+
klass_constant = const_set(const_name, klass)
|
30
|
+
Exceptions::EXCEPTIONS_MAP[code] = klass_constant
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
data/lib/xdelivery/version.rb
CHANGED
data/lib/xdelivery.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: xdelivery
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- eddie
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-05-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -110,6 +110,7 @@ files:
|
|
110
110
|
- lib/xdelivery/api/shops.rb
|
111
111
|
- lib/xdelivery/callback.rb
|
112
112
|
- lib/xdelivery/client.rb
|
113
|
+
- lib/xdelivery/exceptions.rb
|
113
114
|
- lib/xdelivery/version.rb
|
114
115
|
- xdelivery-ruby.gemspec
|
115
116
|
homepage: https://github.com/superlanding/xdelivery-ruby
|
@@ -131,7 +132,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
131
132
|
- !ruby/object:Gem::Version
|
132
133
|
version: '0'
|
133
134
|
requirements: []
|
134
|
-
rubygems_version: 3.0.
|
135
|
+
rubygems_version: 3.0.3.1
|
135
136
|
signing_key:
|
136
137
|
specification_version: 4
|
137
138
|
summary: 火箭快遞 API 串接
|