-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnode_loader.rb
More file actions
33 lines (27 loc) · 761 Bytes
/
Copy pathnode_loader.rb
File metadata and controls
33 lines (27 loc) · 761 Bytes
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
require_relative 'node'
require_relative 'request_helper'
module NodeLoader
include RequestHelper
def load(type:)
with_pagination do |page|
HTTParty.get("#{@host}/api/views/last_updates?display_id=services_1&page=#{page}&type=#{type}",
headers: headers)
.map{|result| Node.new(result)}
end
end
def deep_load(nid:)
HTTParty.get("#{@host}/api/node/#{nid}", headers: headers).parsed_response
end
private
def with_pagination
page = 0
all_results = []
loop do
results = yield(page)
all_results += results
page += 1
break if results.empty?
end
all_results
end
end