search-kit 0.0.2 → 0.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.
Files changed (56) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/config/locales/en.yml +112 -3
  4. data/lib/search_kit.rb +5 -6
  5. data/lib/search_kit/cli.rb +45 -10
  6. data/lib/search_kit/cli/documents.rb +75 -0
  7. data/lib/search_kit/cli/events.rb +88 -0
  8. data/lib/search_kit/cli/indices.rb +96 -0
  9. data/lib/search_kit/cli/search.rb +60 -0
  10. data/lib/search_kit/cli/subscribers.rb +45 -0
  11. data/lib/search_kit/clients.rb +12 -0
  12. data/lib/search_kit/clients/documents.rb +71 -0
  13. data/lib/search_kit/clients/events.rb +77 -0
  14. data/lib/search_kit/clients/indices.rb +70 -0
  15. data/lib/search_kit/clients/keys.rb +78 -0
  16. data/lib/search_kit/clients/populate.rb +72 -0
  17. data/lib/search_kit/clients/scaffold.rb +36 -0
  18. data/lib/search_kit/clients/search.rb +33 -0
  19. data/lib/search_kit/clients/subscribers.rb +54 -0
  20. data/lib/search_kit/configuration.rb +0 -1
  21. data/lib/search_kit/errors.rb +4 -1
  22. data/lib/search_kit/messages.rb +41 -0
  23. data/lib/search_kit/messages/messaging.rb +64 -0
  24. data/lib/search_kit/models.rb +14 -0
  25. data/lib/search_kit/models/document.rb +30 -0
  26. data/lib/search_kit/models/documents.rb +31 -0
  27. data/lib/search_kit/models/event.rb +18 -0
  28. data/lib/search_kit/models/events.rb +31 -0
  29. data/lib/search_kit/models/key.rb +26 -0
  30. data/lib/search_kit/models/keys.rb +38 -0
  31. data/lib/search_kit/models/search.rb +17 -0
  32. data/lib/search_kit/models/subscriber.rb +26 -0
  33. data/lib/search_kit/polling.rb +30 -0
  34. data/lib/search_kit/polling/process.rb +40 -0
  35. data/lib/search_kit/thor.rb +12 -0
  36. data/lib/search_kit/version.rb +1 -1
  37. data/search-kit.gemspec +2 -0
  38. metadata +58 -20
  39. data/lib/search_kit/documents.rb +0 -59
  40. data/lib/search_kit/documents/cli.rb +0 -70
  41. data/lib/search_kit/events.rb +0 -59
  42. data/lib/search_kit/events/cli.rb +0 -52
  43. data/lib/search_kit/events/cli/complete.rb +0 -34
  44. data/lib/search_kit/events/cli/list.rb +0 -48
  45. data/lib/search_kit/events/cli/pending.rb +0 -48
  46. data/lib/search_kit/events/cli/publish.rb +0 -42
  47. data/lib/search_kit/events/cli/status.rb +0 -43
  48. data/lib/search_kit/events/poll.rb +0 -32
  49. data/lib/search_kit/events/poll/process.rb +0 -42
  50. data/lib/search_kit/events/publish.rb +0 -48
  51. data/lib/search_kit/indices.rb +0 -58
  52. data/lib/search_kit/indices/cli.rb +0 -65
  53. data/lib/search_kit/messaging.rb +0 -44
  54. data/lib/search_kit/search.rb +0 -30
  55. data/lib/search_kit/search/cli.rb +0 -49
  56. data/lib/search_kit/search/cli/actions.rb +0 -104
@@ -0,0 +1,17 @@
1
+ module SearchKit
2
+ module Models
3
+ class Search
4
+ include Virtus.model
5
+
6
+ attribute :time
7
+ attribute :results
8
+ attribute :documents, Models::Documents[Models::Document]
9
+
10
+ def initialize(search_data = {})
11
+ attributes = search_data.fetch(:attributes, {})
12
+ super attributes
13
+ end
14
+
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,26 @@
1
+ require 'virtus'
2
+
3
+ module SearchKit
4
+ module Models
5
+ class Subscriber
6
+ include Virtus.model
7
+
8
+ attribute :email, String
9
+ attribute :id, String
10
+ attribute :keys, SearchKit::Models::Keys[SearchKit::Models::Key]
11
+ attribute :uri, String
12
+
13
+ def initialize(subscriber_data = {})
14
+ attributes = subscriber_data.fetch(:attributes, {})
15
+ keys = subscriber_data.fetch(:relationships, {}).fetch(:keys, [])
16
+ uri = subscriber_data.fetch(:links, {}).fetch(:self, '')
17
+
18
+ super(attributes.merge(uri: uri, keys: keys))
19
+ end
20
+
21
+ def creator_tokens
22
+ keys.creator.tokens
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,30 @@
1
+ module SearchKit
2
+ # This file houses the polling loop of the Event service.
3
+ #
4
+ class Polling
5
+ autoload :Process, 'search_kit/polling/process'
6
+
7
+ def self.perform(channel, &block)
8
+ new(channel, &block).perform
9
+ end
10
+
11
+ attr_reader :block, :channel
12
+
13
+ def initialize(channel, &block)
14
+ @block = block
15
+ @channel = channel
16
+ end
17
+
18
+ def perform
19
+ loop do
20
+ process_queue
21
+ sleep 1
22
+ end
23
+ end
24
+
25
+ def process_queue
26
+ SearchKit::Polling::Process.perform(channel, &block)
27
+ end
28
+
29
+ end
30
+ end
@@ -0,0 +1,40 @@
1
+ module SearchKit
2
+ class Polling
3
+ # The logic of interacting with the event service to retrieve and process
4
+ # events is contained here.
5
+ #
6
+ class Process
7
+ def self.perform(channel, &block)
8
+ new(channel, &block).perform
9
+ end
10
+
11
+ attr_reader :block, :channel, :client
12
+
13
+ def initialize(channel, &block)
14
+ @block = block
15
+ @channel = channel
16
+ @client = SearchKit::Clients::Events.new
17
+ end
18
+
19
+ def perform
20
+ events.each do |event|
21
+ begin
22
+ block.call(event)
23
+ rescue
24
+ raise
25
+ else
26
+ client.complete(event.id)
27
+ end
28
+ end
29
+ end
30
+
31
+ private
32
+
33
+ def events
34
+ response = client.pending(channel)
35
+ response.fetch(:data, []).map { |raw| OpenStruct.new(raw) }
36
+ end
37
+ end
38
+
39
+ end
40
+ end
@@ -0,0 +1,12 @@
1
+ require 'thor'
2
+
3
+ class Thor
4
+ def self.document(task)
5
+ usage = I18n.t("cli.#{namespace}.#{task}.command")
6
+ summary = I18n.t("cli.#{namespace}.#{task}.summary")
7
+ detail = I18n.t("cli.#{namespace}.#{task}.detail")
8
+
9
+ desc(usage, summary)
10
+ long_desc(detail)
11
+ end
12
+ end
@@ -12,7 +12,7 @@ module SearchKit
12
12
  module VERSION
13
13
  MAJOR = 0
14
14
  MINOR = 0
15
- TINY = 2
15
+ TINY = 3
16
16
  PRE = nil
17
17
 
18
18
  STRING = [ MAJOR, MINOR, TINY, PRE ].compact.join(".")
@@ -29,7 +29,9 @@ Gem::Specification.new do |spec|
29
29
  spec.add_dependency "faraday", "~> 0.9"
30
30
  spec.add_dependency "thor", "~> 0.19"
31
31
  spec.add_dependency "user_config", "~> 0.0"
32
+ spec.add_dependency "highline", "~> 1.7"
32
33
  spec.add_dependency "i18n", "~> 0.7"
34
+ spec.add_dependency "virtus", "~> 1.0"
33
35
 
34
36
  spec.add_development_dependency "bundler", "~> 1.8"
35
37
  spec.add_development_dependency "pry", "~> 0.10"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: search-kit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joseph McCormick
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-11-18 00:00:00.000000000 Z
11
+ date: 2015-11-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ansi
@@ -66,6 +66,20 @@ dependencies:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: highline
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.7'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.7'
69
83
  - !ruby/object:Gem::Dependency
70
84
  name: i18n
71
85
  requirement: !ruby/object:Gem::Requirement
@@ -80,6 +94,20 @@ dependencies:
80
94
  - - "~>"
81
95
  - !ruby/object:Gem::Version
82
96
  version: '0.7'
97
+ - !ruby/object:Gem::Dependency
98
+ name: virtus
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '1.0'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '1.0'
83
111
  - !ruby/object:Gem::Dependency
84
112
  name: bundler
85
113
  requirement: !ruby/object:Gem::Requirement
@@ -200,27 +228,37 @@ files:
200
228
  - config/locales/en.yml
201
229
  - lib/search_kit.rb
202
230
  - lib/search_kit/cli.rb
231
+ - lib/search_kit/cli/documents.rb
232
+ - lib/search_kit/cli/events.rb
233
+ - lib/search_kit/cli/indices.rb
234
+ - lib/search_kit/cli/search.rb
235
+ - lib/search_kit/cli/subscribers.rb
236
+ - lib/search_kit/clients.rb
237
+ - lib/search_kit/clients/documents.rb
238
+ - lib/search_kit/clients/events.rb
239
+ - lib/search_kit/clients/indices.rb
240
+ - lib/search_kit/clients/keys.rb
241
+ - lib/search_kit/clients/populate.rb
242
+ - lib/search_kit/clients/scaffold.rb
243
+ - lib/search_kit/clients/search.rb
244
+ - lib/search_kit/clients/subscribers.rb
203
245
  - lib/search_kit/configuration.rb
204
- - lib/search_kit/documents.rb
205
- - lib/search_kit/documents/cli.rb
206
246
  - lib/search_kit/errors.rb
207
- - lib/search_kit/events.rb
208
- - lib/search_kit/events/cli.rb
209
- - lib/search_kit/events/cli/complete.rb
210
- - lib/search_kit/events/cli/list.rb
211
- - lib/search_kit/events/cli/pending.rb
212
- - lib/search_kit/events/cli/publish.rb
213
- - lib/search_kit/events/cli/status.rb
214
- - lib/search_kit/events/poll.rb
215
- - lib/search_kit/events/poll/process.rb
216
- - lib/search_kit/events/publish.rb
217
- - lib/search_kit/indices.rb
218
- - lib/search_kit/indices/cli.rb
219
247
  - lib/search_kit/logger.rb
220
- - lib/search_kit/messaging.rb
221
- - lib/search_kit/search.rb
222
- - lib/search_kit/search/cli.rb
223
- - lib/search_kit/search/cli/actions.rb
248
+ - lib/search_kit/messages.rb
249
+ - lib/search_kit/messages/messaging.rb
250
+ - lib/search_kit/models.rb
251
+ - lib/search_kit/models/document.rb
252
+ - lib/search_kit/models/documents.rb
253
+ - lib/search_kit/models/event.rb
254
+ - lib/search_kit/models/events.rb
255
+ - lib/search_kit/models/key.rb
256
+ - lib/search_kit/models/keys.rb
257
+ - lib/search_kit/models/search.rb
258
+ - lib/search_kit/models/subscriber.rb
259
+ - lib/search_kit/polling.rb
260
+ - lib/search_kit/polling/process.rb
261
+ - lib/search_kit/thor.rb
224
262
  - lib/search_kit/version.rb
225
263
  - scripts/console
226
264
  - search-kit.gemspec
@@ -1,59 +0,0 @@
1
- require 'faraday'
2
- require 'json'
3
- require 'uri'
4
-
5
- module SearchKit
6
- class Documents
7
- autoload :CLI, 'search_kit/documents/cli'
8
-
9
- attr_reader :connection
10
-
11
- def initialize
12
- uri = [SearchKit.config.app_uri, "documents"].join("/")
13
- @connection = Faraday.new(uri)
14
- end
15
-
16
- def create(slug, options)
17
- document = { data: { type: "documents", attributes: options } }
18
- response = connection.post(slug, document)
19
- body = JSON.parse(response.body, symbolize_names: true)
20
-
21
- fail Errors::BadRequest if response.status == 400
22
- fail Errors::IndexNotFound if response.status == 404
23
- fail Errors::Unprocessable if response.status == 422
24
-
25
- body
26
- end
27
-
28
- def show(slug, id)
29
- response = connection.get("#{slug}/#{id}")
30
- body = JSON.parse(response.body, symbolize_names: true)
31
-
32
- fail Errors::IndexNotFound if response.status == 404
33
-
34
- body
35
- end
36
-
37
- def update(slug, id, options)
38
- document = { data: { type: "documents", id: id, attributes: options } }
39
- response = connection.patch("#{slug}/#{id}", document)
40
- body = JSON.parse(response.body, symbolize_names: true)
41
-
42
- fail Errors::BadRequest if response.status == 400
43
- fail Errors::IndexNotFound if response.status == 404
44
- fail Errors::Unprocessable if response.status == 422
45
-
46
- body
47
- end
48
-
49
- def delete(slug, id)
50
- response = connection.delete("#{slug}/#{id}")
51
- body = JSON.parse(response.body, symbolize_names: true)
52
-
53
- fail Errors::IndexNotFound if response.status == 404
54
-
55
- body
56
- end
57
-
58
- end
59
- end
@@ -1,70 +0,0 @@
1
- require 'thor'
2
-
3
- module SearchKit
4
- class Documents
5
- class CLI < Thor
6
- include Messaging
7
-
8
- namespace :documents
9
-
10
- desc "show SLUG ID", "View a document"
11
- def show(slug, id)
12
- response = client.show(slug, id)
13
- info response.to_json
14
- rescue Errors::IndexNotFound
15
- warning "No index for that slug found (could also be missing doc)"
16
- rescue Faraday::ConnectionFailed
17
- warning "No running service found"
18
- end
19
-
20
- desc "create SLUG DOCUMENT", "Create a document with a json string"
21
- def create(slug, document)
22
- document = JSON.parse(document, symbolize_names: true)
23
- response = client.create(slug, document)
24
- info response.to_json
25
- rescue JSON::ParserError
26
- warning "Document must be given in the form of a JSON string"
27
- rescue Errors::BadRequest
28
- warning "Bad request given"
29
- rescue Errors::Unprocessable
30
- warning "Options given unprocessable"
31
- rescue Faraday::ConnectionFailed
32
- warning "No running service found"
33
- end
34
-
35
- desc "update SLUG ID DOCUMENT", "Update a document with a json string"
36
- def update(slug, id, document)
37
- document = JSON.parse(document, symbolize_names: true)
38
- response = client.update(slug, id, document)
39
- info response.to_json
40
- rescue JSON::ParserError
41
- warning "Document must be given in the form of a JSON string"
42
- rescue Errors::BadRequest
43
- warning "Bad request given"
44
- rescue Errors::IndexNotFound
45
- warning "Unable to find either the given index or document"
46
- rescue Errors::Unprocessable
47
- warning "Options given unprocessable"
48
- rescue Faraday::ConnectionFailed
49
- warning "No running service found"
50
- end
51
-
52
- desc "delete SLUG ID", "Delete a document"
53
- def delete(slug, id)
54
- response = client.delete(slug, id)
55
- info response.to_json
56
- rescue Errors::IndexNotFound
57
- warning "Unable to find either the given index or document"
58
- rescue Faraday::ConnectionFailed
59
- warning "No running service found"
60
- end
61
-
62
- private
63
-
64
- def client
65
- @client ||= Documents.new
66
- end
67
-
68
- end
69
- end
70
- end
@@ -1,59 +0,0 @@
1
- require 'faraday'
2
- require 'json'
3
- require 'uri'
4
-
5
- module SearchKit
6
- class Events
7
- autoload :CLI, 'search_kit/events/cli'
8
- autoload :Publish, 'search_kit/events/publish'
9
- autoload :Poll, 'search_kit/events/poll'
10
-
11
- attr_reader :connection
12
-
13
- def initialize
14
- uri = [SearchKit.config.app_uri, "events"].join("/")
15
- @connection = Faraday.new(uri)
16
- end
17
-
18
- def complete(id)
19
- response = connection.delete(id)
20
- body = JSON.parse(response.body, symbolize_names: true)
21
-
22
- fail Errors::EventNotFound if response.status == 404
23
-
24
- body
25
- end
26
-
27
- def index
28
- response = connection.get
29
-
30
- JSON.parse(response.body, symbolize_names: true)
31
- end
32
-
33
- def show(id)
34
- response = connection.get(id)
35
- body = JSON.parse(response.body, symbolize_names: true)
36
-
37
- fail Errors::EventNotFound if response.status == 404
38
-
39
- body
40
- end
41
-
42
- def pending(channel)
43
- response = connection.get('', "filter[channel]" => channel)
44
-
45
- JSON.parse(response.body, symbolize_names: true)
46
- end
47
-
48
- def publish(channel, payload)
49
- action = Publish.new(
50
- channel: channel,
51
- connection: connection,
52
- payload: payload
53
- )
54
-
55
- action.perform
56
- end
57
-
58
- end
59
- end