courtfinder-client 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 13ada6003ce78ac35d50232679d81dfc90437902
4
+ data.tar.gz: d0d6b2f1237b1b34e4c6fd6bf548e7b87467b66b
5
+ SHA512:
6
+ metadata.gz: 5992de9d86d641204284116dc80981308f44db42a7505ac4f5007ddd8a216c3a41b38518fd7712424021ea93639ea87d5722bc024d923f0326e95ed685e435ee
7
+ data.tar.gz: 496e63fc92b41c5e2733dbfa02b0346192b54684411c424434b961371b79feb779fd4ae7613ea7acec4ed9f69d6cf169f207458473659d90e19f70c2b05a6371
@@ -0,0 +1,22 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in courtfinder-client.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Aleksandar Simić
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,41 @@
1
+ # Courtfinder::Client
2
+
3
+ Client for UK Government [Court and tribunal finder](https://courttribunalfinder.service.gov.uk/) API
4
+
5
+ Currently **only** implemented querying courts for **'Housing possesion'**
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ gem 'courtfinder-client'
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install courtfinder-client
20
+
21
+ ## Usage
22
+
23
+ Sample usage:
24
+
25
+ require 'courtfinder/client'
26
+
27
+ client = Courtfinder::Client::HousingPossession.new
28
+ client.get 'SG8 0LT'
29
+
30
+ Which will return the address of the court in 'Housing possession'
31
+ area of law for the given postcode.
32
+
33
+ **TODO:** Add support for courts in other areas of law.
34
+
35
+ ## Contributing
36
+
37
+ 1. Fork it ( https://github.com/ministryofjustice/courtfinder-client/fork )
38
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
39
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
40
+ 4. Push to the branch (`git push origin my-new-feature`)
41
+ 5. Create a new Pull Request
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'courtfinder/client/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "courtfinder-client"
8
+ spec.version = Courtfinder::Client::VERSION
9
+ spec.authors = ["Aleksandar Simić"]
10
+ spec.email = ["alex.simic@digital.justice.gov.uk"]
11
+ spec.summary = %q{Courtfinder client gem}
12
+ spec.description = %q{https://courttribunalfinder.service.gov.uk/ API client}
13
+ spec.homepage = "https://github.com/ministryofjustice/courtfinder-client"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.6"
22
+ spec.add_development_dependency "rake", "~> 10.3"
23
+ spec.add_development_dependency "rspec", "~> 3.1"
24
+ spec.add_development_dependency "webmock", "~> 1.18"
25
+ spec.add_development_dependency "faraday", "~> 0.9"
26
+ end
@@ -0,0 +1,36 @@
1
+ require 'courtfinder/client/version'
2
+ require 'faraday'
3
+ require 'json'
4
+ require 'uri'
5
+
6
+ module Courtfinder
7
+ SERVER = 'http://54.72.152.89'
8
+ module Client
9
+ class HousingPossession
10
+ PATH='/search/results.json?area_of_law=Housing+possession&postcode='
11
+
12
+ def get postcode
13
+ conn = Faraday.get "#{Courtfinder::SERVER}#{PATH}#{URI.escape(postcode)}"
14
+ process_address conn.body
15
+ end
16
+
17
+ private
18
+
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
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,5 @@
1
+ module Courtfinder
2
+ module Client
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,49 @@
1
+ require 'webmock/rspec'
2
+ require_relative 'support/helper'
3
+ require 'courtfinder/client'
4
+
5
+ describe Courtfinder::Client::HousingPossession do
6
+ before { WebMock.disable_net_connect! }
7
+
8
+ 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
19
+
20
+ context 'when given postcode with no spaces' do
21
+ postcode = 'sg80lt'
22
+
23
+ it 'should return the court address' do
24
+ stub_with postcode
25
+ expect(client.get(postcode)).to eql address
26
+ end
27
+ end
28
+
29
+ context 'when given postcode with spaces' do
30
+ postcode = 'SG8 0LT'
31
+
32
+ it 'should return the court address' do
33
+ stub_with postcode
34
+ expect(client.get(postcode)).to eql address
35
+ end
36
+ end
37
+
38
+ context 'when invalid postcode is provided' do
39
+ 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 => {})
44
+
45
+ expect(client.get('fake')).to eql '[]'
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,89 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # The generated `.rspec` file contains `--require spec_helper` which will cause this
4
+ # file to always be loaded, without a need to explicitly require it in any files.
5
+ #
6
+ # Given that it is always loaded, you are encouraged to keep this file as
7
+ # light-weight as possible. Requiring heavyweight dependencies from this file
8
+ # will add to the boot time of your test suite on EVERY test run, even for an
9
+ # individual file that may not need all of that loaded. Instead, consider making
10
+ # a separate helper file that requires the additional dependencies and performs
11
+ # the additional setup, and require it from the spec files that actually need it.
12
+ #
13
+ # The `.rspec` file also contains a few flags that are not defaults but that
14
+ # users commonly want.
15
+ #
16
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
17
+ RSpec.configure do |config|
18
+ # rspec-expectations config goes here. You can use an alternate
19
+ # assertion/expectation library such as wrong or the stdlib/minitest
20
+ # assertions if you prefer.
21
+ config.expect_with :rspec do |expectations|
22
+ # This option will default to `true` in RSpec 4. It makes the `description`
23
+ # and `failure_message` of custom matchers include text for helper methods
24
+ # defined using `chain`, e.g.:
25
+ # be_bigger_than(2).and_smaller_than(4).description
26
+ # # => "be bigger than 2 and smaller than 4"
27
+ # ...rather than:
28
+ # # => "be bigger than 2"
29
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
30
+ end
31
+
32
+ # rspec-mocks config goes here. You can use an alternate test double
33
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
34
+ config.mock_with :rspec do |mocks|
35
+ # Prevents you from mocking or stubbing a method that does not exist on
36
+ # a real object. This is generally recommended, and will default to
37
+ # `true` in RSpec 4.
38
+ mocks.verify_partial_doubles = true
39
+ end
40
+
41
+ # The settings below are suggested to provide a good initial experience
42
+ # with RSpec, but feel free to customize to your heart's content.
43
+ =begin
44
+ # These two settings work together to allow you to limit a spec run
45
+ # to individual examples or groups you care about by tagging them with
46
+ # `:focus` metadata. When nothing is tagged with `:focus`, all examples
47
+ # get run.
48
+ config.filter_run :focus
49
+ config.run_all_when_everything_filtered = true
50
+
51
+ # Limits the available syntax to the non-monkey patched syntax that is recommended.
52
+ # For more details, see:
53
+ # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
54
+ # - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
55
+ # - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
56
+ config.disable_monkey_patching!
57
+
58
+ # This setting enables warnings. It's recommended, but in some cases may
59
+ # be too noisy due to issues in dependencies.
60
+ config.warnings = true
61
+
62
+ # Many RSpec users commonly either run the entire suite or an individual
63
+ # file, and it's useful to allow more verbose output when running an
64
+ # individual spec file.
65
+ if config.files_to_run.one?
66
+ # Use the documentation formatter for detailed output,
67
+ # unless a formatter has already been configured
68
+ # (e.g. via a command-line flag).
69
+ config.default_formatter = 'doc'
70
+ end
71
+
72
+ # Print the 10 slowest examples and example groups at the
73
+ # end of the spec run, to help surface which specs are running
74
+ # particularly slow.
75
+ config.profile_examples = 10
76
+
77
+ # Run specs in random order to surface order dependencies. If you find an
78
+ # order dependency and want to debug it, you can fix the order by providing
79
+ # the seed, which is printed after each run.
80
+ # --seed 1234
81
+ config.order = :random
82
+
83
+ # Seed global randomization in this process using the `--seed` CLI option.
84
+ # Setting this allows you to use `--seed` to deterministically reproduce
85
+ # test failures related to randomization by passing the same `--seed` value
86
+ # as the one that triggered the failure.
87
+ Kernel.srand config.seed
88
+ =end
89
+ end
@@ -0,0 +1,3 @@
1
+ def fixture(file)
2
+ File.new(File.expand_path(file, 'spec/support')).read
3
+ end
@@ -0,0 +1,35 @@
1
+ [
2
+ {
3
+ "name": "Cambridge County Court and Family Court",
4
+ "address": {
5
+ "town": "Cambridge",
6
+ "address_lines": [
7
+ "Cambridge County Court and Family Court Hearing Centre",
8
+ "197 East Road"
9
+ ],
10
+ "type": "Postal",
11
+ "postcode": "CB1 1BA",
12
+ "county": "Cambridgeshire"
13
+ },
14
+ "lat": 52.2037125926829,
15
+ "dx_number": "97650 Cambridge 3",
16
+ "areas_of_law": [
17
+ "Forced marriage",
18
+ "Adoption",
19
+ "Money claims",
20
+ "Domestic violence",
21
+ "Children",
22
+ "Housing possession",
23
+ "High court",
24
+ "Bankruptcy",
25
+ "Divorce"
26
+ ],
27
+ "lon": 0.132065389149123,
28
+ "number": 162,
29
+ "types": [
30
+ "County Court",
31
+ "Family court"
32
+ ],
33
+ "slug": "cambridge-county-court-and-family-court"
34
+ }
35
+ ]
metadata ADDED
@@ -0,0 +1,131 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: courtfinder-client
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Aleksandar Simić
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-10-01 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.3'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.3'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.1'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.1'
55
+ - !ruby/object:Gem::Dependency
56
+ name: webmock
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.18'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.18'
69
+ - !ruby/object:Gem::Dependency
70
+ name: faraday
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0.9'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0.9'
83
+ description: https://courttribunalfinder.service.gov.uk/ API client
84
+ email:
85
+ - alex.simic@digital.justice.gov.uk
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - ".rspec"
92
+ - Gemfile
93
+ - LICENSE.txt
94
+ - README.md
95
+ - Rakefile
96
+ - courtfinder-client.gemspec
97
+ - lib/courtfinder/client.rb
98
+ - lib/courtfinder/client/version.rb
99
+ - spec/client_spec.rb
100
+ - spec/spec_helper.rb
101
+ - spec/support/helper.rb
102
+ - spec/support/result.json
103
+ homepage: https://github.com/ministryofjustice/courtfinder-client
104
+ licenses:
105
+ - MIT
106
+ metadata: {}
107
+ post_install_message:
108
+ rdoc_options: []
109
+ require_paths:
110
+ - lib
111
+ required_ruby_version: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - ">="
114
+ - !ruby/object:Gem::Version
115
+ version: '0'
116
+ required_rubygems_version: !ruby/object:Gem::Requirement
117
+ requirements:
118
+ - - ">="
119
+ - !ruby/object:Gem::Version
120
+ version: '0'
121
+ requirements: []
122
+ rubyforge_project:
123
+ rubygems_version: 2.2.2
124
+ signing_key:
125
+ specification_version: 4
126
+ summary: Courtfinder client gem
127
+ test_files:
128
+ - spec/client_spec.rb
129
+ - spec/spec_helper.rb
130
+ - spec/support/helper.rb
131
+ - spec/support/result.json