xe_client 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/lib/xe_client/client.rb +1 -1
- data/lib/xe_client/errors/authentication_error.rb +4 -0
- data/lib/xe_client/errors/error.rb +22 -0
- data/lib/xe_client/responses/base_response.rb +24 -0
- data/lib/xe_client/responses/convert_from_response.rb +0 -1
- data/lib/xe_client/version.rb +1 -1
- data/lib/xe_client.rb +2 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8d73c3eaf3525595e95f21ca48fb2217fd566899
|
4
|
+
data.tar.gz: d45329f75e0b049ceff0b374b241faee4322df2f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4eb21c50a7ef43dae2b59bfebd27fd3050540d640638ce99ba5d0b26f579de4b43cd0e458d6f4e83b037fe28295edbba0c300de8f2ac034a79762c28df026539
|
7
|
+
data.tar.gz: 4c7f3a50da749b7ce55d69a70508db724af451969af26c8ba5da2d404102ea0953fc2b65a02d1f456aec92365c19f2b90e7e5479d14b90226e98313632037639
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,11 @@
|
|
2
2
|
All notable changes to this project will be documented in this file.
|
3
3
|
This project adheres to [Semantic Versioning](http://semver.org/).
|
4
4
|
|
5
|
+
## [0.2.0] - 2016-06-30
|
6
|
+
### Added
|
7
|
+
- Raise XEClient::AuthenticationError when there's an auth issue
|
8
|
+
- Raise XEClient::Error for all other errors
|
9
|
+
|
5
10
|
## [0.1.0] - 2016-06-22
|
6
11
|
### Added
|
7
12
|
- Add initial working version (`#convert_from`)
|
data/lib/xe_client/client.rb
CHANGED
@@ -0,0 +1,22 @@
|
|
1
|
+
module XEClient
|
2
|
+
class Error < StandardError
|
3
|
+
|
4
|
+
CODE_ERROR_MAP = {
|
5
|
+
1 => "AuthenticationError",
|
6
|
+
}
|
7
|
+
attr_accessor :code
|
8
|
+
|
9
|
+
def self.new_from_response(response)
|
10
|
+
return nil if response.code.nil?
|
11
|
+
klass = if class_name = CODE_ERROR_MAP[response.code]
|
12
|
+
XEClient.const_get(class_name)
|
13
|
+
else
|
14
|
+
self
|
15
|
+
end
|
16
|
+
error = klass.new(response.message)
|
17
|
+
error.code = response.code
|
18
|
+
error
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
end
|
@@ -2,6 +2,30 @@ module XEClient
|
|
2
2
|
class BaseResponse
|
3
3
|
|
4
4
|
include Virtus.model
|
5
|
+
attribute :raw_response, IndifferentHash
|
6
|
+
attribute :code, Integer, lazy: true, default: :default_code
|
7
|
+
attribute :message, String, lazy: true, default: :default_message
|
8
|
+
attribute :error, Object, lazy: true, default: :default_error
|
9
|
+
|
10
|
+
def self.call(raw_response)
|
11
|
+
response = self.new(raw_response: raw_response)
|
12
|
+
raise response.error if response.error.present?
|
13
|
+
response
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def default_code
|
19
|
+
raw_response[:code]
|
20
|
+
end
|
21
|
+
|
22
|
+
def default_message
|
23
|
+
raw_response[:message]
|
24
|
+
end
|
25
|
+
|
26
|
+
def default_error
|
27
|
+
Error.new_from_response(self)
|
28
|
+
end
|
5
29
|
|
6
30
|
end
|
7
31
|
end
|
data/lib/xe_client/version.rb
CHANGED
data/lib/xe_client.rb
CHANGED
@@ -10,6 +10,8 @@ require "xe_client/requests/base_request"
|
|
10
10
|
require "xe_client/requests/convert_from_request"
|
11
11
|
require "xe_client/responses/base_response"
|
12
12
|
require "xe_client/responses/convert_from_response"
|
13
|
+
require "xe_client/errors/error"
|
14
|
+
require "xe_client/errors/authentication_error"
|
13
15
|
|
14
16
|
module XEClient
|
15
17
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: xe_client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ramon Tayag
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-06-
|
11
|
+
date: 2016-06-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -171,6 +171,8 @@ files:
|
|
171
171
|
- bin/setup
|
172
172
|
- lib/xe_client.rb
|
173
173
|
- lib/xe_client/client.rb
|
174
|
+
- lib/xe_client/errors/authentication_error.rb
|
175
|
+
- lib/xe_client/errors/error.rb
|
174
176
|
- lib/xe_client/indifferent_hash.rb
|
175
177
|
- lib/xe_client/models/quote.rb
|
176
178
|
- lib/xe_client/requests/base_request.rb
|