national_rail_wrapper 0.1.2 → 0.1.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d647f77e5c3ad869af182903c9bdf177681457e82b44c4dce917091a008c8b50
4
- data.tar.gz: cce5619a39b42eaaad002cf603b3818a966a9f165a929b24efea20d9a50b22da
3
+ metadata.gz: 60858d6a68198583863a9aa97c96fee27c4bd3a29f9a9e6e12dbe1779f9654ae
4
+ data.tar.gz: bfdff1ee26952b22c0147bae89dbe100748359cf4045fa88d172fb4ffb922f63
5
5
  SHA512:
6
- metadata.gz: 42b67e82fa8caa0eed1dd8c508ec8c3c9ed190be4d2d2cb824212b0ea23bf53925486ef367d8a11fb983434f93ad1c185d798b8e0331dd1fa4308248f5ee5a04
7
- data.tar.gz: fc3fe4555f084e7a343eee2542a10fa8f1c456babd14534469d6b5745391db79a8f4208e57bade852310f917ae64e9d2413e956668978075ee144fc1d824fc24
6
+ metadata.gz: 2678154e89067563a21d1c4a188fcad883eaa488c0a145d3739bb7f4ad68117ee9240e1a5002bb898f50dcaf8de13cb1d0e7deeb54178569bafc5ce2078f4d57
7
+ data.tar.gz: 80ab35617e5f152eb21de8c74a7598fc10f4e32298c2a476feeebd985febb23f2947b709310a6907059c80334bdf9d0a9b08f18bd2e3073fc133d5cd9a4552cf
data/Gemfile.lock CHANGED
@@ -1,7 +1,8 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- national_rail_wrapper (0.1.0)
4
+ national_rail_wrapper (0.1.2)
5
+ nokogiri
5
6
  ox
6
7
  typhoeus
7
8
 
@@ -13,8 +14,11 @@ GEM
13
14
  diff-lcs (1.3)
14
15
  ethon (0.12.0)
15
16
  ffi (>= 1.3.0)
16
- ffi (1.11.2)
17
+ ffi (1.11.3)
17
18
  method_source (0.9.2)
19
+ mini_portile2 (2.4.0)
20
+ nokogiri (1.10.5)
21
+ mini_portile2 (~> 2.4.0)
18
22
  ox (2.11.0)
19
23
  pry (0.12.2)
20
24
  coderay (~> 1.1.0)
data/README.md CHANGED
@@ -25,7 +25,6 @@ Or install it yourself as:
25
25
  $ gem install national_rail_wrapper
26
26
 
27
27
  ## Usage
28
- client = NationalRailWrapper::Feeds::Client.new(username: username, password: password)
29
28
 
30
29
  ### Knowledge Base
31
30
  ```
@@ -10,11 +10,14 @@ require_relative "national_rail_wrapper/feeds/knowledge_base/client"
10
10
  require_relative "national_rail_wrapper/feeds/knowledge_base/requests/base"
11
11
  require_relative "national_rail_wrapper/feeds/knowledge_base/requests/incidents"
12
12
  require_relative "national_rail_wrapper/feeds/knowledge_base/requests/national_service_indicators"
13
+ require_relative "national_rail_wrapper/feeds/knowledge_base/parsers/national_service_indicators"
13
14
  require_relative "national_rail_wrapper/feeds/knowledge_base/requests/public_promotions"
14
15
  require_relative "national_rail_wrapper/feeds/knowledge_base/requests/stations"
16
+ require_relative "national_rail_wrapper/feeds/knowledge_base/parsers/stations"
15
17
  require_relative "national_rail_wrapper/feeds/knowledge_base/requests/ticket_restrictions"
16
18
  require_relative "national_rail_wrapper/feeds/knowledge_base/requests/ticket_types"
17
19
  require_relative "national_rail_wrapper/feeds/knowledge_base/requests/tocs"
20
+ require_relative "national_rail_wrapper/feeds/knowledge_base/parsers/tocs"
18
21
 
19
22
  require_relative "national_rail_wrapper/feeds/historical_service_performance/client"
20
23
  require_relative "national_rail_wrapper/feeds/historical_service_performance/requests/base"
@@ -6,47 +6,63 @@ module NationalRailWrapper
6
6
  def incidents(parse_result: true)
7
7
  request = KnowledgeBase::Requests::Incidents.new.run(auth_token)
8
8
 
9
- parse_result ? Ox.parse(request.response_body).to_json : request.response_body
9
+ parse_result ? Ox.parse(request.response_body).to_json : request.response_body
10
10
  end
11
11
 
12
12
  def national_service_indicators(parse_result: true)
13
- request = KnowledgeBase::Requests::NationalServiceIndicators.new.run(auth_token)
13
+ request = KnowledgeBase::Requests::NationalServiceIndicators.new.run(auth_token).response_body
14
14
 
15
- parse_result ? Ox.parse(request.response_body).to_json : request.response_body
15
+ if parse_result
16
+ KnowledgeBase::Parsers::NationalServiceIndicators.new(request).to_json
17
+ else
18
+ request.response_body
19
+ end
16
20
  end
17
21
 
18
22
  def public_promotions(parse_result: true)
19
23
  request = KnowledgeBase::Requests::PublicPromotions.new.run(auth_token)
20
24
 
21
- parse_result ? Ox.parse(request.response_body).to_json : request.response_body
25
+ parse_result ? response.to_json : request.response_body
22
26
  end
23
27
 
24
28
  def stations(parse_result: true)
25
- request = KnowledgeBase::Requests::Stations.new.run(auth_token)
29
+ request = KnowledgeBase::Requests::Stations.new.run(auth_token).response_body
26
30
 
27
- parse_result ? Ox.parse(request.response_body).to_json : request.response_body
31
+ if parse_result
32
+ KnowledgeBase::Parsers::Stations.new(request).to_json
33
+ else
34
+ request.response_body
35
+ end
28
36
  end
29
37
 
30
38
  def ticket_restrictions(parse_result: true)
31
- request = KnowledgeBase::Requests::TicketRestrictions.new.run(auth_token)
39
+ request = KnowledgeBase::Requests::TicketRestrictions.new.run(auth_token)
32
40
 
33
- parse_result ? Ox.parse(request.response_body).to_json : request.response_body
41
+ parse_result ? Ox.parse(request.response_body).to_json : request.response_body
34
42
  end
35
43
 
36
44
  def ticket_types(parse_result: true)
37
45
  request = KnowledgeBase::Requests::TicketTypes.new.run(auth_token)
38
-
39
- parse_result ? Ox.parse(request.response_body).to_json : request.response_body
46
+
47
+ parse_result ? Ox.parse(request.response_body).to_json : request.response_body
40
48
  end
41
49
 
42
50
  def tocs(parse_result: true)
43
- request = KnowledgeBase::Requests::Tocs.new.run(auth_token)
51
+ request = KnowledgeBase::Requests::Tocs.new.run(auth_token).response_body
44
52
 
45
- parse_result ? Ox.parse(request.response_body).to_json : request.response_body
53
+ if parse_result
54
+ KnowledgeBase::Parsers::Tocs.new(request).to_json
55
+ else
56
+ request.response_body
57
+ end
46
58
  end
47
59
 
48
60
  private
49
61
 
62
+ def parse_result(endpoint, response)
63
+ "KnowledgeBase::Parsers::#{endpoint.camelize}".constantize.new(request).to_json
64
+ end
65
+
50
66
  def auth_token
51
67
  return @auth_token if !@auth_token.nil? && @auth_token_expires_at >= Time.now
52
68
 
@@ -0,0 +1,26 @@
1
+ module NationalRailWrapper
2
+ module Feeds
3
+ module KnowledgeBase
4
+ module Parsers
5
+ class Incidents
6
+ def initialize(data)
7
+ @data = data
8
+ end
9
+
10
+ def to_json
11
+ options = Nokogiri::XML::ParseOptions.new.nonet.noent.noblanks
12
+ doc = Nokogiri::XML.parse(@data, nil, nil, options)
13
+ doc.xpath('/xmlns:NSI/xmlns:TOC').map do |toc_node|
14
+ {
15
+
16
+ }
17
+ end
18
+ end
19
+
20
+ private
21
+
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,44 @@
1
+ module NationalRailWrapper
2
+ module Feeds
3
+ module KnowledgeBase
4
+ module Parsers
5
+ class NationalServiceIndicators
6
+ def initialize(data)
7
+ @data = data
8
+ end
9
+
10
+ def to_json
11
+ options = Nokogiri::XML::ParseOptions.new.nonet.noent.noblanks
12
+ doc = Nokogiri::XML.parse(@data, nil, nil, options)
13
+ doc.xpath('/xmlns:NSI/xmlns:TOC').map do |toc_node|
14
+ {
15
+ toc_code: toc_node.xpath('./xmlns:TocCode').first&.content,
16
+ toc_name: toc_node.xpath('./xmlns:TocName').first&.content,
17
+ status: toc_node.xpath('./xmlns:Status').first&.content,
18
+ status_image: toc_node.xpath('./xmlns:StatusImage').first&.content,
19
+ status_description: toc_node.xpath('./xmlns:StatusDescription').first&.content,
20
+ service_groups: service_groups(toc_node.xpath('./xmlns:ServiceGroup')),
21
+ twitter_account: toc_node.xpath('./xmlns:TwitterAccount').first&.content,
22
+ additional_info: toc_node.xpath('./xmlns:AdditionalInfo').first&.content,
23
+ custom_additional_info: toc_node.xpath('./xmlns:CustomAdditionalInfo').first&.content
24
+ }
25
+ end
26
+ end
27
+
28
+ private
29
+
30
+ def service_groups(service_groups)
31
+ service_groups.map do |service_group|
32
+ {
33
+ group_name: service_group.xpath('./xmlns:GroupName').first&.content,
34
+ current_distruption: service_group.xpath('./xmlns:CurrentDisruption').first&.content,
35
+ custom_detail: service_group.xpath('./xmlns:CustomDetail').first&.content,
36
+ custom_url: service_group.xpath('./xmlns:CustomURL').first&.content
37
+ }
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,111 @@
1
+ module NationalRailWrapper
2
+ module Feeds
3
+ module KnowledgeBase
4
+ module Parsers
5
+ class Stations
6
+ def initialize(data)
7
+ @data = data
8
+ end
9
+
10
+ def to_json
11
+ options = Nokogiri::XML::ParseOptions.new.nonet.noent.noblanks.huge
12
+ doc = Nokogiri::XML.parse(@data, nil, nil, options)
13
+
14
+ doc.xpath('/xmlns:StationList/xmlns:Station').map do |toc_node|
15
+ {
16
+ name: toc_node.xpath('./xmlns:Name')&.text,
17
+ crs_code: toc_node.css('CrsCode')&.text,
18
+ alternative_identifiers: toc_node.css('AlternativeIdentifiers')&.text,
19
+ sixteen_character_name: toc_node.css('SixteenCharacterName')&.text,
20
+ longitude: toc_node.css('Longitude')&.text,
21
+ latitude: toc_node.css('Latitude')&.text,
22
+ station_operator: toc_node.css('StationOperator')&.text,
23
+ staffing_level: toc_node.css('Staffing/StaffingLevel')&.text,
24
+ closed_circuit_television: toc_node.css('Staffing/ClosedCircuitTelevision')&.text,
25
+ station_facilities: station_facilities(toc_node.css('StationFacilities')),
26
+ # impaired_access: impaired_access(toc_node.css('ImpairedAccess'))
27
+ car_park: car_park(toc_node.css('CarPark'))
28
+
29
+ }
30
+ end
31
+ end
32
+
33
+
34
+ # national_location_code: toc_node.xpath('./xmlns:NationalLocationCode').first&.content,
35
+ # address: toc_node.xpath('./xmlns:Address').first&.content,
36
+ # postal_address: toc_node.xpath('./xmlns:PostalAddress').first&.content,
37
+ # #<add:A_5LineAddress> (mandatory) See section 2.4.1
38
+
39
+ # station_operator: toc_node.css('StationOperator').text, #
40
+ # Overall: toc_node.xpath('./xmlns:Overall').first&.content,
41
+ # InformationSystems: toc_node.xpath('./xmlns:InformationSystems').first&.content,
42
+ # cis: cis,
43
+ # fares: fares(toc_node.xpath('./xmlns:Fares').first),
44
+ # passenger_services: passenger_services,
45
+ # impaired_access: impaired_access,
46
+ # InterChange: inter_change,
47
+ # StationAlerts: toc_node.xpath('./xmlns:PostalAddress').first&.content,
48
+ # AlertText: toc_node.xpath('./xmlns:PostalAddress').first&.content,
49
+ # LastChangedDate: toc_node.xpath('./xmlns:PostalAddress').first&.content,
50
+ # car_park: car_park,
51
+ # opening_hours: opening_hours,
52
+ # contact_details: contact_details
53
+
54
+ private
55
+
56
+ def cis(toc_node)
57
+ end
58
+
59
+ def fares(fares)
60
+
61
+ end
62
+
63
+ def passenger_services(toc_node)
64
+ end
65
+
66
+ def station_facilities(node_set)
67
+ {
68
+ first_class_lounge: node_set.at('FirstClassLounge')&.text,
69
+ waiting_room: node_set.at('WaitingRoom')&.text,
70
+ trolleys: node_set.at('Trolleys')&.text,
71
+ station_buffet: node_set.at('StationBuffet')&.text,
72
+ toilets: node_set.at('Toilets')&.text,
73
+ baby_change: node_set.at('BabyChange')&.text,
74
+ showers: node_set.at('Showers')&.text,
75
+ # telephone: {
76
+ # exists:
77
+ # usage_type:
78
+ # },
79
+ wifi: node_set.at('WiFi')&.text,
80
+ post_box: node_set.at('BabyChange')&.text,
81
+ # tourist_information_office:
82
+ atm_machine: node_set.at('AtmMachine')&.text,
83
+ bureau_de_change: node_set.at('BureauDeChange')&.text,
84
+ shops: node_set.at('Shops')&.text
85
+ }
86
+ end
87
+
88
+ def impaired_access(toc_node)
89
+ end
90
+
91
+ def inter_change(toc_node)
92
+ end
93
+
94
+ def car_park(node_set)
95
+ {
96
+ name: node_set.at('Name')&.text,
97
+ spaces: node_set.at('Spaces')&.text
98
+ }
99
+ end
100
+
101
+ def opening_hours(toc_node)
102
+ end
103
+
104
+ def contact_details(toc_node)
105
+ end
106
+
107
+ end
108
+ end
109
+ end
110
+ end
111
+ end
@@ -0,0 +1,36 @@
1
+ module NationalRailWrapper
2
+ module Feeds
3
+ module KnowledgeBase
4
+ module Parsers
5
+ class Tocs
6
+ def initialize(data)
7
+ @data = data
8
+ end
9
+
10
+ def to_json
11
+ options = Nokogiri::XML::ParseOptions.new.nonet.noent.noblanks.huge
12
+ doc = Nokogiri::XML.parse(@data, nil, nil, options)
13
+
14
+ doc.xpath('/xmlns:StationList/xmlns:Station').map do |toc_node|
15
+ {
16
+ name: toc_node.xpath('./xmlns:Name')&.text,
17
+ crs_code: toc_node.css('CrsCode')&.text,
18
+ alternative_identifiers: toc_node.css('AlternativeIdentifiers')&.text,
19
+ sixteen_character_name: toc_node.css('SixteenCharacterName')&.text,
20
+ longitude: toc_node.css('Longitude')&.text,
21
+ latitude: toc_node.css('Latitude')&.text,
22
+ station_operator: toc_node.css('StationOperator')&.text,
23
+ staffing_level: toc_node.css('Staffing/StaffingLevel')&.text,
24
+ closed_circuit_television: toc_node.css('Staffing/ClosedCircuitTelevision')&.text,
25
+ station_facilities: station_facilities(toc_node.css('StationFacilities')),
26
+ # impaired_access: impaired_access(toc_node.css('ImpairedAccess'))
27
+ car_park: car_park(toc_node.css('CarPark'))
28
+
29
+ }
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
@@ -1,3 +1,3 @@
1
1
  module NationalRailWrapper
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
@@ -39,6 +39,7 @@ Gem::Specification.new do |spec|
39
39
 
40
40
  spec.add_dependency "typhoeus"
41
41
  spec.add_dependency "ox"
42
+ spec.add_dependency "nokogiri"
42
43
 
43
44
  spec.add_development_dependency "bundler", "~> 2.0"
44
45
  spec.add_development_dependency "rake", "~> 10.0"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: national_rail_wrapper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marc Best
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-11-24 00:00:00.000000000 Z
11
+ date: 2020-04-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: typhoeus
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: nokogiri
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: bundler
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -122,6 +136,13 @@ files:
122
136
  - lib/national_rail_wrapper/feeds/historical_service_performance/requests/service_details.rb
123
137
  - lib/national_rail_wrapper/feeds/historical_service_performance/requests/service_metrics.rb
124
138
  - lib/national_rail_wrapper/feeds/knowledge_base/client.rb
139
+ - lib/national_rail_wrapper/feeds/knowledge_base/parsers/incidents.rb
140
+ - lib/national_rail_wrapper/feeds/knowledge_base/parsers/national_service_indicators.rb
141
+ - lib/national_rail_wrapper/feeds/knowledge_base/parsers/public_promotions.rb
142
+ - lib/national_rail_wrapper/feeds/knowledge_base/parsers/stations.rb
143
+ - lib/national_rail_wrapper/feeds/knowledge_base/parsers/ticket_restrictions.rb
144
+ - lib/national_rail_wrapper/feeds/knowledge_base/parsers/ticket_types.rb
145
+ - lib/national_rail_wrapper/feeds/knowledge_base/parsers/tocs.rb
125
146
  - lib/national_rail_wrapper/feeds/knowledge_base/requests/base.rb
126
147
  - lib/national_rail_wrapper/feeds/knowledge_base/requests/incidents.rb
127
148
  - lib/national_rail_wrapper/feeds/knowledge_base/requests/national_service_indicators.rb
@@ -130,13 +151,6 @@ files:
130
151
  - lib/national_rail_wrapper/feeds/knowledge_base/requests/ticket_restrictions.rb
131
152
  - lib/national_rail_wrapper/feeds/knowledge_base/requests/ticket_types.rb
132
153
  - 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
154
  - lib/national_rail_wrapper/feeds/live_departure_boards/client.rb
141
155
  - lib/national_rail_wrapper/version.rb
142
156
  - national_rail_wrapper.gemspec