Class: Phishtank::Raw

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

Instance Method Summary collapse

Constructor Details

#initialize(api_key, format = 'json') ⇒ Raw

Returns a new instance of Raw.



3
4
5
6
7
8
9
10
11
12
13
# File 'lib/phishtank/raw.rb', line 3

def initialize(api_key, format='json')
  @api_key = api_key
  formats = ['json', 'php', 'xml']

  # Validate formats
  if (formats.include? (format))
    @format = format
  else
    raise Exception.new("Unknown data format. Please use one of the following: #{formats}")
  end
end

Instance Method Details

#check_url(url) ⇒ Object

Validate the url against the Phishtank API



16
17
18
19
20
21
22
# File 'lib/phishtank/raw.rb', line 16

def check_url(url)
  # Prepend HTTP scheme to domain lookups
  url = handle_url(url)
  base_url = 'http://checkurl.phishtank.com/checkurl/'
  resp = RestClient::Request.execute(method: 'POST', url: base_url, payload: {url: url, format: @format, app_key: @api_key}, open_timeout: 20)
  resp.to_s
end