check_mot 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.circleci/config.yml +68 -0
- data/.gitignore +16 -0
- data/.rspec +3 -0
- data/.travis.yml +7 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +55 -0
- data/LICENSE.txt +21 -0
- data/README.md +89 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/check_mot.gemspec +44 -0
- data/lib/check_mot.rb +41 -0
- data/lib/check_mot/attribute.rb +17 -0
- data/lib/check_mot/client.rb +46 -0
- data/lib/check_mot/configuration.rb +3 -0
- data/lib/check_mot/date_attribute.rb +28 -0
- data/lib/check_mot/resource.rb +50 -0
- data/lib/check_mot/response.rb +38 -0
- data/lib/check_mot/version.rb +3 -0
- metadata +139 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 1563ec1966cac396ffb090b7260ac635b1a9e29eb3df5570ef5248e13544a51c
|
4
|
+
data.tar.gz: '0078023d2f227021dd9263489c1d90c94e2e600ee7d26db465fe16fe72f6299f'
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 95a3cc21a158a6d04c6f2727108de58bd905ec5794e59c4911cd4504d4d4abaea71f69d5e33d8130a7528cc20aea38a053dcdaa2632d9b29bbbf67483139b881
|
7
|
+
data.tar.gz: 0a79b48ef58a2fd507f34d6946d9201c10c601b36c8ff09f6d00628e2e73b9ac51b1a75e3e326152bd0834ad080963638e9c84d8f54549891770a9af12355589
|
@@ -0,0 +1,68 @@
|
|
1
|
+
# Ruby CircleCI 2.0 configuration file
|
2
|
+
#
|
3
|
+
# Check https://circleci.com/docs/2.0/language-ruby/ for more details
|
4
|
+
#
|
5
|
+
version: 2
|
6
|
+
jobs:
|
7
|
+
build:
|
8
|
+
docker:
|
9
|
+
# specify the version you desire here
|
10
|
+
- image: circleci/ruby:2.5
|
11
|
+
environment:
|
12
|
+
BUNDLER_VERSION: 2.0.1
|
13
|
+
|
14
|
+
# Specify service dependencies here if necessary
|
15
|
+
# CircleCI maintains a library of pre-built images
|
16
|
+
# documented at https://circleci.com/docs/2.0/circleci-images/
|
17
|
+
# - image: circleci/postgres:9.4
|
18
|
+
|
19
|
+
working_directory: ~/repo
|
20
|
+
|
21
|
+
steps:
|
22
|
+
- checkout
|
23
|
+
|
24
|
+
# Download and cache dependencies
|
25
|
+
- restore_cache:
|
26
|
+
keys:
|
27
|
+
- v1-dependencies-{{ checksum "Gemfile.lock" }}
|
28
|
+
# fallback to using the latest cache if no exact match is found
|
29
|
+
- v1-dependencies-
|
30
|
+
|
31
|
+
- run:
|
32
|
+
name: install bundler 2.0
|
33
|
+
command: |
|
34
|
+
gem install bundler
|
35
|
+
|
36
|
+
- run:
|
37
|
+
name: install dependencies
|
38
|
+
command: |
|
39
|
+
bundle install --jobs=4 --retry=3 --path vendor/bundle
|
40
|
+
|
41
|
+
- save_cache:
|
42
|
+
paths:
|
43
|
+
- ./vendor/bundle
|
44
|
+
key: v1-dependencies-{{ checksum "Gemfile.lock" }}
|
45
|
+
|
46
|
+
# run tests!
|
47
|
+
- run:
|
48
|
+
name: run tests
|
49
|
+
command: |
|
50
|
+
mkdir /tmp/test-results
|
51
|
+
TEST_FILES="$(circleci tests glob "spec/**/*_spec.rb" | \
|
52
|
+
circleci tests split --split-by=timings)"
|
53
|
+
|
54
|
+
echo "TEST_FIlES=\"$TEST_FILES\""
|
55
|
+
|
56
|
+
bundle exec rspec \
|
57
|
+
--format progress \
|
58
|
+
--format RspecJunitFormatter \
|
59
|
+
--out /tmp/test-results/rspec.xml \
|
60
|
+
--format progress \
|
61
|
+
$TEST_FILES
|
62
|
+
|
63
|
+
# collect reports
|
64
|
+
- store_test_results:
|
65
|
+
path: /tmp/test-results
|
66
|
+
- store_artifacts:
|
67
|
+
path: /tmp/test-results
|
68
|
+
destination: test-results
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at ben@clickmechanic.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
check_mot (0.1.0)
|
5
|
+
activesupport (>= 4.0)
|
6
|
+
faraday (>= 0.9)
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
activesupport (5.2.2)
|
12
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
13
|
+
i18n (>= 0.7, < 2)
|
14
|
+
minitest (~> 5.1)
|
15
|
+
tzinfo (~> 1.1)
|
16
|
+
concurrent-ruby (1.1.4)
|
17
|
+
diff-lcs (1.3)
|
18
|
+
faraday (0.15.4)
|
19
|
+
multipart-post (>= 1.2, < 3)
|
20
|
+
i18n (1.5.3)
|
21
|
+
concurrent-ruby (~> 1.0)
|
22
|
+
minitest (5.11.3)
|
23
|
+
multipart-post (2.0.0)
|
24
|
+
rake (10.5.0)
|
25
|
+
rspec (3.8.0)
|
26
|
+
rspec-core (~> 3.8.0)
|
27
|
+
rspec-expectations (~> 3.8.0)
|
28
|
+
rspec-mocks (~> 3.8.0)
|
29
|
+
rspec-core (3.8.0)
|
30
|
+
rspec-support (~> 3.8.0)
|
31
|
+
rspec-expectations (3.8.2)
|
32
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
33
|
+
rspec-support (~> 3.8.0)
|
34
|
+
rspec-mocks (3.8.0)
|
35
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
36
|
+
rspec-support (~> 3.8.0)
|
37
|
+
rspec-support (3.8.0)
|
38
|
+
rspec_junit_formatter (0.4.1)
|
39
|
+
rspec-core (>= 2, < 4, != 2.12.0)
|
40
|
+
thread_safe (0.3.6)
|
41
|
+
tzinfo (1.2.5)
|
42
|
+
thread_safe (~> 0.1)
|
43
|
+
|
44
|
+
PLATFORMS
|
45
|
+
ruby
|
46
|
+
|
47
|
+
DEPENDENCIES
|
48
|
+
bundler (~> 2.0)
|
49
|
+
check_mot!
|
50
|
+
rake (~> 10.0)
|
51
|
+
rspec (~> 3.0)
|
52
|
+
rspec_junit_formatter
|
53
|
+
|
54
|
+
BUNDLED WITH
|
55
|
+
2.0.1
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2019 ClickMechanic
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,89 @@
|
|
1
|
+
[![CircleCI](https://circleci.com/gh/ClickMechanic/check_mot.svg?style=svg)](https://circleci.com/gh/ClickMechanic/check_mot)
|
2
|
+
|
3
|
+
# Check MOT
|
4
|
+
|
5
|
+
Ruby implementation of UK Government [MOT History API](https://www.check-mot.service.gov.uk/mot-history-api).
|
6
|
+
|
7
|
+
From the official API documentation:
|
8
|
+
> The MOT history API gives authorised third-party organisations a way to access MOT test history information for vehicles.
|
9
|
+
>
|
10
|
+
> The information includes:
|
11
|
+
>
|
12
|
+
> - MOT test date
|
13
|
+
> - MOT expiry date
|
14
|
+
> - test result
|
15
|
+
> - mileage reading
|
16
|
+
> - MOT test number
|
17
|
+
> - reasons for failure and advisory notices
|
18
|
+
> - first MOT due date for new vehicles
|
19
|
+
> - vehicle ID
|
20
|
+
> - vehicle registration date
|
21
|
+
> - vehicle manufacturing date
|
22
|
+
> - cylinder capacity of the engine
|
23
|
+
>
|
24
|
+
> To access API you will need an API key that uniquely identifies the source of the request. DVSA will give you an API key if it approves your application.
|
25
|
+
|
26
|
+
|
27
|
+
## Installation
|
28
|
+
|
29
|
+
Add this line to your application's Gemfile:
|
30
|
+
|
31
|
+
```ruby
|
32
|
+
gem 'check_mot'
|
33
|
+
```
|
34
|
+
|
35
|
+
And then execute:
|
36
|
+
|
37
|
+
$ bundle
|
38
|
+
|
39
|
+
Or install it yourself as:
|
40
|
+
|
41
|
+
$ gem install check_mot
|
42
|
+
|
43
|
+
## Usage
|
44
|
+
|
45
|
+
Require the dependency in your project:
|
46
|
+
|
47
|
+
```ruby
|
48
|
+
require 'check_mot'
|
49
|
+
```
|
50
|
+
|
51
|
+
Configure your API key:
|
52
|
+
```ruby
|
53
|
+
CheckMot.configure do |config|
|
54
|
+
config.api_key = <your_api_key>
|
55
|
+
end
|
56
|
+
```
|
57
|
+
|
58
|
+
The gem uses Faraday under the hood. To optionally configure the HTTP adapter for Faraday, add the following to your `CheckMot` config:
|
59
|
+
```ruby
|
60
|
+
config.http_adapter = <your_http_adapter>
|
61
|
+
```
|
62
|
+
|
63
|
+
To check a vehicle's MOT history using the registration number:
|
64
|
+
```ruby
|
65
|
+
check_mot = ChecmMot::Client.new
|
66
|
+
result = check_mot.by_vehicle_registration('AB01CDF')
|
67
|
+
|
68
|
+
result.registration # => "AB01CFD"
|
69
|
+
result.mot_tests.first.completed_date # => 2019-02-16 21:40:00
|
70
|
+
# etc
|
71
|
+
```
|
72
|
+
|
73
|
+
## Development
|
74
|
+
|
75
|
+
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.
|
76
|
+
|
77
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
78
|
+
|
79
|
+
## Contributing
|
80
|
+
|
81
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/ClickMechanic/check_mot. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
82
|
+
|
83
|
+
## License
|
84
|
+
|
85
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
86
|
+
|
87
|
+
## Code of Conduct
|
88
|
+
|
89
|
+
Everyone interacting in the CheckMot project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/check_mot/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "check_mot"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/check_mot.gemspec
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "check_mot/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "check_mot"
|
8
|
+
spec.version = CheckMot::VERSION
|
9
|
+
spec.authors = ["Ben Forrest"]
|
10
|
+
spec.email = ["ben@clickmechanic.com"]
|
11
|
+
|
12
|
+
spec.summary = 'Ruby interface for the UK MOT History API'
|
13
|
+
spec.description = 'See https://www.check-mot.service.gov.uk/mot-history-api for details of the API spec'
|
14
|
+
spec.homepage = "https://github.com/ClickMechanic/check_mot"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
18
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
19
|
+
if spec.respond_to?(:metadata)
|
20
|
+
spec.metadata["allowed_push_host"] = "https://rubygems.org"
|
21
|
+
|
22
|
+
spec.metadata["homepage_uri"] = 'https://www.clickmechanic.com'
|
23
|
+
spec.metadata["source_code_uri"] = 'https://github.com/ClickMechanic/check_mot'
|
24
|
+
else
|
25
|
+
raise "RubyGems 2.0 or newer is required to protect against " \
|
26
|
+
"public gem pushes."
|
27
|
+
end
|
28
|
+
|
29
|
+
# Specify which files should be added to the gem when it is released.
|
30
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
31
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
32
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
33
|
+
end
|
34
|
+
spec.bindir = "exe"
|
35
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
36
|
+
spec.require_paths = ["lib"]
|
37
|
+
|
38
|
+
spec.add_development_dependency "bundler", "~> 2.0"
|
39
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
40
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
41
|
+
|
42
|
+
spec.add_dependency 'activesupport', '>= 4.0'
|
43
|
+
spec.add_dependency 'faraday', '>= 0.9'
|
44
|
+
end
|
data/lib/check_mot.rb
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'date'
|
2
|
+
require 'active_support/core_ext/time'
|
3
|
+
require 'json'
|
4
|
+
require 'faraday'
|
5
|
+
|
6
|
+
require 'check_mot/version'
|
7
|
+
require 'check_mot/configuration'
|
8
|
+
require 'check_mot/attribute'
|
9
|
+
require 'check_mot/date_attribute'
|
10
|
+
require 'check_mot/resource'
|
11
|
+
require 'check_mot/response'
|
12
|
+
require 'check_mot/client'
|
13
|
+
|
14
|
+
module CheckMot
|
15
|
+
class Error < StandardError; end
|
16
|
+
|
17
|
+
class ResponseError < StandardError
|
18
|
+
attr_reader :status
|
19
|
+
|
20
|
+
def initialize(status, message)
|
21
|
+
super(message)
|
22
|
+
@status = status
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
class << self
|
27
|
+
def configure
|
28
|
+
yield _configuration
|
29
|
+
end
|
30
|
+
|
31
|
+
def configuration
|
32
|
+
_configuration.dup
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
def _configuration
|
38
|
+
@_configuration ||= Configuration.new
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module CheckMot
|
2
|
+
|
3
|
+
class Attribute
|
4
|
+
attr_reader :value
|
5
|
+
|
6
|
+
def initialize(name, value)
|
7
|
+
@name, @value = name, value
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.resolve(name, value)
|
11
|
+
[DateAttribute].lazy.map do |attr|
|
12
|
+
attr.try(name, value)
|
13
|
+
end.first || value
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
module CheckMot
|
2
|
+
|
3
|
+
class Client
|
4
|
+
def by_vehicle_registration(registration)
|
5
|
+
response = get(registration: registration)
|
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
|
27
|
+
end
|
28
|
+
|
29
|
+
def create_connection
|
30
|
+
fail Error.new('api_key not configured') unless CheckMot.configuration.api_key
|
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
|
+
}
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module CheckMot
|
2
|
+
|
3
|
+
class DateAttribute < Attribute
|
4
|
+
|
5
|
+
ATTRIBUTE_REGEX = /_date$/
|
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
|
+
|
9
|
+
def self.try(name, value)
|
10
|
+
return unless name.to_s.match(/_date$/)
|
11
|
+
|
12
|
+
new(name, value)
|
13
|
+
end
|
14
|
+
|
15
|
+
def value
|
16
|
+
raw_val = super
|
17
|
+
case raw_val
|
18
|
+
when DATE_REGEX
|
19
|
+
Date.parse(raw_val)
|
20
|
+
when TIME_REGEX
|
21
|
+
Time.parse(raw_val)
|
22
|
+
else
|
23
|
+
raw_val
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
module CheckMot
|
2
|
+
|
3
|
+
class Resource
|
4
|
+
def initialize(source_hash)
|
5
|
+
@source_hash = source_hash
|
6
|
+
end
|
7
|
+
|
8
|
+
def respond_to_missing?(name, include_private = false)
|
9
|
+
super || source_hash.keys.include?(name)
|
10
|
+
end
|
11
|
+
|
12
|
+
def method_missing(name, *args)
|
13
|
+
super unless source_hash.keys.include?(name)
|
14
|
+
resolved_attribute(name)
|
15
|
+
end
|
16
|
+
|
17
|
+
def inspect
|
18
|
+
# prevents extraneous output in the console:
|
19
|
+
to_s
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
attr_reader :source_hash
|
25
|
+
|
26
|
+
def resolved_attribute(name)
|
27
|
+
resolved_attributes[name] ||= resolve_attribute(name, @source_hash[name])
|
28
|
+
end
|
29
|
+
|
30
|
+
def resolved_attributes
|
31
|
+
@_resolved_attributes ||= {}
|
32
|
+
end
|
33
|
+
|
34
|
+
def resolve_attribute(name, value)
|
35
|
+
attr = Attribute.resolve(name, value)
|
36
|
+
|
37
|
+
case attr
|
38
|
+
when Array
|
39
|
+
attr.map { |value| resolve_attribute(name, value) }
|
40
|
+
when Hash
|
41
|
+
Resource.new(attr)
|
42
|
+
when Attribute
|
43
|
+
attr.value
|
44
|
+
else
|
45
|
+
value
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module CheckMot
|
2
|
+
|
3
|
+
class Response
|
4
|
+
def initialize(raw_response)
|
5
|
+
@raw_response = raw_response
|
6
|
+
end
|
7
|
+
|
8
|
+
delegate :success?, :status, to: :raw_response
|
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
|
+
def raw
|
22
|
+
raw_response.body
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
attr_reader :raw_response
|
28
|
+
|
29
|
+
def transform(response_hash)
|
30
|
+
response_hash.deep_transform_keys { |key| key.underscore.to_sym }
|
31
|
+
end
|
32
|
+
|
33
|
+
def parsed_response
|
34
|
+
@_parsed_response ||= JSON.parse(raw_response.body)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
metadata
ADDED
@@ -0,0 +1,139 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: check_mot
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ben Forrest
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-02-16 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: '2.0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.0'
|
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.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
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.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: activesupport
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '4.0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '4.0'
|
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: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0.9'
|
83
|
+
description: See https://www.check-mot.service.gov.uk/mot-history-api for details
|
84
|
+
of the API spec
|
85
|
+
email:
|
86
|
+
- ben@clickmechanic.com
|
87
|
+
executables: []
|
88
|
+
extensions: []
|
89
|
+
extra_rdoc_files: []
|
90
|
+
files:
|
91
|
+
- ".circleci/config.yml"
|
92
|
+
- ".gitignore"
|
93
|
+
- ".rspec"
|
94
|
+
- ".travis.yml"
|
95
|
+
- CODE_OF_CONDUCT.md
|
96
|
+
- Gemfile
|
97
|
+
- Gemfile.lock
|
98
|
+
- LICENSE.txt
|
99
|
+
- README.md
|
100
|
+
- Rakefile
|
101
|
+
- bin/console
|
102
|
+
- bin/setup
|
103
|
+
- check_mot.gemspec
|
104
|
+
- lib/check_mot.rb
|
105
|
+
- lib/check_mot/attribute.rb
|
106
|
+
- lib/check_mot/client.rb
|
107
|
+
- lib/check_mot/configuration.rb
|
108
|
+
- lib/check_mot/date_attribute.rb
|
109
|
+
- lib/check_mot/resource.rb
|
110
|
+
- lib/check_mot/response.rb
|
111
|
+
- lib/check_mot/version.rb
|
112
|
+
homepage: https://github.com/ClickMechanic/check_mot
|
113
|
+
licenses:
|
114
|
+
- MIT
|
115
|
+
metadata:
|
116
|
+
allowed_push_host: https://rubygems.org
|
117
|
+
homepage_uri: https://www.clickmechanic.com
|
118
|
+
source_code_uri: https://github.com/ClickMechanic/check_mot
|
119
|
+
post_install_message:
|
120
|
+
rdoc_options: []
|
121
|
+
require_paths:
|
122
|
+
- lib
|
123
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
124
|
+
requirements:
|
125
|
+
- - ">="
|
126
|
+
- !ruby/object:Gem::Version
|
127
|
+
version: '0'
|
128
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
129
|
+
requirements:
|
130
|
+
- - ">="
|
131
|
+
- !ruby/object:Gem::Version
|
132
|
+
version: '0'
|
133
|
+
requirements: []
|
134
|
+
rubyforge_project:
|
135
|
+
rubygems_version: 2.7.6
|
136
|
+
signing_key:
|
137
|
+
specification_version: 4
|
138
|
+
summary: Ruby interface for the UK MOT History API
|
139
|
+
test_files: []
|