class Streetfoodr::FoodTruck
Constants
- API_ROOT_URL
Public Class Methods
get_api_identifier_by_name(name, city)
click to toggle source
Finds the api identifier of a truck by name and city.
# File lib/streetfoodr.rb, line 37 def self.get_api_identifier_by_name(name, city) truck_info = self.get_city_trucks_identifiers(city) .find { |truck_info| truck_info[:name] == name} if truck_info == nil raise ArgumentError, "A truck with that name in that city could not be found." + " Keep in mind that the name must be exact." end return truck_info end
get_city_trucks(city)
click to toggle source
Gets all the food trucks and their schedules for a given city
# File lib/streetfoodr.rb, line 12 def self.get_city_trucks(city) response = RestClient.get(API_ROOT_URL + "schedule/" + city) JSON.parse(response) end
get_city_trucks_identifiers(city)
click to toggle source
Gets the api identifier information for all the food trucks in a given city. The identifiers are necessary for getting information about a specific food truck only.
# File lib/streetfoodr.rb, line 21 def self.get_city_trucks_identifiers(city) raw_data = self.get_city_trucks(city) identifier_name_pairs = Array.new raw_data['vendors'].map do |truck| truck_info = Hash[identifier: truck[0], name: truck[1]["name"]] identifier_name_pairs << truck_info end return identifier_name_pairs end
new(foodtruck_identifier, city)
click to toggle source
Initializes a new instance of a specific food truck
# File lib/streetfoodr.rb, line 52 def initialize(foodtruck_identifier, city) @identifier = foodtruck_identifier @city = city end
Public Instance Methods
history(year, month)
click to toggle source
Gets the locations and schedule of a given food truck during a specific month and year
# File lib/streetfoodr.rb, line 71 def history(year, month) response = RestClient.get(API_ROOT_URL + "history/" + @city + "/" + year + "/" + month + "/" + @identifier) begin JSON.parse(response) rescue JSON::ParserError => ex raise ArgumentError, "Either this food truck identifier does not exist," + " or there is no history for it available during the period you have chosen." end end
locations()
click to toggle source
Gets the locations and schedule of a given food truck
# File lib/streetfoodr.rb, line 59 def locations response = RestClient.get(API_ROOT_URL + "locations/" + @identifier) begin JSON.parse(response) rescue JSON::ParserError => ex raise ArgumentError, "This food truck identifier does not exist" end end