ns-yapi 0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +21 -0
- data/.rvmrc +5 -0
- data/.travis.yml +3 -0
- data/Gemfile +14 -0
- data/Gemfile.lock +68 -0
- data/README.md +17 -0
- data/lib/ns_client.rb +50 -0
- data/ns.gemspec +22 -0
- data/rakefile.rb +5 -0
- data/spec/fixtures/ns_stations.xml +10628 -0
- data/spec/ns_client_spec.rb +44 -0
- data/spec/spec_helper.rb +25 -0
- metadata +108 -0
data/.gitignore
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
coverage
|
6
|
+
InstalledFiles
|
7
|
+
lib/bundler/man
|
8
|
+
pkg
|
9
|
+
rdoc
|
10
|
+
spec/reports
|
11
|
+
test/tmp
|
12
|
+
test/version_tmp
|
13
|
+
tmp
|
14
|
+
|
15
|
+
# YARD artifacts
|
16
|
+
.yardoc
|
17
|
+
_yardoc
|
18
|
+
doc/
|
19
|
+
|
20
|
+
# IntelliJ IDEA / Rubymine IDEA
|
21
|
+
.idea/
|
data/.rvmrc
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
ns-yapi (0.1)
|
5
|
+
httpi
|
6
|
+
nokogiri
|
7
|
+
nori
|
8
|
+
|
9
|
+
GEM
|
10
|
+
remote: http://rubygems.org/
|
11
|
+
specs:
|
12
|
+
addressable (2.3.4)
|
13
|
+
colorize (0.5.8)
|
14
|
+
coveralls (0.6.7)
|
15
|
+
colorize
|
16
|
+
multi_json (~> 1.3)
|
17
|
+
rest-client
|
18
|
+
simplecov (>= 0.7)
|
19
|
+
thor
|
20
|
+
crack (0.4.0)
|
21
|
+
safe_yaml (~> 0.9.0)
|
22
|
+
diff-lcs (1.2.4)
|
23
|
+
httpclient (2.3.3)
|
24
|
+
httpi (2.0.2)
|
25
|
+
rack
|
26
|
+
metaclass (0.0.1)
|
27
|
+
mime-types (1.23)
|
28
|
+
mini_portile (0.5.0)
|
29
|
+
mocha (0.14.0)
|
30
|
+
metaclass (~> 0.0.1)
|
31
|
+
multi_json (1.7.6)
|
32
|
+
nokogiri (1.6.0)
|
33
|
+
mini_portile (~> 0.5.0)
|
34
|
+
nori (2.2.0)
|
35
|
+
rack (1.5.2)
|
36
|
+
rake (10.0.3)
|
37
|
+
rest-client (1.6.7)
|
38
|
+
mime-types (>= 1.16)
|
39
|
+
rspec (2.13.0)
|
40
|
+
rspec-core (~> 2.13.0)
|
41
|
+
rspec-expectations (~> 2.13.0)
|
42
|
+
rspec-mocks (~> 2.13.0)
|
43
|
+
rspec-core (2.13.1)
|
44
|
+
rspec-expectations (2.13.0)
|
45
|
+
diff-lcs (>= 1.1.3, < 2.0)
|
46
|
+
rspec-mocks (2.13.1)
|
47
|
+
safe_yaml (0.9.3)
|
48
|
+
simplecov (0.7.1)
|
49
|
+
multi_json (~> 1.0)
|
50
|
+
simplecov-html (~> 0.7.1)
|
51
|
+
simplecov-html (0.7.1)
|
52
|
+
thor (0.18.1)
|
53
|
+
webmock (1.11.0)
|
54
|
+
addressable (>= 2.2.7)
|
55
|
+
crack (>= 0.3.2)
|
56
|
+
|
57
|
+
PLATFORMS
|
58
|
+
ruby
|
59
|
+
|
60
|
+
DEPENDENCIES
|
61
|
+
coveralls
|
62
|
+
httpclient (~> 2.3.3)
|
63
|
+
mocha
|
64
|
+
ns-yapi!
|
65
|
+
rake
|
66
|
+
rspec
|
67
|
+
simplecov
|
68
|
+
webmock (~> 1.11.0)
|
data/README.md
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
Yet Another NS API [![Build Status](https://travis-ci.org/stefanhendriks/ns-api.png?branch=master)](https://travis-ci.org/stefanhendriks/ns-api) [![Coverage Status](https://coveralls.io/repos/stefanhendriks/ns-api/badge.png)](https://coveralls.io/r/stefanhendriks/ns-api)
|
2
|
+
==================
|
3
|
+
A Ruby client for the NS API.
|
4
|
+
|
5
|
+
|
6
|
+
|
7
|
+
Usage
|
8
|
+
=====
|
9
|
+
First, make sure you have a username and password from the NS API website.
|
10
|
+
```ruby
|
11
|
+
# get username/password from NS site
|
12
|
+
client = NSClient.new("my-username", "my-password")
|
13
|
+
|
14
|
+
# get all known stations
|
15
|
+
client.stations
|
16
|
+
```
|
17
|
+
|
data/lib/ns_client.rb
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'pathname'
|
2
|
+
require 'time'
|
3
|
+
require 'httpi'
|
4
|
+
require 'nori'
|
5
|
+
require 'nokogiri'
|
6
|
+
|
7
|
+
require 'httpclient'
|
8
|
+
|
9
|
+
this = Pathname.new(__FILE__).realpath
|
10
|
+
lib_path = File.expand_path("..", this)
|
11
|
+
$:.unshift(lib_path)
|
12
|
+
|
13
|
+
$ROOT = File.expand_path("../", lib_path)
|
14
|
+
|
15
|
+
Dir.glob(File.join(lib_path, '/**/*.rb')).each do |file|
|
16
|
+
require file
|
17
|
+
end
|
18
|
+
|
19
|
+
class NSClient
|
20
|
+
|
21
|
+
def initialize(username, password)
|
22
|
+
@client = HTTPClient.new
|
23
|
+
@client.set_auth("http://webservices.ns.nl", username, password)
|
24
|
+
end
|
25
|
+
|
26
|
+
def stations
|
27
|
+
response = @client.get "http://webservices.ns.nl/ns-api-stations-v2"
|
28
|
+
result = []
|
29
|
+
xdoc = Nokogiri.XML(response.content)
|
30
|
+
(xdoc/'/Stations/Station').each { |station|
|
31
|
+
s = Station.new
|
32
|
+
s.code = (station/'./Code').text
|
33
|
+
s.type = (station/'./Type').text
|
34
|
+
s.land = (station/'./Land').text
|
35
|
+
s.short_name = (station/'./Namen/Kort').text
|
36
|
+
s.name = (station/'./Namen/Middel').text
|
37
|
+
s.long_name = (station/'./Namen/Lang').text
|
38
|
+
s.lat = (station/'./Lat').text
|
39
|
+
s.long = (station/'./Lon').text
|
40
|
+
s.uiccode = (station/'./UICCode').text
|
41
|
+
result << s
|
42
|
+
}
|
43
|
+
result
|
44
|
+
end
|
45
|
+
|
46
|
+
class Station
|
47
|
+
attr_accessor :code, :type, :land, :short_name, :name, :long_name, :uiccode, :synonyms, :lat, :long
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
data/ns.gemspec
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
|
5
|
+
Gem::Specification.new do |gem|
|
6
|
+
gem.name = "ns-yapi"
|
7
|
+
gem.version = '0.1'
|
8
|
+
gem.authors = ["Stefan Hendriks"]
|
9
|
+
gem.email = ["stefanhen83@gmail.com"]
|
10
|
+
gem.description = %q{A Ruby client for the NS (Dutch Railways) API}
|
11
|
+
gem.summary = %q{A Ruby client for the NS (Dutch Railways) API}
|
12
|
+
gem.homepage = "https://github.com/stefanhendriks/ns-api"
|
13
|
+
|
14
|
+
gem.files = `git ls-files`.split($/)
|
15
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
16
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
17
|
+
gem.require_paths = ["lib"]
|
18
|
+
|
19
|
+
gem.add_dependency 'httpi'
|
20
|
+
gem.add_dependency 'nori'
|
21
|
+
gem.add_dependency 'nokogiri'
|
22
|
+
end
|