pacer_api 0.1.1 → 0.1.2

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
  SHA256:
3
- metadata.gz: 473783fce650d688b872a923e752b481a03b5c61b3a788ad461d31acdec79a45
4
- data.tar.gz: 10904a7eb6e70afb2b465fbdad1a0a33c7ae644e1932b639e7e2e677f58a6a9d
3
+ metadata.gz: 629a5c4d6afebb3ff0c9d1c3e6e94d83e2d8ce55d8c8864ac328a015b0cc1e68
4
+ data.tar.gz: 1359f7aaccc43f1cb90c5aaddc0feb4174cfc73826dd9d76677b324fb3246fc9
5
5
  SHA512:
6
- metadata.gz: f8839dda6da888056d42585f9158772828c2ba1a877976c2aa97ec8a54872c0747d28f4638b45bdf8db47b8d814a77a44808ba06d251e951374224bc4a542833
7
- data.tar.gz: 1858c0c47161d3449bbd1a1f43b727fa121e3bbf2c547aa392ae4f18d4f46ccddc3766a5d52007c9fb552f854047bdea1c367359e3e24d1a0e59941d6d6dc41c
6
+ metadata.gz: 2232c99c39e6293ff923e37c211735802462acb3f3748924ffcaebc43b17b9844eb8cf0a3ce346c2d6bf15d763b090bb3b0ced4867a9d6a9b63edfa572982a44
7
+ data.tar.gz: 2b1636aefceedda6db5d3a8b8e6be319912de540ec833da0113952585c3d69605a27b090510418b0d109bea461e0d734abaf40d69e92fe4698c99560c3ef5e7c
@@ -3,7 +3,7 @@
3
3
  require "faraday"
4
4
  require "json"
5
5
 
6
- require "pacer_api"
6
+ require "pacer_api/error"
7
7
  require "pacer_api/session"
8
8
 
9
9
  module PacerApi
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ module PacerApi
4
+ Error = Class.new(StandardError)
5
+ AuthenticationError = Class.new(Error)
6
+ NotImplementedError = Class.new(StandardError)
7
+ ResponseError = Class.new(Error)
8
+ EncodeError = Class.new(Error)
9
+ DecodeError = Class.new(Error)
10
+ end
@@ -13,7 +13,7 @@ module PacerApi
13
13
  @params = params
14
14
  end
15
15
 
16
- def fetch(page = 1)
16
+ def fetch(page = 0)
17
17
  path = format(PATH, page)
18
18
  payload = @session.post(path, @params)
19
19
  Page.new(payload)
@@ -21,7 +21,12 @@ module PacerApi
21
21
 
22
22
  class Page < PaginatedResponse
23
23
  def cases
24
- payload.fetch(:content).map { |h| CaseInfo.new(h) }
24
+ @cases ||=
25
+ if payload.key?(:content)
26
+ payload.fetch(:content).map { |h| CaseInfo.new(h) }
27
+ else
28
+ []
29
+ end
25
30
  end
26
31
  end
27
32
  end
@@ -19,6 +19,14 @@ module PacerApi
19
19
  page_info(:last)
20
20
  end
21
21
 
22
+ def errors
23
+ if payload.key?(:error)
24
+ payload.fetch(:error).map { |e| e.fetch(:messages) }.flatten
25
+ else
26
+ []
27
+ end
28
+ end
29
+
22
30
  private
23
31
 
24
32
  def page_info(key)
@@ -13,7 +13,7 @@ module PacerApi
13
13
  @params = params
14
14
  end
15
15
 
16
- def fetch(page = 1)
16
+ def fetch(page = 0)
17
17
  path = format(PATH, page)
18
18
  payload = @session.post(path, @params)
19
19
  Page.new(payload)
@@ -21,7 +21,12 @@ module PacerApi
21
21
 
22
22
  class Page < PaginatedResponse
23
23
  def parties
24
- payload.fetch(:content).map { |h| PartyInfo.new(h) }
24
+ @parties ||=
25
+ if payload.key?(:content)
26
+ payload.fetch(:content).map { |h| PartyInfo.new(h) }
27
+ else
28
+ []
29
+ end
25
30
  end
26
31
  end
27
32
  end
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "time"
3
4
  require "active_support/inflector"
4
5
 
5
6
  module PacerApi
@@ -2,6 +2,7 @@
2
2
 
3
3
  require "faraday"
4
4
 
5
+ require "pacer_api/error"
5
6
  require "pacer_api/translation"
6
7
 
7
8
  module PacerApi
@@ -26,6 +27,9 @@ module PacerApi
26
27
  def get(path)
27
28
  res = request(:get, path)
28
29
  decode_response(res.body)
30
+ rescue PacerApi::Error => e
31
+ raise ResponseError,
32
+ "Error in GET #{path}: #{e.message}", e.backtrace
29
33
  end
30
34
 
31
35
  def post(path, doc)
@@ -34,6 +38,10 @@ module PacerApi
34
38
  req.body = encode_request(doc)
35
39
  }
36
40
  decode_response(res.body)
41
+ rescue PacerApi::Error => e
42
+ raise ResponseError,
43
+ "Error in POST #{path} with #{doc.inspect}: #{e.message}",
44
+ e.backtrace
37
45
  end
38
46
 
39
47
  def delete(path)
@@ -3,6 +3,7 @@
3
3
  require "json"
4
4
  require "pp" if ENV.key?("DEBUG")
5
5
 
6
+ require "pacer_api/error"
6
7
  require "pacer_api/request_translator"
7
8
  require "pacer_api/response_translator"
8
9
 
@@ -14,15 +15,19 @@ module PacerApi
14
15
  pp obj
15
16
  end
16
17
  JSON.generate(RequestTranslator.translate(obj))
18
+ rescue JSON::ParserError => e
19
+ raise PacerApi::EncodeError, "#{e.class} #{e.message}", e.backtrace
17
20
  end
18
21
 
19
22
  def decode_response(body)
20
- ResponseTranslator.translate(JSON.parse(body)).tap { |obj|
21
- if ENV.key?("DEBUG")
22
- puts "<<<<"
23
- pp obj
24
- end
25
- }
23
+ result = ResponseTranslator.translate(JSON.parse(body))
24
+ if ENV.key?("DEBUG")
25
+ puts "<<<<"
26
+ pp result
27
+ end
28
+ result
29
+ rescue JSON::ParserError => e
30
+ raise PacerApi::DecodeError, "#{e.class} #{e.message}", e.backtrace
26
31
  end
27
32
  end
28
33
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PacerApi
4
- VERSION = "0.1.1"
4
+ VERSION = "0.1.2"
5
5
  end
data/lib/pacer_api.rb CHANGED
@@ -1,9 +1,3 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative "pacer_api/version"
4
-
5
- module PacerApi
6
- Error = Class.new(StandardError)
7
- AuthenticationError = Class.new(Error)
8
- NotImplementedError = Class.new(StandardError)
9
- end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pacer_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Paul Battley
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-02-17 00:00:00.000000000 Z
11
+ date: 2022-06-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -158,6 +158,7 @@ files:
158
158
  - lib/pacer_api/batch/status.rb
159
159
  - lib/pacer_api/batch_job.rb
160
160
  - lib/pacer_api/case_info.rb
161
+ - lib/pacer_api/error.rb
161
162
  - lib/pacer_api/immediate/case_search.rb
162
163
  - lib/pacer_api/immediate/paginated_response.rb
163
164
  - lib/pacer_api/immediate/party_search.rb
@@ -174,7 +175,7 @@ licenses:
174
175
  metadata:
175
176
  homepage_uri: https://github.com/gtd/pacer_api
176
177
  source_code_uri: https://github.com/gtd/pacer_api
177
- post_install_message:
178
+ post_install_message:
178
179
  rdoc_options: []
179
180
  require_paths:
180
181
  - lib
@@ -189,9 +190,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
189
190
  - !ruby/object:Gem::Version
190
191
  version: '0'
191
192
  requirements: []
192
- rubyforge_project:
193
- rubygems_version: 2.7.6.2
194
- signing_key:
193
+ rubygems_version: 3.2.22
194
+ signing_key:
195
195
  specification_version: 4
196
196
  summary: PACER Case Locator API
197
197
  test_files: []