ns 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +16 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +14 -0
- data/LICENSE +22 -0
- data/README.md +36 -0
- data/Rakefile +2 -0
- data/lib/ns.rb +8 -0
- data/lib/ns/client.rb +93 -0
- data/lib/ns/version.rb +3 -0
- data/ns.gemspec +17 -0
- metadata +55 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Jaimie van Santen
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
# NS
|
2
|
+
|
3
|
+
Provides a Ruby wrapper for the Dutch NS API.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'ns'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install ns
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
ns_client = Ns::Client.new(api_key, api_password)
|
22
|
+
available_stations = ns_client.get_stations
|
23
|
+
advice = ns_client.get_travel_advice(available_stations[0],
|
24
|
+
available_stations[1])
|
25
|
+
|
26
|
+
Should return a travel advice based on the first and second available station.
|
27
|
+
|
28
|
+
|
29
|
+
|
30
|
+
## Contributing
|
31
|
+
|
32
|
+
1. Fork it
|
33
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
34
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
35
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
36
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/lib/ns.rb
ADDED
data/lib/ns/client.rb
ADDED
@@ -0,0 +1,93 @@
|
|
1
|
+
module Ns
|
2
|
+
class Client
|
3
|
+
|
4
|
+
def initialize(api_key = '', api_password = '', opts = {})
|
5
|
+
@url = 'http://webservices.ns.nl'
|
6
|
+
@port = '80'
|
7
|
+
set_api_cridentials(api_key, api_password)
|
8
|
+
set_options(opts)
|
9
|
+
create_http_client
|
10
|
+
end
|
11
|
+
|
12
|
+
def get_departures(station, opts = {}, &block)
|
13
|
+
options = {}.update(opts)
|
14
|
+
url = "/ns-api-avt?station=#{station.upcase}"
|
15
|
+
get_response(url)
|
16
|
+
end
|
17
|
+
|
18
|
+
def get_prices(from, to, opts = {}, &block)
|
19
|
+
options = {
|
20
|
+
through: false,
|
21
|
+
date: false
|
22
|
+
}.update(opts)
|
23
|
+
|
24
|
+
url = "/ns-api-prijzen-v2?"
|
25
|
+
url << "from=#{from.upcase}"
|
26
|
+
url << "&to=#{to.upcase}"
|
27
|
+
url << "&via=#{options[:via]}" if options[:via].present?
|
28
|
+
url << "&date=#{options[:date]}" if options[:date].present?
|
29
|
+
URI.escape!(url)
|
30
|
+
|
31
|
+
get_response(url)
|
32
|
+
end
|
33
|
+
|
34
|
+
def get_travel_advice(from, to, opts = {}, &block)
|
35
|
+
options = {
|
36
|
+
through: '',
|
37
|
+
previous_advices: 5,
|
38
|
+
next_advices: 5,
|
39
|
+
date_time: false,
|
40
|
+
departure: true,
|
41
|
+
hsl: true,
|
42
|
+
year_card: false
|
43
|
+
}.update(opts)
|
44
|
+
|
45
|
+
url = "/ns-api-treinplanner?"
|
46
|
+
url << "fromStation=#{from.upcase}"
|
47
|
+
url << "&toStation=#{to.upcase}"
|
48
|
+
url << "&viaStation=#{options[:through].upcase}" if options[:through] != ''
|
49
|
+
url << "&previousAdvices=#{options[:previous_advices]}"
|
50
|
+
url << "&nextAdvices=#{options[:next_advices]}"
|
51
|
+
url << "&dateTime=#{options[:date_time]}" if options[:date_time]
|
52
|
+
url << "&departure=#{options[:departure]}"
|
53
|
+
url << "&hslAllowed=#{options[:hsl]}"
|
54
|
+
url << "&yearCard=#{options[:year_card]}"
|
55
|
+
|
56
|
+
get_response(url)
|
57
|
+
# url
|
58
|
+
end
|
59
|
+
|
60
|
+
def get_stations
|
61
|
+
get_response('/ns-api-stations')
|
62
|
+
end
|
63
|
+
|
64
|
+
def get_maintenances(station, actual, unplanned)
|
65
|
+
|
66
|
+
end
|
67
|
+
|
68
|
+
private
|
69
|
+
|
70
|
+
def set_api_cridentials(api_key, api_password)
|
71
|
+
@api_key = api_key
|
72
|
+
@api_password = api_password
|
73
|
+
end
|
74
|
+
|
75
|
+
def set_options(options)
|
76
|
+
@options = {
|
77
|
+
|
78
|
+
}.update(options)
|
79
|
+
end
|
80
|
+
|
81
|
+
def create_http_client
|
82
|
+
uri = URI.parse("#{@url}:#{@port}")
|
83
|
+
@client = Net::HTTP.new(uri.host, uri.port)
|
84
|
+
end
|
85
|
+
|
86
|
+
def get_response(path)
|
87
|
+
request = Net::HTTP::Get.new(path)
|
88
|
+
request.basic_auth(@api_key, @api_password)
|
89
|
+
response = @client.request(request)
|
90
|
+
response.body
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
data/lib/ns/version.rb
ADDED
data/ns.gemspec
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/ns/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Jaimie van Santen"]
|
6
|
+
gem.email = ["jaimie@jaimievansanten.nl"]
|
7
|
+
gem.description = %q{Provides a Ruby wrapper for the Dutch NS API}
|
8
|
+
gem.summary = %q{ns api}
|
9
|
+
gem.homepage = "https://github.com/jaimie-van-santen/ns"
|
10
|
+
|
11
|
+
gem.files = `git ls-files`.split($\)
|
12
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
13
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
14
|
+
gem.name = "ns"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = Ns::VERSION
|
17
|
+
end
|
metadata
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ns
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Jaimie van Santen
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-04-22 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: Provides a Ruby wrapper for the Dutch NS API
|
15
|
+
email:
|
16
|
+
- jaimie@jaimievansanten.nl
|
17
|
+
executables: []
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- .gitignore
|
22
|
+
- Gemfile
|
23
|
+
- Gemfile.lock
|
24
|
+
- LICENSE
|
25
|
+
- README.md
|
26
|
+
- Rakefile
|
27
|
+
- lib/ns.rb
|
28
|
+
- lib/ns/client.rb
|
29
|
+
- lib/ns/version.rb
|
30
|
+
- ns.gemspec
|
31
|
+
homepage: https://github.com/jaimie-van-santen/ns
|
32
|
+
licenses: []
|
33
|
+
post_install_message:
|
34
|
+
rdoc_options: []
|
35
|
+
require_paths:
|
36
|
+
- lib
|
37
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
38
|
+
none: false
|
39
|
+
requirements:
|
40
|
+
- - ! '>='
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: '0'
|
43
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
44
|
+
none: false
|
45
|
+
requirements:
|
46
|
+
- - ! '>='
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '0'
|
49
|
+
requirements: []
|
50
|
+
rubyforge_project:
|
51
|
+
rubygems_version: 1.8.23
|
52
|
+
signing_key:
|
53
|
+
specification_version: 3
|
54
|
+
summary: ns api
|
55
|
+
test_files: []
|