Class: Thm::DataServices::Safebrowsing
- Defined in:
- lib/thm/dataservices/safebrowsing_api.rb
Instance Attribute Summary collapse
-
#debug ⇒ Object
writeonly
Sets the attribute debug.
Attributes inherited from External
Instance Method Summary collapse
- #handle_response?(code) ⇒ Boolean
-
#initialize ⇒ Safebrowsing
constructor
A new instance of Safebrowsing.
- #lookup(url) ⇒ Object
Methods inherited from External
Constructor Details
#initialize ⇒ Safebrowsing
Returns a new instance of Safebrowsing.
17 18 19 |
# File 'lib/thm/dataservices/safebrowsing_api.rb', line 17 def initialize super end |
Instance Attribute Details
#debug=(value) ⇒ Object (writeonly)
Sets the attribute debug
15 16 17 |
# File 'lib/thm/dataservices/safebrowsing_api.rb', line 15 def debug=(value) @debug = value end |
Instance Method Details
#handle_response?(code) ⇒ Boolean
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/thm/dataservices/safebrowsing_api.rb', line 21 def handle_response?(code) if code == "200" return code elsif code == "204" return code elsif code == "400" puts "Bad Request—The HTTP request was not correctly formed. The client did not provide all required CGI parameters." return false elsif code == "401" puts "Not Authorized—The client id is invalid." return false elsif code == "503" puts "Service Unavailable" return false elsif code == "505" puts "HTTP Version Not Supported—The server CANNOT handle the requested protocol major version." return false end end |
#lookup(url) ⇒ Object
41 42 43 44 45 46 47 48 49 50 |
# File 'lib/thm/dataservices/safebrowsing_api.rb', line 41 def lookup(url) response = apiget(url) print "Response: " pp response if handle_response?(response.code) =~ %r=^200|^204= return [response.code, response.body] else return false end end |