-
-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
233 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,4 +5,4 @@ Gemfile.lock | |
/.env | ||
/tmp | ||
/cache | ||
node_modules | ||
node_modules |
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,62 @@ | ||
# frozen_string_literal: true | ||
|
||
class SiteInspector | ||
class Endpoint | ||
class Wappalyzer < Check | ||
ENDPOINT = 'https://api.wappalyzer.com/lookup/v2/' | ||
|
||
def to_h | ||
return {} unless data['technologies'] | ||
|
||
@to_h ||= begin | ||
technologies = {} | ||
data['technologies'].each do |t| | ||
category = t['categories'].first | ||
category = category ? category['name'] : 'Other' | ||
technologies[category] ||= [] | ||
technologies[category].push t['name'] | ||
end | ||
|
||
technologies | ||
end | ||
end | ||
|
||
private | ||
|
||
def request | ||
@request ||= begin | ||
options = SiteInspector.typhoeus_defaults | ||
headers = options[:headers].merge({ "x-api-key": api_key }) | ||
options = options.merge(method: :get, headers: headers) | ||
Typhoeus::Request.new(url, options) | ||
end | ||
end | ||
|
||
def data | ||
return {} unless api_key && api_key != '' | ||
|
||
@data ||= begin | ||
SiteInspector.hydra.queue(request) | ||
SiteInspector.hydra.run | ||
|
||
response = request.response | ||
if response.success? | ||
JSON.parse(response.body).first | ||
else | ||
{} | ||
end | ||
end | ||
end | ||
|
||
def url | ||
url = Addressable::URI.parse(ENDPOINT) | ||
url.query_values = { urls: endpoint.uri } | ||
url | ||
end | ||
|
||
def api_key | ||
@api_key ||= ENV['WAPPALYZER_API_KEY'] | ||
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
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,34 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'spec_helper' | ||
|
||
describe SiteInspector::Endpoint::Wappalyzer do | ||
subject { described_class.new(endpoint) } | ||
|
||
let(:domain) { 'http://ben.balter.com.com' } | ||
let(:endpoint) { SiteInspector::Endpoint.new(domain) } | ||
let(:url) { "https://api.wappalyzer.com/lookup/v2/?urls=#{domain}/" } | ||
|
||
before do | ||
path = File.expand_path '../fixtures/wappalyzer.json', __dir__ | ||
body = File.read path | ||
stub_request(:get, url).to_return(status: 200, body: body) | ||
end | ||
|
||
it 'returns the API response' do | ||
expected = { | ||
'Analytics' => ['Google Analytics'], | ||
'CDN' => %w[Cloudflare Fastly], | ||
'Caching' => ['Varnish'], | ||
'Other' => %w[Disqus Jekyll], | ||
'PaaS' => ['GitHub Pages'], | ||
'Web frameworks' => ['Ruby on Rails'] | ||
} | ||
expect(subject.to_h).to eql(expected) | ||
end | ||
|
||
it 'fails gracefully' do | ||
stub_request(:get, url).to_return(status: 400, body: '') | ||
expect(subject.to_h).to eql({}) | ||
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,125 @@ | ||
[ | ||
{ | ||
"url":"https://ben.balter.com", | ||
"technologies":[ | ||
{ | ||
"slug":"cloudflare", | ||
"name":"Cloudflare", | ||
"versions":[ | ||
|
||
], | ||
"trafficRank":11, | ||
"categories":[ | ||
{ | ||
"id":31, | ||
"slug":"cdn", | ||
"name":"CDN" | ||
} | ||
] | ||
}, | ||
{ | ||
"slug":"varnish", | ||
"name":"Varnish", | ||
"versions":[ | ||
|
||
], | ||
"trafficRank":11, | ||
"categories":[ | ||
{ | ||
"id":23, | ||
"slug":"caching", | ||
"name":"Caching" | ||
} | ||
] | ||
}, | ||
{ | ||
"slug":"disqus", | ||
"name":"Disqus", | ||
"versions":[ | ||
|
||
], | ||
"trafficRank":11, | ||
"categories":[ | ||
|
||
] | ||
}, | ||
{ | ||
"slug":"google-analytics", | ||
"name":"Google Analytics", | ||
"versions":[ | ||
|
||
], | ||
"trafficRank":11, | ||
"categories":[ | ||
{ | ||
"id":10, | ||
"slug":"analytics", | ||
"name":"Analytics" | ||
}, | ||
{ | ||
"id":61, | ||
"slug":"saas", | ||
"name":"SaaS" | ||
} | ||
] | ||
}, | ||
{ | ||
"slug":"jekyll", | ||
"name":"Jekyll", | ||
"versions":[ | ||
"v3.9.0" | ||
], | ||
"trafficRank":11, | ||
"categories":[ | ||
|
||
] | ||
}, | ||
{ | ||
"slug":"ruby-on-rails", | ||
"name":"Ruby on Rails", | ||
"versions":[ | ||
|
||
], | ||
"trafficRank":11, | ||
"categories":[ | ||
{ | ||
"id":18, | ||
"slug":"web-frameworks", | ||
"name":"Web frameworks" | ||
} | ||
] | ||
}, | ||
{ | ||
"slug":"fastly", | ||
"name":"Fastly", | ||
"versions":[ | ||
|
||
], | ||
"trafficRank":11, | ||
"categories":[ | ||
{ | ||
"id":31, | ||
"slug":"cdn", | ||
"name":"CDN" | ||
} | ||
] | ||
}, | ||
{ | ||
"slug":"github-pages", | ||
"name":"GitHub Pages", | ||
"versions":[ | ||
|
||
], | ||
"trafficRank":11, | ||
"categories":[ | ||
{ | ||
"id":62, | ||
"slug":"paas", | ||
"name":"PaaS" | ||
} | ||
] | ||
} | ||
], | ||
"crawl":true | ||
} | ||
] |