Sha256: 973c8c1115b1a645d7845a0510d3ebfe6ad0ef0b18550f970f62fe9c46b3a171

Contents?: true

Size: 833 Bytes

Versions: 1

Compression:

Stored size: 833 Bytes

Contents

require 'typhoeus'

module PhishTank
  class Request    
    attr_accessor :etag
    
    def initialize(etag = nil)
      @etag = etag || PhishTank.configuration.etag
    end

    def update?
      return true if @etag.nil?
      response = head(update_uri, :headers => {"ETag" => @etag})
      response.headers_hash['Etag'] != "\"#{@etag}\""
    end
    
    def get_update
      response = get(update_uri)
      file = File.new("#{PhishTank.configuration.temp_directory}/online-valid.xml", 'w')
      file.puts response.body
      file.close
    end
    
    def update_uri
      "#{BASE_URI}/data/#{PhishTank.configuration.api_key}/online-valid.xml"
    end
    
    def head(uri, opts = {})
      Typhoeus::Request.head(uri, opts)
    end
    
    def get(uri, opts = {})
      Typhoeus::Request.get(uri, opts)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
phishtank-0.1.0 lib/phishtank/request.rb