module Mygasfeed
Constants
- API_KEY
- API_URL
- Brand
- Location
- PreviousPrice
- Station
- VERSION
Public Class Methods
# File lib/mygasfeed/request.rb, line 18 def _build_url path, params=[] uri = API_URL + path params.each { |param| uri = uri + param.to_s + '/' } uri = uri + API_KEY + ".json" end
Providing the latitude & longitude of the current location, you will retrieve the full address.
# File lib/mygasfeed/dsl/get_address.rb, line 6 def get_address latitude, longitude response = request('/locations/geoaddress/', [latitude, longitude]) Location.build response['location'] end
Retrieves a list of all gas station brands.
# File lib/mygasfeed/dsl/get_brands.rb, line 6 def get_brands response = request "/stations/brands/" response['stations'].map { |brand| Brand.build brand } end
Retrieve a list of other gas stations that are close by to a particular station by just suppling the station id.
# File lib/mygasfeed/dsl/get_close_by.rb, line 7 def get_close_by station_id, limit response = request '/locations/otherclosebystations/', [station_id, limit] response['stations'].map { |station| Station.build station } end
Retrieves gas station details by providing the station id. The station id can be retrieved when making a request for a list of stations.
# File lib/mygasfeed/dsl/get_details.rb, line 7 def get_details station_id response = request '/stations/details/', [station_id] Station.build response['details'] end
Retrieves a list of gas price histroy for a particular gas station by id.
# File lib/mygasfeed/dsl/get_history.rb, line 6 def get_history station_id response = request '/locations/pricehistory/', [station_id] response['histroy'].map { |price| PreviousPrice.build price } end
Retrieves nearby gas stations according to a user’s geo location. ‘Distance` - a number of miles under 50. `fuel_type` - reg, mid, pre, or diesel `sort_by` - distance or price
# File lib/mygasfeed/dsl/get_stations.rb, line 9 def get_stations latitude, longitude, distance, fuel_type, sort_by params = [latitude, longitude, distance, fuel_type, sort_by] response = request "/stations/radius/", params response['stations'].map { |station| Station.build station } end
# File lib/mygasfeed/request.rb, line 13 def post path, params={} response = HTTParty.post _build_url(path), params JSON.parse response.body end
# File lib/mygasfeed/request.rb, line 8 def request path, params=[] response = HTTParty.get _build_url(path, params) JSON.parse response.body end
Updates gas prices for a particular station. ‘price` - Actual gas price. Format (3.64) `fuel_type` - reg, mid, pre, or diesel
# File lib/mygasfeed/dsl/update_price.rb, line 8 def update_price price, fuel_type, station_id response = post '/locations/price/', body: {price: price, fueltype: fuel_type, stationid: station_id} Station.build response['details'] end