hachi 0.2.3 → 0.2.4

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: 293861a0525887a1d226fe9c8673de534787fc243b6fa8c0feddc61e3cf7ff48
4
- data.tar.gz: 4f2aecbe26c66918b393921e4f0666b34c62f2b8fc13d2c337d89789b86a22a3
3
+ metadata.gz: 25c386c075dc1e5962bd50ab50194d9489ab6ac017eb582be0136ea80b130fee
4
+ data.tar.gz: 50c9377cbf664c06aeb72675799d5657ae9368a3dcbd52e1dab29bf6990e928a
5
5
  SHA512:
6
- metadata.gz: dd3136e1b68d371109ea98957d9a09b18459f3086d14ec94d9f023cda5b81ae06ae477d180535014d1a3ba9d33541d215e62283b87c9e101ad3a85c115bde9cf
7
- data.tar.gz: 4e866aed081ac5a526db9460c4b2ef148d0ee7ce17f5ffe758ef81cbbef6acb2970a7ec710ea4cc457825cb775c3a07bc7fdc46d1adc4ed0c04becd9e61a85c8
6
+ metadata.gz: fcea0e7d85452ee6a9bfc94cb154abe28234bf0bc87db4b855d296a1ec7119085973fb29d5c71a5304c58c2f78a7a9df30a1b9d6bc3cdc0ea6f72ba02fab8ee0
7
+ data.tar.gz: b31c9631dc876c7d030fb3171a35985a442cb0c8da5755cd64644d5041e16f995435ef921ef72e4739fafd0048d2f2024c2e499aacb8eb61e4883ecd7611f0dd
data/README.md CHANGED
@@ -41,7 +41,7 @@ See `samples` for more.
41
41
  | HTTP Method | URI | Action | API method |
42
42
  |-------------|-----------------------------------|-----------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------|
43
43
  | GET | /api/alert | List alerts | `#api.alert.list` |
44
- | POST | /api/alert/_search | Find alerts | `#api.alert.search(attributes:, range: "all")` |
44
+ | POST | /api/alert/_search | Find alerts | `#api.alert.search(attributes, range: "all")` |
45
45
  | PATCH | /api/alert/_bulk | Update alerts in bulk | N/A |
46
46
  | POST | /api/alert/_stats | Compute stats on alerts | N/A |
47
47
  | POST | /api/alert | Create an alert | `#api.alert.create(title:, description:, severity: nil, date: nil, tags: nil, tlp: nil, status: nil, type:, source:, source_ref: nil, artifacts: nil, follow: nil)` |
@@ -36,8 +36,8 @@ module Hachi
36
36
  post("/api/alert", alert.payload) { |json| json }
37
37
  end
38
38
 
39
- def search(attributes, range: "all")
40
- _search("/api/alert/_search", attributes: attributes, range: range) { |json| json }
39
+ def search(attributes, range: "all", sort: nil)
40
+ _search("/api/alert/_search", attributes: attributes, range: range, sort: sort) { |json| json }
41
41
  end
42
42
  end
43
43
  end
@@ -2,6 +2,7 @@
2
2
 
3
3
  require "json"
4
4
  require "net/https"
5
+ require "uri"
5
6
 
6
7
  module Hachi
7
8
  module Clients
@@ -113,7 +114,7 @@ module Hachi
113
114
  raise ArgumentError, "from should be smaller than to"
114
115
  end
115
116
 
116
- def _search(path, attributes:, range: "all")
117
+ def _search(path, attributes:, range: "all", sort: nil)
117
118
  validate_range range
118
119
 
119
120
  attributes = normalize_attributes(attributes)
@@ -136,7 +137,9 @@ module Hachi
136
137
  _and: [conditions, default_conditions].flatten,
137
138
  }
138
139
 
139
- post("#{path}?range=#{range}", query: query) { |json| json }
140
+ query_string = build_query_string(range: range, sort: sort)
141
+
142
+ post("#{path}?#{query_string}", query: query) { |json| json }
140
143
  end
141
144
 
142
145
  def decompose_data(data)
@@ -157,6 +160,10 @@ module Hachi
157
160
  head, *others = string.to_s.split("_")
158
161
  [head, others.map(&:capitalize)].flatten.join
159
162
  end
163
+
164
+ def build_query_string(params)
165
+ URI.encode_www_form(params.reject { |_k, v| v.nil? })
166
+ end
160
167
  end
161
168
  end
162
169
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Hachi
4
- VERSION = "0.2.3"
4
+ VERSION = "0.2.4"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hachi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Manabu Niseki