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
@@ -1,52 +0,0 @@
1
- require 'thor'
2
- require 'ansi'
3
-
4
- module SearchKit
5
- class Events
6
- class CLI < Thor
7
- autoload :Complete, 'search_kit/events/cli/complete'
8
- autoload :List, 'search_kit/events/cli/list'
9
- autoload :Pending, 'search_kit/events/cli/pending'
10
- autoload :Publish, 'search_kit/events/cli/publish'
11
- autoload :Status, 'search_kit/events/cli/status'
12
-
13
- include Messaging
14
-
15
- namespace :events
16
-
17
- desc "complete ID", "Complete event for a given ID"
18
- def complete(id)
19
- Complete.new(client, id).perform
20
- end
21
-
22
- desc "pending", "Get all pending events, --channel to filter by channel"
23
- option :channel, aliases: ['-c']
24
- def pending
25
- channel = options.fetch('channel', nil)
26
- if channel
27
- Pending.new(client, channel).perform
28
- else
29
- List.new(client).perform
30
- end
31
- end
32
-
33
- desc "publish CHANNEL", "Publish an event to CHANNEL"
34
- option :payload, aliases: ['-p'], type: :hash, required: true
35
- def publish(channel)
36
- Publish.new(client, channel, options).perform
37
- end
38
-
39
- desc "status ID", "Check status of a specific event ID"
40
- def status(id)
41
- Status.new(client, id).perform
42
- end
43
-
44
- private
45
-
46
- def client
47
- @client ||= Events.new
48
- end
49
-
50
- end
51
- end
52
- end
@@ -1,34 +0,0 @@
1
- require 'thor'
2
-
3
- module SearchKit
4
- class Events
5
- class CLI < Thor
6
- # An extraction of the CLI command, "complete".
7
- #
8
- class Complete
9
- include Messaging
10
-
11
- attr_reader :client, :id
12
-
13
- def initialize(client, id)
14
- @client = client
15
- @id = id
16
- end
17
-
18
- def perform
19
- client.complete(id)
20
-
21
- info "Event #{id} completed"
22
- rescue Errors::EventNotFound
23
- warning "No event found for #{id}"
24
- rescue Faraday::ConnectionFailed
25
- warning "Remote events service not found"
26
- rescue JSON::ParserError => error
27
- warning "Response unreadable: #{error}"
28
- error.backtrace.each(&method(:warning))
29
- end
30
-
31
- end
32
- end
33
- end
34
- end
@@ -1,48 +0,0 @@
1
- require 'thor'
2
-
3
- module SearchKit
4
- class Events
5
- class CLI < Thor
6
- # An extraction of the CLI command, "pending". When the pending comand
7
- # is not given any parameters, it looks for all pending events despite
8
- # of channel - or in other words, the index of events.
9
- #
10
- class List
11
- include Messaging
12
-
13
- attr_reader :client
14
-
15
- def initialize(client)
16
- @client = client
17
- end
18
-
19
- def perform
20
- report_events
21
- rescue Faraday::ConnectionFailed
22
- warning "Remote events service not found"
23
- rescue JSON::ParserError => error
24
- warning "Response unreadable: #{error}"
25
- error.backtrace.each(&method(:warning))
26
- end
27
-
28
- private
29
-
30
- def report_events
31
- if events.any?
32
- info "Pending events:"
33
- events.each { |event| info(event.to_json) }
34
- else
35
- info "No pending events found"
36
- end
37
- end
38
-
39
- def events
40
- return @events if @events
41
- response = client.index
42
- @events = response.fetch(:data, [])
43
- end
44
-
45
- end
46
- end
47
- end
48
- end
@@ -1,48 +0,0 @@
1
- require 'thor'
2
-
3
- module SearchKit
4
- class Events
5
- class CLI < Thor
6
- # An extraction of the CLI command, "list", when given the `channel`
7
- # option.
8
- #
9
- class Pending
10
- include Messaging
11
-
12
- attr_reader :client, :channel
13
-
14
- def initialize(client, channel = nil)
15
- @client = client
16
- @channel = channel
17
- end
18
-
19
- def perform
20
- report_events
21
- rescue Faraday::ConnectionFailed
22
- warning "Remote events service not found"
23
- rescue JSON::ParserError => error
24
- warning "Response unreadable: #{error}"
25
- error.backtrace.each(&method(:warning))
26
- end
27
-
28
- private
29
-
30
- def report_events
31
- if events.any?
32
- info "Pending events for channel `#{channel}`:"
33
- events.each { |event| info(event.to_json) }
34
- else
35
- info "No pending events found for channel `#{channel}`"
36
- end
37
- end
38
-
39
- def events
40
- return @events if @events
41
- response = client.pending(channel)
42
- @events = response.fetch(:data, [])
43
- end
44
-
45
- end
46
- end
47
- end
48
- end
@@ -1,42 +0,0 @@
1
- require 'thor'
2
-
3
- module SearchKit
4
- class Events
5
- class CLI < Thor
6
- # An extraction of the CLI command, "publish".
7
- #
8
- class Publish
9
- include Messaging
10
-
11
- attr_reader :client, :channel, :payload
12
-
13
- def initialize(client, channel, options = {})
14
- @client = client
15
- @channel = channel
16
- @payload = options.fetch('payload', {})
17
- end
18
-
19
- def perform
20
- info "Event published, status @ #{status_uri}"
21
- rescue Faraday::ConnectionFailed
22
- warning "Remote events service not found"
23
- rescue Errors::PublicationFailed => error
24
- warning "Publication failed: #{error}"
25
- rescue JSON::ParserError => error
26
- warning "Response unreadable: #{error}"
27
- error.backtrace.each(&method(:warning))
28
- end
29
-
30
- private
31
-
32
- def status_uri
33
- return @status_uri if @status_uri
34
- response = client.publish(channel, payload)
35
- links = response.fetch(:data, {}).fetch(:links, {})
36
- @status_uri = links.fetch(:self, '')
37
- end
38
-
39
- end
40
- end
41
- end
42
- end
@@ -1,43 +0,0 @@
1
- require 'thor'
2
-
3
- module SearchKit
4
- class Events
5
- class CLI < Thor
6
- # An extraction of the CLI command, "all".
7
- #
8
- class Status
9
- include Messaging
10
-
11
- attr_reader :client, :id
12
-
13
- def initialize(client, id)
14
- @client = client
15
- @id = id
16
- end
17
-
18
- def perform
19
- info "Event #{id} status: #{status}"
20
- rescue Errors::EventNotFound
21
- warning "No event found for #{id}"
22
- rescue Faraday::ConnectionFailed
23
- warning "Remote events service not found"
24
- rescue JSON::ParserError => error
25
- warning "Response unreadable: #{error}"
26
- error.backtrace.each(&method(:warning))
27
- end
28
-
29
- private
30
-
31
- def status
32
- response = client.show(id)
33
-
34
- response
35
- .fetch(:data, {})
36
- .fetch(:attributes, {})
37
- .fetch(:state, '')
38
- end
39
-
40
- end
41
- end
42
- end
43
- end
@@ -1,32 +0,0 @@
1
- module SearchKit
2
- class Events
3
- # This file houses the polling loop of the Event service.
4
- #
5
- class Poll
6
- autoload :Process, 'search_kit/events/poll/process'
7
-
8
- def self.perform(channel, &block)
9
- new(channel, &block).perform
10
- end
11
-
12
- attr_reader :block, :channel
13
-
14
- def initialize(channel, &block)
15
- @block = block
16
- @channel = channel
17
- end
18
-
19
- def perform
20
- loop do
21
- process_queue
22
- sleep 1
23
- end
24
- end
25
-
26
- def process_queue
27
- SearchKit::Events::Poll::Process.perform(channel, &block)
28
- end
29
-
30
- end
31
- end
32
- end
@@ -1,42 +0,0 @@
1
- module SearchKit
2
- class Events
3
- class Poll
4
- # The logic of interacting with the event service to retrieve and process
5
- # events is contained here.
6
- #
7
- class Process
8
- def self.perform(channel, &block)
9
- new(channel, &block).perform
10
- end
11
-
12
- attr_reader :block, :channel, :client
13
-
14
- def initialize(channel, &block)
15
- @block = block
16
- @channel = channel
17
- @client = SearchKit::Events.new
18
- end
19
-
20
- def perform
21
- events.each do |event|
22
- begin
23
- block.call(event)
24
- rescue
25
- raise
26
- else
27
- client.complete(event.id)
28
- end
29
- end
30
- end
31
-
32
- private
33
-
34
- def events
35
- response = client.pending(channel)
36
- response.fetch(:data, []).map { |raw| OpenStruct.new(raw) }
37
- end
38
- end
39
-
40
- end
41
- end
42
- end
@@ -1,48 +0,0 @@
1
- module SearchKit
2
- class Events
3
- # An extraction of the publication client action, which contains a certain
4
- # amount of logic in handling success/failure, parameter building and
5
- # API interaction.
6
- #
7
- class Publish
8
- SUCCESS = 202
9
-
10
- attr_reader :channel, :connection, :payload
11
-
12
- def initialize(options = {})
13
- @connection = options.fetch(:connection)
14
- @channel = options.fetch(:channel)
15
- @payload = options.fetch(:payload)
16
- end
17
-
18
- def perform
19
- body = JSON.parse(response.body, symbolize_names: true)
20
-
21
- if success?
22
- body
23
- else
24
- fail Errors::PublicationFailed, body.fetch(:error)
25
- end
26
- end
27
-
28
- private
29
-
30
- def success?
31
- response.status == SUCCESS
32
- end
33
-
34
- def response
35
- @response ||= connection.post("/api/events", params)
36
- end
37
-
38
- def params
39
- {
40
- type: 'events',
41
- data: { attributes: { channel: channel, payload: payload } }
42
- }
43
- end
44
-
45
- end
46
-
47
- end
48
- end
@@ -1,58 +0,0 @@
1
- require 'faraday'
2
- require 'json'
3
- require 'uri'
4
-
5
- module SearchKit
6
- class Indices
7
- autoload :CLI, 'search_kit/indices/cli'
8
-
9
- attr_reader :connection
10
-
11
- def initialize
12
- uri = [SearchKit.config.app_uri, "indices"].join("/")
13
- @connection = Faraday.new(uri)
14
- end
15
-
16
- def show(slug)
17
- response = connection.get(slug)
18
- body = JSON.parse(response.body, symbolize_names: true)
19
-
20
- fail Errors::IndexNotFound if response.status == 404
21
-
22
- body
23
- end
24
-
25
- def create(name)
26
- options = { data: { type: 'indices', attributes: { name: name } } }
27
- response = connection.post('/', options)
28
- body = JSON.parse(response.body, symbolize_names: true)
29
-
30
- fail Errors::Unprocessable if response.status == 422
31
- fail Errors::BadRequest if response.status == 400
32
-
33
- body
34
- end
35
-
36
- def update(slug, options)
37
- options = { data: { type: 'indices', attributes: options } }
38
- response = connection.patch(slug, options)
39
- body = JSON.parse(response.body, symbolize_names: true)
40
-
41
- fail Errors::BadRequest if response.status == 400
42
- fail Errors::IndexNotFound if response.status == 404
43
- fail Errors::Unprocessable if response.status == 422
44
-
45
- body
46
- end
47
-
48
- def delete(slug)
49
- response = connection.delete(slug)
50
- body = JSON.parse(response.body, symbolize_names: true)
51
-
52
- fail Errors::IndexNotFound if response.status == 404
53
-
54
- body
55
- end
56
-
57
- end
58
- end