Class: TransilienRealtime::Base
- Inherits:
-
Object
- Object
- TransilienRealtime::Base
- Defined in:
- lib/transilien_realtime/base.rb
Constant Summary collapse
- DOCUMENTATION_VERSION =
'0.2'
- API_VERSION =
'1.0'
- API_TARGETS =
{ production: 'http://api.transilien.com/', staging: 'http://85.233.209.222:1399/' }
- ACCEPT_STRINGS =
{ '1.0' => 'application/vnd.sncf.transilien.od.depart+xml;vers=1.0' }
Instance Method Summary collapse
- #body ⇒ Object
- #content ⇒ Object
-
#initialize(user: ENV['RTT_API_USER'], pwd: ENV['RTT_API_PWD'], target: :production) ⇒ Base
constructor
A new instance of Base.
- #json ⇒ Object
- #next(from:, to: nil) ⇒ Object
- #response ⇒ Object
- #trains ⇒ Object
- #xml ⇒ Object
- #xml_document ⇒ Object
Constructor Details
#initialize(user: ENV['RTT_API_USER'], pwd: ENV['RTT_API_PWD'], target: :production) ⇒ Base
Returns a new instance of Base.
19 20 21 22 23 24 |
# File 'lib/transilien_realtime/base.rb', line 19 def initialize(user: ENV['RTT_API_USER'], pwd: ENV['RTT_API_PWD'], target: :production) @user = user @pwd = pwd @target = target end |
Instance Method Details
#body ⇒ Object
47 |
# File 'lib/transilien_realtime/base.rb', line 47 def body; @body; end |
#content ⇒ Object
48 |
# File 'lib/transilien_realtime/base.rb', line 48 def content; @content; end |
#json ⇒ Object
41 42 43 44 |
# File 'lib/transilien_realtime/base.rb', line 41 def json return nil unless trains "[#{trains.map(&:to_json).join(',')}]" end |
#next(from:, to: nil) ⇒ Object
26 27 28 29 30 |
# File 'lib/transilien_realtime/base.rb', line 26 def next(from:, to: nil) raise ArgumentError, 'from param is mandatory' unless from fetch(build_request(from, to)) self end |
#response ⇒ Object
46 |
# File 'lib/transilien_realtime/base.rb', line 46 def response; @response; end |
#trains ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/transilien_realtime/base.rb', line 50 def trains @trains ||= begin return nil unless xml_document trains = [] xml_document.xpath('//train').each do |train_node| begin trains << Train.from_xml(train_node) rescue Exception => e $stderr << "FAILURE! WAS READING #{train_node.to_s.inspect}" raise e end end trains.freeze end end |
#xml ⇒ Object
37 38 39 |
# File 'lib/transilien_realtime/base.rb', line 37 def xml @content end |
#xml_document ⇒ Object
32 33 34 35 |
# File 'lib/transilien_realtime/base.rb', line 32 def xml_document return nil unless @content Nokogiri::XML(@content) end |