hachi 0.1.1 → 0.1.2

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: 87cd25193f5c029ffe10e1c1dffcd423c7fb33ee7b6de160774435e27addf39e
4
- data.tar.gz: 517b92aa1ad86f6fe91256aa2c1f7ca17aa963c68d39cd0bc0801348e8df6c28
3
+ metadata.gz: 789e04c496071bb676e874312b47929b538a1d6a028ca5042ac18b85364d2ac7
4
+ data.tar.gz: 439eccca76345fb3b74aacc2a9749ef4875652b5ba1ab15f171b7b47a9f0d45b
5
5
  SHA512:
6
- metadata.gz: 571b2bfe288550645f5158a43a63170a4067c3ef66e2d0e1170d597548548b57fa91b5028476e453008cab0f4083fcf3b1688cacb6c0a570258df9bbd8ae0bcd
7
- data.tar.gz: 5b55a9c1a62ec128b7ef5b73af436e77331c8bdb44ee40e21fbf228bc1216b63e36407938ba14973445b6f8f6fdc28ffa4404246490b62ca04c91fad3231ba6e
6
+ metadata.gz: ba111b9284560325d00bcbe3f09240130c75428072a85fe596db524e35f9437c603a0788ca008ae309b179f475aac0ab11c0872455b6233f178da687b1c01996
7
+ data.tar.gz: c9c720cf508b16cc10170d52732b6a2cdb0d0b39899810a5f3b559d1a561574cea3298b5a64911cc2addb574f117e5afd8870f32445ef0ca5f90f3dc42ac0ab4
data/README.md CHANGED
@@ -1,5 +1,6 @@
1
1
  # Hachi
2
2
 
3
+ [![Gem Version](https://badge.fury.io/rb/hachi.svg)](https://badge.fury.io/rb/hachi)
3
4
  [![Build Status](https://travis-ci.org/ninoseki/hachi.svg?branch=master)](https://travis-ci.org/ninoseki/hachi)
4
5
  [![Coverage Status](https://coveralls.io/repos/github/ninoseki/hachi/badge.svg?branch=master)](https://coveralls.io/github/ninoseki/hachi?branch=master)
5
6
 
@@ -23,7 +23,9 @@ module Hachi
23
23
  delete("/api/case/artifact/#{id}") { |json| json }
24
24
  end
25
25
 
26
- def search(data:, data_type:)
26
+ def search(data:, data_type:, range: "all")
27
+ validate_range range
28
+
27
29
  artifact = Models::Artifact.new(data: data, data_type: data_type)
28
30
  payload = {
29
31
  query: {
@@ -41,7 +43,7 @@ module Hachi
41
43
  }
42
44
  }
43
45
 
44
- post("/api/case/artifact/_search?range=all", payload) { |json| json }
46
+ post("/api/case/artifact/_search?range=#{range}", payload) { |json| json }
45
47
  end
46
48
  end
47
49
  end
@@ -99,6 +99,16 @@ module Hachi
99
99
  delete.add_field "Authorization", "Bearer #{api_key}"
100
100
  request(delete, &block)
101
101
  end
102
+
103
+ def validate_range(range)
104
+ return true if range == "all"
105
+ raise ArgumentError, "range should be 'all' or `from-to`" unless range.match?(/(\d+)-(\d+)/)
106
+
107
+ from, to = range.split("-").map(&:to_i)
108
+ return true if from < to
109
+
110
+ raise ArgumentError, "from should be smaller than to"
111
+ end
102
112
  end
103
113
  end
104
114
  end
@@ -30,7 +30,9 @@ module Hachi
30
30
  post("/api/case", kase.payload) { |json| json }
31
31
  end
32
32
 
33
- def search(query)
33
+ def search(query, range: "all")
34
+ validate_range range
35
+
34
36
  payload = {
35
37
  query: {
36
38
  _and:
@@ -45,7 +47,8 @@ module Hachi
45
47
  ]
46
48
  }
47
49
  }
48
- post("/api/case/_search?range=all", payload) { |json| json }
50
+
51
+ post("/api/case/_search?range=#{range}", payload) { |json| json }
49
52
  end
50
53
  end
51
54
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Hachi
4
- VERSION = "0.1.1"
4
+ VERSION = "0.1.2"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hachi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
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-04-14 00:00:00.000000000 Z
11
+ date: 2019-04-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler