15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
# File 'lib/tvdb_client/service/threading/threaded_request.rb', line 15
def make_request( route )
response = connection.get( route )
return response if response.code != 200
links = connection.get( route ).body["links"]
first_page = links["first"]
last_page = links["last"]
@results = Array.new
for page in first_page..last_page
manage_thread_pool
threads << Thread.new( page ) do |page_num|
params = { :params => { page: page_num } }
@results << connection.get( route, params ).body["data"]
end
end
threads.each { |thread| thread.join }
return @results.flatten
end
|