Class: UrlFetcher
- Inherits:
-
Object
- Object
- UrlFetcher
- Defined in:
- lib/fundamentus_data/util/url_fetcher.rb
Instance Method Summary collapse
- #download(url) ⇒ Object
- #fetch(urls) ⇒ Object
-
#initialize(options = {}) ⇒ UrlFetcher
constructor
A new instance of UrlFetcher.
Constructor Details
#initialize(options = {}) ⇒ UrlFetcher
Returns a new instance of UrlFetcher.
5 6 7 8 9 |
# File 'lib/fundamentus_data/util/url_fetcher.rb', line 5 def initialize( = {}) if .has_key?(:verbose) @verbose = [:verbose] end end |
Instance Method Details
#download(url) ⇒ Object
23 24 25 26 27 |
# File 'lib/fundamentus_data/util/url_fetcher.rb', line 23 def download(url) URI.open(url, "User-Agent" => "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:122.0) Gecko/20100101 Firefox/122.0") do |f| f.read end end |
#fetch(urls) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/fundamentus_data/util/url_fetcher.rb', line 11 def fetch(urls) responses = {} urls.each do |key, url| if @verbose puts "Downloading #{key} from #{url}" end responses[key] = download(url) sleep(0.5) end responses end |