-
-
Save ltran/3ca61dde2f932b495bf3f570b7460d81 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 1.upto(pages) do |t| | |
| spawn do | |
| search_request(query, country, api_key, t) | |
| end | |
| end | |
| def search_request(query, country, api_key, page) | |
| url = api_request_url(query, country ,api_key, page) | |
| HTTP::Client.get(url) do |response| | |
| jbody = JSON.parse(response.body_io)["data"] | |
| search_response = SearchResponse.from_json(jbody.to_json) | |
| search_response.hits.each do |hit| | |
| PRODUCT_CHANNEL.send(hit._links["self"]["href"].as_s) | |
| end | |
| 1.upto(search_response.hitsPerPage) do | |
| spawn do | |
| url = PRODUCT_CHANNEL.receive | |
| product_request(url, api_key) | |
| end | |
| end | |
| end | |
| end | |
| def product_request(product_url, api_key) | |
| HTTP::Client.get("#{product_url}?api_key=#{api_key}") do |response| | |
| if response.status_code == 200 || response.status_code == 304 | |
| STDOUT.puts "#{uuid(product_url)}: (#{response.status_code})".colorize(:green) | |
| else | |
| STDOUT.puts "#{uuid(product_url)}: (#{response.status_code})".colorize(:red) | |
| end | |
| end | |
| end | |
| # sleep for a while for now | |
| sleep(60) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment