urlscan 0.2.1 → 0.3.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.
- checksums.yaml +4 -4
- data/README.md +15 -12
- data/lib/urlscan.rb +2 -1
- data/lib/urlscan/api.rb +14 -12
- data/lib/urlscan/cli.rb +17 -9
- data/lib/urlscan/version.rb +1 -1
- data/urlscan.gemspec +1 -1
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0e026187891feb001443e0380f839bd4ad5cb08d0601be2c73af45345d8a1f3d
|
4
|
+
data.tar.gz: 8b027008ebdb5c6686c4f1b2cfd841cebe4e933949473163d36f9ac8e3527ba4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a8c269b3080f8ec2e8d0785eba8b5fa3531ae169bd2718f02011920d20907d4c19a7c2293e6a146e391c6e5f231bc353732ae7d3f83f7ece50c66a068d8cff56
|
7
|
+
data.tar.gz: 251095794ae5577e33d887497caa82fccea882f89a322eb8b02cac86f8f31e27e975c156131e0bb29ccb966a96b32159bcb0297bee8644edbc3829a5e80c5167
|
data/README.md
CHANGED
@@ -1,5 +1,6 @@
|
|
1
|
-
#
|
1
|
+
# urlscan
|
2
2
|
|
3
|
+
[](https://badge.fury.io/rb/urlscan)
|
3
4
|
[](https://travis-ci.org/ninoseki/urlscan)
|
4
5
|
[](https://codeclimate.com/github/ninoseki/urlscan/maintainability)
|
5
6
|
[](https://coveralls.io/github/ninoseki/urlscan?branch=master)
|
@@ -45,23 +46,25 @@ p res # => See the following URL as an example of the reponse.
|
|
45
46
|
|
46
47
|
### Supported API endpoints
|
47
48
|
|
48
|
-
| HTTP Method | URI
|
49
|
-
|
50
|
-
| POST | /scan
|
51
|
-
| GET | /result
|
52
|
-
| GET | /dom
|
53
|
-
| GET | /
|
49
|
+
| HTTP Method | URI | API method |
|
50
|
+
|-------------|-------------------------|----------------------------------------------------------------|
|
51
|
+
| POST | /scan | `UrlScan::API#submit(url, is_public = true)` |
|
52
|
+
| GET | /result/`uuid`/ | `UrlScan::API#result(uuid)` |
|
53
|
+
| GET | /dom/`uuid`/ | `UrlScan::API#dom(uuid)` |
|
54
|
+
| GET | /screenshots/`uuid`.png | `UrlScan::API#screenshot(uuid)` |
|
55
|
+
| GET | /search | `UrlScan::API#search(q, size: 100, offset: 0, sort: "_score")` |
|
54
56
|
|
55
57
|
## CLI usage
|
56
58
|
|
57
59
|
```bash
|
58
60
|
$ urlscan
|
59
61
|
Commands:
|
60
|
-
urlscan dom [UUID]
|
61
|
-
urlscan help [COMMAND]
|
62
|
-
urlscan result [UUID]
|
63
|
-
urlscan
|
64
|
-
urlscan
|
62
|
+
urlscan dom [UUID] # get the DOM of a scan using the scan id [UUID]
|
63
|
+
urlscan help [COMMAND] # Describe available commands or one specific command
|
64
|
+
urlscan result [UUID] # get the result of a scan using the scan id [UUID]
|
65
|
+
urlscan screenshot [UUID] # get the screenshot(image/png) of a scan using the scan id [UUID]
|
66
|
+
urlscan search [QUERY] # search for scans by [QUERY]
|
67
|
+
urlscan submit [URL] # submit a scan to [URL]
|
65
68
|
|
66
69
|
Options:
|
67
70
|
[--API-KEY=API_KEY]
|
data/lib/urlscan.rb
CHANGED
data/lib/urlscan/api.rb
CHANGED
@@ -1,9 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
5
|
-
|
6
|
-
require 'urlscan/exceptions'
|
3
|
+
require "net/https"
|
4
|
+
require "json"
|
7
5
|
|
8
6
|
module UrlScan
|
9
7
|
class API
|
@@ -35,8 +33,12 @@ module UrlScan
|
|
35
33
|
get("/dom/#{uuid}/") { |dom| dom }
|
36
34
|
end
|
37
35
|
|
36
|
+
def screenshot(uuid)
|
37
|
+
get("/screenshots/#{uuid}.png") { |png| png }
|
38
|
+
end
|
39
|
+
|
38
40
|
# @return [Hash]
|
39
|
-
def search(q, size
|
41
|
+
def search(q, size: 100, offset: 0, sort: "_score")
|
40
42
|
params = { q: q, size: size, offset: offset, sort: sort }
|
41
43
|
query = URI.encode_www_form(params)
|
42
44
|
get("/search/?#{query}") { |json| json }
|
@@ -65,17 +67,17 @@ module UrlScan
|
|
65
67
|
response = http.request(req)
|
66
68
|
|
67
69
|
case response.code
|
68
|
-
when
|
70
|
+
when "200"
|
69
71
|
if response["Content-Type"].to_s.include? "application/json"
|
70
72
|
yield JSON.parse(response.body)
|
71
73
|
else
|
72
74
|
yield response.body
|
73
75
|
end
|
74
|
-
when
|
75
|
-
when
|
76
|
-
when
|
77
|
-
when
|
78
|
-
when
|
76
|
+
when "400" then raise ProcessingError, response.body
|
77
|
+
when "401" then raise AuthenticationError, response.body
|
78
|
+
when "404" then raise NotFound, response.body
|
79
|
+
when "429" then raise RateLimited, response.body
|
80
|
+
when "500" then raise InternalServerError, response.body
|
79
81
|
else
|
80
82
|
raise ResponseError, response.body
|
81
83
|
end
|
@@ -93,7 +95,7 @@ module UrlScan
|
|
93
95
|
|
94
96
|
def post(path, json, &block)
|
95
97
|
post = Net::HTTP::Post.new(url_for(path), auth_header)
|
96
|
-
post.content_type =
|
98
|
+
post.content_type = "application/json"
|
97
99
|
post.body = json.to_json
|
98
100
|
|
99
101
|
request(post, &block)
|
data/lib/urlscan/cli.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
3
|
+
require "json"
|
4
|
+
require "thor"
|
5
5
|
|
6
6
|
module UrlScan
|
7
7
|
class CLI < Thor
|
@@ -16,7 +16,7 @@ module UrlScan
|
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
19
|
-
desc "result [UUID]", "get the result of a scan using the [UUID]"
|
19
|
+
desc "result [UUID]", "get the result of a scan using the scan id [UUID]"
|
20
20
|
def result(uuid)
|
21
21
|
with_error_handling do
|
22
22
|
res = api.result(uuid)
|
@@ -30,12 +30,12 @@ module UrlScan
|
|
30
30
|
method_option :sort, type: :string, default: "_score"
|
31
31
|
def search(query)
|
32
32
|
with_error_handling do
|
33
|
-
res = api.search(query, options[
|
33
|
+
res = api.search(query, size: options["size"], offset: options["offset"], sort: options["sort"])
|
34
34
|
puts JSON.pretty_generate(res)
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
38
|
-
desc "dom [UUID]", "get the DOM of a scan using the [UUID]"
|
38
|
+
desc "dom [UUID]", "get the DOM of a scan using the scan id [UUID]"
|
39
39
|
def dom(uuid)
|
40
40
|
with_error_handling do
|
41
41
|
res = api.dom(uuid)
|
@@ -43,17 +43,25 @@ module UrlScan
|
|
43
43
|
end
|
44
44
|
end
|
45
45
|
|
46
|
+
desc "screenshot [UUID]", "get the screenshot(image/png) of a scan using the scan id [UUID]"
|
47
|
+
def screenshot(uuid)
|
48
|
+
with_error_handling do
|
49
|
+
res = api.screenshot(uuid)
|
50
|
+
puts res
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
46
54
|
no_commands do
|
47
55
|
def api
|
48
|
-
options[
|
56
|
+
options["API_KEY"] ? API.new(options["API_KEY"]) : API.new
|
49
57
|
end
|
50
58
|
|
51
59
|
def with_error_handling
|
52
60
|
yield
|
53
61
|
rescue ArgumentError => _e
|
54
|
-
puts "Warning: please specify your urlscan.io API key via ENV['URLSCAN_API_KEY] or --API-KEY"
|
55
|
-
rescue ResponseError =>
|
56
|
-
puts "Warning: #{
|
62
|
+
puts "Warning: please specify your urlscan.io API key via ENV['URLSCAN_API_KEY'] or --API-KEY"
|
63
|
+
rescue ResponseError => e
|
64
|
+
puts "Warning: #{e}"
|
57
65
|
end
|
58
66
|
end
|
59
67
|
end
|
data/lib/urlscan/version.rb
CHANGED
data/urlscan.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: urlscan
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Manabu Niseki
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-08-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -114,14 +114,14 @@ dependencies:
|
|
114
114
|
requirements:
|
115
115
|
- - "~>"
|
116
116
|
- !ruby/object:Gem::Version
|
117
|
-
version: '0.
|
117
|
+
version: '0.20'
|
118
118
|
type: :runtime
|
119
119
|
prerelease: false
|
120
120
|
version_requirements: !ruby/object:Gem::Requirement
|
121
121
|
requirements:
|
122
122
|
- - "~>"
|
123
123
|
- !ruby/object:Gem::Version
|
124
|
-
version: '0.
|
124
|
+
version: '0.20'
|
125
125
|
description:
|
126
126
|
email:
|
127
127
|
- manabu.niseki@gmail.com
|
@@ -165,7 +165,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
165
165
|
- !ruby/object:Gem::Version
|
166
166
|
version: '0'
|
167
167
|
requirements: []
|
168
|
-
rubygems_version: 3.0.
|
168
|
+
rubygems_version: 3.0.4
|
169
169
|
signing_key:
|
170
170
|
specification_version: 4
|
171
171
|
summary: Ruby API client for urlscan.io
|