Class: PhishTank::FeedRequest

Inherits:
Object
  • Object
show all
Defined in:
lib/phishtank/feed_request.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(etag = nil) ⇒ FeedRequest

Returns a new instance of FeedRequest.



5
6
7
# File 'lib/phishtank/feed_request.rb', line 5

def initialize(etag = nil)
  @etag = etag || PhishTank.configuration.etag
end

Instance Attribute Details

#etagObject

Returns the value of attribute etag.



3
4
5
# File 'lib/phishtank/feed_request.rb', line 3

def etag
  @etag
end

Instance Method Details

#get(uri, opts = {}) ⇒ Object



30
31
32
# File 'lib/phishtank/feed_request.rb', line 30

def get(uri, opts = {})
  Typhoeus::Request.get(uri, opts)
end

#get_updateObject



15
16
17
18
19
20
# File 'lib/phishtank/feed_request.rb', line 15

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

#head(uri, opts = {}) ⇒ Object



26
27
28
# File 'lib/phishtank/feed_request.rb', line 26

def head(uri, opts = {})
  Typhoeus::Request.head(uri, opts)
end

#update?Boolean

Returns:

  • (Boolean)


9
10
11
12
13
# File 'lib/phishtank/feed_request.rb', line 9

def update?
  return true if @etag.nil?
  response = head(update_uri, :headers => {"ETag" => @etag})
  response.headers_hash['Etag'] != "\"#{@etag}\""
end

#update_uriObject



22
23
24
# File 'lib/phishtank/feed_request.rb', line 22

def update_uri
  "#{BASE_URI}/data/#{PhishTank.configuration.api_key}/online-valid.xml"
end