streetfoodr 0.0.0 → 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/streetfoodr.rb +62 -42
- 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: 74d59e8f2399884ef340f2ba841f3cc7d1afeeda
|
4
|
+
data.tar.gz: c9ef5ed17a334a7a61e7b4239e69e179556ac947
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f7f37f8ac058816e047e257089709ff5300edc7611a94fe15991cad906e29346742a94976f22d525f912ff5ebaff73189c103606ba1d30a9245be61444352f5c
|
7
|
+
data.tar.gz: bbce8e46f380d8472c45ca9d54c82ecc010bc045d7b248207794963b5e4ea0922d0b76605877b6db7800cc3d9779b2fe33d8d3eaab535946565535c1953a3885
|
data/lib/streetfoodr.rb
CHANGED
@@ -1,62 +1,82 @@
|
|
1
1
|
require 'rest-client'
|
2
2
|
|
3
|
-
|
4
|
-
|
3
|
+
##
|
4
|
+
#This class represents food trucks
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
6
|
+
module Streetfoodr
|
7
|
+
class FoodTruck
|
8
|
+
API_ROOT_URL = 'http://data.streetfoodapp.com/1.1/'
|
9
|
+
|
10
|
+
##
|
11
|
+
#Gets all the food trucks and their schedules for a given city
|
12
|
+
def self.get_city_trucks(city)
|
13
|
+
response = RestClient.get(API_ROOT_URL + "schedule/" + city)
|
14
|
+
JSON.parse(response)
|
15
|
+
end
|
10
16
|
|
11
|
-
|
12
|
-
|
17
|
+
##
|
18
|
+
#Gets the api identifier information for all the food trucks in a
|
19
|
+
#given city. The identifiers are necessary for getting information
|
20
|
+
#about a specific food truck only.
|
21
|
+
def self.get_city_trucks_identifiers(city)
|
22
|
+
raw_data = self.get_city_trucks(city)
|
13
23
|
|
14
|
-
|
24
|
+
identifier_name_pairs = Array.new
|
15
25
|
|
16
|
-
|
17
|
-
|
26
|
+
raw_data['vendors'].map do |truck|
|
27
|
+
truck_info = Hash[identifier: truck[0], name: truck[1]["name"]]
|
18
28
|
|
19
|
-
|
29
|
+
identifier_name_pairs << truck_info
|
30
|
+
end
|
31
|
+
|
32
|
+
return identifier_name_pairs
|
20
33
|
end
|
21
34
|
|
22
|
-
|
23
|
-
|
35
|
+
##
|
36
|
+
#Finds the api identifier of a truck by name and city.
|
37
|
+
def self.get_api_identifier_by_name(name, city)
|
24
38
|
|
25
|
-
|
39
|
+
truck_info = self.get_city_trucks_identifiers(city)
|
40
|
+
.find { |truck_info| truck_info[:name] == name}
|
26
41
|
|
27
|
-
|
28
|
-
|
42
|
+
if truck_info == nil
|
43
|
+
raise ArgumentError, "A truck with that name in that city could not be found." +
|
44
|
+
" Keep in mind that the name must be exact."
|
45
|
+
end
|
29
46
|
|
30
|
-
|
31
|
-
raise ArgumentError, "A truck with that name in that city could not be found." +
|
32
|
-
" Keep in mind that the name must be exact."
|
47
|
+
return truck_info
|
33
48
|
end
|
34
49
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
end
|
50
|
+
##
|
51
|
+
#Initializes a new instance of a specific food truck
|
52
|
+
def initialize(foodtruck_identifier, city)
|
53
|
+
@identifier = foodtruck_identifier
|
54
|
+
@city = city
|
55
|
+
end
|
42
56
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
57
|
+
##
|
58
|
+
#Gets the locations and schedule of a given food truck
|
59
|
+
def locations
|
60
|
+
response = RestClient.get(API_ROOT_URL + "locations/" + @identifier)
|
61
|
+
begin
|
62
|
+
JSON.parse(response)
|
63
|
+
rescue JSON::ParserError => ex
|
64
|
+
raise ArgumentError, "This food truck identifier does not exist"
|
65
|
+
end
|
49
66
|
end
|
50
|
-
end
|
51
67
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
68
|
+
##
|
69
|
+
#Gets the locations and schedule of a given food truck
|
70
|
+
#during a specific month and year
|
71
|
+
def history(year, month)
|
72
|
+
response = RestClient.get(API_ROOT_URL + "history/" + @city + "/" +
|
73
|
+
year + "/" + month + "/" + @identifier)
|
74
|
+
begin
|
75
|
+
JSON.parse(response)
|
76
|
+
rescue JSON::ParserError => ex
|
77
|
+
raise ArgumentError, "Either this food truck identifier does not exist," +
|
78
|
+
" or there is no history for it available during the period you have chosen."
|
79
|
+
end
|
60
80
|
end
|
61
81
|
end
|
62
82
|
end
|