-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.rb
44 lines (30 loc) · 999 Bytes
/
app.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
$LOAD_PATH << '.'
require 'shop.rb'
require 'url.rb'
require 'input.rb'
# call prompt methods to handle user inputs
url = Input.prompt_shop_url
products_to_find = Input.prompt_products_list
# initialize product count and price hashes
Shop.create_count_hash(products_to_find)
Shop.create_price_hash(products_to_find)
# process products json on each page until reached end of page
end_of_page = false
page = 1
until end_of_page
base_url = url + page.to_s
#format :json
# connect to current base url
res = Url.read_response(base_url)
# parse the response into json
json = Url.parse_response(res)
# extract array from json hash
products_array = json["products"]
# check if reached end of json result
end_of_page = Shop.is_page_end(products_array)
# iterate over json to find product prices
Shop.find_prices(products_array)
page += 1
end
# call shop method to print price results of requeste products
Shop.print_result