Sha256: b3c50f44ed9473ac46c42ab4e8dae0ddb60781ff9c7ff80b63ba8dee6b4492de

Contents?: true

Size: 1.22 KB

Versions: 7

Compression:

Stored size: 1.22 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 }

      ResponseHelper.parse_full_hash_response(response.body)
    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')
      lists = Net::HTTP.get(uri).split("\n")
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
google_safe_browsing-0.3.4 lib/google_safe_browsing/http_helper.rb
google_safe_browsing-0.3.3 lib/google_safe_browsing/http_helper.rb
google_safe_browsing-0.3.2 lib/google_safe_browsing/http_helper.rb
google_safe_browsing-0.3.1 lib/google_safe_browsing/http_helper.rb
google_safe_browsing-0.3.0 lib/google_safe_browsing/http_helper.rb
google_safe_browsing-0.2.0 lib/google_safe_browsing/http_helper.rb
google_safe_browsing-0.1.0 lib/google_safe_browsing/http_helper.rb