Class: VirusScanner::HTTP
- Inherits:
-
Object
- Object
- VirusScanner::HTTP
- Defined in:
- lib/virus_scanner/http.rb
Instance Attribute Summary collapse
-
#method ⇒ Object
Returns the value of attribute method.
-
#options ⇒ Object
Returns the value of attribute options.
-
#url ⇒ Object
Returns the value of attribute url.
Instance Method Summary collapse
- #get(uuid) ⇒ Object
-
#initialize ⇒ HTTP
constructor
A new instance of HTTP.
- #post(url) ⇒ Object
Constructor Details
#initialize ⇒ HTTP
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
#method ⇒ Object
Returns the value of attribute method.
3 4 5 |
# File 'lib/virus_scanner/http.rb', line 3 def method @method end |
#options ⇒ Object
Returns the value of attribute options.
3 4 5 |
# File 'lib/virus_scanner/http.rb', line 3 def @options end |
#url ⇒ Object
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 |