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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 13ada6003ce78ac35d50232679d81dfc90437902
4
- data.tar.gz: d0d6b2f1237b1b34e4c6fd6bf548e7b87467b66b
3
+ metadata.gz: c10363b23a4abddd239820d39fb1f96dbc0080f6
4
+ data.tar.gz: 08cb9e811c67d11728e4f61d43c1354cdf4b818f
5
5
  SHA512:
6
- metadata.gz: 5992de9d86d641204284116dc80981308f44db42a7505ac4f5007ddd8a216c3a41b38518fd7712424021ea93639ea87d5722bc024d923f0326e95ed685e435ee
7
- data.tar.gz: 496e63fc92b41c5e2733dbfa02b0346192b54684411c424434b961371b79feb779fd4ae7613ea7acec4ed9f69d6cf169f207458473659d90e19f70c2b05a6371
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 )
@@ -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
- process_address conn.body
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 process_address data
20
- if data == '[]'
21
- data
22
- else
23
- json = JSON.parse data
24
- address_json = json[0]["address"]
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
@@ -1,5 +1,5 @@
1
1
  module Courtfinder
2
2
  module Client
3
- VERSION = "0.0.1"
3
+ VERSION = "0.0.2"
4
4
  end
5
5
  end
@@ -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
- let(:client) { Courtfinder::Client::HousingPossession.new }
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 = 'sg80lt'
44
+ let(:postcode) { 'sg80lt' }
22
45
 
23
46
  it 'should return the court address' do
24
- stub_with postcode
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 = 'SG8 0LT'
52
+ let(:postcode) { 'SG8 0LT' }
31
53
 
32
54
  it 'should return the court address' do
33
- stub_with postcode
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
- stub_request(:get, "#{Courtfinder::SERVER}#{Courtfinder::Client::HousingPossession::PATH}fake")
41
- .to_return(:status => 200,
42
- :body => '[]',
43
- :headers => {})
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
- expect(client.get('fake')).to eql '[]'
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.1
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-01 00:00:00.000000000 Z
11
+ date: 2014-10-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler