Class: Threatinator::Fetchers::Http
- Inherits:
-
Threatinator::Fetcher
- Object
- Threatinator::Fetcher
- Threatinator::Fetchers::Http
- Defined in:
- lib/threatinator/fetchers/http.rb
Instance Attribute Summary collapse
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#fetch ⇒ IO
An IO-style object.
-
#initialize(opts = {}) ⇒ Http
constructor
A new instance of Http.
Methods inherited from Threatinator::Fetcher
Constructor Details
#initialize(opts = {}) ⇒ Http
Returns a new instance of Http.
14 15 16 17 |
# File 'lib/threatinator/fetchers/http.rb', line 14 def initialize(opts = {}) @url = opts.delete(:url) or raise ArgumentError.new("Missing :url") super(opts) end |
Instance Attribute Details
#url ⇒ Object (readonly)
Returns the value of attribute url.
9 10 11 |
# File 'lib/threatinator/fetchers/http.rb', line 9 def url @url end |
Instance Method Details
#==(other) ⇒ Object
19 20 21 |
# File 'lib/threatinator/fetchers/http.rb', line 19 def ==(other) @url == other.url && super(other) end |
#fetch ⇒ IO
Returns an IO-style object.
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/threatinator/fetchers/http.rb', line 25 def fetch tempfile = Tempfile.new("threatinator_http") request = Typhoeus::Request.new(@url, ssl_verifypeer: false, followlocation: true, forbid_reuse: true ) request.on_headers do |response| if response.response_code != 200 raise Threatinator::Exceptions::FetchFailed.new("Request failed!") end end request.on_body do |chunk| tempfile.write(chunk) end # Run it request.run # Reset the IO to the beginning of the file tempfile.rewind tempfile end |