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.
64 65 66 67 68 69 |
# File 'lib/tradingview_screener/screen_data.rb', line 64 def initialize(cookies: nil, proxy: nil, timeout: 20, headers: nil) @cookies = @proxy = proxy @timeout = timeout @headers = headers end |
Instance Method Details
#fetch(url) ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/tradingview_screener/screen_data.rb', line 71 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" => ScreenData.to_validated_payload(data, client: client) } end |