Sha256: a95638b24a754d9ec37b737213cacd402f60896648111ede35a75af6948551eb
Contents?: true
Size: 1.43 KB
Versions: 2
Compression:
Stored size: 1.43 KB
Contents
module GoogleSafeBrowsing class HttpHelper def self.uri_builder(action) uri = URI("#{GoogleSafeBrowsing.config.host}/#{action}#{encoded_params}") uri end def self.encoded_params "?client=#{GoogleSafeBrowsing.config.client}" + "&apikey=#{GoogleSafeBrowsing.config.api_key}" + "&appver=#{GoogleSafeBrowsing.config.app_ver}" + "&pver=#{GoogleSafeBrowsing.config.p_ver}" end def self.request_full_hashes(hash_array) uri = uri_builder('gethash') request = Net::HTTP::Post.new(uri.request_uri) request.body = "4:#{hash_array.length * 4}\n" hash_array.each do |h| request.body << BinaryHelper.hex_to_bin(h[0..7]) end response = Net::HTTP.start(uri.host) { |http| http.request request } if response.is_a?(Net::HTTPSuccess) && !response.body.blank? # we are seeing blank responses from Google ResponseHelper.parse_full_hash_response(response.body) else # if response not good, return empty array to represent no full hashes [] end end def self.get_data(list=nil) # Get (via Post) List Data uri = uri_builder('downloads') request = Net::HTTP::Post.new(uri.request_uri) request.body = ChunkHelper.build_chunk_list(list) Net::HTTP.start(uri.host) { |http| http.request request } end def get_lists uri = uri_builder('list') Net::HTTP.get(uri).split("\n") end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
google_safe_browsing-0.4.2 | lib/google_safe_browsing/http_helper.rb |
google_safe_browsing-0.4.1 | lib/google_safe_browsing/http_helper.rb |