diff options
| author | mo <mo.khan@gmail.com> | 2018-03-18 14:30:48 -0600 |
|---|---|---|
| committer | mo <mo.khan@gmail.com> | 2018-03-18 14:30:48 -0600 |
| commit | b07079259635abaf0d13f21d8740dc8783dbb7d3 (patch) | |
| tree | 86e4f68aca20bdeb90da85e65ac87711bef95a3f /lib | |
| parent | de57b4dd50b355b9ac74ebf64fb6108ceb3cefff (diff) | |
add search command.
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/ats.rb | 1 | ||||
| -rw-r--r-- | lib/ats/cli/threat_grid.rb | 1 | ||||
| -rw-r--r-- | lib/ats/cli/threat_grid/application.rb | 3 | ||||
| -rw-r--r-- | lib/ats/cli/threat_grid/search.rb | 12 | ||||
| -rw-r--r-- | lib/ats/threat_grid/api.rb | 12 | ||||
| -rw-r--r-- | lib/ats/threat_grid/organizations.rb | 2 | ||||
| -rw-r--r-- | lib/ats/threat_grid/samples.rb | 2 | ||||
| -rw-r--r-- | lib/ats/threat_grid/search.rb | 15 |
8 files changed, 42 insertions, 6 deletions
@@ -8,6 +8,7 @@ require 'ats/http_api' require 'ats/threat_grid/api' require 'ats/threat_grid/organizations' require 'ats/threat_grid/samples' +require 'ats/threat_grid/search' require 'ats/threat_grid/users' require 'ats/version' diff --git a/lib/ats/cli/threat_grid.rb b/lib/ats/cli/threat_grid.rb index 16c6461..18ebeec 100644 --- a/lib/ats/cli/threat_grid.rb +++ b/lib/ats/cli/threat_grid.rb @@ -1,6 +1,7 @@ require 'ats/cli/threat_grid/command' require 'ats/cli/threat_grid/organizations' require 'ats/cli/threat_grid/samples' +require 'ats/cli/threat_grid/search' require 'ats/cli/threat_grid/users' require 'ats/cli/threat_grid/application' diff --git a/lib/ats/cli/threat_grid/application.rb b/lib/ats/cli/threat_grid/application.rb index a73e2d9..11eea38 100644 --- a/lib/ats/cli/threat_grid/application.rb +++ b/lib/ats/cli/threat_grid/application.rb @@ -13,6 +13,9 @@ module ATS desc 'samples SUBCOMMAND ...ARGS', 'interact with the Threat Grid API' subcommand :samples, ATS::CLI::ThreatGrid::Samples + desc 'search SUBCOMMAND ...ARGS', 'interact with the Threat Grid API' + subcommand :search, ATS::CLI::ThreatGrid::Search + desc 'whoami', 'whoami' def whoami say JSON.pretty_generate(ATS::ThreatGrid::API.new(profile: options['profile']).whoami) diff --git a/lib/ats/cli/threat_grid/search.rb b/lib/ats/cli/threat_grid/search.rb new file mode 100644 index 0000000..e00c6c7 --- /dev/null +++ b/lib/ats/cli/threat_grid/search.rb @@ -0,0 +1,12 @@ +module ATS + module CLI + module ThreatGrid + class Search < Command + desc 'urls <URL>', 'Search urls' + def urls(url) + print_json api.search.urls(url) + end + end + end + end +end diff --git a/lib/ats/threat_grid/api.rb b/lib/ats/threat_grid/api.rb index a3f5d56..474b547 100644 --- a/lib/ats/threat_grid/api.rb +++ b/lib/ats/threat_grid/api.rb @@ -36,8 +36,12 @@ module ATS ATS::ThreatGrid::Samples.new(self) end - def get(url, params = {}) - http.get(build_uri(url), body: default_payload.merge(params)) do |request, response| + def search + ATS::ThreatGrid::Search.new(self) + end + + def get(url, params: {}, version: 3) + http.get(build_uri(url, version: version), body: default_payload.merge(params)) do |request, response| JSON.parse(response.body, symbolize_names: true)[:data] end end @@ -48,8 +52,8 @@ module ATS { api_key: api_key } end - def build_uri(relative_url) - URI.parse("#{api_host}/api/v3/#{relative_url}") + def build_uri(relative_url, version:) + URI.parse("#{api_host}/api/v#{version}/#{relative_url}") end def api_key diff --git a/lib/ats/threat_grid/organizations.rb b/lib/ats/threat_grid/organizations.rb index 039d87f..0194fde 100644 --- a/lib/ats/threat_grid/organizations.rb +++ b/lib/ats/threat_grid/organizations.rb @@ -12,7 +12,7 @@ module ATS end def search(term) - api.get("organizations", query: term) + api.get("organizations", params: { query: term }) end def show(id) diff --git a/lib/ats/threat_grid/samples.rb b/lib/ats/threat_grid/samples.rb index 720f100..78f9109 100644 --- a/lib/ats/threat_grid/samples.rb +++ b/lib/ats/threat_grid/samples.rb @@ -8,7 +8,7 @@ module ATS end def search(term) - api.get("samples/search", checksum: term) + api.get("samples/search", params: { checksum: term }) end end end diff --git a/lib/ats/threat_grid/search.rb b/lib/ats/threat_grid/search.rb new file mode 100644 index 0000000..b07f8d2 --- /dev/null +++ b/lib/ats/threat_grid/search.rb @@ -0,0 +1,15 @@ +module ATS + module ThreatGrid + class Search + attr_reader :api + + def initialize(api) + @api = api + end + + def urls(url) + api.get("search/urls", params: { url: url }, version: 2) + end + end + end +end |
