Skip to content

Instantly share code, notes, and snippets.

@bretcj7
Created October 10, 2018 15:17
Show Gist options
  • Save bretcj7/2d3d15fef1014814cda88cc1588423e4 to your computer and use it in GitHub Desktop.
Save bretcj7/2d3d15fef1014814cda88cc1588423e4 to your computer and use it in GitHub Desktop.
parallel get request
require 'parallel'
require 'rest-client'
require 'json'
class Star < ApplicationRecord
include ActiveModel::Serializers::JSON
BASE_URL = 'https://api.github.com/search/repositories?q='
STARS = '1..2000'
DATE = Time.now.strftime('%Y-%m-%d')
CODE1 = 'ruby'
CODE2 = 'javascript'
LIC1 = 'mit'
LIC2 = 'gpl'
LIC3 = 'lgpl'
LIC4 = 'apache-2.0'
#base_uri 'https://api.github.com/search?q=language:ruby&forks:0'#&pushed:>2018-10-08&type=Repositories'
URL1 = URI::encode("#{BASE_URL}language:#{CODE1}&forks:0&pushed:>=#{DATE}&stars:#{STARS}&license:#{LIC1}")
URL2 = URI::encode("#{BASE_URL}language:#{CODE1}&forks:0&pushed:>=#{DATE}&stars:#{STARS}&license:#{LIC2}")
URL3 = URI::encode("#{BASE_URL}language:#{CODE1}&forks:0&pushed:>=#{DATE}&stars:#{STARS}&license:#{LIC3}")
URL4 = URI::encode("#{BASE_URL}language:#{CODE1}&forks:0&pushed:>=#{DATE}&stars:#{STARS}&license:#{LIC4}")
URL5 = URI::encode("#{BASE_URL}language:#{CODE2}&forks:0&pushed:>=#{DATE}&stars:#{STARS}&license:#{LIC1}")
def get_stars()
sarray = [URL1, URL2, URL3, URL4, URL5]
results = Parallel.each(sarray) do |req|
response = RestClient.get(req, {accept: :json})
puts response.code
#results = HTTParty.get("https://api.github.com/zen")
#puts response.code
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment