glimr-api-client 0.2.4 → 0.3.2

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: 7f0fab32d65bceb85478c42d25d708be7a828877
4
- data.tar.gz: 500efa86ddf1c3c125339577e38a9b2e6b8e228c
3
+ metadata.gz: ac6a21364fe651bf2530a4149c43d3f93e5d7a1a
4
+ data.tar.gz: 335d61a17a2c08b598040e60bf1764354ec56402
5
5
  SHA512:
6
- metadata.gz: ff8a5075972da215af4d15837cea074989ec3054338b61a9017c5022acacc7c99ba5b5645a07376f9198139a0f75dd38e837a722717c1b391f49f54e95b6171d
7
- data.tar.gz: 981204f7a2da494acff182198933c6e84a0dcdbd262e4d05d38be5413caabd39f5fc1057cdfe6d3b38af7302abcfc81a4a83d612d49b2562d17665b31d875287
6
+ metadata.gz: 42c3ff09a2d3f938833cee3cbd4364ef8d63c2ed0e8a92e7abfc84766fc9afb61434ae3e686b54e92f7fcd295fd479c20316e027c70d95fd61866fd1b6209566
7
+ data.tar.gz: 98167bccf7e1c4bc10b3b19da9d7072bd36b8c8d208b44971b045489a3dccd690984e024e798ac15d11d138c303ad25f669d7b01cefcc1ab6c19d0a7cf4f6951
@@ -81,7 +81,7 @@ Lint/EnsureReturn:
81
81
  StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-return-ensure'
82
82
  Enabled: true
83
83
 
84
- Lint/Eval:
84
+ Security/Eval:
85
85
  Description: 'The use of eval represents a serious security risk.'
86
86
  Enabled: true
87
87
 
@@ -711,7 +711,7 @@ Style/LineEndConcatenation:
711
711
  line end.
712
712
  Enabled: false
713
713
 
714
- Style/MethodCallParentheses:
714
+ Style/MethodCallWithoutArgsParentheses:
715
715
  Description: 'Do not use parentheses for method calls with no arguments.'
716
716
  StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-args-no-parens'
717
717
  Enabled: false
@@ -1 +1 @@
1
- 2.3.1
1
+ 2.3.3
@@ -0,0 +1 @@
1
+ language: ruby
@@ -1,8 +1,8 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- glimr-api-client (0.2.2)
5
- excon (~> 0.51)
4
+ glimr-api-client (0.3.2)
5
+ typhoeus (~> 1.1.2)
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
@@ -11,14 +11,15 @@ GEM
11
11
  adamantium (0.2.0)
12
12
  ice_nine (~> 0.11.0)
13
13
  memoizable (~> 0.4.0)
14
- addressable (2.4.0)
14
+ addressable (2.5.1)
15
+ public_suffix (~> 2.0, >= 2.0.2)
15
16
  anima (0.3.0)
16
17
  abstract_type (~> 0.0.7)
17
18
  adamantium (~> 0.2)
18
19
  equalizer (~> 0.0.11)
19
20
  ast (2.3.0)
20
21
  byebug (9.0.6)
21
- capybara (2.10.1)
22
+ capybara (2.13.0)
22
23
  addressable
23
24
  mime-types (>= 1.16)
24
25
  nokogiri (>= 1.3.3)
@@ -31,15 +32,20 @@ GEM
31
32
  concord (0.1.5)
32
33
  adamantium (~> 0.2.0)
33
34
  equalizer (~> 0.0.9)
35
+ crack (0.4.3)
36
+ safe_yaml (~> 1.0.0)
34
37
  diff-lcs (1.2.5)
35
38
  docile (1.1.5)
36
39
  equalizer (0.0.11)
37
- excon (0.54.0)
40
+ ethon (0.10.1)
41
+ ffi (>= 1.3.0)
42
+ ffi (1.9.18)
38
43
  fuubar (2.2.0)
39
44
  rspec-core (~> 3.0)
40
45
  ruby-progressbar (~> 1.4)
46
+ hashdiff (0.3.2)
41
47
  ice_nine (0.11.2)
42
- json (2.0.2)
48
+ json (2.1.0)
43
49
  memoizable (0.4.2)
44
50
  thread_safe (~> 0.3, >= 0.3.1)
45
51
  method_source (0.8.2)
@@ -75,10 +81,10 @@ GEM
75
81
  mutant-rspec (0.8.11)
76
82
  mutant (~> 0.8.11)
77
83
  rspec-core (>= 3.4.0, < 3.6.0)
78
- nokogiri (1.6.8.1)
84
+ nokogiri (1.7.1)
79
85
  mini_portile2 (~> 2.1.0)
80
- parallel (1.9.0)
81
- parser (2.3.1.4)
86
+ parallel (1.11.1)
87
+ parser (2.3.3.1)
82
88
  ast (~> 2.2)
83
89
  powerpack (0.1.1)
84
90
  procto (0.0.3)
@@ -86,13 +92,14 @@ GEM
86
92
  coderay (~> 1.1.0)
87
93
  method_source (~> 0.8.1)
88
94
  slop (~> 3.4)
89
- pry-byebug (3.4.0)
95
+ pry-byebug (3.4.2)
90
96
  byebug (~> 9.0)
91
97
  pry (~> 0.10)
98
+ public_suffix (2.0.5)
92
99
  rack (2.0.1)
93
100
  rack-test (0.6.3)
94
101
  rack (>= 1.0)
95
- rainbow (2.1.0)
102
+ rainbow (2.2.1)
96
103
  rake (10.5.0)
97
104
  regexp_parser (0.3.6)
98
105
  rspec (3.5.0)
@@ -108,21 +115,24 @@ GEM
108
115
  diff-lcs (>= 1.2.0, < 2.0)
109
116
  rspec-support (~> 3.5.0)
110
117
  rspec-support (3.5.0)
111
- rubocop (0.45.0)
112
- parser (>= 2.3.1.1, < 3.0)
118
+ rubocop (0.48.1)
119
+ parser (>= 2.3.3.1, < 3.0)
113
120
  powerpack (~> 0.1)
114
121
  rainbow (>= 1.99.1, < 3.0)
115
122
  ruby-progressbar (~> 1.7)
116
123
  unicode-display_width (~> 1.0, >= 1.0.1)
117
124
  ruby-progressbar (1.8.1)
118
- simplecov (0.12.0)
125
+ safe_yaml (1.0.4)
126
+ simplecov (0.14.1)
119
127
  docile (~> 1.1.0)
120
128
  json (>= 1.8, < 3)
121
129
  simplecov-html (~> 0.10.0)
122
130
  simplecov-html (0.10.0)
123
131
  slop (3.6.0)
124
- thread_safe (0.3.5)
125
- unicode-display_width (1.1.1)
132
+ thread_safe (0.3.6)
133
+ typhoeus (1.1.2)
134
+ ethon (>= 0.9.0)
135
+ unicode-display_width (1.2.1)
126
136
  unparser (0.2.5)
127
137
  abstract_type (~> 0.0.7)
128
138
  adamantium (~> 0.2.0)
@@ -131,6 +141,10 @@ GEM
131
141
  equalizer (~> 0.0.9)
132
142
  parser (~> 2.3.0)
133
143
  procto (~> 0.0.2)
144
+ webmock (3.0.1)
145
+ addressable (>= 2.3.6)
146
+ crack (>= 0.3.2)
147
+ hashdiff
134
148
  xpath (2.0.0)
135
149
  nokogiri (~> 1.3)
136
150
 
@@ -148,6 +162,7 @@ DEPENDENCIES
148
162
  rake (~> 10.0)
149
163
  rspec (~> 3.5)
150
164
  rubocop (~> 0.41)
165
+ webmock (~> 3.0.1)
151
166
 
152
167
  BUNDLED WITH
153
- 1.13.6
168
+ 1.14.3
data/README.md CHANGED
@@ -1,4 +1,5 @@
1
- [![CircleCI](https://circleci.com/gh/ministryofjustice/glimr-api-client.svg?style=svg&circle-token=1d291c45a14d48ef123ffd904169e10b7f47411f)](https://circleci.com/gh/ministryofjustice/glimr-api-client)
1
+ [![Build
2
+ Status](https://travis-ci.org/ministryofjustice/glimr-api-client.svg?branch=master)](https://travis-ci.org/ministryofjustice/glimr-api-client)
2
3
 
3
4
  # GlimrApiClient
4
5
 
@@ -15,9 +16,14 @@ endpoint at which the API can be found. This will be something like;
15
16
 
16
17
  This URL must be accessible from wherever your code is running.
17
18
 
18
- If you need to set the api time, use the `GLIMR_API_TIMEOUT_SECONDS`
19
+ If you need to set the api timeout, use the `GLIMR_API_TIMEOUT_SECONDS`
19
20
  environment variable. This defaults to 5 seconds.
20
21
 
22
+ The call to register new cases can take a long time. It has its own
23
+ timeout as a result: 32 seconds. Use the
24
+ `GLIMR_REGISTER_NEW_CASE_TIMEOUT_SECONDS` environment variable to
25
+ override this.
26
+
21
27
  ### Check Availablity
22
28
 
23
29
  ```ruby
@@ -28,56 +34,6 @@ Check if the GLiMR API is available. Raises
28
34
  `GlimrApiClient::Unavailable` if anything other than a positive response
29
35
  is received; this includes network errors and timeouts.
30
36
 
31
- ### Find a case
32
-
33
- ```ruby
34
- GlimrApiClient::Case.find(<case reference>, <confirmation code>)
35
- ```
36
-
37
- Find a case on GLiMR using the case reference (‘TT/2012/00001’ in Tax
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`.
42
-
43
- Please note that `#amount` returns the amount in pence.
44
-
45
- If a case is not found, the client will raise `GlimrApiClient::CaseNotFound`.
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
37
  ### Register a New Case
82
38
 
83
39
  ```ruby
@@ -118,20 +74,18 @@ Accepts the following parameters:
118
74
 
119
75
  Currently only `jurisdictionId` and `onlineMappingCode` are mandatory.
120
76
 
121
- ### Update a case, mark as paid
77
+ ## Deprecated Calls
122
78
 
123
- ```ruby
124
- GlimrApiClient::Update.call(<Fee object>)
125
- ```
79
+ Pending a Ministerial review of fees in tribunals, the four method
80
+ related to managing payment were deprecated in late April, 2017.
81
+
82
+ In the event that these methods are required at a later date, the code
83
+ can be re-vivfied in the repo. See the following commit for details of
84
+ files removed:
126
85
 
127
- Update a GLiMR case to indicate that payment has been received for a
128
- fee. The fee object passed must respond to `#glimr_id`,
129
- `#govpay_reference`, `#govpay_payment_id`, and `#amount`. `#amount`
130
- must be the amount in pence. The client will validate the request and raise
131
- `GlimrApiClient::RequestError` if any of these methods are missing.
86
+ 02fe1117956089a4b2e62f2e93540165443de06e
132
87
 
133
- Network errors or API failures will raise
134
- `GlimrApiClient::PaymentNotificationFailure`.
88
+ The specs may require some adaption.
135
89
 
136
90
  ### Examples
137
91
 
@@ -23,6 +23,7 @@ Gem::Specification.new do |spec|
23
23
  spec.add_development_dependency 'rake', '~> 10.0'
24
24
  spec.add_development_dependency 'rspec', '~> 3.5'
25
25
  spec.add_development_dependency 'rubocop', '~> 0.41'
26
+ spec.add_development_dependency 'webmock', '~> 3.0.1'
26
27
 
27
- spec.add_dependency 'excon', '~> 0.51'
28
+ spec.add_dependency 'typhoeus', '~> 1.1.2'
28
29
  end
@@ -1,17 +1,17 @@
1
1
  require 'json'
2
2
  require 'glimr_api_client/version'
3
+
3
4
  require 'glimr_api_client/api'
4
5
  require 'glimr_api_client/base'
6
+
5
7
  require 'glimr_api_client/available'
6
- require 'glimr_api_client/case'
7
- require 'glimr_api_client/update'
8
- require 'glimr_api_client/register_new_case'
9
- require 'glimr_api_client/pay_by_account'
8
+ require 'glimr_api_client/find_case'
10
9
  require 'glimr_api_client/hwf_requested'
11
-
10
+ require 'glimr_api_client/pay_by_account'
11
+ require 'glimr_api_client/register_new_case'
12
+ require 'glimr_api_client/update'
12
13
 
13
14
  module GlimrApiClient
14
- class PaymentNotificationFailure < StandardError; end
15
15
  class RegisterNewCaseFailure < StandardError; end
16
16
  class Unavailable < StandardError; end
17
17
  class CaseNotFound < StandardError; end
@@ -1,7 +1,9 @@
1
- require 'excon'
1
+ require 'typhoeus'
2
2
 
3
3
  module GlimrApiClient
4
4
  module Api
5
+ attr_reader :response_body
6
+
5
7
  # Showing the GLiMR post & response in the container logs is helpful
6
8
  # for troubleshooting in the staging environment (when we are using
7
9
  # the websocket link to communicate with a GLiMR instance to which
@@ -9,18 +11,8 @@ module GlimrApiClient
9
11
  # DO NOT SET THIS ENV VAR IN PRODUCTION - we should not be logging
10
12
  # this sensitive user data from the live service.
11
13
  def post
14
+ @response_body = make_request("#{api_url}#{endpoint}", request_body.to_json)
12
15
  puts "GLIMR POST: #{endpoint} - #{request_body.to_json}" if ENV.key?('GLIMR_API_DEBUG')
13
- client("#{api_url}#{endpoint}").post(body: request_body.to_json).tap { |resp|
14
- handle_response_errors(resp) if (400..599).cover?(resp.status)
15
- puts "GLIMR RESPONSE: #{resp.body}" if ENV.key?('GLIMR_API_DEBUG')
16
- @body = resp.body
17
- }
18
- rescue Excon::Error => e
19
- re_raise_error(message: e)
20
- end
21
-
22
- def response_body
23
- @response_body ||= JSON.parse(@body, symbolize_names: true)
24
16
  end
25
17
 
26
18
  def timeout
@@ -29,6 +21,26 @@ module GlimrApiClient
29
21
 
30
22
  private
31
23
 
24
+ # This uses the REST response body instead of a simple error string in
25
+ # order to provide a consistent interface for raising errors. GLiMR errors
26
+ # are indicated by a successful response that has the `:glimrerrorcode` key
27
+ # set. See `::RegisterNewCase` for an example.
28
+ def re_raise_error(body)
29
+ raise Unavailable, body.fetch(:message)
30
+ end
31
+
32
+ def parse_response(response_body)
33
+ JSON.parse(response_body, symbolize_names: true).tap { |body|
34
+ # These are required because GLiMR can return errors in an otherwise
35
+ # successful response.
36
+ re_raise_error(body) if body.key?(:glimrerrorcode)
37
+ # `:message` is only returned if there is an error This *shouldn't*
38
+ # happen as all errors should have both `:glimrerrorcode` and
39
+ # `:message`...
40
+ re_raise_error(body) if body.key?(:message)
41
+ }
42
+ end
43
+
32
44
  # If this is set using a constant, and the gem is included in a project
33
45
  # that uses the dotenv gem, then it will always fall through to the default
34
46
  # unless dotenv is included and required before this gem is loaded.
@@ -37,32 +49,36 @@ module GlimrApiClient
37
49
  'https://glimr-api.taxtribunals.dsd.io/Live_API/api/tdsapi')
38
50
  end
39
51
 
40
- # Only timeouts and network issues raise errors.
41
- def handle_response_errors(resp)
42
- # TODO: log error as well.
43
- # Deal with cases where we get an otherwise unparseable response body.
44
- body = begin
45
- JSON.parse(resp.body, symbolize_names: true)
46
- rescue JSON::ParserError
47
- { message: resp.status }
48
- end
49
- re_raise_error(body)
50
- end
52
+ def make_request(endpoint, body)
53
+ response_body = nil
54
+ request = client(endpoint, body)
51
55
 
52
- def re_raise_error(body)
53
- error = body.fetch(:message)
54
- raise Unavailable, error
56
+ request.on_complete do |response|
57
+ if response.success?
58
+ body = response.body
59
+ puts "GLIMR RESPONSE: #{body}" if ENV.key?('GLIMR_API_DEBUG')
60
+ response_body = parse_response(body)
61
+ elsif response.timed_out?
62
+ re_raise_error(message: 'timed out')
63
+ elsif (400..599).cover?(response.code)
64
+ re_raise_error(message: response.code)
65
+ end
66
+ end
67
+
68
+ request.run
69
+ response_body
55
70
  end
56
71
 
57
- def client(uri)
58
- Excon.new(
72
+ def client(uri, body)
73
+ Typhoeus::Request.new(
59
74
  uri,
75
+ method: :post,
76
+ body: body,
60
77
  headers: {
61
- 'Content-Type' => 'application/json',
62
- 'Accept' => 'application/json'
63
- },
64
- persistent: true,
65
- read_timeout: timeout
78
+ 'Content-Type' => 'application/json',
79
+ 'Accept' => 'application/json'
80
+ },
81
+ timeout: timeout
66
82
  )
67
83
  end
68
84
  end
@@ -1,17 +1,24 @@
1
1
  module GlimrApiClient
2
2
  class Base
3
3
  include GlimrApiClient::Api
4
+ attr_reader :args
4
5
 
5
6
  def self.call(*args)
6
7
  new(*args).call
7
8
  end
8
9
 
10
+ def initialize(*args)
11
+ @args = args
12
+ end
13
+
9
14
  def call
10
15
  check_request!
11
16
  post
12
17
  self
13
18
  end
14
19
 
20
+ def check_request!
21
+ end
15
22
  end
16
23
  end
17
24
 
@@ -1,11 +1,9 @@
1
1
  module GlimrApiClient
2
2
  # TODO: rename so it follow api spec
3
- class Case
3
+ class FindCase < Base
4
4
  class NotFound < StandardError; end
5
5
  class InvalidCaseNumber < StandardError; end
6
6
 
7
- include GlimrApiClient::Api
8
-
9
7
  TRIBUNAL_JURISDICTION_ID = 8
10
8
 
11
9
  # TODO: Case should use `#call(params)` directly, like everything else.
@@ -3,12 +3,23 @@ module GlimrApiClient
3
3
  class JurisdictionNotFound < StandardError; end
4
4
  class OnlineMappingNotFoundOrInvalid < StandardError; end
5
5
  class CaseCreationFailed < StandardError; end
6
+
7
+ TRIBUNAL_JURISDICTION_ID = 8
8
+
6
9
  attr_reader :request_body
7
10
 
8
11
  def initialize(params)
9
12
  @request_body = params
10
13
  end
11
14
 
15
+ # This addresses the problem that RegisterNewCase calls can take a much
16
+ # longer time to respond than availability calls. At the time this was
17
+ # written, the connection was periodically timing out at just over 30
18
+ # seconds.
19
+ def timeout
20
+ Integer(ENV.fetch('GLIMR_REGISTER_NEW_CASE_TIMEOUT_SECONDS', 32))
21
+ end
22
+
12
23
  private
13
24
 
14
25
  def check_request!
@@ -1,3 +1,3 @@
1
1
  module GlimrApiClient
2
- VERSION = '0.2.4'
2
+ VERSION = '0.3.2'
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.2.4
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Todd Tyree
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-02-07 00:00:00.000000000 Z
11
+ date: 2017-04-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -137,19 +137,33 @@ dependencies:
137
137
  - !ruby/object:Gem::Version
138
138
  version: '0.41'
139
139
  - !ruby/object:Gem::Dependency
140
- name: excon
140
+ name: webmock
141
141
  requirement: !ruby/object:Gem::Requirement
142
142
  requirements:
143
143
  - - "~>"
144
144
  - !ruby/object:Gem::Version
145
- version: '0.51'
145
+ version: 3.0.1
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - "~>"
151
+ - !ruby/object:Gem::Version
152
+ version: 3.0.1
153
+ - !ruby/object:Gem::Dependency
154
+ name: typhoeus
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - "~>"
158
+ - !ruby/object:Gem::Version
159
+ version: 1.1.2
146
160
  type: :runtime
147
161
  prerelease: false
148
162
  version_requirements: !ruby/object:Gem::Requirement
149
163
  requirements:
150
164
  - - "~>"
151
165
  - !ruby/object:Gem::Version
152
- version: '0.51'
166
+ version: 1.1.2
153
167
  description:
154
168
  email:
155
169
  - todd.tyree@digital.justice.gov.uk
@@ -161,6 +175,7 @@ files:
161
175
  - ".gitignore"
162
176
  - ".rubocop.yml"
163
177
  - ".ruby-version"
178
+ - ".travis.yml"
164
179
  - Gemfile
165
180
  - Gemfile.lock
166
181
  - MIT-LICENSE
@@ -173,7 +188,7 @@ files:
173
188
  - lib/glimr_api_client/api.rb
174
189
  - lib/glimr_api_client/available.rb
175
190
  - lib/glimr_api_client/base.rb
176
- - lib/glimr_api_client/case.rb
191
+ - lib/glimr_api_client/find_case.rb
177
192
  - lib/glimr_api_client/hwf_requested.rb
178
193
  - lib/glimr_api_client/pay_by_account.rb
179
194
  - lib/glimr_api_client/register_new_case.rb
@@ -201,7 +216,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
201
216
  version: '0'
202
217
  requirements: []
203
218
  rubyforge_project:
204
- rubygems_version: 2.5.1
219
+ rubygems_version: 2.5.2
205
220
  signing_key:
206
221
  specification_version: 4
207
222
  summary: Easy integration with the glimr case management system