-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #55 from ninoseki/add-st-feed
Add SecurityTrails feed
- Loading branch information
Showing
11 changed files
with
160 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#!/usr/bin/env ruby | ||
# frozen_string_literal: true | ||
|
||
$LOAD_PATH.unshift("#{__dir__}/../lib") | ||
|
||
require "ayashige" | ||
|
||
Ayashige::Jobs::SecurityTrails.new.perform |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# frozen_string_literal: true | ||
|
||
module Ayashige | ||
module Jobs | ||
class SecurityTrails < Job | ||
def initialize | ||
@source = Ayashige::Sources::SecurityTrails.new | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# frozen_string_literal: true | ||
|
||
require "date" | ||
require "securitytrails" | ||
|
||
module Ayashige | ||
module Sources | ||
class SecurityTrails < Source | ||
def initialize | ||
super | ||
|
||
@api = ::SecurityTrails::API.new | ||
end | ||
|
||
def store_newly_registered_domains | ||
records.each { |record| store record } | ||
end | ||
|
||
def records | ||
domains = @api.feeds.domains("new") | ||
date = DateTime.now.to_s | ||
domains.map do |domain| | ||
Record.new( domain_name: domain, updated: date) | ||
end | ||
end | ||
end | ||
end | ||
end |
53 changes: 53 additions & 0 deletions
53
...hige_Sources_WhoisDS/_store_newly_registered_domains/stores_parsed_domains_into_Redis.yml
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# frozen_string_literal: true | ||
|
||
RSpec.describe Ayashige::Jobs::SecurityTrails, :vcr do | ||
include_context "job context" | ||
subject { Ayashige::Jobs::SecurityTrails.new } | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# frozen_string_literal: true | ||
|
||
require "mock_redis" | ||
|
||
RSpec.describe Ayashige::Sources::SecurityTrails do | ||
subject { described_class.new } | ||
|
||
let(:redis) { MockRedis.new } | ||
|
||
before do | ||
allow(Ayashige::Redis).to receive(:client).and_return(redis) | ||
end | ||
|
||
after do | ||
redis.flushdb | ||
end | ||
|
||
describe "#get_records" do | ||
before do | ||
mock = double("Feeds API") | ||
allow(mock).to receive(:domains).and_return(["example.com"]) | ||
allow(SecurityTrails::Clients::Feeds).to receive(:new).and_return(mock) | ||
end | ||
|
||
it do | ||
records = subject.records | ||
records.each do |record| | ||
expect(record.domain).to be_a(Ayashige::Domain) | ||
expect(record.updated_on).to be_a(String) | ||
end | ||
end | ||
end | ||
|
||
describe "#store_newly_registered_domains" do | ||
before do | ||
allow(subject).to receive(:records).and_return(records) | ||
end | ||
|
||
include_examples "#store_newly_registered_domains example" | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters