-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtestapi.rb
More file actions
35 lines (28 loc) · 1.04 KB
/
Copy pathtestapi.rb
File metadata and controls
35 lines (28 loc) · 1.04 KB
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
require 'json'
require 'net/http'
require 'uri'
def openthis(url)
Net::HTTP.get(URI.parse(url))
end
# Get data from API and parse into object
api_url = "https://apts.jp/api/properties.json?rent_range[max]=150000&bedroom_range[min]=0&rent_range[min]="
puts api_url
response = openthis(api_url)
data = JSON.parse(response)
x = 0
while data['page']['current_page'].to_i != data['page']['total_pages'].to_i + 1
data['properties'].each do |child|
puts "Looking at property with ID " + child['id'].to_s + "..."
x = x + 1
end
api_url = "https://apts.jp/api/properties.json?rent_range[max]=150000&bedroom_range[min]=0&rent_range[min]=" + "&page=" + (data['page']['current_page'] + 1).to_s
response = openthis(api_url)
data = JSON.parse(response)
end
puts "I expected " + data['page']['total_count'].to_s + " and the last one I looked at was " + x.to_s
if data['page']['total_count'].to_i == x
puts "Everything seems to be in order."
else
puts "Something is off..."
end
puts "Whoo! Finished processing properties."