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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fdaeee0666ddaa0e81f9425aad6e689dd5853570
4
- data.tar.gz: 7b10ff686963faebee6dbd019c0726e9599c94c4
3
+ metadata.gz: 8d73c3eaf3525595e95f21ca48fb2217fd566899
4
+ data.tar.gz: d45329f75e0b049ceff0b374b241faee4322df2f
5
5
  SHA512:
6
- metadata.gz: a7328447e7f2bd6871fbf40f0613a5eb4591b169cc1008ac9fbecdbdbef9d78c84de04d21b3737a07f4686e1359cfc0e770f26aae6ba66293d1247c61c1d2dbe
7
- data.tar.gz: 50d146942dd556d3606ba348404c70f08b46990e4cecac8596023ff5f7f5ab0820227857f6cbc717e4b71d3c7cb7ddb8df4d7c04af5bb142a208d2a3efd1c31b
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`)
@@ -18,7 +18,7 @@ module XEClient
18
18
  amount: amount,
19
19
  )
20
20
  raw_response = ConvertFromRequest.(args)
21
- ConvertFromResponse.new(raw_response: raw_response)
21
+ ConvertFromResponse.(raw_response)
22
22
  end
23
23
 
24
24
  private
@@ -0,0 +1,4 @@
1
+ module XEClient
2
+ class AuthenticationError < Error
3
+ end
4
+ end
@@ -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
@@ -3,7 +3,6 @@ module XEClient
3
3
 
4
4
  attribute :from, String, lazy: true, default: :default_from
5
5
  attribute :to, Array, lazy: true, default: :default_to
6
- attribute :raw_response, IndifferentHash
7
6
 
8
7
  private
9
8
 
@@ -1,3 +1,3 @@
1
1
  module XEClient
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
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.1.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-22 00:00:00.000000000 Z
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