ns-yapi 0.4.0 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -11,6 +11,7 @@ spec/reports
11
11
  test/tmp
12
12
  test/version_tmp
13
13
  tmp
14
+ *.DS_Store
14
15
 
15
16
  # YARD artifacts
16
17
  .yardoc
@@ -19,3 +20,6 @@ doc/
19
20
 
20
21
  # IntelliJ IDEA / Rubymine IDEA
21
22
  .idea/
23
+
24
+ # Ignore credentials
25
+ spec/fixtures/credentials.yml
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
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ns-yapi (0.4.0)
4
+ ns-yapi (0.4.1)
5
5
  httpclient
6
6
  nokogiri
7
7
  nori
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
- Nokogiri.XML(remove_unwanted_whitespace(response.content))
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 /<(\s+?)/, '<'
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.0'
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}