national_rail_wrapper 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/.gitignore +11 -0
- data/.rspec +3 -0
- data/.travis.yml +7 -0
- data/CHANGELOG.md +0 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +53 -0
- data/LICENSE.txt +21 -0
- data/README.md +104 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/national_rail_wrapper/client.rb +9 -0
- data/lib/national_rail_wrapper/feeds/base/requests/base.rb +34 -0
- data/lib/national_rail_wrapper/feeds/historical_service_performance/client.rb +23 -0
- data/lib/national_rail_wrapper/feeds/historical_service_performance/requests/base.rb +22 -0
- data/lib/national_rail_wrapper/feeds/historical_service_performance/requests/service_details.rb +9 -0
- data/lib/national_rail_wrapper/feeds/historical_service_performance/requests/service_metrics.rb +10 -0
- data/lib/national_rail_wrapper/feeds/knowledge_base/client.rb +66 -0
- data/lib/national_rail_wrapper/feeds/knowledge_base/requests/base.rb +21 -0
- data/lib/national_rail_wrapper/feeds/knowledge_base/requests/incidents.rb +10 -0
- data/lib/national_rail_wrapper/feeds/knowledge_base/requests/national_service_indicators.rb +9 -0
- data/lib/national_rail_wrapper/feeds/knowledge_base/requests/public_promotions.rb +9 -0
- data/lib/national_rail_wrapper/feeds/knowledge_base/requests/stations.rb +10 -0
- data/lib/national_rail_wrapper/feeds/knowledge_base/requests/ticket_restrictions.rb +9 -0
- data/lib/national_rail_wrapper/feeds/knowledge_base/requests/ticket_types.rb +9 -0
- data/lib/national_rail_wrapper/feeds/knowledge_base/requests/tocs.rb +9 -0
- data/lib/national_rail_wrapper/feeds/knowledge_base/response_parser/incidents.rb +0 -0
- data/lib/national_rail_wrapper/feeds/knowledge_base/response_parser/national_services_indicators.rb +0 -0
- data/lib/national_rail_wrapper/feeds/knowledge_base/response_parser/public_promotions.rb +0 -0
- data/lib/national_rail_wrapper/feeds/knowledge_base/response_parser/stations.rb +0 -0
- data/lib/national_rail_wrapper/feeds/knowledge_base/response_parser/ticket_restrictions.rb +0 -0
- data/lib/national_rail_wrapper/feeds/knowledge_base/response_parser/ticket_types.rb +0 -0
- data/lib/national_rail_wrapper/feeds/knowledge_base/response_parser/tocs.rb +0 -0
- data/lib/national_rail_wrapper/feeds/live_departure_boards/client.rb +14 -0
- data/lib/national_rail_wrapper/version.rb +3 -0
- data/lib/national_rail_wrapper.rb +27 -0
- data/national_rail_wrapper.gemspec +47 -0
- data/spec/national_rail_wrapper_spec.rb +9 -0
- data/spec/spec_helper.rb +14 -0
- metadata +172 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 99ee836dcd2515425170ffaa55ee22ae480f2c78cadabf9760e23875b75bcedd
|
4
|
+
data.tar.gz: 6f853eb30da343fe43f2e203e1d90c6e17689eb70ec6fdde19f812bdc5cf93fe
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 31e503ebae006ce399d95db1c681ce26b4730b6d7a8cc7d87c97e548c8e954a9b68d811877a9ff1eed6522ed863008ef347814a352ff75c5743dc2fc14b77cac
|
7
|
+
data.tar.gz: '081b46ce7cea303c5affdfb24f51610414ee407312225af55579d6535a6a6daa5db099f592e6142c41b2199980852ceb6e2ff7d0720402c15b28932e126c8e19'
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CHANGELOG.md
ADDED
File without changes
|
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 marc.best@intellectionsoftware.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,53 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
national_rail_wrapper (0.1.0)
|
5
|
+
ox
|
6
|
+
typhoeus
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
byebug (11.0.1)
|
12
|
+
coderay (1.1.2)
|
13
|
+
diff-lcs (1.3)
|
14
|
+
ethon (0.12.0)
|
15
|
+
ffi (>= 1.3.0)
|
16
|
+
ffi (1.11.2)
|
17
|
+
method_source (0.9.2)
|
18
|
+
ox (2.11.0)
|
19
|
+
pry (0.12.2)
|
20
|
+
coderay (~> 1.1.0)
|
21
|
+
method_source (~> 0.9.0)
|
22
|
+
pry-byebug (3.7.0)
|
23
|
+
byebug (~> 11.0)
|
24
|
+
pry (~> 0.10)
|
25
|
+
rake (10.5.0)
|
26
|
+
rspec (3.9.0)
|
27
|
+
rspec-core (~> 3.9.0)
|
28
|
+
rspec-expectations (~> 3.9.0)
|
29
|
+
rspec-mocks (~> 3.9.0)
|
30
|
+
rspec-core (3.9.0)
|
31
|
+
rspec-support (~> 3.9.0)
|
32
|
+
rspec-expectations (3.9.0)
|
33
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
34
|
+
rspec-support (~> 3.9.0)
|
35
|
+
rspec-mocks (3.9.0)
|
36
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
37
|
+
rspec-support (~> 3.9.0)
|
38
|
+
rspec-support (3.9.0)
|
39
|
+
typhoeus (1.3.1)
|
40
|
+
ethon (>= 0.9.0)
|
41
|
+
|
42
|
+
PLATFORMS
|
43
|
+
ruby
|
44
|
+
|
45
|
+
DEPENDENCIES
|
46
|
+
bundler (~> 2.0)
|
47
|
+
national_rail_wrapper!
|
48
|
+
pry-byebug
|
49
|
+
rake (~> 10.0)
|
50
|
+
rspec (~> 3.0)
|
51
|
+
|
52
|
+
BUNDLED WITH
|
53
|
+
2.0.1
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2019 Marc Best
|
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,104 @@
|
|
1
|
+
# NationalRailWrapper
|
2
|
+
|
3
|
+
A wrapper around the National Rail open data API
|
4
|
+
|
5
|
+
| Service | Integrated |
|
6
|
+
| ------------------------------ | --------------- |
|
7
|
+
| Knowledge Base | Yes |
|
8
|
+
| Historical Service Performance | Yes |
|
9
|
+
| Live Departure Boards | No |
|
10
|
+
|
11
|
+
## Installation
|
12
|
+
|
13
|
+
Add this line to your application's Gemfile:
|
14
|
+
|
15
|
+
```ruby
|
16
|
+
gem 'national_rail_wrapper'
|
17
|
+
```
|
18
|
+
|
19
|
+
And then execute:
|
20
|
+
|
21
|
+
$ bundle
|
22
|
+
|
23
|
+
Or install it yourself as:
|
24
|
+
|
25
|
+
$ gem install national_rail_wrapper
|
26
|
+
|
27
|
+
## Usage
|
28
|
+
client = NationalRailWrapper::Feeds::Client.new(username: username, password: password)
|
29
|
+
|
30
|
+
### Knowledge Base
|
31
|
+
```
|
32
|
+
client = NationalRailWrapper::Feeds::KnowledgeBase::Client.new(username: USER_NAME, password: PASSWORD)
|
33
|
+
```
|
34
|
+
#### Incidents
|
35
|
+
```
|
36
|
+
client.incidents
|
37
|
+
```
|
38
|
+
#### National Service Indicators
|
39
|
+
```
|
40
|
+
client.national_service_indicators
|
41
|
+
```
|
42
|
+
#### Public Promotions
|
43
|
+
```
|
44
|
+
client.public_promotions
|
45
|
+
```
|
46
|
+
#### Stations
|
47
|
+
```
|
48
|
+
client.stations
|
49
|
+
```
|
50
|
+
#### Ticket Restrictions
|
51
|
+
```
|
52
|
+
client.ticket_restrictions
|
53
|
+
```
|
54
|
+
#### Ticket Types
|
55
|
+
```
|
56
|
+
client.ticket_types
|
57
|
+
```
|
58
|
+
#### TOC's
|
59
|
+
```
|
60
|
+
client.tocs
|
61
|
+
```
|
62
|
+
|
63
|
+
### Historical Service Performance
|
64
|
+
```
|
65
|
+
client = NationalRailWrapper::Feeds::HistoricalServicePerformance::Client.new(username: USER_NAME, password: PASSWORD)
|
66
|
+
```
|
67
|
+
|
68
|
+
#### ServiceMetrics
|
69
|
+
```
|
70
|
+
params = {
|
71
|
+
from_loc: 'HML',
|
72
|
+
to_loc: 'EUS',
|
73
|
+
from_time: '0800',
|
74
|
+
to_time: '0822',
|
75
|
+
from_date: '2019-10-01',
|
76
|
+
to_date: '2019-10-01',
|
77
|
+
days: 'WEEKDAY'
|
78
|
+
}
|
79
|
+
|
80
|
+
client.service_metrics(params)
|
81
|
+
```
|
82
|
+
#### ServiceDetails
|
83
|
+
```
|
84
|
+
rid = '201607294212242'
|
85
|
+
client.service_details(rid)
|
86
|
+
```
|
87
|
+
|
88
|
+
#### Development
|
89
|
+
|
90
|
+
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.
|
91
|
+
|
92
|
+
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).
|
93
|
+
|
94
|
+
## Contributing
|
95
|
+
|
96
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/national_rail_wrapper. 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.
|
97
|
+
|
98
|
+
## License
|
99
|
+
|
100
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
101
|
+
|
102
|
+
## Code of Conduct
|
103
|
+
|
104
|
+
Everyone interacting in the NationalRailWrapper project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/national_rail_wrapper/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 "national_rail_wrapper"
|
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
@@ -0,0 +1,34 @@
|
|
1
|
+
module NationalRailWrapper
|
2
|
+
module Feeds
|
3
|
+
module Base
|
4
|
+
module Requests
|
5
|
+
class Base
|
6
|
+
|
7
|
+
def call(options = {})
|
8
|
+
method = options.fetch(:method, :get)
|
9
|
+
path = options.fetch(:path, '')
|
10
|
+
body = options.fetch(:body, {})
|
11
|
+
query = options.fetch(:query, {})
|
12
|
+
auth_token = options.fetch(:auth_token, {})
|
13
|
+
|
14
|
+
url = base_url + path
|
15
|
+
|
16
|
+
request = Typhoeus::Request.new(url, request_params(method, body, query, auth_token))
|
17
|
+
response = request.run
|
18
|
+
|
19
|
+
response
|
20
|
+
end
|
21
|
+
|
22
|
+
def request_params(method, body, query, auth_token)
|
23
|
+
raise NotImplementedError
|
24
|
+
end
|
25
|
+
|
26
|
+
def base_url
|
27
|
+
raise NotImplementedError
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module NationalRailWrapper
|
2
|
+
module Feeds
|
3
|
+
module HistoricalServicePerformance
|
4
|
+
class Client < NationalRailWrapper::Client
|
5
|
+
|
6
|
+
def service_details(rid, parse_result: false)
|
7
|
+
body = {rid: rid}
|
8
|
+
HistoricalServicePerformance::Requests::ServiceDetails.new.run(auth_token: auth_token, body: body)
|
9
|
+
end
|
10
|
+
|
11
|
+
def service_metrics(body, parse_result: false)
|
12
|
+
HistoricalServicePerformance::Requests::ServiceMetrics.new.run(auth_token: auth_token, body: body)
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def auth_token
|
18
|
+
Base64.strict_encode64("#{@credentials[:username]}:#{@credentials[:password]}")
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module NationalRailWrapper
|
2
|
+
module Feeds::HistoricalServicePerformance::Requests
|
3
|
+
class Base < Feeds::Base::Requests::Base
|
4
|
+
def request_params(method, body, query, auth_token)
|
5
|
+
{
|
6
|
+
method: method,
|
7
|
+
body: body.empty? ? '' : body.to_json,
|
8
|
+
params: query,
|
9
|
+
headers: {
|
10
|
+
'Content-Type' => 'application/json',
|
11
|
+
"Authorization" => "Basic #{auth_token}"
|
12
|
+
},
|
13
|
+
ssl_verifypeer: false
|
14
|
+
}
|
15
|
+
end
|
16
|
+
|
17
|
+
def base_url
|
18
|
+
'https://hsp-prod.rockshore.net/api/v1'
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
module NationalRailWrapper
|
2
|
+
module Feeds
|
3
|
+
module KnowledgeBase
|
4
|
+
class Client < NationalRailWrapper::Client
|
5
|
+
|
6
|
+
def incidents(parse_result: true)
|
7
|
+
request = KnowledgeBase::Requests::Incidents.new.run(auth_token)
|
8
|
+
|
9
|
+
parse_result ? Ox.parse(request.response_body).to_json : request.response_body
|
10
|
+
end
|
11
|
+
|
12
|
+
def national_service_indicators(parse_result: true)
|
13
|
+
request = KnowledgeBase::Requests::NationalServiceIndicators.new.run(auth_token)
|
14
|
+
|
15
|
+
parse_result ? Ox.parse(request.response_body).to_json : request.response_body
|
16
|
+
end
|
17
|
+
|
18
|
+
def public_promotions(parse_result: true)
|
19
|
+
request = KnowledgeBase::Requests::PublicPromotions.new.run(auth_token)
|
20
|
+
|
21
|
+
parse_result ? Ox.parse(request.response_body).to_json : request.response_body
|
22
|
+
end
|
23
|
+
|
24
|
+
def stations(parse_result: true)
|
25
|
+
request = KnowledgeBase::Requests::Stations.new.run(auth_token)
|
26
|
+
|
27
|
+
parse_result ? Ox.parse(request.response_body).to_json : request.response_body
|
28
|
+
end
|
29
|
+
|
30
|
+
def ticket_restrictions(parse_result: true)
|
31
|
+
request = KnowledgeBase::Requests::TicketRestrictions.new.run(auth_token)
|
32
|
+
|
33
|
+
parse_result ? Ox.parse(request.response_body).to_json : request.response_body
|
34
|
+
end
|
35
|
+
|
36
|
+
def ticket_types(parse_result: true)
|
37
|
+
request = KnowledgeBase::Requests::TicketTypes.new.run(auth_token)
|
38
|
+
|
39
|
+
parse_result ? Ox.parse(request.response_body).to_json : request.response_body
|
40
|
+
end
|
41
|
+
|
42
|
+
def tocs(parse_result: true)
|
43
|
+
request = KnowledgeBase::Requests::Tocs.new.run(auth_token)
|
44
|
+
|
45
|
+
parse_result ? Ox.parse(request.response_body).to_json : request.response_body
|
46
|
+
end
|
47
|
+
|
48
|
+
private
|
49
|
+
|
50
|
+
def auth_token
|
51
|
+
return @auth_token if !@auth_token.nil? && @auth_token_expires_at >= Time.now
|
52
|
+
|
53
|
+
response = Net::HTTP.post_form(URI('https://opendata.nationalrail.co.uk/authenticate'), @credentials)
|
54
|
+
response.value # Raise an exception if not successful
|
55
|
+
data = JSON.parse(response.body)
|
56
|
+
token = data.fetch('token')
|
57
|
+
|
58
|
+
# Token expires in 1 hour. Using 55 minutes provides a safety margin.
|
59
|
+
@auth_token_expires_at = Time.now + (55 * 60)
|
60
|
+
|
61
|
+
@auth_token = token
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module NationalRailWrapper
|
2
|
+
module Feeds::KnowledgeBase::Requests
|
3
|
+
class Base < Feeds::Base::Requests::Base
|
4
|
+
|
5
|
+
def request_params(method, body, query, auth_token)
|
6
|
+
{
|
7
|
+
method: method,
|
8
|
+
body: body.empty? ? '' : body.to_json,
|
9
|
+
params: query,
|
10
|
+
headers: {'X-Auth-Token' => auth_token},
|
11
|
+
ssl_verifypeer: false
|
12
|
+
}
|
13
|
+
end
|
14
|
+
|
15
|
+
def base_url
|
16
|
+
'https://opendata.nationalrail.co.uk/api/staticfeeds'
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
File without changes
|
data/lib/national_rail_wrapper/feeds/knowledge_base/response_parser/national_services_indicators.rb
ADDED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module NationalRailWrapper
|
2
|
+
module Feeds
|
3
|
+
module LiveDepartureBoards
|
4
|
+
class Client < NationalRailWrapper::Client
|
5
|
+
|
6
|
+
private
|
7
|
+
|
8
|
+
def auth_token
|
9
|
+
Base64.strict_encode64("#{@credentials[:username]}:#{@credentials[:password]}")
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'typhoeus'
|
2
|
+
require 'ox'
|
3
|
+
|
4
|
+
require "national_rail_wrapper/version"
|
5
|
+
require "national_rail_wrapper/client"
|
6
|
+
|
7
|
+
require_relative "national_rail_wrapper/feeds/base/requests/base"
|
8
|
+
|
9
|
+
require_relative "national_rail_wrapper/feeds/knowledge_base/client"
|
10
|
+
require_relative "national_rail_wrapper/feeds/knowledge_base/requests/base"
|
11
|
+
require_relative "national_rail_wrapper/feeds/knowledge_base/requests/incidents"
|
12
|
+
require_relative "national_rail_wrapper/feeds/knowledge_base/requests/national_service_indicators"
|
13
|
+
require_relative "national_rail_wrapper/feeds/knowledge_base/requests/public_promotions"
|
14
|
+
require_relative "national_rail_wrapper/feeds/knowledge_base/requests/stations"
|
15
|
+
require_relative "national_rail_wrapper/feeds/knowledge_base/requests/ticket_restrictions"
|
16
|
+
require_relative "national_rail_wrapper/feeds/knowledge_base/requests/ticket_types"
|
17
|
+
require_relative "national_rail_wrapper/feeds/knowledge_base/requests/tocs"
|
18
|
+
|
19
|
+
require_relative "national_rail_wrapper/feeds/historical_service_performance/client"
|
20
|
+
require_relative "national_rail_wrapper/feeds/historical_service_performance/requests/base"
|
21
|
+
require_relative "national_rail_wrapper/feeds/historical_service_performance/requests/service_details"
|
22
|
+
require_relative "national_rail_wrapper/feeds/historical_service_performance/requests/service_metrics"
|
23
|
+
|
24
|
+
module NationalRailWrapper
|
25
|
+
class Error < StandardError; end
|
26
|
+
# Your code goes here...
|
27
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "national_rail_wrapper/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "national_rail_wrapper"
|
8
|
+
spec.version = NationalRailWrapper::VERSION
|
9
|
+
spec.authors = ["Marc Best"]
|
10
|
+
spec.email = ["marcbest123@gmail.com.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{A wrapper for the National Rail open data API}
|
13
|
+
spec.description = %q{A wrapper around the National Rail open data API. Including Darwin and Knowledge base}
|
14
|
+
spec.homepage = "https://github.com/marcbest/national_rails_wrapper"
|
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"] = spec.homepage
|
23
|
+
spec.metadata["source_code_uri"] = "https://github.com/marcbest/national_rails_wrapper"
|
24
|
+
spec.metadata["changelog_uri"] = "https://github.com/marcbest/national_rails_wrapper"
|
25
|
+
else
|
26
|
+
raise "RubyGems 2.0 or newer is required to protect against " \
|
27
|
+
"public gem pushes."
|
28
|
+
end
|
29
|
+
|
30
|
+
# Specify which files should be added to the gem when it is released.
|
31
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
32
|
+
spec.files = `git ls-files`.split("\n")
|
33
|
+
# spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
34
|
+
# `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
35
|
+
# end
|
36
|
+
spec.bindir = "exe"
|
37
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
38
|
+
spec.require_paths = ["lib"]
|
39
|
+
|
40
|
+
spec.add_dependency "typhoeus"
|
41
|
+
spec.add_dependency "ox"
|
42
|
+
|
43
|
+
spec.add_development_dependency "bundler", "~> 2.0"
|
44
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
45
|
+
spec.add_development_dependency "pry-byebug"
|
46
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
47
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require "bundler/setup"
|
2
|
+
require "national_rail_wrapper"
|
3
|
+
|
4
|
+
RSpec.configure do |config|
|
5
|
+
# Enable flags like --only-failures and --next-failure
|
6
|
+
config.example_status_persistence_file_path = ".rspec_status"
|
7
|
+
|
8
|
+
# Disable RSpec exposing methods globally on `Module` and `main`
|
9
|
+
config.disable_monkey_patching!
|
10
|
+
|
11
|
+
config.expect_with :rspec do |c|
|
12
|
+
c.syntax = :expect
|
13
|
+
end
|
14
|
+
end
|
metadata
ADDED
@@ -0,0 +1,172 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: national_rail_wrapper
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Marc Best
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-11-24 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: typhoeus
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: ox
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '2.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '2.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '10.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '10.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: pry-byebug
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rspec
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '3.0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '3.0'
|
97
|
+
description: A wrapper around the National Rail open data API. Including Darwin and
|
98
|
+
Knowledge base
|
99
|
+
email:
|
100
|
+
- marcbest123@gmail.com.com
|
101
|
+
executables: []
|
102
|
+
extensions: []
|
103
|
+
extra_rdoc_files: []
|
104
|
+
files:
|
105
|
+
- ".gitignore"
|
106
|
+
- ".rspec"
|
107
|
+
- ".travis.yml"
|
108
|
+
- CHANGELOG.md
|
109
|
+
- CODE_OF_CONDUCT.md
|
110
|
+
- Gemfile
|
111
|
+
- Gemfile.lock
|
112
|
+
- LICENSE.txt
|
113
|
+
- README.md
|
114
|
+
- Rakefile
|
115
|
+
- bin/console
|
116
|
+
- bin/setup
|
117
|
+
- lib/national_rail_wrapper.rb
|
118
|
+
- lib/national_rail_wrapper/client.rb
|
119
|
+
- lib/national_rail_wrapper/feeds/base/requests/base.rb
|
120
|
+
- lib/national_rail_wrapper/feeds/historical_service_performance/client.rb
|
121
|
+
- lib/national_rail_wrapper/feeds/historical_service_performance/requests/base.rb
|
122
|
+
- lib/national_rail_wrapper/feeds/historical_service_performance/requests/service_details.rb
|
123
|
+
- lib/national_rail_wrapper/feeds/historical_service_performance/requests/service_metrics.rb
|
124
|
+
- lib/national_rail_wrapper/feeds/knowledge_base/client.rb
|
125
|
+
- lib/national_rail_wrapper/feeds/knowledge_base/requests/base.rb
|
126
|
+
- lib/national_rail_wrapper/feeds/knowledge_base/requests/incidents.rb
|
127
|
+
- lib/national_rail_wrapper/feeds/knowledge_base/requests/national_service_indicators.rb
|
128
|
+
- lib/national_rail_wrapper/feeds/knowledge_base/requests/public_promotions.rb
|
129
|
+
- lib/national_rail_wrapper/feeds/knowledge_base/requests/stations.rb
|
130
|
+
- lib/national_rail_wrapper/feeds/knowledge_base/requests/ticket_restrictions.rb
|
131
|
+
- lib/national_rail_wrapper/feeds/knowledge_base/requests/ticket_types.rb
|
132
|
+
- lib/national_rail_wrapper/feeds/knowledge_base/requests/tocs.rb
|
133
|
+
- lib/national_rail_wrapper/feeds/knowledge_base/response_parser/incidents.rb
|
134
|
+
- lib/national_rail_wrapper/feeds/knowledge_base/response_parser/national_services_indicators.rb
|
135
|
+
- lib/national_rail_wrapper/feeds/knowledge_base/response_parser/public_promotions.rb
|
136
|
+
- lib/national_rail_wrapper/feeds/knowledge_base/response_parser/stations.rb
|
137
|
+
- lib/national_rail_wrapper/feeds/knowledge_base/response_parser/ticket_restrictions.rb
|
138
|
+
- lib/national_rail_wrapper/feeds/knowledge_base/response_parser/ticket_types.rb
|
139
|
+
- lib/national_rail_wrapper/feeds/knowledge_base/response_parser/tocs.rb
|
140
|
+
- lib/national_rail_wrapper/feeds/live_departure_boards/client.rb
|
141
|
+
- lib/national_rail_wrapper/version.rb
|
142
|
+
- national_rail_wrapper.gemspec
|
143
|
+
- spec/national_rail_wrapper_spec.rb
|
144
|
+
- spec/spec_helper.rb
|
145
|
+
homepage: https://github.com/marcbest/national_rails_wrapper
|
146
|
+
licenses:
|
147
|
+
- MIT
|
148
|
+
metadata:
|
149
|
+
allowed_push_host: https://rubygems.org
|
150
|
+
homepage_uri: https://github.com/marcbest/national_rails_wrapper
|
151
|
+
source_code_uri: https://github.com/marcbest/national_rails_wrapper
|
152
|
+
changelog_uri: https://github.com/marcbest/national_rails_wrapper
|
153
|
+
post_install_message:
|
154
|
+
rdoc_options: []
|
155
|
+
require_paths:
|
156
|
+
- lib
|
157
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
158
|
+
requirements:
|
159
|
+
- - ">="
|
160
|
+
- !ruby/object:Gem::Version
|
161
|
+
version: '0'
|
162
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
163
|
+
requirements:
|
164
|
+
- - ">="
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: '0'
|
167
|
+
requirements: []
|
168
|
+
rubygems_version: 3.0.6
|
169
|
+
signing_key:
|
170
|
+
specification_version: 4
|
171
|
+
summary: A wrapper for the National Rail open data API
|
172
|
+
test_files: []
|