streetfoodr 0.0.0 → 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/streetfoodr.rb +62 -42
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 613a4aeff572ff4e20f6435a02400bff712a2d3b
4
- data.tar.gz: 98b0b6cc7d2cc5d62016d987695ff73f535792b4
3
+ metadata.gz: 74d59e8f2399884ef340f2ba841f3cc7d1afeeda
4
+ data.tar.gz: c9ef5ed17a334a7a61e7b4239e69e179556ac947
5
5
  SHA512:
6
- metadata.gz: 44389dc8e7be2aabaed21ee65d3610ef93abb7a7749f3aaf423482b54dcd42b06fac1b39bb18487a8ae0d0c73833cc826ef40bf37a29c125ec06220b05e0c102
7
- data.tar.gz: b13918d4651f444763d7ce307e657959d4aa8a030d44f19675ba3166420b242aec0fc776367e329bd4ae00689f35f41ae9c8935855bb450bc958fcffb98dc2da
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
- class FoodTruck
4
- API_ROOT_URL = 'http://data.streetfoodapp.com/1.1/'
3
+ ##
4
+ #This class represents food trucks
5
5
 
6
- def self.get_city_trucks(city)
7
- response = RestClient.get(API_ROOT_URL + "schedule/" + city)
8
- JSON.parse(response)
9
- end
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
- def self.get_city_trucks_identifiers(city)
12
- raw_data = self.get_city_trucks(city)
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
- identifier_name_pairs = Array.new
24
+ identifier_name_pairs = Array.new
15
25
 
16
- raw_data['vendors'].map do |truck|
17
- truck_info = Hash[identifier: truck[0], name: truck[1]["name"]]
26
+ raw_data['vendors'].map do |truck|
27
+ truck_info = Hash[identifier: truck[0], name: truck[1]["name"]]
18
28
 
19
- identifier_name_pairs << truck_info
29
+ identifier_name_pairs << truck_info
30
+ end
31
+
32
+ return identifier_name_pairs
20
33
  end
21
34
 
22
- return identifier_name_pairs
23
- end
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
- def self.get_api_identifier_by_name(name, city)
39
+ truck_info = self.get_city_trucks_identifiers(city)
40
+ .find { |truck_info| truck_info[:name] == name}
26
41
 
27
- truck_info = self.get_city_trucks_identifiers(city)
28
- .find { |truck_info| truck_info[:name] == name}
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
- if truck_info == nil
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
- return truck_info
36
- end
37
-
38
- def initialize(foodtruck_identifier, city)
39
- @identifier = foodtruck_identifier
40
- @city = city
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
- def locations
44
- response = RestClient.get(API_ROOT_URL + "locations/" + @identifier)
45
- begin
46
- JSON.parse(response)
47
- rescue JSON::ParserError => ex
48
- raise ArgumentError, "This food truck identifier does not exist"
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
- def history(year, month)
53
- response = RestClient.get(API_ROOT_URL + "history/" + @city + "/" +
54
- year + "/" + month + "/" + @identifier)
55
- begin
56
- JSON.parse(response)
57
- rescue JSON::ParserError => ex
58
- raise ArgumentError, "Either this food truck identifier does not exist," +
59
- " or there is no history for it available during the period you have chosen."
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: streetfoodr
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.0
4
+ version: 0.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alla Hoffman