Class: HttpClient

Inherits:
Object
  • Object
show all
Defined in:
lib/scopes_extractor/http_client.rb

Overview

HttpClient Class

Class Method Summary collapse

Class Method Details

.get(url, authentication = nil) ⇒ Object



27
28
29
30
31
32
# File 'lib/scopes_extractor/http_client.rb', line 27

def self.get(url, authentication = nil)
  options = request_options
  options[:headers] = headers(url, authentication)

  Typhoeus.get(url, options)
end

.headers(url, authentication) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/scopes_extractor/http_client.rb', line 12

def self.headers(url, authentication)
  if url.include?('yeswehack')
    { 'Content-Type' => 'application/json', Authorization: "Bearer #{authentication}" }
  elsif url.include?('intigriti')
    { Authorization: "Bearer #{authentication}" }
  elsif url.include?('bugcrowd')
    { 'Cookie' => authentication }
  elsif url.include?('hackerone')
    h1_credz = Base64.urlsafe_encode64("#{ENV.fetch('H1_USERNAME', nil)}:#{ENV.fetch('H1_API_KEY', nil)}")
    { 'Accept' => 'application/json', 'Authorization' => "Basic #{h1_credz}" }
  else
    { 'Content-Type' => 'application/json' }
  end
end

.post(url, data) ⇒ Object



34
35
36
37
38
39
40
# File 'lib/scopes_extractor/http_client.rb', line 34

def self.post(url, data)
  options = request_options
  options[:headers] = { 'Content-Type' => 'application/json' }
  options[:body] = data

  Typhoeus.post(url, options)
end

.request_optionsObject



5
6
7
8
9
10
# File 'lib/scopes_extractor/http_client.rb', line 5

def self.request_options
  {
    ssl_verifypeer: false,
    ssl_verifyhost: 0
  }
end