rochefort 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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/rochefort.rb +38 -15
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bc8b15abe5b9fc1c8b93e4a885c3ecfb91a11f4f
4
- data.tar.gz: 9ff9c898a2e7d14c646214591e0522aa7c434333
3
+ metadata.gz: fa87001a98b3f2cf7a5c008dba36df9425cd473e
4
+ data.tar.gz: 0f945723f6133643e4bd4c2ed144c0639177ff1d
5
5
  SHA512:
6
- metadata.gz: 2705f8e5cb3609da99029270ff62e6c61fde9c837774ab8a49af3445fc247b4d95ff5fd0607687ddff1962c8e4e1ded2f67d20a22cf69d95586320d11d214484
7
- data.tar.gz: 0f6625494b8b8d7a60f4123318bd11c1a5f18fa4234d7f0a0ab18eff11af9e9de3e668c132a1d0cf76411d0eaa037f633494b9b44afcdd00acdf4dd69c9ce31b
6
+ metadata.gz: 688eab3f7fbaa1480e4205ac669ad8ba8e8f0841d0154cb3cda3003a6587281977daa288659a03e97113e9286b291d308acc6d73d87594cad4fa0f0f26822e8e
7
+ data.tar.gz: 9c52c1ea55bacb0b048ef5e5d2b2f7f4edbfaddf3b292ca4d78db00b0c2d5c56fd968b1f30957a7bb66e22ee3401836e48615c4caa017086ac5a490f618b08b0
data/lib/rochefort.rb CHANGED
@@ -2,7 +2,7 @@ require 'rest-client'
2
2
  require 'uri'
3
3
  require 'json'
4
4
 
5
- # client for https://github.com/jackdoe/rochefort - disk speed append + offset service (poor man's kafka),
5
+ # client for https://github.com/jackdoe/rochefort - disk speed append + offset service (poor man's kafka),
6
6
  # example usage
7
7
  # r = new Rochefort("http://localhost:8001")
8
8
  # offset = r.append(namespace: "example-namespace", data:"example-data")
@@ -14,6 +14,7 @@ class Rochefort
14
14
  @urlModify = URI::join(url,'modify').to_s
15
15
  @urlGet = URI::join(url,'get').to_s
16
16
  @urlScan = URI::join(url,'scan').to_s
17
+ @urlQuery = URI::join(url,'query').to_s
17
18
  @urlGetMulti = URI::join(url,'getMulti').to_s
18
19
  end
19
20
 
@@ -60,7 +61,7 @@ class Rochefort
60
61
  return out["success"]
61
62
  end
62
63
 
63
-
64
+
64
65
  # get data from rochefort
65
66
  # r = Rochefort.new(url)
66
67
  # r.get(
@@ -103,14 +104,8 @@ class Rochefort
103
104
  return out
104
105
  end
105
106
 
106
- # scans a namespace, reading from a stream, so the namespace can be very big
107
- # also accepts array of tags to search for
108
- # r = Rochefort.new(url)
109
- # r.scan(namespace: ns) do |len, offset, value|
110
- # puts value
111
- # end
112
- # @return calls the block for each item
113
- def scan(opts,&input_block)
107
+
108
+ def scanParser(input_block)
114
109
  block = proc do |response|
115
110
  buffer = ""
116
111
  header_len = 12
@@ -124,7 +119,6 @@ class Rochefort
124
119
  response.read_body do |chunk|
125
120
  buffer << chunk
126
121
  while buffer.length >= need
127
-
128
122
  if waiting_for_header
129
123
  h = buffer.unpack('l<q<')
130
124
  len = h[0]
@@ -135,7 +129,7 @@ class Rochefort
135
129
  end
136
130
 
137
131
  if buffer.length >= need
138
- input_block.call(len, rochefort_offset, buffer[0, len])
132
+ input_block.call(rochefort_offset, buffer[0, len])
139
133
  buffer = buffer[len, buffer.length - len]
140
134
  need = header_len
141
135
  waiting_for_header = true
@@ -143,12 +137,41 @@ class Rochefort
143
137
  end
144
138
  end
145
139
  end
140
+ return block
141
+ end
146
142
 
147
- tags = opts[:tags] || []
143
+
144
+ # scans a namespace, reading from a stream, so the namespace can be very big
145
+ # r = Rochefort.new(url)
146
+ # r.scan(namespace: ns) do |offset, value|
147
+ # puts value
148
+ # end
149
+ # @return calls the block for each item
150
+ def scan(opts,&input_block)
148
151
  RestClient::Request.execute(method: :get,
149
- url: "#{@urlScan}?namespace=#{opts[:namespace]}&tags=#{tags.join(",")}",
152
+ url: "#{@urlScan}?namespace=#{opts[:namespace]}",
153
+ read_timeout: opts[:read_timeout] || 1,
154
+ open_timeout: opts[:open_timeout] || 1,
155
+ block_response: scanParser(input_block))
156
+ end
157
+
158
+ # searches a namespace, for the tagged /append blobs, reading from a stream, so the namespace can be very big
159
+ # r = Rochefort.new(url)
160
+ # r.search(query: {tag: 'a'}, namespace: ns) do |offset, value|
161
+ # puts value
162
+ # end
163
+ #
164
+ # the dsl is fairly simple: (A OR B OR (C AND D)
165
+ # {
166
+ # or: [ { tag: 'a' }, { tag: 'a' }, { and: [ {tag: 'c'}, {tag:'d'} ] } ]
167
+ # }
168
+ # @return calls the block for each item
169
+ def search(opts,&input_block)
170
+ RestClient::Request.execute(method: :post,
171
+ payload: JSON.generate(opts[:query]),
172
+ url: "#{@urlQuery}?namespace=#{opts[:namespace]}",
150
173
  read_timeout: opts[:read_timeout] || 1,
151
174
  open_timeout: opts[:open_timeout] || 1,
152
- block_response: block)
175
+ block_response: scanParser(input_block))
153
176
  end
154
177
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rochefort
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
  - Borislav Nikolov