class DivvyBike
Constants
- VALID_ARGS
Public Class Methods
all()
click to toggle source
# File lib/divvy_bike.rb, line 15 def self.all get_data end
get(args)
click to toggle source
# File lib/divvy_bike.rb, line 19 def self.get(args) # Only valid arguments allowed args.each do |k_arg, v_arg| if !VALID_ARGS.has_key?(k_arg) return "#{k_arg} is not a valid argument" end end stations = get_data filtered_stations = [] stations.each do |station| if args.all? { |k_arg, v_arg| station[VALID_ARGS[k_arg]] == v_arg } filtered_stations.push(station) end end return filtered_stations end
has_available_bikes()
click to toggle source
# File lib/divvy_bike.rb, line 39 def self.has_available_bikes stations = get_data stations.select { |station| station["availableBikes"] > 0 } end
has_available_docks()
click to toggle source
# File lib/divvy_bike.rb, line 44 def self.has_available_docks stations = get_data stations.select { |station| station["availableDocks"] > 0 } end
Private Class Methods
get_data()
click to toggle source
# File lib/divvy_bike.rb, line 51 def self.get_data if Time.now > @@response_date+60 response = Net::HTTP.get(URI 'http://www.divvybikes.com/stations/json') response_json = JSON.parse(response) @@stations = response_json['stationBeanList'] @@response_date = Time.parse(response_json['executionTime']) end return @@stations end