ns-yapi 0.3.0 → 0.4.0

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.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ns-yapi (0.3.0)
4
+ ns-yapi (0.4.0)
5
5
  httpclient
6
6
  nokogiri
7
7
  nori
@@ -26,7 +26,7 @@ GEM
26
26
  mini_portile (0.5.0)
27
27
  mocha (0.14.0)
28
28
  metaclass (~> 0.0.1)
29
- multi_json (1.7.6)
29
+ multi_json (1.7.7)
30
30
  nokogiri (1.6.0)
31
31
  mini_portile (~> 0.5.0)
32
32
  nori (2.2.0)
data/lib/ns_client.rb CHANGED
@@ -1,3 +1,4 @@
1
+ #encoding: utf-8
1
2
  require 'pathname'
2
3
  require 'time'
3
4
  require 'nori'
@@ -158,7 +159,11 @@ class NSClient
158
159
 
159
160
  def get_xml(url)
160
161
  response = @client.get url
161
- Nokogiri.XML(response.content)
162
+ Nokogiri.XML(remove_unwanted_whitespace(response.content))
163
+ end
164
+
165
+ def remove_unwanted_whitespace content
166
+ content.gsub /<(\s+?)/, '<'
162
167
  end
163
168
 
164
169
  def disruption_url(query)
@@ -206,4 +211,4 @@ class NSClient
206
211
  class MissingParameter < StandardError
207
212
  end
208
213
 
209
- end
214
+ end
data/ns.gemspec CHANGED
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
 
5
5
  Gem::Specification.new do |gem|
6
6
  gem.name = "ns-yapi"
7
- gem.version = '0.3.0'
7
+ gem.version = '0.4.0'
8
8
  gem.authors = ["Stefan Hendriks"]
9
9
  gem.email = ["stefanhen83@gmail.com"]
10
10
  gem.description = %q{Yet Another (Ruby) NS API client}
@@ -0,0 +1,40 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <Stations>
3
+
4
+ <Station>
5
+ <Code>LC</Code>
6
+ <Type>stoptreinstation</Type>
7
+ <Namen>
8
+ <Kort>Lochem</Kort>
9
+ <
10
+ Middel>Lochem</Middel>
11
+ <Lang>Lochem</Lang>
12
+ </Namen>
13
+ <Land>NL</Land>
14
+ <UICCode>8400399</UICCode>
15
+ <Lat>52.166668</Lat>
16
+ <Lon>6.4263887</Lon>
17
+ <Synoniemen>
18
+
19
+ </Synoniemen>
20
+ </Station>
21
+
22
+ <Station>
23
+ <Code>HT</Code>
24
+ <Type>intercitystation</Type>
25
+ <Namen>
26
+ <Kort>Den Bosch</Kort>
27
+ <Middel>'s-Hertogenbosch</Middel>
28
+ <Lang>'s-Hertogenbosch</Lang>
29
+ </Namen>
30
+ <Land>NL</Land>
31
+ <UICCode>12</UICCode>
32
+ <Lat>52.166668</Lat>
33
+ <Lon>6.4263887</Lon>
34
+ <Synoniemen>
35
+
36
+ </Synoniemen>
37
+ </Station>
38
+
39
+
40
+ </Stations>
@@ -1,3 +1,4 @@
1
+ #encoding: utf-8
1
2
  require 'spec_helper'
2
3
 
3
4
  describe NSClient do
@@ -8,36 +9,52 @@ describe NSClient do
8
9
 
9
10
  context "Stations" do
10
11
 
11
- before :each do
12
- stub_ns_client_request "http://username:password@webservices.ns.nl/ns-api-stations-v2", load_fixture('stations.xml')
13
- end
12
+ context "with valid xml" do
14
13
 
15
- it "should return all stations" do
16
- stations = @client.stations
17
- stations.size.should == 620
18
- end
14
+ before :each do
15
+ stub_ns_client_request "http://username:password@webservices.ns.nl/ns-api-stations-v2", load_fixture('stations.xml')
16
+ end
19
17
 
20
- it "should return expected first station from list" do
21
- stations = @client.stations
22
- first_station = stations.first
23
- first_station.class.should == NSClient::Station
24
- first_station.type.should == "knooppuntIntercitystation"
25
- first_station.code.should == "HT"
26
- first_station.short_name.should == "H'bosch"
27
- first_station.name.should == "'s-Hertogenbosch"
28
- first_station.long_name.should == "'s-Hertogenbosch"
29
- first_station.country.should == "NL"
30
- first_station.uiccode.should == "8400319"
31
- first_station.lat.should == "51.69048"
32
- first_station.long.should == "5.29362"
33
- end
18
+ it "should return all stations" do
19
+ stations = @client.stations
20
+ stations.size.should == 620
21
+ end
22
+
23
+ it "should return expected first station from list" do
24
+ stations = @client.stations
25
+ first_station = stations.first
26
+ first_station.class.should == NSClient::Station
27
+ first_station.type.should == "knooppuntIntercitystation"
28
+ first_station.code.should == "HT"
29
+ first_station.short_name.should == "H'bosch"
30
+ first_station.name.should == "'s-Hertogenbosch"
31
+ first_station.long_name.should == "'s-Hertogenbosch"
32
+ first_station.country.should == "NL"
33
+ first_station.uiccode.should == "8400319"
34
+ first_station.lat.should == "51.69048"
35
+ first_station.long.should == "5.29362"
36
+ end
37
+
38
+ it "should retrieve a convenient hash with usable station names and codes for prices usage" do
39
+ stations = @client.stations_short
40
+ stations.size.should == 620
41
+ stations["HT"].should == ["'s-Hertogenbosch", "NL"]
42
+ end
34
43
 
35
- it "should retrieve a convenient hash with usable station names and codes for prices usage" do
36
- stations = @client.stations_short
37
- stations.size.should == 620
38
- stations["HT"].should == ["'s-Hertogenbosch", "NL"]
39
44
  end
40
45
 
46
+ describe "invalid stations xml" do
47
+
48
+ before :each do
49
+ stub_ns_client_request "http://username:password@webservices.ns.nl/ns-api-stations-v2", load_fixture('stations_list_with_invalid_new_lines.xml')
50
+ end
51
+
52
+ it "should return all stations" do
53
+ stations = @client.stations
54
+ stations.size.should == 2
55
+ end
56
+
57
+ end
41
58
 
42
59
  end
43
60
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ns-yapi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-06-24 00:00:00.000000000 Z
12
+ date: 2013-08-05 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: httpclient
@@ -84,6 +84,7 @@ files:
84
84
  - spec/fixtures/prices.xml
85
85
  - spec/fixtures/prices_invalid_station_name.xml
86
86
  - spec/fixtures/stations.xml
87
+ - spec/fixtures/stations_list_with_invalid_new_lines.xml
87
88
  - spec/model/prices_url_spec.rb
88
89
  - spec/ns_client_spec.rb
89
90
  - spec/nsyapi_spec.rb
@@ -102,7 +103,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
102
103
  version: '0'
103
104
  segments:
104
105
  - 0
105
- hash: -1397451197090581967
106
+ hash: -1576565984611129262
106
107
  required_rubygems_version: !ruby/object:Gem::Requirement
107
108
  none: false
108
109
  requirements:
@@ -111,7 +112,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
111
112
  version: '0'
112
113
  segments:
113
114
  - 0
114
- hash: -1397451197090581967
115
+ hash: -1576565984611129262
115
116
  requirements: []
116
117
  rubyforge_project:
117
118
  rubygems_version: 1.8.24
@@ -126,6 +127,7 @@ test_files:
126
127
  - spec/fixtures/prices.xml
127
128
  - spec/fixtures/prices_invalid_station_name.xml
128
129
  - spec/fixtures/stations.xml
130
+ - spec/fixtures/stations_list_with_invalid_new_lines.xml
129
131
  - spec/model/prices_url_spec.rb
130
132
  - spec/ns_client_spec.rb
131
133
  - spec/nsyapi_spec.rb