Class: Miteru::HTTPClient
- Inherits:
-
Object
- Object
- Miteru::HTTPClient
- Defined in:
- lib/miteru/http_client.rb
Constant Summary collapse
- DEFAULT_UA =
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36"
- URLSCAN_UA =
"miteru/#{Miteru::VERSION}"
Instance Attribute Summary collapse
-
#ssl_context ⇒ Object
readonly
Returns the value of attribute ssl_context.
Class Method Summary collapse
- .download(url, base_dir = "/tmp") ⇒ Object
- .get(url, options = {}) ⇒ Object
- .post(url, options = {}) ⇒ Object
Instance Method Summary collapse
- #download(url, destination) ⇒ Object
- #get(url, options = {}) ⇒ Object
-
#initialize ⇒ HTTPClient
constructor
A new instance of HTTPClient.
- #post(url, options = {}) ⇒ Object
Constructor Details
#initialize ⇒ HTTPClient
Returns a new instance of HTTPClient.
14 15 16 17 18 |
# File 'lib/miteru/http_client.rb', line 14 def initialize ctx = OpenSSL::SSL::SSLContext.new ctx.verify_mode = OpenSSL::SSL::VERIFY_NONE @ssl_context = ctx end |
Instance Attribute Details
#ssl_context ⇒ Object (readonly)
Returns the value of attribute ssl_context.
12 13 14 |
# File 'lib/miteru/http_client.rb', line 12 def ssl_context @ssl_context end |
Class Method Details
.download(url, base_dir = "/tmp") ⇒ Object
40 41 42 |
# File 'lib/miteru/http_client.rb', line 40 def download(url, base_dir = "/tmp") new.download(url, base_dir) end |
.get(url, options = {}) ⇒ Object
44 45 46 |
# File 'lib/miteru/http_client.rb', line 44 def get(url, = {}) new.get url, end |
.post(url, options = {}) ⇒ Object
48 49 50 |
# File 'lib/miteru/http_client.rb', line 48 def post(url, = {}) new.post url, end |
Instance Method Details
#download(url, destination) ⇒ Object
20 21 22 23 24 |
# File 'lib/miteru/http_client.rb', line 20 def download(url, destination) down = Down::Http.new() { |client| client.headers(default_headers) } down.download(url, destination: destination) destination end |
#get(url, options = {}) ⇒ Object
26 27 28 29 30 31 32 33 |
# File 'lib/miteru/http_client.rb', line 26 def get(url, = {}) = .merge HTTP.follow .timeout(write: 2, connect: 5, read: 10) .headers(urlscan_url?(url) ? urlscan_headers : default_headers) .get(url, ) end |
#post(url, options = {}) ⇒ Object
35 36 37 |
# File 'lib/miteru/http_client.rb', line 35 def post(url, = {}) HTTP.post url, end |