Class: GoogleSafeBrowsing::HttpHelper
- Inherits:
-
Object
- Object
- GoogleSafeBrowsing::HttpHelper
- Defined in:
- lib/google_safe_browsing/http_helper.rb
Class Method Summary collapse
- .get_data(list = nil) ⇒ Object
- .get_keys ⇒ Object
- .request_full_hashes(hash_array) ⇒ Object
- .uri_builder(action, use_ssl = false) ⇒ Object
Class Method Details
.get_data(list = nil) ⇒ Object
33 34 35 36 37 38 39 |
# File 'lib/google_safe_browsing/http_helper.rb', line 33 def self.get_data(list=nil) uri = uri_builder('downloads') post_data(uri) do ChunkHelper.build_chunk_list(list) end end |
.get_keys ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/google_safe_browsing/http_helper.rb', line 41 def self.get_keys uri = URI("#{GoogleSafeBrowsing.config.rekey_host}/newkey#{encoded_params}") http = Net::HTTP.new(uri.host, uri.port) http.use_ssl = true http.verify_mode = OpenSSL::SSL::VERIFY_NONE request = Net::HTTP::Get.new(uri.request_uri) response = http.request(request) response.body.split("\n").each do |key_line| key_name, _, key_value = key_line.split(':') key_value.gsub!('=', '') case key_name when 'clientkey' key_value = KeyHelper::web_safe_base64_decode(key_value) GoogleSafeBrowsing.config.client_key = key_value when 'wrappedkey' GoogleSafeBrowsing.config.wrapped_key = key_value else GoogleSafeBrwosing::Logger.warn "Unknown MAC key: #{key_name}" end end end |
.request_full_hashes(hash_array) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/google_safe_browsing/http_helper.rb', line 11 def self.request_full_hashes(hash_array) get_keys unless GoogleSafeBrowsing.config.have_keys? uri = uri_builder('gethash') response = post_data(uri) do body = "4:#{hash_array.length * 4}\n" hash_array.each do |h| body << BinaryHelper.hex_to_bin(h[0..7]) end body end if response.is_a?(Net::HTTPSuccess) && !response.body.blank? ResponseHelper.parse_full_hash_response(response.body) else [] end end |
.uri_builder(action, use_ssl = false) ⇒ Object
3 4 5 6 7 8 9 |
# File 'lib/google_safe_browsing/http_helper.rb', line 3 def self.uri_builder(action, use_ssl=false) host = GoogleSafeBrowsing.config.host host = switch_to_https(host) if use_ssl uri = URI("#{host}/#{action}#{encoded_params}") uri end |