Class: Drivenow::Agent
- Inherits:
-
Object
- Object
- Drivenow::Agent
- Defined in:
- lib/drivenow/drivenow_agent.rb
Instance Attribute Summary collapse
-
#cars ⇒ Object
readonly
Returns the value of attribute cars.
Class Method Summary collapse
-
.cities ⇒ Object
Gets all cities that are available at the moment, currently * Berlin * Düsseldorf * München Can easily be overridden if there are more cities available in the future.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Agent
constructor
Creates a new instance of the Drivenow::Agent.
- #inspect ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Agent
Creates a new instance of the Drivenow::Agent. options:
:city => The City you want to get all for. e.g. :berlin
:uri => The URI can be changed in case you want to test locally or anything else
– TODO: Option for the Xpath for cars-array inside the JSON
15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/drivenow/drivenow_agent.rb', line 15 def initialize( = {}) cities = Agent.cities unless [:city].nil? url_params = "cit=#{cities[[:city]]}" end = { :uri => "https://www.drive-now.com/php/metropolis/json.vehicle_filter?#{url_params}" }.merge() page = open([:uri]).read cars = JSON(page)["rec"]["vehicles"]["vehicles"] cities = cities.invert cars.each { |item| item["cit"] = cities[item["cit"]] } cars.map! { |item| Car.new(item) } @cars = cars end |
Instance Attribute Details
#cars ⇒ Object (readonly)
Returns the value of attribute cars.
7 8 9 |
# File 'lib/drivenow/drivenow_agent.rb', line 7 def cars @cars end |
Class Method Details
.cities ⇒ Object
Gets all cities that are available at the moment, currently
* Berlin
* Düsseldorf
* München
Can easily be overridden if there are more cities available in the future
39 40 41 42 43 44 45 46 |
# File 'lib/drivenow/drivenow_agent.rb', line 39 def self.cities { :duesseldorf => "1293", :berlin => "6099", :muenchen => "4604", :koeln => "1774" } end |
Instance Method Details
#inspect ⇒ Object
30 31 32 |
# File 'lib/drivenow/drivenow_agent.rb', line 30 def inspect @cars.inspect end |