Class: TradingviewScreener::ScreenData::Fetcher
- Inherits:
-
Object
- Object
- TradingviewScreener::ScreenData::Fetcher
- Defined in:
- lib/tradingview_screener/screen_data.rb
Instance Method Summary collapse
- #fetch(url) ⇒ Object
-
#initialize(cookies: nil, proxy: nil, timeout: 20, headers: nil) ⇒ Fetcher
constructor
A new instance of Fetcher.
Constructor Details
#initialize(cookies: nil, proxy: nil, timeout: 20, headers: nil) ⇒ Fetcher
Returns a new instance of Fetcher.
47 48 49 50 51 52 |
# File 'lib/tradingview_screener/screen_data.rb', line 47 def initialize(cookies: nil, proxy: nil, timeout: 20, headers: nil) @cookies = @proxy = proxy @timeout = timeout @headers = headers end |
Instance Method Details
#fetch(url) ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/tradingview_screener/screen_data.rb', line 54 def fetch(url) client = Client.new( timeout: @timeout, cookies: @cookies, proxy: @proxy, headers: { "accept" => "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8", "user-agent" => "tradingview-screener-rb/#{VERSION}" }.merge(@headers || {}) ) html = client.get(url) data = Parser.extract_screen_data(html) { "url" => url, "screen_data" => data, "payload" => Converter.new(data).to_payload } end |