glimr-api-client 0.1.13 → 0.2.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6cbd60fb640a1ffbeae5e9bb2b4e886a9013095a
4
- data.tar.gz: 932ef88b4ea067de7969970e9ba2f71142a8c339
3
+ metadata.gz: 57083af961a58b65ac82caa95841d63b96bb2b49
4
+ data.tar.gz: cd7283d7a308d26be3cb023a11e40b3ae1992e58
5
5
  SHA512:
6
- metadata.gz: 22d04e89360d24aa9a537ef7a8bbe26772b31f915fc3b794935932316e14b90fdb77f2ef565571a1a503a1f4b7373485cce689134a81f3936bfae4ad82b7a043
7
- data.tar.gz: 033de5166aaf1c4f2bb39ad393a40e9e2799bca4edde1ef1c0f0c08915c7aeaa4c4df3b722017e56b1a4338c8ef2080bb9a71520621c4d0c30d0d2fe62f2eb2e
6
+ metadata.gz: a043236ebe96657fa5ca5b5b099cabba86bb5283a5a7fb29adc1eb1e0cba3ee36a3251205b94ae0df5993f510c5989c25f1a69692ee3004a17167f9ce846c6a6
7
+ data.tar.gz: 676991232ce35c066064dc63574995a1085cb8d27f5fe599cfd099945d7f8d8d6717390d90b30758c486ace558cf2fcb27aac81208f046bbc72e3bdd975d580f
@@ -1,50 +1,13 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- glimr-api-client (0.1.13)
4
+ glimr-api-client (0.1.14)
5
5
  excon (~> 0.51)
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
9
9
  specs:
10
10
  abstract_type (0.0.7)
11
- actioncable (5.0.0.1)
12
- actionpack (= 5.0.0.1)
13
- nio4r (~> 1.2)
14
- websocket-driver (~> 0.6.1)
15
- actionmailer (5.0.0.1)
16
- actionpack (= 5.0.0.1)
17
- actionview (= 5.0.0.1)
18
- activejob (= 5.0.0.1)
19
- mail (~> 2.5, >= 2.5.4)
20
- rails-dom-testing (~> 2.0)
21
- actionpack (5.0.0.1)
22
- actionview (= 5.0.0.1)
23
- activesupport (= 5.0.0.1)
24
- rack (~> 2.0)
25
- rack-test (~> 0.6.3)
26
- rails-dom-testing (~> 2.0)
27
- rails-html-sanitizer (~> 1.0, >= 1.0.2)
28
- actionview (5.0.0.1)
29
- activesupport (= 5.0.0.1)
30
- builder (~> 3.1)
31
- erubis (~> 2.7.0)
32
- rails-dom-testing (~> 2.0)
33
- rails-html-sanitizer (~> 1.0, >= 1.0.2)
34
- activejob (5.0.0.1)
35
- activesupport (= 5.0.0.1)
36
- globalid (>= 0.3.6)
37
- activemodel (5.0.0.1)
38
- activesupport (= 5.0.0.1)
39
- activerecord (5.0.0.1)
40
- activemodel (= 5.0.0.1)
41
- activesupport (= 5.0.0.1)
42
- arel (~> 7.0)
43
- activesupport (5.0.0.1)
44
- concurrent-ruby (~> 1.0, >= 1.0.2)
45
- i18n (~> 0.7)
46
- minitest (~> 5.1)
47
- tzinfo (~> 1.1)
48
11
  adamantium (0.2.0)
49
12
  ice_nine (~> 0.11.0)
50
13
  memoizable (~> 0.4.0)
@@ -53,9 +16,7 @@ GEM
53
16
  abstract_type (~> 0.0.7)
54
17
  adamantium (~> 0.2)
55
18
  equalizer (~> 0.0.11)
56
- arel (7.1.4)
57
19
  ast (2.3.0)
58
- builder (3.2.2)
59
20
  byebug (9.0.6)
60
21
  capybara (2.10.1)
61
22
  addressable
@@ -70,24 +31,15 @@ GEM
70
31
  concord (0.1.5)
71
32
  adamantium (~> 0.2.0)
72
33
  equalizer (~> 0.0.9)
73
- concurrent-ruby (1.0.2)
74
34
  diff-lcs (1.2.5)
75
35
  docile (1.1.5)
76
36
  equalizer (0.0.11)
77
- erubis (2.7.0)
78
37
  excon (0.54.0)
79
38
  fuubar (2.2.0)
80
39
  rspec-core (~> 3.0)
81
40
  ruby-progressbar (~> 1.4)
82
- globalid (0.3.7)
83
- activesupport (>= 4.1.0)
84
- i18n (0.7.0)
85
41
  ice_nine (0.11.2)
86
42
  json (2.0.2)
87
- loofah (2.0.3)
88
- nokogiri (>= 1.5.9)
89
- mail (2.6.4)
90
- mime-types (>= 1.16, < 4)
91
43
  memoizable (0.4.2)
92
44
  thread_safe (~> 0.3, >= 0.3.1)
93
45
  method_source (0.8.2)
@@ -95,7 +47,6 @@ GEM
95
47
  mime-types-data (~> 3.2015)
96
48
  mime-types-data (3.2016.0521)
97
49
  mini_portile2 (2.1.0)
98
- minitest (5.9.1)
99
50
  morpher (0.2.6)
100
51
  abstract_type (~> 0.0.7)
101
52
  adamantium (~> 0.2.0)
@@ -124,7 +75,6 @@ GEM
124
75
  mutant-rspec (0.8.11)
125
76
  mutant (~> 0.8.11)
126
77
  rspec-core (>= 3.4.0, < 3.6.0)
127
- nio4r (1.2.1)
128
78
  nokogiri (1.6.8.1)
129
79
  mini_portile2 (~> 2.1.0)
130
80
  parallel (1.9.0)
@@ -142,32 +92,13 @@ GEM
142
92
  rack (2.0.1)
143
93
  rack-test (0.6.3)
144
94
  rack (>= 1.0)
145
- rails (5.0.0.1)
146
- actioncable (= 5.0.0.1)
147
- actionmailer (= 5.0.0.1)
148
- actionpack (= 5.0.0.1)
149
- actionview (= 5.0.0.1)
150
- activejob (= 5.0.0.1)
151
- activemodel (= 5.0.0.1)
152
- activerecord (= 5.0.0.1)
153
- activesupport (= 5.0.0.1)
154
- bundler (>= 1.3.0, < 2.0)
155
- railties (= 5.0.0.1)
156
- sprockets-rails (>= 2.0.0)
157
- rails-dom-testing (2.0.1)
158
- activesupport (>= 4.2.0, < 6.0)
159
- nokogiri (~> 1.6.0)
160
- rails-html-sanitizer (1.0.3)
161
- loofah (~> 2.0)
162
- railties (5.0.0.1)
163
- actionpack (= 5.0.0.1)
164
- activesupport (= 5.0.0.1)
165
- method_source
166
- rake (>= 0.8.7)
167
- thor (>= 0.18.1, < 2.0)
168
95
  rainbow (2.1.0)
169
96
  rake (10.5.0)
170
97
  regexp_parser (0.3.6)
98
+ rspec (3.5.0)
99
+ rspec-core (~> 3.5.0)
100
+ rspec-expectations (~> 3.5.0)
101
+ rspec-mocks (~> 3.5.0)
171
102
  rspec-core (3.5.4)
172
103
  rspec-support (~> 3.5.0)
173
104
  rspec-expectations (3.5.0)
@@ -176,14 +107,6 @@ GEM
176
107
  rspec-mocks (3.5.0)
177
108
  diff-lcs (>= 1.2.0, < 2.0)
178
109
  rspec-support (~> 3.5.0)
179
- rspec-rails (3.5.2)
180
- actionpack (>= 3.0)
181
- activesupport (>= 3.0)
182
- railties (>= 3.0)
183
- rspec-core (~> 3.5.0)
184
- rspec-expectations (~> 3.5.0)
185
- rspec-mocks (~> 3.5.0)
186
- rspec-support (~> 3.5.0)
187
110
  rspec-support (3.5.0)
188
111
  rubocop (0.45.0)
189
112
  parser (>= 2.3.1.1, < 3.0)
@@ -198,18 +121,7 @@ GEM
198
121
  simplecov-html (~> 0.10.0)
199
122
  simplecov-html (0.10.0)
200
123
  slop (3.6.0)
201
- sprockets (3.7.0)
202
- concurrent-ruby (~> 1.0)
203
- rack (> 1, < 3)
204
- sprockets-rails (3.2.0)
205
- actionpack (>= 4.0)
206
- activesupport (>= 4.0)
207
- sprockets (>= 3.0.0)
208
- sqlite3 (1.3.12)
209
- thor (0.19.1)
210
124
  thread_safe (0.3.5)
211
- tzinfo (1.2.2)
212
- thread_safe (~> 0.1)
213
125
  unicode-display_width (1.1.1)
214
126
  unparser (0.2.5)
215
127
  abstract_type (~> 0.0.7)
@@ -219,9 +131,6 @@ GEM
219
131
  equalizer (~> 0.0.9)
220
132
  parser (~> 2.3.0)
221
133
  procto (~> 0.0.2)
222
- websocket-driver (0.6.4)
223
- websocket-extensions (>= 0.1.0)
224
- websocket-extensions (0.1.2)
225
134
  xpath (2.0.0)
226
135
  nokogiri (~> 1.3)
227
136
 
@@ -236,11 +145,9 @@ DEPENDENCIES
236
145
  glimr-api-client!
237
146
  mutant-rspec (~> 0.8)
238
147
  pry-byebug (~> 3.4)
239
- rails (~> 5.0)
240
148
  rake (~> 10.0)
241
- rspec-rails (~> 3.5)
149
+ rspec (~> 3.5)
242
150
  rubocop (~> 0.41)
243
- sqlite3 (~> 1.3)
244
151
 
245
152
  BUNDLED WITH
246
153
  1.13.6
data/README.md CHANGED
@@ -9,10 +9,15 @@ use in various UK tribunals.
9
9
 
10
10
  ### Configuration
11
11
 
12
- The gem expects a `GLIMR_API_URL` environment variable, providing the endpoint at which the API can be found. This will be something like; `https://glimr-api.taxtribunals.dsd.io`
12
+ The gem expects a `GLIMR_API_URL` environment variable, providing the
13
+ endpoint at which the API can be found. This will be something like;
14
+ `https://glimr-api.taxtribunals.dsd.io`
13
15
 
14
16
  This URL must be accessible from wherever your code is running.
15
17
 
18
+ If you need to set the api time, use the `GLIMR_API_TIMEOUT_SECONDS`
19
+ environment variable. This defaults to 5 seconds.
20
+
16
21
  ### Check Availablity
17
22
 
18
23
  ```ruby
@@ -26,23 +31,97 @@ is received; this includes network errors and timeouts.
26
31
  ### Find a case
27
32
 
28
33
  ```ruby
29
- GlimrApiClient::Case.find(<case reference>)
34
+ GlimrApiClient::Case.find(<case reference>, <confirmation code>)
30
35
  ```
31
36
 
32
37
  Find a case on GLiMR using the case reference (‘TT/2012/00001’ in Tax
33
- Tribunals, for example). `#title` returns case title from GLiMR, and `#fees`
34
- returns an array of anonymous objects (OpenStructs) detailing any
35
- outstanding fees. Each fee object responds to `#glimr_id`,
36
- `#description`, and `#amount`.
38
+ Tribunals, for example) and confirmation code. `#title` returns case
39
+ title from GLiMR, and `#fees` returns an array of anonymous objects
40
+ (OpenStructs) detailing any outstanding fees. Each fee object responds
41
+ to `#glimr_id`, `#description`, and `#amount`.
37
42
 
38
43
  Please note that `#amount` returns the amount in pence.
39
44
 
40
45
  If a case is not found, the client will raise `GlimrApiClient::CaseNotFound`.
41
46
 
47
+ ### Pay by Account
48
+
49
+ ```ruby
50
+ GlimrApiClient::PayByAccount.call(<params>)
51
+ ```
52
+
53
+ Pay tribunal fees with a Pay By Account reference.
54
+
55
+ Params are as follows:
56
+
57
+ ```ruby
58
+ feeLiabilityId: 123456789
59
+ pbaAccountNumber: "PBA1234567"
60
+ pbaConfirmationCode: "AC-D3-46" or "ACD346" - Glimr accepts hyphens
61
+ pbaTransactionReference: User's own reference. Max of 240 characters
62
+ amountToPayInPence: 9999
63
+ ```
64
+
65
+ ### Help With Fees Request
66
+
67
+ ```ruby
68
+ GlimrApiClient::HwfRequested.call(<params>)
69
+ ```
70
+
71
+ Pay tribunal fees with a Help With Fees reference.
72
+
73
+ Params are as follows:
74
+
75
+ ```ruby
76
+ feeLiabilityId: 123456789
77
+ hwfRequestReference: ABCD12345
78
+ amountToPayInPence: 9999
79
+ ```
80
+
81
+ ### Register a New Case
82
+
83
+ ```ruby
84
+ GlimrApiClient::RegisterNewCase.call(<case parameters>)
85
+ ```
86
+
87
+ Accepts the following parameters:
88
+
89
+ ```ruby
90
+ jurisdictionId: 8,
91
+ onlineMappingCode: 'something',
92
+ contactPhone: '1234',
93
+ contactFax: '5678',
94
+ contactEmail: 'foo_at_bar.com',
95
+ contactPreference: 'Email',
96
+ contactFirstName: 'Alice',
97
+ contactLastName: 'Caroll',
98
+ contactStreet1: '5_Wonderstreet',
99
+ contactStreet2: 'contact_street_2',
100
+ contactStreet3: 'contact_street_3',
101
+ contactStreet4: 'contact_street_4',
102
+ contactCity: 'London',
103
+ documentsURL: 'http...google.com',
104
+ repPhone: '7890',
105
+ repFax: '6789',
106
+ repEmail: 'bar_at_baz.com',
107
+ repPreference: 'Fax',
108
+ repReference: 'MYREF',
109
+ repIsAuthorised: 'Yes',
110
+ repOrganisationName: 'Acme._Ltd.',
111
+ repFAO: 'Bob_Hope',
112
+ repStreet1: '5_Repstreet',
113
+ repStreet2: 'Repton',
114
+ repStreet3: 'Repshire',
115
+ repStreet4: 'Rep_st._4',
116
+ repCity: 'City_of_reps'
117
+ ```
118
+
119
+ Currently only `jurisdictionId` and `onlineMappingCode` are mandatory.
120
+
42
121
  ### Update a case, mark as paid
43
122
 
44
123
  ```ruby
45
- GlimrApiClient::Update.call(<Fee object>)
124
+ GlimrApiClient::Update.call(<Fee object>)
46
125
  ```
47
126
 
48
127
  Update a GLiMR case to indicate that payment has been received for a
data/Rakefile CHANGED
@@ -14,11 +14,6 @@ RDoc::Task.new(:rdoc) do |rdoc|
14
14
  rdoc.rdoc_files.include('lib/**/*.rb')
15
15
  end
16
16
 
17
- APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__)
18
- load 'rails/tasks/engine.rake'
19
-
20
- load 'rails/tasks/statistics.rake'
21
-
22
17
  require 'bundler/gem_tasks'
23
18
 
24
19
  require 'rspec/core/rake_task'
data/circle.yml CHANGED
@@ -1,6 +1,6 @@
1
1
  database:
2
2
  override:
3
- - bundle exec rake db:setup
3
+ - touch 'not needed'
4
4
 
5
5
  test:
6
6
  override:
@@ -20,11 +20,9 @@ Gem::Specification.new do |spec|
20
20
  spec.add_development_dependency 'fuubar', '~> 2.0'
21
21
  spec.add_development_dependency 'mutant-rspec', '~> 0.8'
22
22
  spec.add_development_dependency 'pry-byebug', '~> 3.4'
23
- spec.add_development_dependency 'rails', '~> 5.0'
24
23
  spec.add_development_dependency 'rake', '~> 10.0'
25
- spec.add_development_dependency 'rspec-rails', '~> 3.5'
24
+ spec.add_development_dependency 'rspec', '~> 3.5'
26
25
  spec.add_development_dependency 'rubocop', '~> 0.41'
27
- spec.add_development_dependency 'sqlite3', '~> 1.3'
28
26
 
29
27
  spec.add_dependency 'excon', '~> 0.51'
30
28
  end
@@ -6,6 +6,8 @@ require 'glimr_api_client/available'
6
6
  require 'glimr_api_client/case'
7
7
  require 'glimr_api_client/update'
8
8
  require 'glimr_api_client/register_new_case'
9
+ require 'glimr_api_client/pay_by_account'
10
+ require 'glimr_api_client/hwf_requested'
9
11
 
10
12
 
11
13
  module GlimrApiClient
@@ -4,11 +4,11 @@ module GlimrApiClient
4
4
  module Api
5
5
  def post
6
6
  client("#{api_url}#{endpoint}").post(body: request_body.to_json).tap { |resp|
7
- handle_response_errors(resp)
7
+ handle_response_errors(resp) if (400..599).cover?(resp.status)
8
8
  @body = resp.body
9
9
  }
10
10
  rescue Excon::Error => e
11
- re_raise_error(endpoint, e)
11
+ re_raise_error(message: e)
12
12
  end
13
13
 
14
14
  def response_body
@@ -27,22 +27,19 @@ module GlimrApiClient
27
27
 
28
28
  # Only timeouts and network issues raise errors.
29
29
  def handle_response_errors(resp)
30
- if resp.status.equal?(404) && endpoint.eql?('/requestpayablecasefees')
31
- raise CaseNotFound, resp.status
32
- elsif (400..599).cover?(resp.status)
33
- re_raise_error(endpoint, resp.status)
34
- end
30
+ # TODO: log error as well.
31
+ # Deal with cases where we get an otherwise unparseable response body.
32
+ body = begin
33
+ JSON.parse(resp.body, symbolize_names: true)
34
+ rescue JSON::ParserError
35
+ { message: resp.status }
36
+ end
37
+ re_raise_error(body)
35
38
  end
36
39
 
37
- def re_raise_error(docpath, e)
38
- case docpath
39
- when '/paymenttaken'
40
- raise PaymentNotificationFailure, e
41
- when '/registernewcase'
42
- raise RegisterNewCaseFailure, e
43
- else
44
- raise Unavailable, e
45
- end
40
+ def re_raise_error(body)
41
+ error = body.fetch(:message)
42
+ raise Unavailable, error
46
43
  end
47
44
 
48
45
  def client(uri)
@@ -52,7 +49,8 @@ module GlimrApiClient
52
49
  'Content-Type' => 'application/json',
53
50
  'Accept' => 'application/json'
54
51
  },
55
- persistent: true
52
+ persistent: true,
53
+ read_timeout: ENV.fetch('GLIMR_API_TIMEOUT_SECONDS', 5)
56
54
  )
57
55
  end
58
56
  end
@@ -1,9 +1,14 @@
1
1
  module GlimrApiClient
2
+ # TODO: rename so it follow api spec
2
3
  class Case
4
+ class NotFound < StandardError; end
5
+ class InvalidCaseNumber < StandardError; end
6
+
3
7
  include GlimrApiClient::Api
4
8
 
5
9
  TRIBUNAL_JURISDICTION_ID = 8
6
10
 
11
+ # TODO: Case should use `#call(params)` directly, like everything else.
7
12
  def self.find(case_reference, confirmation_code)
8
13
  new(case_reference, confirmation_code).call
9
14
  end
@@ -18,24 +23,31 @@ module GlimrApiClient
18
23
  self
19
24
  end
20
25
 
26
+ # Case title is returned with each fee liability, rather than as a top-level
27
+ # attribute of the case. If there are any unpaid fee liabilities, we want to
28
+ # take the title from the first of these (because that is the most relevant
29
+ # title)
21
30
  def title
22
- # This should be;
23
- #
24
- # @title ||= response_body.fetch(:caseTitle)
25
- #
26
- # But, a change in the Glimr API means that the title is
27
- # currently being returned with each fee liability. So,
28
- # for the time being, we will fetch it from there.
29
- # I'm leaving the "Missing Title" text so that nobody forgets
30
- # that this needs to be fixed, preferably by changing the
31
- # Glimr RequestPayableCaseFees API call back to returning
32
- # caseTitle at the top-level of the response data.
33
-
34
- @title ||= fees.any? ? fees.first.case_title : "Missing Title"
31
+ @title ||= begin
32
+ fee = unpaid_fees.any? ? unpaid_fees.first : all_fees.first
33
+ fee.nil? ? 'Missing Title' : fee.case_title
34
+ end
35
35
  end
36
36
 
37
+ # We only care about outstanding fee liabilities, wrt what we are asking the
38
+ # taxpayer to pay
37
39
  def fees
38
- @fees ||= response_body.fetch(:feeLiabilities).map do |fee|
40
+ unpaid_fees
41
+ end
42
+
43
+ private
44
+
45
+ def unpaid_fees
46
+ @unpaid_fees ||= all_fees.find_all {|fee| fee.amount > 0}
47
+ end
48
+
49
+ def all_fees
50
+ @all_fees ||= response_body.fetch(:feeLiabilities).map do |fee|
39
51
  OpenStruct.new(
40
52
  glimr_id: Integer(fee.fetch(:feeLiabilityId)),
41
53
  description: fee.fetch(:onlineFeeTypeDescription),
@@ -45,10 +57,19 @@ module GlimrApiClient
45
57
  end
46
58
  end
47
59
 
48
- private
49
-
50
60
  def endpoint
51
- '/requestpayablecasefees'
61
+ '/requestcasefees'
62
+ end
63
+
64
+ def re_raise_error(body)
65
+ error = body.fetch(:message, nil)
66
+ case body.fetch(:glimrerrorcode, nil)
67
+ when 212 # TribunalCase for CaseNumber not found
68
+ raise NotFound, error
69
+ when 213 # Invalid CaseNumber/CaseConfirmationCode combination
70
+ raise InvalidCaseNumber, error
71
+ end
72
+ super(message: error)
52
73
  end
53
74
 
54
75
  def request_body
@@ -0,0 +1,40 @@
1
+ module GlimrApiClient
2
+ class HwfRequested < Base
3
+ class FeeLiabilityNotFound < StandardError; end;
4
+ class InvalidAmount < StandardError; end
5
+
6
+ attr_reader :request_body
7
+
8
+ def initialize(params)
9
+ @request_body = params
10
+ end
11
+
12
+ private
13
+
14
+ def check_request!
15
+ errors = []
16
+ [
17
+ :feeLiabilityId,
18
+ :hwfRequestReference
19
+ ].each do |required|
20
+ errors << required if request_body.fetch(required, nil).nil?
21
+ end
22
+ raise RequestError, errors unless errors.empty?
23
+ end
24
+
25
+ def endpoint
26
+ '/hwfrequested'
27
+ end
28
+
29
+ def re_raise_error(body)
30
+ error = body.fetch(:message, nil)
31
+ case body.fetch(:glimrerrorcode, nil)
32
+ when 611 # FeeLiability not found for FeeLiabilityID
33
+ raise FeeLiabilityNotFound, error
34
+ when 612 # Invalid AmountToPay
35
+ raise InvalidAmount, error
36
+ end
37
+ super(message: error)
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,61 @@
1
+ module GlimrApiClient
2
+ class PayByAccount < Base
3
+ class FeeLiabilityNotFound < StandardError; end;
4
+ class AccountNotFound < StandardError; end
5
+ class InvalidAccountAndConfirmation < StandardError; end
6
+ class InvalidAmount < StandardError; end
7
+ class GlobalStatusInactive < StandardError; end
8
+ class JurisdictionStatusInactive < StandardError; end
9
+ class UnspecifiedError < StandardError; end
10
+
11
+ attr_reader :request_body
12
+
13
+ def initialize(params)
14
+ @request_body = params
15
+ end
16
+
17
+ private
18
+
19
+ def check_request!
20
+ errors = []
21
+ [
22
+ :feeLiabilityId,
23
+ :pbaAccountNumber,
24
+ :pbaConfirmationCode,
25
+ :pbaTransactionReference
26
+ ].each do |required|
27
+ errors << required if request_body.fetch(required, nil).nil?
28
+ end
29
+
30
+ if request_body.fetch(:pbaTransactionReference, '').size > 240
31
+ errors << :pbaTransactionReferenceTooLong
32
+ end
33
+ raise RequestError, errors unless errors.empty?
34
+ end
35
+
36
+ def endpoint
37
+ '/pbapaymentrequest'
38
+ end
39
+
40
+ # rubocop:disable Metrics/CyclomaticComplexity
41
+ def re_raise_error(body)
42
+ error = body.fetch(:message, nil)
43
+ case body.fetch(:glimrerrorcode, nil)
44
+ when 511 # FeeLiability not found for FeeLiabilityID
45
+ raise FeeLiabilityNotFound, error
46
+ when 512 # PBA account \w+ not found
47
+ raise AccountNotFound, error
48
+ when 513 # Invalid PBAAccountNumber/PBAConfirmationCode combination
49
+ raise InvalidAccountAndConfirmation, error
50
+ when 514 # Invalid AmountToPay
51
+ raise InvalidAmount, error
52
+ when 521 # PBAGlobalStatus is inactive
53
+ raise GlobalStatusInactive, error
54
+ when 522 # PBAJurisdictionStatus is inactive
55
+ raise JurisdictionStatusInactive, error
56
+ end
57
+ super(message: error)
58
+ end
59
+ # rubocop:enable Metrics/CyclomaticComplexity
60
+ end
61
+ end
@@ -1,7 +1,12 @@
1
1
  module GlimrApiClient
2
2
  class RegisterNewCase < Base
3
+ class JurisdictionNotFound < StandardError; end
4
+ class OnlineMappingNotFoundOrInvalid < StandardError; end
5
+ class CaseCreationFailed < StandardError; end
6
+ attr_reader :request_body
7
+
3
8
  def initialize(params)
4
- @params = params
9
+ @request_body = params
5
10
  end
6
11
 
7
12
  private
@@ -21,8 +26,17 @@ module GlimrApiClient
21
26
  '/registernewcase'
22
27
  end
23
28
 
24
- def request_body
25
- @params
29
+ def re_raise_error(body)
30
+ error = body.fetch(:message, nil)
31
+ case body.fetch(:glimrerrorcode, nil)
32
+ when 411 # Jusidiction not found
33
+ raise JurisdictionNotFound, error
34
+ when 412 # Online Mapping not found or invalid
35
+ raise OnlineMappingNotFoundOrInvalid, error
36
+ when 421 # Creation failed (due to a database problem)
37
+ raise CaseCreationFailed, error
38
+ end
39
+ super(message: error)
26
40
  end
27
41
  end
28
42
  end
@@ -1,15 +1,31 @@
1
1
  module GlimrApiClient
2
+ # TODO: rename so it follow api spec
2
3
  class Update < Base
3
- def initialize(fee)
4
- @fee = fee
4
+ class FeeLiabilityNotFound < StandardError; end
5
+ class PaymentReferenceInvalidFormat < StandardError; end
6
+ class GovPayReferenceInvalidFormat < StandardError; end
7
+ class InvalidAmount < StandardError; end
8
+ class GovPayReferenceExistsOnSystem < StandardError; end
9
+
10
+ # TODO: Move this and initialize into Base. It's the same for all but Case.
11
+ attr_reader :request_body
12
+
13
+ def initialize(params)
14
+ @request_body = params
5
15
  end
6
16
 
7
17
  private
8
18
 
19
+ # TODO: Set the attributes in a constant and move this to Base.
9
20
  def check_request!
10
21
  errors = []
11
- [:feeLiabilityId, :paymentReference, :govpayReference, :paidAmountInPence].each do |required|
12
- errors << required if request_body.fetch(required).nil?
22
+ [
23
+ :feeLiabilityId,
24
+ :paymentReference,
25
+ :govpayReference,
26
+ :paidAmountInPence
27
+ ].each do |required|
28
+ errors << required if request_body.fetch(required, nil).nil?
13
29
  end
14
30
  raise RequestError, errors unless errors.empty?
15
31
  end
@@ -18,13 +34,21 @@ module GlimrApiClient
18
34
  '/paymenttaken'
19
35
  end
20
36
 
21
- def request_body
22
- {
23
- feeLiabilityId: @fee.glimr_id,
24
- paymentReference: @fee.govpay_reference,
25
- govpayReference: @fee.govpay_payment_id,
26
- paidAmountInPence: @fee.amount
27
- }
37
+ def re_raise_error(body)
38
+ error = body.fetch(:message, nil)
39
+ case body.fetch(:glimrerrorcode, nil)
40
+ when 311 # FeeLiability not found
41
+ raise FeeLiabilityNotFound, error
42
+ when 312 # Invalid format for PaymentReference
43
+ raise PaymentReferenceInvalidFormat, error
44
+ when 314 # Invalid format for GovPayReference
45
+ raise GovPayReferenceInvalidFormat, error
46
+ when 315 # Invalid PaidAmount
47
+ raise InvalidAmount, error
48
+ when 321 # GovPay reference already exists on system
49
+ raise GovPayReferenceExistsOnSystem, error
50
+ end
51
+ super(message: error)
28
52
  end
29
53
  end
30
54
  end
@@ -1,3 +1,3 @@
1
1
  module GlimrApiClient
2
- VERSION = '0.1.13'
2
+ VERSION = '0.2.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: glimr-api-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.13
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Todd Tyree
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-11-03 00:00:00.000000000 Z
11
+ date: 2016-11-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -94,20 +94,6 @@ dependencies:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
96
  version: '3.4'
97
- - !ruby/object:Gem::Dependency
98
- name: rails
99
- requirement: !ruby/object:Gem::Requirement
100
- requirements:
101
- - - "~>"
102
- - !ruby/object:Gem::Version
103
- version: '5.0'
104
- type: :development
105
- prerelease: false
106
- version_requirements: !ruby/object:Gem::Requirement
107
- requirements:
108
- - - "~>"
109
- - !ruby/object:Gem::Version
110
- version: '5.0'
111
97
  - !ruby/object:Gem::Dependency
112
98
  name: rake
113
99
  requirement: !ruby/object:Gem::Requirement
@@ -123,7 +109,7 @@ dependencies:
123
109
  - !ruby/object:Gem::Version
124
110
  version: '10.0'
125
111
  - !ruby/object:Gem::Dependency
126
- name: rspec-rails
112
+ name: rspec
127
113
  requirement: !ruby/object:Gem::Requirement
128
114
  requirements:
129
115
  - - "~>"
@@ -150,20 +136,6 @@ dependencies:
150
136
  - - "~>"
151
137
  - !ruby/object:Gem::Version
152
138
  version: '0.41'
153
- - !ruby/object:Gem::Dependency
154
- name: sqlite3
155
- requirement: !ruby/object:Gem::Requirement
156
- requirements:
157
- - - "~>"
158
- - !ruby/object:Gem::Version
159
- version: '1.3'
160
- type: :development
161
- prerelease: false
162
- version_requirements: !ruby/object:Gem::Requirement
163
- requirements:
164
- - - "~>"
165
- - !ruby/object:Gem::Version
166
- version: '1.3'
167
139
  - !ruby/object:Gem::Dependency
168
140
  name: excon
169
141
  requirement: !ruby/object:Gem::Requirement
@@ -202,6 +174,8 @@ files:
202
174
  - lib/glimr_api_client/available.rb
203
175
  - lib/glimr_api_client/base.rb
204
176
  - lib/glimr_api_client/case.rb
177
+ - lib/glimr_api_client/hwf_requested.rb
178
+ - lib/glimr_api_client/pay_by_account.rb
205
179
  - lib/glimr_api_client/register_new_case.rb
206
180
  - lib/glimr_api_client/update.rb
207
181
  - lib/glimr_api_client/version.rb