paypoint-blue 0.2.1 → 0.3.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: 196ba7d8670cc9b3596ef38f0c008f9097cdbf45
4
- data.tar.gz: 43f721a154465801513512613976e36cb6d1067d
3
+ metadata.gz: 82b114473871861140e8796d61ac85a852a273d2
4
+ data.tar.gz: 1034d197286e603f13b8f5b409db165c89ce5edb
5
5
  SHA512:
6
- metadata.gz: ff7818b94e3d54489c54b72371613c5529f4a2c6b9264bdedfc443d90c8705f2722840845de5f88173072447f7e923811ab7f4006126582b12b95f796bcc0a33
7
- data.tar.gz: 5ce4939d65e3ed259f410e5cf4926151b06f9293601056cf948c62e9a2f4cdc96255c3a30d080fb320f8bccb575cc3ecd6e83bd65676c5cf88e840851f5b24f2
6
+ metadata.gz: 721d6ef451f97773e72f2fef33a9895d9a0c624ac527ffad46320e14928d23814f2a29a6ea30c33233b780a67f39b08161e59d9dfeaeb6c60f1141321af5f85d
7
+ data.tar.gz: 041fdf89fdf82280b6459a32f1d7a0992d28d3a4b2f2057b4ed316d01854fe8a9cfb598e1a0a201484382fe79ad531af1b15e376259f64dbbafce2259eaf40e9
@@ -60,11 +60,11 @@ module PayPoint
60
60
  api_password: ENV['BLUE_API_PASSWORD'],
61
61
  **options)
62
62
 
63
- @endpoint = self.class.const_get('ENDPOINTS').fetch(endpoint, endpoint.to_s)
63
+ @endpoint = get_endpoint_or_override_with(endpoint)
64
64
 
65
- @inst_id = inst_id or raise ArgumentError, "missing inst_id"
66
- @api_id = api_id or raise ArgumentError, "missing api_id"
67
- @api_password = api_password or raise ArgumentError, "missing api_password"
65
+ @inst_id = inst_id or raise ArgumentError, 'missing inst_id'
66
+ @api_id = api_id or raise ArgumentError, 'missing api_id'
67
+ @api_password = api_password or raise ArgumentError, 'missing api_password'
68
68
 
69
69
  options[:url] = @endpoint
70
70
  @options = options
@@ -78,8 +78,12 @@ module PayPoint
78
78
 
79
79
  attr_reader :inst_id, :options
80
80
 
81
+ def get_endpoint_or_override_with(endpoint)
82
+ self.class.const_get('ENDPOINTS').fetch(endpoint, endpoint.to_s)
83
+ end
84
+
81
85
  def client_options
82
- options.select { |k,v| Faraday::ConnectionOptions.members.include?(k) }
86
+ options.select { |k, _| Faraday::ConnectionOptions.members.include?(k) }
83
87
  end
84
88
 
85
89
  def build_client
@@ -114,8 +118,6 @@ module PayPoint
114
118
  f.adapter Faraday.default_adapter
115
119
  end
116
120
  end
117
-
118
121
  end
119
-
120
122
  end
121
123
  end
@@ -36,6 +36,9 @@ module PayPoint
36
36
  # types of errors
37
37
  class Client < Error; end
38
38
 
39
+ # Specific error class for non existing sessions
40
+ class NotFound < Error; end
41
+
39
42
  # Specific error class for errors with a +'V'+ outcome code
40
43
  class Validation < Error; end
41
44
 
@@ -19,8 +19,6 @@ module PayPoint
19
19
  end
20
20
  end
21
21
  end
22
-
23
22
  end
24
-
25
23
  end
26
24
  end
@@ -11,7 +11,11 @@ module PayPoint
11
11
  end
12
12
 
13
13
  module ClassMethods
14
- attr_accessor :shortcuts
14
+ def shortcuts
15
+ @shortcuts ||= {}
16
+ end
17
+
18
+ attr_writer :shortcuts
15
19
 
16
20
  # Define a payload shortcut
17
21
  #
@@ -27,11 +31,10 @@ module PayPoint
27
31
  # @param [Symbol] key the shortcut key
28
32
  # @param [String] path a path into the payload with segments
29
33
  # separated by dots (e.g. +'transaction.money.amount.fixed'+)
30
- def shortcut(key, path=nil)
34
+ def shortcut(key, path = nil)
31
35
  if path.nil?
32
- shortcuts && shortcuts[key]
36
+ shortcuts[key]
33
37
  else
34
- self.shortcuts ||= {}
35
38
  shortcuts[key] = path
36
39
  end
37
40
  end
@@ -83,8 +86,6 @@ module PayPoint
83
86
  def interpolate_values(value, payload)
84
87
  value.gsub(/%(\w+)%/) {|m| payload[$1.to_sym] || m}
85
88
  end
86
-
87
89
  end
88
-
89
90
  end
90
91
  end
@@ -28,13 +28,23 @@ module PayPoint
28
28
  else
29
29
  raise Error::Client, response_values(env)
30
30
  end
31
- elsif env.status >= 400
31
+ elsif not_found?(env)
32
+ raise Error::NotFound, response_values(env)
33
+ elsif client_error?(env)
32
34
  raise Error::Client, response_values(env)
33
35
  end
34
36
  end
35
37
 
36
38
  private
37
39
 
40
+ def not_found?(env)
41
+ env.status == 404 && env.body[:reason_code] == "A400"
42
+ end
43
+
44
+ def client_error?(env)
45
+ env.status >= 400
46
+ end
47
+
38
48
  def fetch_outcome(env)
39
49
  env.body.is_a?(Hash) && env.body[:outcome]
40
50
  end
@@ -46,8 +56,6 @@ module PayPoint
46
56
  body: env.body
47
57
  }
48
58
  end
49
-
50
59
  end
51
-
52
60
  end
53
61
  end
@@ -1,5 +1,5 @@
1
1
  module PayPoint
2
2
  module Blue
3
- VERSION = "0.2.1"
3
+ VERSION = "0.3.0"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: paypoint-blue
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Laszlo Bacsi
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-05-05 00:00:00.000000000 Z
11
+ date: 2015-05-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday