phishtank 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
data/.rvmrc ADDED
@@ -0,0 +1,48 @@
1
+ #!/usr/bin/env bash
2
+
3
+ # This is an RVM Project .rvmrc file, used to automatically load the ruby
4
+ # development environment upon cd'ing into the directory
5
+
6
+ # First we specify our desired <ruby>[@<gemset>], the @gemset name is optional,
7
+ # Only full ruby name is supported here, for short names use:
8
+ # echo "rvm use 1.9.3" > .rvmrc
9
+ environment_id="ruby-1.9.3-p125@phishtank"
10
+
11
+ # Uncomment the following lines if you want to verify rvm version per project
12
+ # rvmrc_rvm_version="1.10.3" # 1.10.1 seams as a safe start
13
+ # eval "$(echo ${rvm_version}.${rvmrc_rvm_version} | awk -F. '{print "[[ "$1*65536+$2*256+$3" -ge "$4*65536+$5*256+$6" ]]"}' )" || {
14
+ # echo "This .rvmrc file requires at least RVM ${rvmrc_rvm_version}, aborting loading."
15
+ # return 1
16
+ # }
17
+
18
+ # First we attempt to load the desired environment directly from the environment
19
+ # file. This is very fast and efficient compared to running through the entire
20
+ # CLI and selector. If you want feedback on which environment was used then
21
+ # insert the word 'use' after --create as this triggers verbose mode.
22
+ if [[ -d "${rvm_path:-$HOME/.rvm}/environments"
23
+ && -s "${rvm_path:-$HOME/.rvm}/environments/$environment_id" ]]
24
+ then
25
+ \. "${rvm_path:-$HOME/.rvm}/environments/$environment_id"
26
+ [[ -s "${rvm_path:-$HOME/.rvm}/hooks/after_use" ]] &&
27
+ \. "${rvm_path:-$HOME/.rvm}/hooks/after_use" || true
28
+ else
29
+ # If the environment file has not yet been created, use the RVM CLI to select.
30
+ rvm --create "$environment_id" || {
31
+ echo "Failed to create RVM environment '${environment_id}'."
32
+ return 1
33
+ }
34
+ fi
35
+
36
+ # If you use bundler, this might be useful to you:
37
+ if [[ -s Gemfile ]] && {
38
+ ! builtin command -v bundle >/dev/null ||
39
+ builtin command -v bundle | grep $rvm_path/bin/bundle >/dev/null
40
+ }
41
+ then
42
+ printf "%b" "The rubygem 'bundler' is not installed. Installing it now.\n"
43
+ gem install bundler
44
+ fi
45
+ if [[ -s Gemfile ]] && builtin command -v bundle >/dev/null
46
+ then
47
+ bundle install | grep -vE '^Using|Your bundle is complete'
48
+ fi
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.2
4
+ - 1.9.3
data/Gemfile ADDED
@@ -0,0 +1,11 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in phishtank.gemspec
4
+ gemspec
5
+
6
+ group :development, :test do
7
+ gem 'guard-rspec', :require => false
8
+ gem 'growl', :require => false
9
+ gem 'rake'
10
+ end
11
+
@@ -0,0 +1,6 @@
1
+ guard 'rspec', :version => 2 do
2
+ watch(%r{^spec/.+_spec\.rb$})
3
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
4
+ watch('spec/spec_helper.rb') { "spec" }
5
+ end
6
+
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Ezekiel Templin
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,48 @@
1
+ # PhishTank
2
+ This is a Ruby interface to [OpenDNS's PhishTank developer API](http://www.phishtank.com/developer_info.php). The PhishTank dataset contains quite a bit of human-verified and classified phishing data, if you're into that sort of thing.
3
+
4
+ Tested against Ruby 1.9.2 and 1.9.3 w/ Travis-CI. Current Build Status: [![Build Status](https://secure.travis-ci.org/ezkl/phishtank.png?branch=master)](http://travis-ci.org/ezkl/phishtank)
5
+
6
+ ## Installation
7
+ From the Rubygems CLI:
8
+
9
+ `gem install phishtank`
10
+
11
+ or w/ Bundler, add the following to the Gemfile.
12
+
13
+ `gem 'phishtank'`
14
+
15
+ ## Usage
16
+
17
+ require 'phishtank'
18
+ PhishTank.configure do |c|
19
+ c.api_key = "YOUR_PHISHTANK_API_KEY" #required
20
+ c.temp_directory = "/path/to/temporary/directory" #optional - default: /tmp
21
+ c.etag = "ETag" #optional
22
+ end
23
+
24
+ PhishTank.update!
25
+
26
+ data = PhishTank::Data.new
27
+
28
+ data.entries.first
29
+ # => #<OpenStruct:0x1021026f8
30
+ # attr_reader :modifiable = true,
31
+ # attr_reader :table = {
32
+ # :url => "http://www.grovesgas.co.uk/TAMFidelidade/clientetam.htm",
33
+ # :phish_id => "1389753",
34
+ # :phish_detail_url => "http://www.phishtank.com/phish_detail.php?phish_id=1389753",
35
+ # :ip_address => "209.235.144.9",
36
+ # :submission_time => "2012-03-13T21:46:39+00:00",
37
+ # :verified => "yes",
38
+ # :verification_time => "2012-03-13T22:51:43+00:00",
39
+ # :online_status => "yes",
40
+ # :target => "TAM Fidelidade"
41
+ # }
42
+ #>
43
+
44
+ Read specs for more details.
45
+
46
+ ## TODO
47
+ * Add interface for [checking URL's](http://www.phishtank.com/api_info.php)
48
+ * Add errors for service-specific rate limiting errors
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
3
+ require 'rspec/core/rake_task'
4
+ RSpec::Core::RakeTask.new(:spec)
5
+ task :test => :spec
6
+ task :default => :test
@@ -0,0 +1,39 @@
1
+ require "phishtank/version"
2
+ require "phishtank/configuration"
3
+ require "phishtank/request"
4
+ require "phishtank/data"
5
+
6
+ module PhishTank
7
+ BASE_URI = "http://data.phishtank.com"
8
+
9
+ attr_accessor :configuration
10
+
11
+ def self.configure(&block)
12
+ yield configuration
13
+ end
14
+
15
+ def self.configuration
16
+ @configuration ||= Configuration.new
17
+ end
18
+
19
+ def self.update!
20
+ request = Request.new
21
+ request.get_update if request.update?
22
+ end
23
+
24
+ def self.api_key
25
+ @configuration.api_key
26
+ end
27
+
28
+ def self.api_key=(api_key)
29
+ @configuration = Configuration.new(api_key)
30
+ end
31
+
32
+ def self.temp_directory
33
+ @configuration.temp_directory
34
+ end
35
+
36
+ def self.etag
37
+ @configuration.etag
38
+ end
39
+ end
@@ -0,0 +1,11 @@
1
+ module PhishTank
2
+ class Configuration
3
+ attr_accessor :api_key, :temp_directory, :etag
4
+
5
+ def initialize(api_key = "", temp_directory = "/tmp", etag = nil)
6
+ @api_key = api_key
7
+ @temp_directory = temp_directory
8
+ @etag = etag
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,37 @@
1
+ require 'nokogiri'
2
+ require 'ostruct'
3
+
4
+ module PhishTank
5
+ class Data
6
+ attr_reader :file, :doc, :entries
7
+
8
+ def initialize(data_file_path = nil)
9
+ @file = data_file_path || "#{PhishTank.configuration.temp_directory}/online-valid.xml"
10
+ raise "Data File Not Found!" unless File.exists?(@file)
11
+
12
+ @doc = parse_data_file
13
+ @entries = []
14
+ process_data_file
15
+ end
16
+
17
+ def process_data_file
18
+ @doc.xpath("//entry").each do |entry_item|
19
+ entry = OpenStruct.new
20
+ entry.url = entry_item.at("url").text
21
+ entry.phish_id = entry_item.at("phish_id").text
22
+ entry.phish_detail_url = entry_item.at("phish_detail_url").text
23
+ entry.ip_address = entry_item.at("ip_address").text
24
+ entry.submission_time = entry_item.at("submission_time").text
25
+ entry.verified = entry_item.at("verified").text
26
+ entry.verification_time = entry_item.at("verification_time").text
27
+ entry.online_status = entry_item.at("online").text
28
+ entry.target = entry_item.at("target").text
29
+ @entries.push entry
30
+ end
31
+ end
32
+
33
+ def parse_data_file
34
+ Nokogiri::XML(File.read(@file))
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,36 @@
1
+ require 'typhoeus'
2
+
3
+ module PhishTank
4
+ class Request
5
+ attr_accessor :etag
6
+
7
+ def initialize(etag = nil)
8
+ @etag = etag || PhishTank.configuration.etag
9
+ end
10
+
11
+ def update?
12
+ return true if @etag.nil?
13
+ response = head(update_uri, :headers => {"ETag" => @etag})
14
+ response.headers_hash['Etag'] != "\"#{@etag}\""
15
+ end
16
+
17
+ def get_update
18
+ response = get(update_uri)
19
+ file = File.new("#{PhishTank.configuration.temp_directory}/online-valid.xml", 'w')
20
+ file.puts response.body
21
+ file.close
22
+ end
23
+
24
+ def update_uri
25
+ "#{BASE_URI}/data/#{PhishTank.configuration.api_key}/online-valid.xml"
26
+ end
27
+
28
+ def head(uri, opts = {})
29
+ Typhoeus::Request.head(uri, opts)
30
+ end
31
+
32
+ def get(uri, opts = {})
33
+ Typhoeus::Request.get(uri, opts)
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,3 @@
1
+ module PhishTank
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,23 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/phishtank/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Ezekiel Templin"]
6
+ gem.email = ["zeke@templ.in"]
7
+ gem.description = %q{Ruby interface to OpenDNS's PhishTank API}
8
+ gem.summary = %q{Provides a simple interface to work with OpenDNS's PhishTank developer API by handling caching and parsing of PhishTank data.}
9
+ gem.homepage = "https://github.com/ezkl/phishtank"
10
+
11
+ gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
12
+ gem.files = `git ls-files`.split("\n")
13
+ gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
14
+ gem.name = "phishtank"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = PhishTank::VERSION
17
+
18
+ gem.add_dependency("typhoeus", "~> 0.3.3")
19
+ gem.add_dependency("nokogiri", "~> 1.5.2")
20
+
21
+ gem.add_development_dependency("rspec", "~> 2.8.0")
22
+ gem.add_development_dependency("vcr", "~> 2.0.0")
23
+ end
@@ -0,0 +1,58 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: head
5
+ uri: http://data.phishtank.com/data/<API_KEY>/online-valid.xml
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ ETag:
11
+ - Tue, 14 Mar 2012 00:00:00
12
+ response:
13
+ status:
14
+ code: 200
15
+ message: !binary |-
16
+ T0s=
17
+ headers:
18
+ !binary "RGF0ZQ==":
19
+ - !binary |-
20
+ V2VkLCAxNCBNYXIgMjAxMiAwMDowNTozNCBHTVQ=
21
+ !binary "U2VydmVy":
22
+ - !binary |-
23
+ QXBhY2hlLzIuMi45IChEZWJpYW4pIFBIUC81LjIuNi0xK2xlbm55OSB3aXRo
24
+ IFN1aG9zaW4tUGF0Y2g=
25
+ !binary "WC1Qb3dlcmVkLUJ5":
26
+ - !binary |-
27
+ UEhQLzUuMi42LTErbGVubnk5
28
+ !binary "TGFzdC1Nb2RpZmllZA==":
29
+ - !binary |-
30
+ V2VkLCAxNCBNYXIgMjAxMiAwMDowMDowMCBHTVQ=
31
+ !binary "RXRhZw==":
32
+ - !binary |-
33
+ IldlZCwgMTQgTWFyIDIwMTIgMDA6MDA6MDAi
34
+ !binary "Q29udGVudC1EaXNwb3NpdGlvbg==":
35
+ - !binary |-
36
+ YXR0YWNobWVudDsgZmlsZW5hbWU9dmVyaWZpZWRfb25saW5lLnhtbA==
37
+ !binary "VmFyeQ==":
38
+ - !binary |-
39
+ QWNjZXB0LUVuY29kaW5n
40
+ !binary "Q29udGVudC1FbmNvZGluZw==":
41
+ - !binary |-
42
+ Z3ppcA==
43
+ !binary "Q29udGVudC1MZW5ndGg=":
44
+ - !binary |-
45
+ MjA=
46
+ !binary "Q29ubmVjdGlvbg==":
47
+ - !binary |-
48
+ Y2xvc2U=
49
+ !binary "Q29udGVudC1UeXBl":
50
+ - !binary |-
51
+ dGV4dC94bWw=
52
+ body:
53
+ encoding: ASCII-8BIT
54
+ string: !binary ""
55
+ http_version: !binary |-
56
+ MS4x
57
+ recorded_at: Wed, 14 Mar 2012 00:03:56 GMT
58
+ recorded_with: VCR 2.0.0
@@ -0,0 +1,58 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: head
5
+ uri: http://data.phishtank.com/data/<API_KEY>/online-valid.xml
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ ETag:
11
+ - Tue, 12 Mar 2012 22:00:00
12
+ response:
13
+ status:
14
+ code: 200
15
+ message: !binary |-
16
+ T0s=
17
+ headers:
18
+ !binary "RGF0ZQ==":
19
+ - !binary |-
20
+ V2VkLCAxNCBNYXIgMjAxMiAwMDowMjo1MSBHTVQ=
21
+ !binary "U2VydmVy":
22
+ - !binary |-
23
+ QXBhY2hlLzIuMi45IChEZWJpYW4pIFBIUC81LjIuNi0xK2xlbm55OSB3aXRo
24
+ IFN1aG9zaW4tUGF0Y2g=
25
+ !binary "WC1Qb3dlcmVkLUJ5":
26
+ - !binary |-
27
+ UEhQLzUuMi42LTErbGVubnk5
28
+ !binary "TGFzdC1Nb2RpZmllZA==":
29
+ - !binary |-
30
+ V2VkLCAxNCBNYXIgMjAxMiAwMDowMDowMCBHTVQ=
31
+ !binary "RXRhZw==":
32
+ - !binary |-
33
+ IldlZCwgMTQgTWFyIDIwMTIgMDA6MDA6MDAi
34
+ !binary "Q29udGVudC1EaXNwb3NpdGlvbg==":
35
+ - !binary |-
36
+ YXR0YWNobWVudDsgZmlsZW5hbWU9dmVyaWZpZWRfb25saW5lLnhtbA==
37
+ !binary "VmFyeQ==":
38
+ - !binary |-
39
+ QWNjZXB0LUVuY29kaW5n
40
+ !binary "Q29udGVudC1FbmNvZGluZw==":
41
+ - !binary |-
42
+ Z3ppcA==
43
+ !binary "Q29udGVudC1MZW5ndGg=":
44
+ - !binary |-
45
+ MjA=
46
+ !binary "Q29ubmVjdGlvbg==":
47
+ - !binary |-
48
+ Y2xvc2U=
49
+ !binary "Q29udGVudC1UeXBl":
50
+ - !binary |-
51
+ dGV4dC94bWw=
52
+ body:
53
+ encoding: ASCII-8BIT
54
+ string: !binary ""
55
+ http_version: !binary |-
56
+ MS4x
57
+ recorded_at: Wed, 14 Mar 2012 00:01:13 GMT
58
+ recorded_with: VCR 2.0.0
@@ -0,0 +1,109 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <output>
3
+ <meta>
4
+ <generated_at>2012-03-13T23:00:09+00:00</generated_at>
5
+ <total_entries>4</total_entries>
6
+ </meta>
7
+ <entries>
8
+ <entry>
9
+ <url>http://www.grovesgas.co.uk/TAMFidelidade/clientetam.htm</url>
10
+ <phish_id>1389753</phish_id>
11
+ <phish_detail_url>http://www.phishtank.com/phish_detail.php?phish_id=1389753</phish_detail_url>
12
+ <details>
13
+ <detail>
14
+ <ip_address>209.235.144.9</ip_address>
15
+ <cidr_block>209.235.144.0/21</cidr_block>
16
+ <announcing_network>30447</announcing_network>
17
+ <rir>arin</rir>
18
+ <detail_time>2012-03-13T21:47:18+00:00</detail_time>
19
+ </detail>
20
+ </details>
21
+ <submission>
22
+ <submission_time>2012-03-13T21:46:39+00:00</submission_time>
23
+ </submission>
24
+ <verification>
25
+ <verified>yes</verified>
26
+ <verification_time>2012-03-13T22:51:43+00:00</verification_time>
27
+ </verification>
28
+ <status>
29
+ <online>yes</online>
30
+ </status>
31
+ <target>TAM Fidelidade</target>
32
+ </entry>
33
+ <entry>
34
+ <url>http://www.grovesgas.co.uk/TAMFidelidade/</url>
35
+ <phish_id>1389752</phish_id>
36
+ <phish_detail_url>http://www.phishtank.com/phish_detail.php?phish_id=1389752</phish_detail_url>
37
+ <details>
38
+ <detail>
39
+ <ip_address>209.235.144.9</ip_address>
40
+ <cidr_block>209.235.144.0/21</cidr_block>
41
+ <announcing_network>30447</announcing_network>
42
+ <rir>arin</rir>
43
+ <detail_time>2012-03-13T21:47:18+00:00</detail_time>
44
+ </detail>
45
+ </details>
46
+ <submission>
47
+ <submission_time>2012-03-13T21:46:16+00:00</submission_time>
48
+ </submission>
49
+ <verification>
50
+ <verified>yes</verified>
51
+ <verification_time>2012-03-13T22:52:13+00:00</verification_time>
52
+ </verification>
53
+ <status>
54
+ <online>yes</online>
55
+ </status>
56
+ <target>TAM Fidelidade</target>
57
+ </entry>
58
+ <entry>
59
+ <url>http://intimvela.lv/administrator/.js/53453434/</url>
60
+ <phish_id>1389747</phish_id>
61
+ <phish_detail_url>http://www.phishtank.com/phish_detail.php?phish_id=1389747</phish_detail_url>
62
+ <details>
63
+ <detail>
64
+ <ip_address>92.240.69.19</ip_address>
65
+ <cidr_block>92.240.64.0/19</cidr_block>
66
+ <announcing_network>5538</announcing_network>
67
+ <rir>ripencc</rir>
68
+ <detail_time>2012-03-13T21:38:22+00:00</detail_time>
69
+ </detail>
70
+ </details>
71
+ <submission>
72
+ <submission_time>2012-03-13T21:37:40+00:00</submission_time>
73
+ </submission>
74
+ <verification>
75
+ <verified>yes</verified>
76
+ <verification_time>2012-03-13T22:19:48+00:00</verification_time>
77
+ </verification>
78
+ <status>
79
+ <online>yes</online>
80
+ </status>
81
+ <target>Santander UK</target>
82
+ </entry>
83
+ <entry>
84
+ <url>http://222.189.238.37/www.americanexpress.com/</url>
85
+ <phish_id>1389746</phish_id>
86
+ <phish_detail_url>http://www.phishtank.com/phish_detail.php?phish_id=1389746</phish_detail_url>
87
+ <details>
88
+ <detail>
89
+ <ip_address>222.189.238.37</ip_address>
90
+ <cidr_block>222.189.238.0/23</cidr_block>
91
+ <announcing_network>23650</announcing_network>
92
+ <rir>apnic</rir>
93
+ <detail_time>2012-03-13T21:38:21+00:00</detail_time>
94
+ </detail>
95
+ </details>
96
+ <submission>
97
+ <submission_time>2012-03-13T21:37:10+00:00</submission_time>
98
+ </submission>
99
+ <verification>
100
+ <verified>yes</verified>
101
+ <verification_time>2012-03-13T22:52:45+00:00</verification_time>
102
+ </verification>
103
+ <status>
104
+ <online>yes</online>
105
+ </status>
106
+ <target>Other</target>
107
+ </entry>
108
+ </entries>
109
+ </output>
@@ -0,0 +1,11 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe PhishTank::Configuration do
4
+ describe "defaults" do
5
+ subject { described_class.new }
6
+
7
+ its(:api_key) { should eq "" }
8
+ its(:etag) { should eq nil }
9
+ its(:temp_directory) { should eq "/tmp" }
10
+ end
11
+ end
@@ -0,0 +1,50 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe PhishTank::Data do
4
+ context "success" do
5
+ before(:all) do
6
+ PhishTank.configure do |c|
7
+ c.temp_directory = fixture_path
8
+ end
9
+ @data = described_class.new
10
+ end
11
+
12
+ it "should store the path to the data file at #file" do
13
+ @data.file.should eq fixture_path + '/online-valid.xml'
14
+ end
15
+
16
+ it "should store the parsed Nokogiri XML document at #doc" do
17
+ @data.doc.should be_kind_of(Nokogiri::XML::Document)
18
+ end
19
+
20
+ it "should return a list of entries at #entries" do
21
+ @data.entries.should be_kind_of(Array)
22
+ @data.entries.count.should >= 1
23
+ end
24
+
25
+ context "entry" do
26
+ subject { @data.entries.first }
27
+
28
+ its(:url) { should eq "http://www.grovesgas.co.uk/TAMFidelidade/clientetam.htm" }
29
+ its(:phish_id) { should eq "1389753" }
30
+ its(:phish_detail_url) { should eq "http://www.phishtank.com/phish_detail.php?phish_id=1389753" }
31
+ its(:ip_address) { should eq "209.235.144.9" }
32
+ its(:submission_time) { should eq "2012-03-13T21:46:39+00:00" }
33
+ its(:verified) { should eq "yes" }
34
+ its(:verification_time) { should eq "2012-03-13T22:51:43+00:00" }
35
+ its(:online_status) { should eq "yes" }
36
+ its(:target) { should eq "TAM Fidelidade" }
37
+ end
38
+
39
+ end
40
+
41
+ context "errors" do
42
+ it "should raise an error unless file exists in temporary directory" do
43
+ PhishTank.configure do |c|
44
+ c.temp_directory = "/tmp"
45
+ end
46
+
47
+ expect { described_class.new }.to raise_error("Data File Not Found!")
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,50 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe PhishTank::Request do
4
+ describe "#update?" do
5
+ before(:all) do
6
+ PhishTank.api_key = API_KEY
7
+ end
8
+ let(:update_needed) { described_class.new("Tue, 12 Mar 2012 22:00:00") }
9
+ let(:no_update_needed) { described_class.new("Wed, 14 Mar 2012 00:00:00") }
10
+
11
+ it "should respond true if an update is available", :vcr => { :cassette_name => 'update_needed' } do
12
+ update_needed.update?.should eq true
13
+ end
14
+
15
+ it "should respond false if an update isn't available", :vcr => { :cassette_name => 'no_update_needed' } do
16
+ no_update_needed.update?.should eq false
17
+ end
18
+ end
19
+
20
+ describe "#get_update" do
21
+ before(:all) do
22
+ PhishTank.configure do |c|
23
+ c.api_key = API_KEY
24
+ c.temp_directory = fixture_path
25
+ end
26
+ request = described_class.new
27
+
28
+ if File.exists?(fixture_path + "/online-valid.xml")
29
+ @response = File.read(fixture_path + "/online-valid.xml")
30
+ else
31
+ VCR.use_cassette("get_update") do
32
+ @response = request.get_update
33
+ end
34
+ end
35
+ end
36
+
37
+ it "should create an XML file in the temporary directory" do
38
+ File.exists?(fixture_path + "/online-valid.xml").should eq true
39
+ end
40
+ end
41
+
42
+ describe "#update_uri" do
43
+ subject do
44
+ PhishTank.api_key = "12345"
45
+ described_class.new
46
+ end
47
+
48
+ its(:update_uri) { should eq "http://data.phishtank.com/data/12345/online-valid.xml"}
49
+ end
50
+ end
@@ -0,0 +1,28 @@
1
+ require "spec_helper"
2
+
3
+ describe PhishTank do
4
+ it "should have a BASE_URI" do
5
+ subject::BASE_URI.should eq "http://data.phishtank.com"
6
+ end
7
+
8
+ it 'should take an API key' do
9
+ subject.api_key = "12345"
10
+ subject.api_key.should eq "12345"
11
+ end
12
+
13
+ describe "#configure" do
14
+ before(:all) do
15
+ described_class.configure do |c|
16
+ c.api_key = "12345"
17
+ c.temp_directory = "/temporary"
18
+ c.etag = "123456"
19
+ end
20
+ end
21
+
22
+ its(:api_key) { should eq "12345" }
23
+ its(:temp_directory) { should eq "/temporary" }
24
+ its(:etag) { should eq "123456" }
25
+ end
26
+
27
+ it { should respond_to(:update!) }
28
+ end
@@ -0,0 +1,21 @@
1
+ require 'vcr'
2
+ require File.expand_path(File.dirname(__FILE__) + '/../lib/phishtank')
3
+
4
+ API_KEY = "dad4255d1d50896dd9d981d0bde43176ed5020cda62ecd077a4e1652e12e1e3f"
5
+
6
+ def fixture_path
7
+ File.expand_path(File.dirname(__FILE__) + '/fixtures')
8
+ end
9
+
10
+ VCR.configure do |c|
11
+ c.cassette_library_dir = 'spec/cassettes'
12
+ c.hook_into :typhoeus
13
+ c.filter_sensitive_data('<API_KEY>') { API_KEY }
14
+ c.configure_rspec_metadata!
15
+ end
16
+
17
+ RSpec.configure do |config|
18
+ config.treat_symbols_as_metadata_keys_with_true_values = true
19
+ config.run_all_when_everything_filtered = true
20
+ config.filter_run :focus
21
+ end
metadata ADDED
@@ -0,0 +1,147 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: phishtank
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Ezekiel Templin
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-03-14 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: typhoeus
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 0.3.3
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: 0.3.3
30
+ - !ruby/object:Gem::Dependency
31
+ name: nokogiri
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: 1.5.2
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: 1.5.2
46
+ - !ruby/object:Gem::Dependency
47
+ name: rspec
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: 2.8.0
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 2.8.0
62
+ - !ruby/object:Gem::Dependency
63
+ name: vcr
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ~>
68
+ - !ruby/object:Gem::Version
69
+ version: 2.0.0
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ~>
76
+ - !ruby/object:Gem::Version
77
+ version: 2.0.0
78
+ description: Ruby interface to OpenDNS's PhishTank API
79
+ email:
80
+ - zeke@templ.in
81
+ executables: []
82
+ extensions: []
83
+ extra_rdoc_files: []
84
+ files:
85
+ - .gitignore
86
+ - .rspec
87
+ - .rvmrc
88
+ - .travis.yml
89
+ - Gemfile
90
+ - Guardfile
91
+ - LICENSE
92
+ - README.md
93
+ - Rakefile
94
+ - lib/phishtank.rb
95
+ - lib/phishtank/configuration.rb
96
+ - lib/phishtank/data.rb
97
+ - lib/phishtank/request.rb
98
+ - lib/phishtank/version.rb
99
+ - phishtank.gemspec
100
+ - spec/cassettes/no_update_needed.yml
101
+ - spec/cassettes/update_needed.yml
102
+ - spec/fixtures/online-valid.xml
103
+ - spec/phishtank/configuration_spec.rb
104
+ - spec/phishtank/data_spec.rb
105
+ - spec/phishtank/request_spec.rb
106
+ - spec/phishtank_spec.rb
107
+ - spec/spec_helper.rb
108
+ homepage: https://github.com/ezkl/phishtank
109
+ licenses: []
110
+ post_install_message:
111
+ rdoc_options: []
112
+ require_paths:
113
+ - lib
114
+ required_ruby_version: !ruby/object:Gem::Requirement
115
+ none: false
116
+ requirements:
117
+ - - ! '>='
118
+ - !ruby/object:Gem::Version
119
+ version: '0'
120
+ segments:
121
+ - 0
122
+ hash: 1039292126321332298
123
+ required_rubygems_version: !ruby/object:Gem::Requirement
124
+ none: false
125
+ requirements:
126
+ - - ! '>='
127
+ - !ruby/object:Gem::Version
128
+ version: '0'
129
+ segments:
130
+ - 0
131
+ hash: 1039292126321332298
132
+ requirements: []
133
+ rubyforge_project:
134
+ rubygems_version: 1.8.18
135
+ signing_key:
136
+ specification_version: 3
137
+ summary: Provides a simple interface to work with OpenDNS's PhishTank developer API
138
+ by handling caching and parsing of PhishTank data.
139
+ test_files:
140
+ - spec/cassettes/no_update_needed.yml
141
+ - spec/cassettes/update_needed.yml
142
+ - spec/fixtures/online-valid.xml
143
+ - spec/phishtank/configuration_spec.rb
144
+ - spec/phishtank/data_spec.rb
145
+ - spec/phishtank/request_spec.rb
146
+ - spec/phishtank_spec.rb
147
+ - spec/spec_helper.rb