urlscan 0.2.1 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c860d94c43d840a9ae3e1de318125cd3751bb7343ddc0c6804befda52f07fd51
4
- data.tar.gz: 4a3c41475e008a8c2e20507a17b3a69476be3741e7d2010906d34a4bfdf47b86
3
+ metadata.gz: 0e026187891feb001443e0380f839bd4ad5cb08d0601be2c73af45345d8a1f3d
4
+ data.tar.gz: 8b027008ebdb5c6686c4f1b2cfd841cebe4e933949473163d36f9ac8e3527ba4
5
5
  SHA512:
6
- metadata.gz: 396ff9ada2223c5a2dae1db5cdd79c76d62b6673f2750e9cbcd3c6285c4bb940d0dcf8cdd9533b583641d1f299eb1abb668f882e02489dc476fb49011112f07a
7
- data.tar.gz: d9f65c8c0d4c79d23e665f2d32b96103068a5b0b8c2f15e67e0ab8289786e34d279712187570866ad768bd7a06ffe160203de1fdf619efaa958a74deb86ff547
6
+ metadata.gz: a8c269b3080f8ec2e8d0785eba8b5fa3531ae169bd2718f02011920d20907d4c19a7c2293e6a146e391c6e5f231bc353732ae7d3f83f7ece50c66a068d8cff56
7
+ data.tar.gz: 251095794ae5577e33d887497caa82fccea882f89a322eb8b02cac86f8f31e27e975c156131e0bb29ccb966a96b32159bcb0297bee8644edbc3829a5e80c5167
data/README.md CHANGED
@@ -1,5 +1,6 @@
1
- # UrlScan
1
+ # urlscan
2
2
 
3
+ [![Gem Version](https://badge.fury.io/rb/urlscan.svg)](https://badge.fury.io/rb/urlscan)
3
4
  [![Build Status](https://travis-ci.org/ninoseki/urlscan.svg?branch=master)](https://travis-ci.org/ninoseki/urlscan)
4
5
  [![Maintainability](https://api.codeclimate.com/v1/badges/c6625486f2d57039adef/maintainability)](https://codeclimate.com/github/ninoseki/urlscan/maintainability)
5
6
  [![Coverage Status](https://coveralls.io/repos/github/ninoseki/urlscan/badge.svg?branch=master)](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 | API method |
49
- | ----------- | --------------- | ----------------------------------------------------------------- |
50
- | POST | /scan | `UrlScan::API#submit(url, is_public = true)` |
51
- | GET | /result/\$uuid/ | `UrlScan::API#result(uuid)` |
52
- | GET | /dom/\$uuid/ | `UrlScan::API#dom(uuid)` |
53
- | GET | /search | `UrlScan::API#search(q, size = 100, offset = 0, sort = "_score")` |
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] # get the DOM of a scan using the [UUID]
61
- urlscan help [COMMAND] # Describe available commands or one specific command
62
- urlscan result [UUID] # get the result of a scan using the [UUID]
63
- urlscan search [QUERY] # search for scans by [QUERY]
64
- urlscan submit [URL] # submit a scan to [URL]
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]
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "urlscan/version"
4
+ require "urlscan/exceptions"
3
5
  require "urlscan/api"
4
6
  require "urlscan/cli"
5
- require "urlscan/version"
@@ -1,9 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'net/https'
4
- require 'json'
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 = 100, offset = 0, sort = "_score")
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 '200'
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 '400' then raise ProcessingError, response.body
75
- when '401' then raise AuthenticationError, response.body
76
- when '404' then raise NotFound, response.body
77
- when '429' then raise RateLimited, response.body
78
- when '500' then raise InternalServerError, response.body
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 = 'application/json'
98
+ post.content_type = "application/json"
97
99
  post.body = json.to_json
98
100
 
99
101
  request(post, &block)
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'json'
4
- require 'thor'
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[:size], options[:offset], options[:sort])
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[:API_KEY] ? API.new(options[:API_KEY]) : API.new
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 => _e
56
- puts "Warning: #{_e}"
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module UrlScan
4
- VERSION = "0.2.1"
4
+ VERSION = "0.3.0"
5
5
  end
@@ -29,5 +29,5 @@ Gem::Specification.new do |spec|
29
29
  spec.add_development_dependency "vcr", "~> 5.0"
30
30
  spec.add_development_dependency "webmock", "~> 3.6"
31
31
 
32
- spec.add_runtime_dependency "thor", "~> 0.19"
32
+ spec.add_runtime_dependency "thor", "~> 0.20"
33
33
  end
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.2.1
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-07-24 00:00:00.000000000 Z
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.19'
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.19'
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.2
168
+ rubygems_version: 3.0.4
169
169
  signing_key:
170
170
  specification_version: 4
171
171
  summary: Ruby API client for urlscan.io