Class: Ns::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/ns/client.rb

Instance Method Summary collapse

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)
  set_options(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)
  options = {}.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)
  options = {
    through: false,
    date: false
  }.update(opts)

  url = "/ns-api-prijzen-v2?"
  url << "from=#{from.upcase}"
  url << "&to=#{to.upcase}"
  url << "&via=#{options[:via]}" if options[:via].present?
  url << "&date=#{options[:date]}" if options[:date].present?
  URI.escape!(url)

  get_response(url)
end

#get_stationsObject



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)
  options = {
    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=#{options[:through].upcase}" if options[:through] != ''
  url << "&previousAdvices=#{options[:previous_advices]}"
  url << "&nextAdvices=#{options[:next_advices]}"
  url << "&dateTime=#{options[:date_time]}" if options[:date_time]
  url << "&departure=#{options[:departure]}"
  url << "&hslAllowed=#{options[:hsl]}"
  url << "&yearCard=#{options[:year_card]}"

  get_response(url)
  # url
end