janio_api 0.2.0 → 0.2.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 +4 -4
- data/bin/console +1 -1
- data/lib/{dev_config.rb → dev/config.rb} +0 -0
- data/lib/{zeitwerk_loader.rb → dev/zeitwerk_loader.rb} +1 -1
- data/lib/janio_api.rb +3 -2
- data/lib/janio_api/connection.rb +31 -0
- data/lib/janio_api/exceptions.rb +79 -0
- data/lib/janio_api/resources/order.rb +1 -1
- data/lib/janio_api/version.rb +1 -1
- metadata +5 -5
- data/lib/patch_exception.rb +0 -18
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6563c2fcc213efcc5814f62dc6f7d710a8d4d686519c2bfc2a31879f55df06fd
|
4
|
+
data.tar.gz: e079a825f69e71d7a8bacc2724e01df367836707c3cec657ac23a5e4d6778e81
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 074abb6b51f02c06a2682b0b0907a76030550871fd0e3461eda9c71cbd46ae1ebbe5fe819edf934bbd85f228e308e9a0374a33c8b35a11f02b44f230f11b8623
|
7
|
+
data.tar.gz: d2e9ad3547f786c0a6353fa6b7353a8d8dd0898d2dcce38df9e69043fa4dbe6e058dc0a3e257873a29d5d7b1f474e14eacc52a51f140d27f5fa0b2fca5997951
|
data/bin/console
CHANGED
@@ -5,7 +5,7 @@ require "janio_api"
|
|
5
5
|
|
6
6
|
# You can add fixtures and/or initialization code here to make experimenting
|
7
7
|
# with your gem easier. You can also use a different console, if you like.
|
8
|
-
require "
|
8
|
+
require "dev/config"
|
9
9
|
|
10
10
|
# (If you use this, don't forget to add pry to your Gemfile!)
|
11
11
|
require "pry"
|
File without changes
|
data/lib/janio_api.rb
CHANGED
@@ -1,9 +1,10 @@
|
|
1
1
|
require "janio_api/version"
|
2
2
|
require "active_resource"
|
3
3
|
require "dotenv/load"
|
4
|
-
require_relative "zeitwerk_loader" if ENV["JANIO_API_GEM_ENV"] == "development"
|
5
|
-
require_relative "patch_exception"
|
4
|
+
require_relative "dev/zeitwerk_loader" if ENV["JANIO_API_GEM_ENV"] == "development"
|
6
5
|
module JanioAPI
|
6
|
+
require "janio_api/exceptions"
|
7
|
+
|
7
8
|
require "janio_api/configuration"
|
8
9
|
|
9
10
|
require "janio_api/redirect_fetcher"
|
data/lib/janio_api/connection.rb
CHANGED
@@ -17,5 +17,36 @@ module JanioAPI
|
|
17
17
|
rescue OpenSSL::SSL::SSLError => e
|
18
18
|
raise SSLError.new(e.message)
|
19
19
|
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def handle_response(response)
|
24
|
+
case response.code.to_i
|
25
|
+
when 200...400
|
26
|
+
response
|
27
|
+
when 400
|
28
|
+
raise(BadRequest.new(response))
|
29
|
+
when 401
|
30
|
+
raise(UnauthorizedAccess.new(response))
|
31
|
+
when 403
|
32
|
+
raise(ForbiddenAccess.new(response))
|
33
|
+
when 404
|
34
|
+
raise(ResourceNotFound.new(response))
|
35
|
+
when 405
|
36
|
+
raise(MethodNotAllowed.new(response))
|
37
|
+
when 409
|
38
|
+
raise(ResourceConflict.new(response))
|
39
|
+
when 410
|
40
|
+
raise(ResourceGone.new(response))
|
41
|
+
when 422
|
42
|
+
raise(ResourceInvalid.new(response))
|
43
|
+
when 401...500
|
44
|
+
raise(ClientError.new(response))
|
45
|
+
when 500...600
|
46
|
+
raise(ServerError.new(response))
|
47
|
+
else
|
48
|
+
raise(ConnectionError.new(response, "Unknown response code: #{response.code}"))
|
49
|
+
end
|
50
|
+
end
|
20
51
|
end
|
21
52
|
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
module JanioAPI
|
2
|
+
class ConnectionError < StandardError # :nodoc:
|
3
|
+
attr_reader :response
|
4
|
+
|
5
|
+
def initialize(response, message = nil)
|
6
|
+
@response = response
|
7
|
+
@message = message
|
8
|
+
end
|
9
|
+
|
10
|
+
def to_s
|
11
|
+
message = "Failed.".dup
|
12
|
+
message << " Response code = #{response.code}." if response.respond_to?(:code)
|
13
|
+
message << " Response message = #{response.message}." if response.respond_to?(:message)
|
14
|
+
message << " Response body = #{response.body}." if response.respond_to?(:body)
|
15
|
+
message
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
# Raised when a Timeout::Error occurs.
|
20
|
+
class TimeoutError < ConnectionError
|
21
|
+
def initialize(message)
|
22
|
+
@message = message
|
23
|
+
end
|
24
|
+
|
25
|
+
def to_s
|
26
|
+
@message
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
# Raised when a OpenSSL::SSL::SSLError occurs.
|
31
|
+
class SSLError < ConnectionError
|
32
|
+
def initialize(message)
|
33
|
+
@message = message
|
34
|
+
end
|
35
|
+
|
36
|
+
def to_s
|
37
|
+
@message
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
# 4xx Client Error
|
42
|
+
class ClientError < ConnectionError # :nodoc:
|
43
|
+
end
|
44
|
+
|
45
|
+
# 400 Bad Request
|
46
|
+
class BadRequest < ClientError # :nodoc:
|
47
|
+
end
|
48
|
+
|
49
|
+
# 401 Unauthorized
|
50
|
+
class UnauthorizedAccess < ClientError # :nodoc:
|
51
|
+
end
|
52
|
+
|
53
|
+
# 403 Forbidden
|
54
|
+
class ForbiddenAccess < ClientError # :nodoc:
|
55
|
+
end
|
56
|
+
|
57
|
+
# 404 Not Found
|
58
|
+
class ResourceNotFound < ClientError # :nodoc:
|
59
|
+
end
|
60
|
+
|
61
|
+
# 409 Conflict
|
62
|
+
class ResourceConflict < ClientError # :nodoc:
|
63
|
+
end
|
64
|
+
|
65
|
+
# 410 Gone
|
66
|
+
class ResourceGone < ClientError # :nodoc:
|
67
|
+
end
|
68
|
+
|
69
|
+
# 5xx Server Error
|
70
|
+
class ServerError < ConnectionError # :nodoc:
|
71
|
+
end
|
72
|
+
|
73
|
+
# 405 Method Not Allowed
|
74
|
+
class MethodNotAllowed < ClientError # :nodoc:
|
75
|
+
def allowed_methods
|
76
|
+
@response["Allow"].split(",").map { |verb| verb.strip.downcase.to_sym }
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
@@ -18,7 +18,7 @@ module JanioAPI
|
|
18
18
|
SUPPORTED_PICKUP_COUNTRIES = ["Singapore", "China", "Hong Kong", "Indonesia", "Malaysia", "Philippines", "Thailand"].freeze
|
19
19
|
SUPPORTED_CONSIGNEE_COUNTRIES = ["Indonesia", "Singapore", "Thailand", "Malaysia", "Philippines", "China", "Hong Kong", "Taiwan", "Brunei", "South Korea", "Japan", "Vietnam"].freeze
|
20
20
|
|
21
|
-
POSTAL_EXCLUDED_COUNTRIES = ["Hong Kong", "Vietnam"].freeze
|
21
|
+
POSTAL_EXCLUDED_COUNTRIES = ["Hong Kong", "Vietnam", "Brunei"].freeze
|
22
22
|
VALID_PAYMENT_TYPES = ["cod", "prepaid"].freeze
|
23
23
|
|
24
24
|
SERVICE_ID_MAP = [
|
data/lib/janio_api/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: janio_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andy Chong
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-04-
|
11
|
+
date: 2020-04-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activeresource
|
@@ -99,17 +99,17 @@ files:
|
|
99
99
|
- bin/console
|
100
100
|
- bin/setup
|
101
101
|
- janio_api.gemspec
|
102
|
-
- lib/
|
102
|
+
- lib/dev/config.rb
|
103
|
+
- lib/dev/zeitwerk_loader.rb
|
103
104
|
- lib/janio_api.rb
|
104
105
|
- lib/janio_api/configuration.rb
|
105
106
|
- lib/janio_api/connection.rb
|
107
|
+
- lib/janio_api/exceptions.rb
|
106
108
|
- lib/janio_api/redirect_fetcher.rb
|
107
109
|
- lib/janio_api/resources/base.rb
|
108
110
|
- lib/janio_api/resources/item.rb
|
109
111
|
- lib/janio_api/resources/order.rb
|
110
112
|
- lib/janio_api/version.rb
|
111
|
-
- lib/patch_exception.rb
|
112
|
-
- lib/zeitwerk_loader.rb
|
113
113
|
homepage: https://github.com/PostCo/janio_api
|
114
114
|
licenses:
|
115
115
|
- MIT
|
data/lib/patch_exception.rb
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
module ActiveResource
|
2
|
-
class ConnectionError < StandardError # :nodoc:
|
3
|
-
attr_reader :response
|
4
|
-
|
5
|
-
def initialize(response, message = nil)
|
6
|
-
@response = response
|
7
|
-
@message = message
|
8
|
-
end
|
9
|
-
|
10
|
-
def to_s
|
11
|
-
message = "Failed.".dup
|
12
|
-
message << " Response code = #{response.code}." if response.respond_to?(:code)
|
13
|
-
message << " Response message = #{response.message}." if response.respond_to?(:message)
|
14
|
-
message << " Response body = #{response.body}." if response.respond_to?(:body)
|
15
|
-
message
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|