ns-yapi 0.4.0 → 0.4.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.
- data/.gitignore +4 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/Gemfile.lock +1 -1
- data/lib/ns_client.rb +18 -2
- data/ns.gemspec +1 -1
- data/spec/fixtures/invalid_stations_xml.xml +10510 -0
- data/spec/fixtures/stations_cannot_find_pmw.xml +10475 -0
- data/spec/fixtures/stations_list_mangled.xml +52 -0
- data/spec/fixtures/stations_list_with_invalid_new_lines.xml +34 -33
- data/spec/ns_client_spec.rb +79 -23
- data/spec/spec_helper.rb +11 -0
- metadata +12 -5
- data/.rvmrc +0 -5
data/.gitignore
CHANGED
data/.ruby-gemset
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
ns-api
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
ruby-1.9.3-p194
|
data/Gemfile.lock
CHANGED
data/lib/ns_client.rb
CHANGED
@@ -42,10 +42,14 @@ end
|
|
42
42
|
|
43
43
|
class NSClient
|
44
44
|
|
45
|
+
attr_accessor :last_received_raw_xml, :last_received_corrected_xml
|
46
|
+
|
45
47
|
def initialize(username, password)
|
46
48
|
@client = HTTPClient.new
|
47
49
|
@client.set_auth("http://webservices.ns.nl", username, password)
|
48
50
|
@prices_url = PricesUrl.new("http://webservices.ns.nl/ns-api-prijzen-v2")
|
51
|
+
@last_received_raw_xml = ""
|
52
|
+
@last_received_corrected_xml = ""
|
49
53
|
end
|
50
54
|
|
51
55
|
def stations
|
@@ -159,11 +163,20 @@ class NSClient
|
|
159
163
|
|
160
164
|
def get_xml(url)
|
161
165
|
response = @client.get url
|
162
|
-
|
166
|
+
@last_received_raw_xml = response.content
|
167
|
+
@last_received_corrected_xml = remove_unwanted_whitespace(@last_received_raw_xml)
|
168
|
+
begin
|
169
|
+
Nokogiri.XML(@last_received_corrected_xml) do |config|
|
170
|
+
config.options = Nokogiri::XML::ParseOptions::STRICT
|
171
|
+
end
|
172
|
+
rescue Nokogiri::XML::SyntaxError => e
|
173
|
+
raise UnparseableXMLError.new e
|
174
|
+
end
|
175
|
+
|
163
176
|
end
|
164
177
|
|
165
178
|
def remove_unwanted_whitespace content
|
166
|
-
content.gsub
|
179
|
+
content.gsub /<\s*(\/?)\s*?([a-zA-Z0-9]*)\s*>/, '<\1\2>'
|
167
180
|
end
|
168
181
|
|
169
182
|
def disruption_url(query)
|
@@ -211,4 +224,7 @@ class NSClient
|
|
211
224
|
class MissingParameter < StandardError
|
212
225
|
end
|
213
226
|
|
227
|
+
class UnparseableXMLError < StandardError
|
228
|
+
end
|
229
|
+
|
214
230
|
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.4.
|
7
|
+
gem.version = '0.4.1'
|
8
8
|
gem.authors = ["Stefan Hendriks"]
|
9
9
|
gem.email = ["stefanhen83@gmail.com"]
|
10
10
|
gem.description = %q{Yet Another (Ruby) NS API client}
|