courtfinder-client 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +8 -0
- data/lib/courtfinder/client.rb +11 -14
- data/lib/courtfinder/client/version.rb +1 -1
- data/spec/client_spec.rb +68 -21
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c10363b23a4abddd239820d39fb1f96dbc0080f6
|
4
|
+
data.tar.gz: 08cb9e811c67d11728e4f61d43c1354cdf4b818f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 99c976648f26c260a0a6d4fd326552fea827f0db3c831b6bf14ab433ad5c1ba583793d310084406a71033e89bf2b5f5402ce7309cdf08a3710411fcf85cc3410
|
7
|
+
data.tar.gz: b4f082467c62a7896ea47876857baeb866701d4935cbb9e94479c4541330f9ab039ed5412f1abff19186d6531f1b1b10e26583c19eef96edafd8ef5c814ad4d3
|
data/README.md
CHANGED
@@ -32,6 +32,14 @@ area of law for the given postcode.
|
|
32
32
|
|
33
33
|
**TODO:** Add support for courts in other areas of law.
|
34
34
|
|
35
|
+
## Updating the gem
|
36
|
+
|
37
|
+
When you add more features and you feel that a significant change has
|
38
|
+
been made, increase the gem version number and publish it to [RubyGems](https://rubygems.org/):
|
39
|
+
|
40
|
+
$ gem build courtfinder-client.gemspec
|
41
|
+
$ gem push courtfinder-client-X.Y.Z.gem
|
42
|
+
|
35
43
|
## Contributing
|
36
44
|
|
37
45
|
1. Fork it ( https://github.com/ministryofjustice/courtfinder-client/fork )
|
data/lib/courtfinder/client.rb
CHANGED
@@ -11,24 +11,21 @@ module Courtfinder
|
|
11
11
|
|
12
12
|
def get postcode
|
13
13
|
conn = Faraday.get "#{Courtfinder::SERVER}#{PATH}#{URI.escape(postcode)}"
|
14
|
-
|
14
|
+
process conn.body
|
15
|
+
end
|
16
|
+
|
17
|
+
def empty?
|
18
|
+
@json.empty?
|
15
19
|
end
|
16
20
|
|
17
21
|
private
|
18
22
|
|
19
|
-
def
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
name_n_street = "#{address_json["address_lines"].join("\n")}"
|
26
|
-
<<-EOS.chomp.gsub(' ', '')
|
27
|
-
#{name_n_street}
|
28
|
-
#{address_json["town"]}
|
29
|
-
#{address_json["county"]}
|
30
|
-
#{address_json["postcode"]}
|
31
|
-
EOS
|
23
|
+
def process data
|
24
|
+
@json = JSON.parse data
|
25
|
+
unwanted_attributes = ['areas_of_law', 'slug', 'dx_number',
|
26
|
+
'lon', 'lat', 'types', 'number']
|
27
|
+
@json.each do |court|
|
28
|
+
unwanted_attributes.each {|attr| court.delete attr }
|
32
29
|
end
|
33
30
|
end
|
34
31
|
end
|
data/spec/client_spec.rb
CHANGED
@@ -5,44 +5,91 @@ require 'courtfinder/client'
|
|
5
5
|
describe Courtfinder::Client::HousingPossession do
|
6
6
|
before { WebMock.disable_net_connect! }
|
7
7
|
|
8
|
+
let(:result) do
|
9
|
+
[{ "name" => "Cambridge County Court and Family Court",
|
10
|
+
"address" =>
|
11
|
+
{ "town" => "Cambridge",
|
12
|
+
"address_lines" =>
|
13
|
+
["Cambridge County Court and Family Court Hearing Centre",
|
14
|
+
"197 East Road"],
|
15
|
+
"type" => "Postal",
|
16
|
+
"postcode" => "CB1 1BA",
|
17
|
+
"county" => "Cambridgeshire"
|
18
|
+
}
|
19
|
+
}]
|
20
|
+
end
|
21
|
+
let(:client) { Courtfinder::Client::HousingPossession.new }
|
22
|
+
|
23
|
+
def full_url postcode
|
24
|
+
"#{Courtfinder::SERVER}#{Courtfinder::Client::HousingPossession::PATH}#{postcode}"
|
25
|
+
end
|
26
|
+
|
27
|
+
def stub_with postcode
|
28
|
+
stub_request(:get, full_url(postcode))
|
29
|
+
.to_return(:body => fixture('result.json'),
|
30
|
+
:headers => {:content_type => 'application/json; charset=utf-8'})
|
31
|
+
end
|
32
|
+
|
33
|
+
def blank_result postcode
|
34
|
+
stub_request(:get, full_url(postcode))
|
35
|
+
.to_return(:status => 200,
|
36
|
+
:body => '[]',
|
37
|
+
:headers => {})
|
38
|
+
end
|
39
|
+
|
8
40
|
describe '.get' do
|
9
|
-
|
10
|
-
let(:address) {
|
11
|
-
"Cambridge County Court and Family Court Hearing Centre\n197 East Road\nCambridge\nCambridgeshire\nCB1 1BA"
|
12
|
-
}
|
13
|
-
|
14
|
-
def stub_with postcode
|
15
|
-
stub_request(:get, "#{Courtfinder::SERVER}#{Courtfinder::Client::HousingPossession::PATH}#{postcode}")
|
16
|
-
.to_return(:body => fixture('result.json'),
|
17
|
-
:headers => {:content_type => 'application/json; charset=utf-8'})
|
18
|
-
end
|
41
|
+
before { stub_with postcode }
|
19
42
|
|
20
43
|
context 'when given postcode with no spaces' do
|
21
|
-
postcode
|
44
|
+
let(:postcode) { 'sg80lt' }
|
22
45
|
|
23
46
|
it 'should return the court address' do
|
24
|
-
|
25
|
-
expect(client.get(postcode)).to eql address
|
47
|
+
expect(client.get(postcode)).to eql result
|
26
48
|
end
|
27
49
|
end
|
28
50
|
|
29
51
|
context 'when given postcode with spaces' do
|
30
|
-
postcode
|
52
|
+
let(:postcode) { 'SG8 0LT' }
|
31
53
|
|
32
54
|
it 'should return the court address' do
|
33
|
-
|
34
|
-
expect(client.get(postcode)).to eql address
|
55
|
+
expect(client.get(postcode)).to eql result
|
35
56
|
end
|
36
57
|
end
|
37
58
|
|
38
59
|
context 'when invalid postcode is provided' do
|
60
|
+
let(:postcode) { 'fake' }
|
61
|
+
before { blank_result postcode }
|
62
|
+
|
39
63
|
it 'should return an error' do
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
64
|
+
expect(client.get(postcode)).to eql []
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
describe '.empty?' do
|
70
|
+
context 'when there are results returned' do
|
71
|
+
let(:postcode) { 'SG8 0LT' }
|
72
|
+
|
73
|
+
before do
|
74
|
+
stub_with postcode
|
75
|
+
client.get postcode
|
76
|
+
end
|
77
|
+
|
78
|
+
it 'should be false' do
|
79
|
+
expect(client.empty?).to be false
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
context 'when there are no results returned' do
|
84
|
+
let(:postcode) { 'fake' }
|
85
|
+
|
86
|
+
before do
|
87
|
+
blank_result postcode
|
88
|
+
client.get postcode
|
89
|
+
end
|
44
90
|
|
45
|
-
|
91
|
+
it 'should be true' do
|
92
|
+
expect(client.empty?).to be true
|
46
93
|
end
|
47
94
|
end
|
48
95
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: courtfinder-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Aleksandar Simić
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-10-
|
11
|
+
date: 2014-10-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|