divvy_bike 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/divvy_bike.rb +36 -0
- metadata +1 -1
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA1:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 3ded21bd568e60c6545914b19cdf80472da90e7c
         | 
| 4 | 
            +
              data.tar.gz: 9ab289a93e6329d576104e7a8d9e3f58c3a87af6
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 200582f41706f8238d7c6c60a5c983676fe6a7f01a740feb7f5d6bea24ad125aa7ea6fdc725b87a57b8d31912ebb42bede2bc82d46899f658606ae2841eccdac
         | 
| 7 | 
            +
              data.tar.gz: 72ff2c4e7ccbbbf1b3ae723fd21143cfcd10e2015f817196dbcc711433f9f2242e30ec93fe641597454ff8f6569dfe52c13a54b681050cae949ad8028173e2a5
         | 
    
        data/lib/divvy_bike.rb
    CHANGED
    
    | @@ -3,6 +3,12 @@ require 'json' | |
| 3 3 | 
             
            require 'time'
         | 
| 4 4 |  | 
| 5 5 | 
             
            class DivvyBike
         | 
| 6 | 
            +
            	VALID_ARGS = {:id => "id", :station_name => "stationName", :available_docks => "availableDocks", :total_docks => "totalDocks", 
         | 
| 7 | 
            +
            				 :latitude => "latitude", :longitude => "longitude", :status_value => "statusValue", :status_key => "statusKey", 
         | 
| 8 | 
            +
            				 :available_bikes => "availableBikes", :st_address_1 => "stAddress1", :st_address_2 => "stAddress2", :city => "city",
         | 
| 9 | 
            +
            				 :postal_code => "postalCode", :location => "location", :altitude => "altitude", :test_station => "testStation", 
         | 
| 10 | 
            +
            				 :last_communication_time => "lastCommunicationTime", :land_mark => "landMark"}
         | 
| 11 | 
            +
             | 
| 6 12 | 
             
            	@@stations = {}
         | 
| 7 13 | 
             
            	@@response_date = Time.now-60
         | 
| 8 14 |  | 
| @@ -10,6 +16,36 @@ class DivvyBike | |
| 10 16 | 
             
            		get_data
         | 
| 11 17 | 
             
            	end
         | 
| 12 18 |  | 
| 19 | 
            +
            	def self.get(args)
         | 
| 20 | 
            +
            		# Only valid arguments allowed
         | 
| 21 | 
            +
            			args.each do |k_arg, v_arg| 
         | 
| 22 | 
            +
            			if !VALID_ARGS.has_key?(k_arg)
         | 
| 23 | 
            +
            				return "#{k_arg} is not a valid argument"
         | 
| 24 | 
            +
            			end
         | 
| 25 | 
            +
            		end
         | 
| 26 | 
            +
             | 
| 27 | 
            +
            		stations = get_data
         | 
| 28 | 
            +
            		filtered_stations = []
         | 
| 29 | 
            +
             | 
| 30 | 
            +
            		stations.each do |station|
         | 
| 31 | 
            +
            			if args.all? { |k_arg, v_arg| station[VALID_ARGS[k_arg]] == v_arg }
         | 
| 32 | 
            +
            				filtered_stations.push(station) 
         | 
| 33 | 
            +
            			end
         | 
| 34 | 
            +
            		end
         | 
| 35 | 
            +
             | 
| 36 | 
            +
            		return filtered_stations
         | 
| 37 | 
            +
            	end
         | 
| 38 | 
            +
             | 
| 39 | 
            +
            	def self.has_available_bikes
         | 
| 40 | 
            +
            		stations = get_data
         | 
| 41 | 
            +
            		stations.select { |station| station["availableBikes"] > 0 }
         | 
| 42 | 
            +
            	end
         | 
| 43 | 
            +
             | 
| 44 | 
            +
            	def self.has_available_docks
         | 
| 45 | 
            +
            		stations = get_data
         | 
| 46 | 
            +
            		stations.select { |station| station["availableDocks"] > 0 }
         | 
| 47 | 
            +
            	end
         | 
| 48 | 
            +
             | 
| 13 49 | 
             
            	private
         | 
| 14 50 |  | 
| 15 51 | 
             
            	def self.get_data
         |