Class: VirusScanner::HTTP

Inherits:
Object
  • Object
show all
Defined in:
lib/virus_scanner/http.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeHTTP

Returns a new instance of HTTP.



5
6
7
8
9
10
11
12
13
14
# File 'lib/virus_scanner/http.rb', line 5

def initialize
  @conn = ::Faraday.new(url: ENV["VIRUS_SCANNER_API_URL"]) do |c|
    c.request :url_encoded
    c.response :json, content_type: /\bjson$/
    c.adapter ::Faraday.default_adapter
    c.headers = { "X-Auth-Token" => ENV["VIRUS_SCANNER_API_KEY"] }
  end
rescue VirusScanner::HttpError => e
  handle_exception(e)
end

Instance Attribute Details

#methodObject

Returns the value of attribute method.



3
4
5
# File 'lib/virus_scanner/http.rb', line 3

def method
  @method
end

#optionsObject

Returns the value of attribute options.



3
4
5
# File 'lib/virus_scanner/http.rb', line 3

def options
  @options
end

#urlObject

Returns the value of attribute url.



3
4
5
# File 'lib/virus_scanner/http.rb', line 3

def url
  @url
end

Instance Method Details

#get(uuid) ⇒ Object



23
24
25
26
27
28
# File 'lib/virus_scanner/http.rb', line 23

def get(uuid)
  response = @conn.get "/status/#{uuid}"
  response.body
rescue VirusScanner::Error => e
  handle_exception(e)
end

#post(url) ⇒ Object



16
17
18
19
20
21
# File 'lib/virus_scanner/http.rb', line 16

def post(url)
  response = @conn.post "/scan", url: url
  response.body
rescue VirusScanner::Error => e
  handle_exception(e)
end