Class: Ns::Client
- Inherits:
-
Object
- Object
- Ns::Client
- Defined in:
- lib/ns/client.rb
Instance Method Summary collapse
- #get_departures(station, opts = {}, &block) ⇒ Object
- #get_maintenances(station, actual, unplanned) ⇒ Object
- #get_prices(from, to, opts = {}, &block) ⇒ Object
- #get_stations ⇒ Object
- #get_travel_advice(from, to, opts = {}, &block) ⇒ Object
-
#initialize(api_key = '', api_password = '', opts = {}) ⇒ Client
constructor
A new instance of Client.
Constructor Details
#initialize(api_key = '', api_password = '', opts = {}) ⇒ Client
Returns a new instance of Client.
4 5 6 7 8 9 10 |
# File 'lib/ns/client.rb', line 4 def initialize(api_key = '', api_password = '', opts = {}) @url = 'http://webservices.ns.nl' @port = '80' set_api_cridentials(api_key, api_password) (opts) create_http_client end |
Instance Method Details
#get_departures(station, opts = {}, &block) ⇒ Object
12 13 14 15 16 |
# File 'lib/ns/client.rb', line 12 def get_departures(station, opts = {}, &block) = {}.update(opts) url = "/ns-api-avt?station=#{station.upcase}" get_response(url) end |
#get_maintenances(station, actual, unplanned) ⇒ Object
64 65 66 |
# File 'lib/ns/client.rb', line 64 def get_maintenances(station, actual, unplanned) end |
#get_prices(from, to, opts = {}, &block) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/ns/client.rb', line 18 def get_prices(from, to, opts = {}, &block) = { through: false, date: false }.update(opts) url = "/ns-api-prijzen-v2?" url << "from=#{from.upcase}" url << "&to=#{to.upcase}" url << "&via=#{[:via]}" if [:via].present? url << "&date=#{[:date]}" if [:date].present? URI.escape!(url) get_response(url) end |
#get_stations ⇒ Object
60 61 62 |
# File 'lib/ns/client.rb', line 60 def get_stations get_response('/ns-api-stations') end |
#get_travel_advice(from, to, opts = {}, &block) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/ns/client.rb', line 34 def get_travel_advice(from, to, opts = {}, &block) = { through: '', previous_advices: 5, next_advices: 5, date_time: false, departure: true, hsl: true, year_card: false }.update(opts) url = "/ns-api-treinplanner?" url << "fromStation=#{from.upcase}" url << "&toStation=#{to.upcase}" url << "&viaStation=#{[:through].upcase}" if [:through] != '' url << "&previousAdvices=#{[:previous_advices]}" url << "&nextAdvices=#{[:next_advices]}" url << "&dateTime=#{[:date_time]}" if [:date_time] url << "&departure=#{[:departure]}" url << "&hslAllowed=#{[:hsl]}" url << "&yearCard=#{[:year_card]}" get_response(url) # url end |