check_mot 0.1.0 → 0.3.1
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 +4 -4
- data/.circleci/config.yml +5 -3
- data/Gemfile.lock +42 -29
- data/README.md +10 -1
- data/check_mot.gemspec +3 -3
- data/lib/check_mot/attribute.rb +4 -4
- data/lib/check_mot/by_date_request.rb +10 -0
- data/lib/check_mot/by_date_response.rb +17 -0
- data/lib/check_mot/by_vehicle_registration_request.rb +10 -0
- data/lib/check_mot/by_vehicle_registration_response.rb +14 -0
- data/lib/check_mot/client.rb +3 -38
- data/lib/check_mot/date_attribute.rb +4 -4
- data/lib/check_mot/request.rb +35 -0
- data/lib/check_mot/resource.rb +7 -8
- data/lib/check_mot/response.rb +10 -15
- data/lib/check_mot/version.rb +1 -1
- data/lib/check_mot.rb +6 -0
- metadata +12 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5af2047cd12c8506e2c58d0e12e0392bd9d9166184e93c99f5bfdca16dfb04dd
|
4
|
+
data.tar.gz: 595d9183f18ca4f590a7c700977ede40a62ff4b27a35842da17b922b228f53c6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: addb1af08ca795a70679f785ed6eb3acd416500086a1f382c683dd45f8dedc43d63f0f2471c0077e7a75b829cd13ac6b88d2210809acb3eacbcdce35c643d1e0
|
7
|
+
data.tar.gz: 9a2e46b02b31783df140696da11f5d7aed8acc9a91a4d24b690f79ab33d905f9cea6ae85a03839d792e424ecae87779df047c8eb3c75e005580928de361e1953
|
data/.circleci/config.yml
CHANGED
@@ -7,9 +7,9 @@ jobs:
|
|
7
7
|
build:
|
8
8
|
docker:
|
9
9
|
# specify the version you desire here
|
10
|
-
- image:
|
10
|
+
- image: cimg/ruby:3.1.4
|
11
11
|
environment:
|
12
|
-
BUNDLER_VERSION: 2.
|
12
|
+
BUNDLER_VERSION: 2.5.7
|
13
13
|
|
14
14
|
# Specify service dependencies here if necessary
|
15
15
|
# CircleCI maintains a library of pre-built images
|
@@ -29,8 +29,10 @@ jobs:
|
|
29
29
|
- v1-dependencies-
|
30
30
|
|
31
31
|
- run:
|
32
|
-
name:
|
32
|
+
name: Configure Bundler
|
33
33
|
command: |
|
34
|
+
echo 'export BUNDLER_VERSION=$(cat Gemfile.lock | tail -1 | tr -d " ")' >> $BASH_ENV
|
35
|
+
source $BASH_ENV
|
34
36
|
gem install bundler
|
35
37
|
|
36
38
|
- run:
|
data/Gemfile.lock
CHANGED
@@ -1,45 +1,58 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
check_mot (0.
|
4
|
+
check_mot (0.3.0)
|
5
5
|
activesupport (>= 4.0)
|
6
6
|
faraday (>= 0.9)
|
7
7
|
|
8
8
|
GEM
|
9
9
|
remote: https://rubygems.org/
|
10
10
|
specs:
|
11
|
-
activesupport (
|
11
|
+
activesupport (7.1.3.2)
|
12
|
+
base64
|
13
|
+
bigdecimal
|
12
14
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
15
|
+
connection_pool (>= 2.2.5)
|
16
|
+
drb
|
17
|
+
i18n (>= 1.6, < 2)
|
18
|
+
minitest (>= 5.1)
|
19
|
+
mutex_m
|
20
|
+
tzinfo (~> 2.0)
|
21
|
+
base64 (0.2.0)
|
22
|
+
bigdecimal (3.1.7)
|
23
|
+
concurrent-ruby (1.2.3)
|
24
|
+
connection_pool (2.4.1)
|
25
|
+
diff-lcs (1.5.1)
|
26
|
+
drb (2.2.1)
|
27
|
+
faraday (2.9.0)
|
28
|
+
faraday-net_http (>= 2.0, < 3.2)
|
29
|
+
faraday-net_http (3.1.0)
|
30
|
+
net-http
|
31
|
+
i18n (1.14.4)
|
21
32
|
concurrent-ruby (~> 1.0)
|
22
|
-
minitest (5.
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
rspec-
|
29
|
-
|
30
|
-
rspec-
|
31
|
-
rspec-
|
33
|
+
minitest (5.22.3)
|
34
|
+
mutex_m (0.2.0)
|
35
|
+
net-http (0.4.1)
|
36
|
+
uri
|
37
|
+
rake (13.0.1)
|
38
|
+
rspec (3.13.0)
|
39
|
+
rspec-core (~> 3.13.0)
|
40
|
+
rspec-expectations (~> 3.13.0)
|
41
|
+
rspec-mocks (~> 3.13.0)
|
42
|
+
rspec-core (3.13.0)
|
43
|
+
rspec-support (~> 3.13.0)
|
44
|
+
rspec-expectations (3.13.0)
|
32
45
|
diff-lcs (>= 1.2.0, < 2.0)
|
33
|
-
rspec-support (~> 3.
|
34
|
-
rspec-mocks (3.
|
46
|
+
rspec-support (~> 3.13.0)
|
47
|
+
rspec-mocks (3.13.0)
|
35
48
|
diff-lcs (>= 1.2.0, < 2.0)
|
36
|
-
rspec-support (~> 3.
|
37
|
-
rspec-support (3.
|
49
|
+
rspec-support (~> 3.13.0)
|
50
|
+
rspec-support (3.13.1)
|
38
51
|
rspec_junit_formatter (0.4.1)
|
39
52
|
rspec-core (>= 2, < 4, != 2.12.0)
|
40
|
-
|
41
|
-
|
42
|
-
|
53
|
+
tzinfo (2.0.6)
|
54
|
+
concurrent-ruby (~> 1.0)
|
55
|
+
uri (0.13.0)
|
43
56
|
|
44
57
|
PLATFORMS
|
45
58
|
ruby
|
@@ -47,9 +60,9 @@ PLATFORMS
|
|
47
60
|
DEPENDENCIES
|
48
61
|
bundler (~> 2.0)
|
49
62
|
check_mot!
|
50
|
-
rake (~>
|
63
|
+
rake (~> 13.0)
|
51
64
|
rspec (~> 3.0)
|
52
65
|
rspec_junit_formatter
|
53
66
|
|
54
67
|
BUNDLED WITH
|
55
|
-
2.
|
68
|
+
2.4.22
|
data/README.md
CHANGED
@@ -62,7 +62,7 @@ config.http_adapter = <your_http_adapter>
|
|
62
62
|
|
63
63
|
To check a vehicle's MOT history using the registration number:
|
64
64
|
```ruby
|
65
|
-
check_mot =
|
65
|
+
check_mot = CheckMot::Client.new
|
66
66
|
result = check_mot.by_vehicle_registration('AB01CDF')
|
67
67
|
|
68
68
|
result.registration # => "AB01CFD"
|
@@ -70,6 +70,15 @@ result.mot_tests.first.completed_date # => 2019-02-16 21:40:00
|
|
70
70
|
# etc
|
71
71
|
```
|
72
72
|
|
73
|
+
To request MOT tests completed on 15 August 2024 for page 1:
|
74
|
+
```ruby
|
75
|
+
check_mot = CheckMot::Client.new
|
76
|
+
result = check_mot.by_date('20240815', page: 1)
|
77
|
+
result.first.mot_tests.first.test_result # => "PASSED"
|
78
|
+
# etc
|
79
|
+
```
|
80
|
+
Note: `page` is between 1 and 1440 inclusive. Dates that are over 5 weeks before the current date will produce a 400 error.
|
81
|
+
|
73
82
|
## Development
|
74
83
|
|
75
84
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
data/check_mot.gemspec
CHANGED
@@ -6,8 +6,8 @@ require "check_mot/version"
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
7
|
spec.name = "check_mot"
|
8
8
|
spec.version = CheckMot::VERSION
|
9
|
-
spec.authors = ["Ben Forrest"]
|
10
|
-
spec.email =
|
9
|
+
spec.authors = ["Ben Forrest", "clickmechanic-dev"]
|
10
|
+
spec.email = "dev@clickmechanic.com"
|
11
11
|
|
12
12
|
spec.summary = 'Ruby interface for the UK MOT History API'
|
13
13
|
spec.description = 'See https://www.check-mot.service.gov.uk/mot-history-api for details of the API spec'
|
@@ -36,7 +36,7 @@ Gem::Specification.new do |spec|
|
|
36
36
|
spec.require_paths = ["lib"]
|
37
37
|
|
38
38
|
spec.add_development_dependency "bundler", "~> 2.0"
|
39
|
-
spec.add_development_dependency "rake", "~>
|
39
|
+
spec.add_development_dependency "rake", "~> 13.0"
|
40
40
|
spec.add_development_dependency "rspec", "~> 3.0"
|
41
41
|
|
42
42
|
spec.add_dependency 'activesupport', '>= 4.0'
|
data/lib/check_mot/attribute.rb
CHANGED
@@ -3,13 +3,13 @@ module CheckMot
|
|
3
3
|
class Attribute
|
4
4
|
attr_reader :value
|
5
5
|
|
6
|
-
def initialize(
|
7
|
-
@
|
6
|
+
def initialize(value)
|
7
|
+
@value = value
|
8
8
|
end
|
9
9
|
|
10
10
|
def self.resolve(name, value)
|
11
|
-
[DateAttribute].
|
12
|
-
|
11
|
+
[DateAttribute].map do |attribute|
|
12
|
+
attribute.try(name, value)
|
13
13
|
end.first || value
|
14
14
|
end
|
15
15
|
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module CheckMot
|
4
|
+
class ByDateResponse < Response
|
5
|
+
def resources
|
6
|
+
return [] if status == 404
|
7
|
+
|
8
|
+
validate
|
9
|
+
|
10
|
+
sanitized.map { |source_hash| Resource.new(source_hash) }
|
11
|
+
end
|
12
|
+
|
13
|
+
def sanitized
|
14
|
+
parsed_response.map(&method(:transform))
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/lib/check_mot/client.rb
CHANGED
@@ -1,46 +1,11 @@
|
|
1
1
|
module CheckMot
|
2
|
-
|
3
2
|
class Client
|
4
3
|
def by_vehicle_registration(registration)
|
5
|
-
|
6
|
-
Resource.new(response.sanitized.first)
|
7
|
-
end
|
8
|
-
|
9
|
-
private
|
10
|
-
|
11
|
-
def get(params)
|
12
|
-
Response.new(connection.get path, params).tap do |response|
|
13
|
-
fail ResponseError.new(response.status, response.raw) unless response.success?
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
def url
|
18
|
-
'https://beta.check-mot.service.gov.uk'
|
19
|
-
end
|
20
|
-
|
21
|
-
def path
|
22
|
-
'/trade/vehicles/mot-tests'
|
23
|
-
end
|
24
|
-
|
25
|
-
def connection
|
26
|
-
@connection ||= create_connection
|
4
|
+
ByVehicleRegistrationRequest.new.get(registration)
|
27
5
|
end
|
28
6
|
|
29
|
-
def
|
30
|
-
|
31
|
-
|
32
|
-
Faraday.new(:url => url) do |builder|
|
33
|
-
builder.headers = headers
|
34
|
-
builder.adapter CheckMot.configuration.http_adapter || Faraday.default_adapter
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
def headers
|
39
|
-
{
|
40
|
-
'Accept': 'application/json+v6',
|
41
|
-
'x-api-key': CheckMot.configuration.api_key
|
42
|
-
}
|
7
|
+
def by_date(date, page:)
|
8
|
+
ByDateRequest.new.get(date, page: page)
|
43
9
|
end
|
44
10
|
end
|
45
|
-
|
46
11
|
end
|
@@ -3,13 +3,13 @@ module CheckMot
|
|
3
3
|
class DateAttribute < Attribute
|
4
4
|
|
5
5
|
ATTRIBUTE_REGEX = /_date$/
|
6
|
-
DATE_REGEX = /^\d{4}
|
7
|
-
TIME_REGEX = /^\d{4}
|
6
|
+
DATE_REGEX = /^\d{4}[.-\/]\d{2}[.-\/]\d{2}$/
|
7
|
+
TIME_REGEX = /^\d{4}[.-\/]\d{2}[.-\/]\d{2} \d{2}:\d{2}:\d{2}$/
|
8
8
|
|
9
9
|
def self.try(name, value)
|
10
|
-
return unless name.to_s.match(
|
10
|
+
return unless name.to_s.match(ATTRIBUTE_REGEX)
|
11
11
|
|
12
|
-
new(
|
12
|
+
new(value)
|
13
13
|
end
|
14
14
|
|
15
15
|
def value
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module CheckMot
|
4
|
+
class Request
|
5
|
+
URL = 'https://beta.check-mot.service.gov.uk'
|
6
|
+
PATH = '/trade/vehicles/mot-tests'
|
7
|
+
|
8
|
+
def get_raw(params)
|
9
|
+
connection.get PATH, params
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
def connection
|
15
|
+
@connection ||= create_connection
|
16
|
+
end
|
17
|
+
|
18
|
+
def create_connection
|
19
|
+
fail Error.new('api_key not configured') unless CheckMot.configuration.api_key
|
20
|
+
|
21
|
+
Faraday.new(url: URL) do |builder|
|
22
|
+
builder.headers = headers
|
23
|
+
builder.adapter CheckMot.configuration.http_adapter || Faraday.default_adapter
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def headers
|
28
|
+
{
|
29
|
+
'Accept': 'application/json+v6',
|
30
|
+
'x-api-key': CheckMot.configuration.api_key
|
31
|
+
}
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
data/lib/check_mot/resource.rb
CHANGED
@@ -6,11 +6,10 @@ module CheckMot
|
|
6
6
|
end
|
7
7
|
|
8
8
|
def respond_to_missing?(name, include_private = false)
|
9
|
-
|
9
|
+
true
|
10
10
|
end
|
11
11
|
|
12
12
|
def method_missing(name, *args)
|
13
|
-
super unless source_hash.keys.include?(name)
|
14
13
|
resolved_attribute(name)
|
15
14
|
end
|
16
15
|
|
@@ -24,7 +23,7 @@ module CheckMot
|
|
24
23
|
attr_reader :source_hash
|
25
24
|
|
26
25
|
def resolved_attribute(name)
|
27
|
-
resolved_attributes[name] ||= resolve_attribute(name,
|
26
|
+
resolved_attributes[name] ||= resolve_attribute(name, source_hash[name])
|
28
27
|
end
|
29
28
|
|
30
29
|
def resolved_attributes
|
@@ -32,15 +31,15 @@ module CheckMot
|
|
32
31
|
end
|
33
32
|
|
34
33
|
def resolve_attribute(name, value)
|
35
|
-
|
34
|
+
attribute = Attribute.resolve(name, value)
|
36
35
|
|
37
|
-
case
|
36
|
+
case attribute
|
38
37
|
when Array
|
39
|
-
|
38
|
+
attribute.map { |value| resolve_attribute(name, value) }
|
40
39
|
when Hash
|
41
|
-
Resource.new(
|
40
|
+
Resource.new(attribute)
|
42
41
|
when Attribute
|
43
|
-
|
42
|
+
attribute.value
|
44
43
|
else
|
45
44
|
value
|
46
45
|
end
|
data/lib/check_mot/response.rb
CHANGED
@@ -7,21 +7,20 @@ module CheckMot
|
|
7
7
|
|
8
8
|
delegate :success?, :status, to: :raw_response
|
9
9
|
|
10
|
-
def sanitized
|
11
|
-
return unless success?
|
12
|
-
|
13
|
-
case parsed_response
|
14
|
-
when Array
|
15
|
-
parsed_response.map(&method(:transform))
|
16
|
-
else
|
17
|
-
transform(parsed_response)
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
10
|
def raw
|
22
11
|
raw_response.body
|
23
12
|
end
|
24
13
|
|
14
|
+
def validate
|
15
|
+
fail ResponseError.new(status, raw) unless success?
|
16
|
+
end
|
17
|
+
|
18
|
+
protected
|
19
|
+
|
20
|
+
def parsed_response
|
21
|
+
@_parsed_response ||= JSON.parse(raw_response.body)
|
22
|
+
end
|
23
|
+
|
25
24
|
private
|
26
25
|
|
27
26
|
attr_reader :raw_response
|
@@ -29,10 +28,6 @@ module CheckMot
|
|
29
28
|
def transform(response_hash)
|
30
29
|
response_hash.deep_transform_keys { |key| key.underscore.to_sym }
|
31
30
|
end
|
32
|
-
|
33
|
-
def parsed_response
|
34
|
-
@_parsed_response ||= JSON.parse(raw_response.body)
|
35
|
-
end
|
36
31
|
end
|
37
32
|
|
38
33
|
end
|
data/lib/check_mot/version.rb
CHANGED
data/lib/check_mot.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'date'
|
2
|
+
require "active_support"
|
2
3
|
require 'active_support/core_ext/time'
|
3
4
|
require 'json'
|
4
5
|
require 'faraday'
|
@@ -8,7 +9,12 @@ require 'check_mot/configuration'
|
|
8
9
|
require 'check_mot/attribute'
|
9
10
|
require 'check_mot/date_attribute'
|
10
11
|
require 'check_mot/resource'
|
12
|
+
require 'check_mot/request'
|
11
13
|
require 'check_mot/response'
|
14
|
+
require 'check_mot/by_vehicle_registration_request'
|
15
|
+
require 'check_mot/by_date_request'
|
16
|
+
require 'check_mot/by_vehicle_registration_response'
|
17
|
+
require 'check_mot/by_date_response'
|
12
18
|
require 'check_mot/client'
|
13
19
|
|
14
20
|
module CheckMot
|
metadata
CHANGED
@@ -1,14 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: check_mot
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ben Forrest
|
8
|
+
- clickmechanic-dev
|
8
9
|
autorequire:
|
9
10
|
bindir: exe
|
10
11
|
cert_chain: []
|
11
|
-
date:
|
12
|
+
date: 2024-09-09 00:00:00.000000000 Z
|
12
13
|
dependencies:
|
13
14
|
- !ruby/object:Gem::Dependency
|
14
15
|
name: bundler
|
@@ -30,14 +31,14 @@ dependencies:
|
|
30
31
|
requirements:
|
31
32
|
- - "~>"
|
32
33
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
34
|
+
version: '13.0'
|
34
35
|
type: :development
|
35
36
|
prerelease: false
|
36
37
|
version_requirements: !ruby/object:Gem::Requirement
|
37
38
|
requirements:
|
38
39
|
- - "~>"
|
39
40
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
41
|
+
version: '13.0'
|
41
42
|
- !ruby/object:Gem::Dependency
|
42
43
|
name: rspec
|
43
44
|
requirement: !ruby/object:Gem::Requirement
|
@@ -82,8 +83,7 @@ dependencies:
|
|
82
83
|
version: '0.9'
|
83
84
|
description: See https://www.check-mot.service.gov.uk/mot-history-api for details
|
84
85
|
of the API spec
|
85
|
-
email:
|
86
|
-
- ben@clickmechanic.com
|
86
|
+
email: dev@clickmechanic.com
|
87
87
|
executables: []
|
88
88
|
extensions: []
|
89
89
|
extra_rdoc_files: []
|
@@ -103,9 +103,14 @@ files:
|
|
103
103
|
- check_mot.gemspec
|
104
104
|
- lib/check_mot.rb
|
105
105
|
- lib/check_mot/attribute.rb
|
106
|
+
- lib/check_mot/by_date_request.rb
|
107
|
+
- lib/check_mot/by_date_response.rb
|
108
|
+
- lib/check_mot/by_vehicle_registration_request.rb
|
109
|
+
- lib/check_mot/by_vehicle_registration_response.rb
|
106
110
|
- lib/check_mot/client.rb
|
107
111
|
- lib/check_mot/configuration.rb
|
108
112
|
- lib/check_mot/date_attribute.rb
|
113
|
+
- lib/check_mot/request.rb
|
109
114
|
- lib/check_mot/resource.rb
|
110
115
|
- lib/check_mot/response.rb
|
111
116
|
- lib/check_mot/version.rb
|
@@ -131,8 +136,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
131
136
|
- !ruby/object:Gem::Version
|
132
137
|
version: '0'
|
133
138
|
requirements: []
|
134
|
-
|
135
|
-
rubygems_version: 2.7.6
|
139
|
+
rubygems_version: 3.1.6
|
136
140
|
signing_key:
|
137
141
|
specification_version: 4
|
138
142
|
summary: Ruby interface for the UK MOT History API
|