shodanz 2.0.2 → 2.0.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 410e95de412de33cdbe2fb4fd47ed7eda7e9bdbc1dc86f68a09050cf5ec316fc
4
- data.tar.gz: 94dc8c3425f95bd0d7294499618e58f2f3e4b88f174f132ced5b2316a52800b1
3
+ metadata.gz: f4b13cd6886a40478480be6963df243daff8a70bc89386aaf837589a2d8ad301
4
+ data.tar.gz: 90f764801640b90765c5e2bbf84cc7be70f0dbfbf788f60315bebf3a24f3e8ee
5
5
  SHA512:
6
- metadata.gz: 29dea01f7e595b0b7eb6700eaa5e04dac0a426606c6bd28882b9ac484c48e48bb9ff35aa26cfd7b60996cde16273ff27d92534dd5e7909997c75c58c94b0d228
7
- data.tar.gz: e7c851400c229bd11749d4acafc8c9b784ef29b61c40f1187db7774886f565aa82935086f648178eac2e3f6782f5618572074fa5a468803c670a3ae31d4ed2d6
6
+ metadata.gz: b2da8666780fe6fd7560155c868a821c0ea353ac5515f7e794429a07b5b600729ee117fbb6d269d3316b1c502afd9a914b656d7cfd0ca2cf8a5a1b410cab1ed4
7
+ data.tar.gz: 4f44aac093e59b2f38ac942b7c6548abe25189180109f91a78e81b2f0ebbda235edf147625468252632f49cc806c0ad584f517074d6771716485e9d84be306b3
@@ -19,13 +19,13 @@ module Shodanz
19
19
  attr_accessor :key
20
20
 
21
21
  # The path to the REST API endpoint.
22
- URL = 'https://exploits.shodan.io/api/'
22
+ URL = 'https://exploits.shodan.io/'
23
23
 
24
24
  # @param key [String] SHODAN API key, defaulted to
25
25
  # the *SHODAN_API_KEY* enviroment variable.
26
26
  def initialize(key: ENV['SHODAN_API_KEY'])
27
27
  @url = URL
28
- @internet = Async::HTTP::Internet.new
28
+ @client = Async::HTTP::Client.new(Async::HTTP::Endpoint.parse(@url))
29
29
  self.key = key
30
30
 
31
31
  warn 'No key has been found or provided!' unless key?
@@ -50,7 +50,7 @@ module Shodanz
50
50
  params = turn_into_query(**params)
51
51
  facets = turn_into_facets(**facets)
52
52
  params[:page] = page
53
- get('search', **params.merge(**facets))
53
+ get('api/search', **params.merge(**facets))
54
54
  end
55
55
 
56
56
  # This method behaves identical to the "/search" method with
@@ -62,7 +62,7 @@ module Shodanz
62
62
  params = turn_into_query(**params)
63
63
  facets = turn_into_facets(**facets)
64
64
  params[:page] = page
65
- get('count', **params.merge(**facets))
65
+ get('api/count', **params.merge(**facets))
66
66
  end
67
67
  end
68
68
  end
@@ -22,7 +22,7 @@ module Shodanz
22
22
  # @param key [String] SHODAN API key, defaulted to the *SHODAN_API_KEY* enviroment variable.
23
23
  def initialize(key: ENV['SHODAN_API_KEY'])
24
24
  @url = URL
25
- @internet = Async::HTTP::Internet.new
25
+ @client = Async::HTTP::Client.new(Async::HTTP::Endpoint.parse(@url))
26
26
  self.key = key
27
27
 
28
28
  warn 'No key has been found or provided!' unless key?
@@ -28,7 +28,7 @@ module Shodanz
28
28
  # @param key [String] SHODAN API key, defaulted to the *SHODAN_API_KEY* enviroment variable.
29
29
  def initialize(key: ENV['SHODAN_API_KEY'])
30
30
  @url = URL
31
- @internet = Async::HTTP::Internet.new
31
+ @client = Async::HTTP::Client.new(Async::HTTP::Endpoint.parse(@url))
32
32
  self.key = key
33
33
 
34
34
  warn 'No key has been found or provided!' unless key?
@@ -78,11 +78,11 @@ module Shodanz
78
78
  return json
79
79
  end
80
80
 
81
- def getter(path, one_shot=false, **params)
81
+ def getter(path, **params)
82
82
  # param keys should all be strings
83
83
  params = params.transform_keys(&:to_s)
84
84
  # build up url string based on special params
85
- url = "#{@url}#{path}?key=#{@key}"
85
+ url = "/#{path}?key=#{@key}"
86
86
  # special params
87
87
  params.each do |param,value|
88
88
  next if value.is_a?(String) && value.empty?
@@ -90,38 +90,41 @@ module Shodanz
90
90
  url += "&#{param}=#{value}"
91
91
  end
92
92
 
93
- resp = @internet.get(url)
93
+ resp = @client.get(url)
94
94
 
95
- # parse all lines in the response body as JSON
96
- json = JSON.parse(resp.body.join)
95
+ if resp.success?
96
+ # parse all lines in the response body as JSON
97
+ json = JSON.parse(resp.body.join)
97
98
 
98
- @internet.close if one_shot
99
+ handle_any_json_errors(json)
99
100
 
100
- handle_any_json_errors(json)
101
-
102
- return json
101
+ return json
102
+ else
103
+ raise "Got response status #{resp.status}"
104
+ end
103
105
  ensure
106
+ @client.pool.close
104
107
  resp&.close
105
- @internet = Async::HTTP::Internet.new if one_shot
106
108
  end
107
109
 
108
110
  def poster(path, one_shot=false, **params)
109
111
  # param keys should all be strings
110
112
  params = params.transform_keys(&:to_s)
111
113
  # make POST request to server
112
- resp = @internet.post("#{@url}#{path}?key=#{@key}", params)
114
+ resp = @client.post("/#{path}?key=#{@key}", nil, JSON.dump(params))
113
115
 
114
- # parse all lines in the response body as JSON
115
- json = JSON.parse(resp.body.join)
116
+ if resp.success?
117
+ json = JSON.parse(resp.body.join)
116
118
 
117
- @internet.close if one_shot
119
+ handle_any_json_errors(json)
118
120
 
119
- handle_any_json_errors(json)
120
-
121
- return json
121
+ return json
122
+ else
123
+ raise "Got response status #{resp.status}"
124
+ end
122
125
  ensure
126
+ @client.pool.close
123
127
  resp&.close
124
- @internet = Async::HTTP::Internet.new if one_shot
125
128
  end
126
129
 
127
130
  def slurper(path, **params)
@@ -132,7 +135,7 @@ module Shodanz
132
135
  counter = 0
133
136
  end
134
137
  # make GET request to server
135
- resp = @internet.get("#{@url}#{path}?key=#{@key}", params)
138
+ resp = @client.get("/#{path}?key=#{@key}", params)
136
139
  # read body line-by-line
137
140
  until resp.body.nil? || resp.body.empty?
138
141
  resp.body.read.each_line do |line|
@@ -151,25 +154,25 @@ module Shodanz
151
154
 
152
155
  def async_get(path, **params)
153
156
  Async::Task.current.async do
154
- getter(path, false, **params)
157
+ getter(path, **params)
155
158
  end
156
159
  end
157
160
 
158
161
  def sync_get(path, **params)
159
162
  Async do
160
- getter(path, true, **params)
163
+ getter(path, **params)
161
164
  end.wait
162
165
  end
163
166
 
164
167
  def async_post(path, **params)
165
168
  Async::Task.current.async do
166
- poster(path, false, **params)
169
+ poster(path, **params)
167
170
  end
168
171
  end
169
172
 
170
173
  def sync_post(path, **params)
171
174
  Async do
172
- poster(path, true, **params)
175
+ poster(path, **params)
173
176
  end.wait
174
177
  end
175
178
 
@@ -15,7 +15,7 @@ module Shodanz
15
15
  end
16
16
 
17
17
  class NoAPIKey < StandardError
18
- def initialize(msg = 'No API key has been found or provided! ( setup your SHODAN_API_KEY environment varialbe )')
18
+ def initialize(msg = 'No API key has been found or provided! ( setup your SHODAN_API_KEY environment variable )')
19
19
  super
20
20
  end
21
21
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Shodanz
4
- VERSION = '2.0.2'
4
+ VERSION = '2.0.3'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shodanz
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.2
4
+ version: 2.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kent 'picatz' Gruber
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-02-01 00:00:00.000000000 Z
11
+ date: 2020-02-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: async-http
@@ -186,7 +186,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
186
186
  - !ruby/object:Gem::Version
187
187
  version: '0'
188
188
  requirements: []
189
- rubygems_version: 3.1.2
189
+ rubygems_version: 3.0.6
190
190
  signing_key:
191
191
  specification_version: 4
192
192
  summary: A modern, async Ruby gem for Shodan, the world's first search engine for