Class: Bysykkel::Rack
- Inherits:
-
Object
- Object
- Bysykkel::Rack
- Defined in:
- lib/bysykkel/rack.rb
Constant Summary collapse
- RACKS_URL =
'http://smartbikeportal.clearchannel.no/public/mobapp/maq.asmx/getRacks'
- RACK_URL =
'http://smartbikeportal.clearchannel.no/public/mobapp/maq.asmx/getRack?id=%s'
Instance Attribute Summary collapse
-
#empty_locks ⇒ Object
Returns the value of attribute empty_locks.
-
#id ⇒ Object
Returns the value of attribute id.
-
#lat ⇒ Object
Returns the value of attribute lat.
-
#lng ⇒ Object
Returns the value of attribute lng.
-
#name ⇒ Object
Returns the value of attribute name.
-
#online ⇒ Object
Returns the value of attribute online.
-
#ready_bikes ⇒ Object
Returns the value of attribute ready_bikes.
Class Method Summary collapse
-
.all ⇒ Object
Query the Bysykkel XML API @ clearchannel.no for racks.
-
.find(id) ⇒ Object
Query the Bysykkel XML API @ clearchannel.no for a rack.
Instance Method Summary collapse
-
#initialize(attrs = {}) ⇒ Rack
constructor
A new instance of Rack.
Constructor Details
#initialize(attrs = {}) ⇒ Rack
Returns a new instance of Rack.
12 13 14 15 16 |
# File 'lib/bysykkel/rack.rb', line 12 def initialize(attrs = {}) attrs.each do |k,v| self.__send__("#{k}=", v) end end |
Instance Attribute Details
#empty_locks ⇒ Object
Returns the value of attribute empty_locks.
10 11 12 |
# File 'lib/bysykkel/rack.rb', line 10 def empty_locks @empty_locks end |
#id ⇒ Object
Returns the value of attribute id.
10 11 12 |
# File 'lib/bysykkel/rack.rb', line 10 def id @id end |
#lat ⇒ Object
Returns the value of attribute lat.
10 11 12 |
# File 'lib/bysykkel/rack.rb', line 10 def lat @lat end |
#lng ⇒ Object
Returns the value of attribute lng.
10 11 12 |
# File 'lib/bysykkel/rack.rb', line 10 def lng @lng end |
#name ⇒ Object
Returns the value of attribute name.
10 11 12 |
# File 'lib/bysykkel/rack.rb', line 10 def name @name end |
#online ⇒ Object
Returns the value of attribute online.
10 11 12 |
# File 'lib/bysykkel/rack.rb', line 10 def online @online end |
#ready_bikes ⇒ Object
Returns the value of attribute ready_bikes.
10 11 12 |
# File 'lib/bysykkel/rack.rb', line 10 def ready_bikes @ready_bikes end |
Class Method Details
.all ⇒ Object
Query the Bysykkel XML API @ clearchannel.no for racks.
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/bysykkel/rack.rb', line 19 def self.all() raw = open(RACKS_URL) doc = Nokogiri::XML.parse raw racks_xml = Nokogiri::XML('<stations>' + doc.children[0].children[0].text + '</stations>') racks = racks_xml.xpath('//station').children.inject([]) do |ary, rack| ary << Rack.new({ :id => rack.text.to_i }) unless rack.text.to_i >= 500 ary end hydra = Typhoeus::Hydra.new( :max_concurrency => 6, :initial_pool_size => 5 ) racks_all = [] racks.each do |rack| req = Typhoeus::Request.new( RACK_URL % rack.id ) req.on_complete do |response| doc = Nokogiri::XML.parse response.body parsed_rack = self.parse_rack(rack.id, Nokogiri::XML(doc.children[0].children[0].text).children[0]) racks_all << parsed_rack unless parsed_rack.nil? end hydra.queue req end hydra.run racks_all end |
.find(id) ⇒ Object
Query the Bysykkel XML API @ clearchannel.no for a rack.
47 48 49 50 51 52 |
# File 'lib/bysykkel/rack.rb', line 47 def self.find(id) raw = open(RACK_URL % id ) doc = Nokogiri::XML.parse raw parsed_rack = self.parse_rack(id, Nokogiri::XML(doc.children[0].children[0].text).children[0]) return parsed_rack ? [parsed_rack] : [] end |