Class: SearchKit::Events

Inherits:
Object
  • Object
show all
Defined in:
lib/search_kit/events.rb,
lib/search_kit/events/cli.rb,
lib/search_kit/events/poll.rb,
lib/search_kit/events/publish.rb,
lib/search_kit/events/cli/list.rb,
lib/search_kit/events/cli/status.rb,
lib/search_kit/events/cli/pending.rb,
lib/search_kit/events/cli/publish.rb,
lib/search_kit/events/cli/complete.rb,
lib/search_kit/events/poll/process.rb

Defined Under Namespace

Classes: CLI, Poll, Publish

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeEvents

Returns a new instance of Events.



13
14
15
16
# File 'lib/search_kit/events.rb', line 13

def initialize
  uri = [SearchKit.config.app_uri, "events"].join("/")
  @connection = Faraday.new(uri)
end

Instance Attribute Details

#connectionObject (readonly)

Returns the value of attribute connection.



11
12
13
# File 'lib/search_kit/events.rb', line 11

def connection
  @connection
end

Instance Method Details

#complete(id) ⇒ Object



18
19
20
21
22
23
24
25
# File 'lib/search_kit/events.rb', line 18

def complete(id)
  response = connection.delete(id)
  body     = JSON.parse(response.body, symbolize_names: true)

  fail Errors::EventNotFound if response.status == 404

  body
end

#indexObject



27
28
29
30
31
# File 'lib/search_kit/events.rb', line 27

def index
  response = connection.get

  JSON.parse(response.body, symbolize_names: true)
end

#pending(channel) ⇒ Object



42
43
44
45
46
# File 'lib/search_kit/events.rb', line 42

def pending(channel)
  response = connection.get('', "filter[channel]" => channel)

  JSON.parse(response.body, symbolize_names: true)
end

#publish(channel, payload) ⇒ Object



48
49
50
51
52
53
54
55
56
# File 'lib/search_kit/events.rb', line 48

def publish(channel, payload)
  action = Publish.new(
    channel:    channel,
    connection: connection,
    payload:    payload
  )

  action.perform
end

#show(id) ⇒ Object



33
34
35
36
37
38
39
40
# File 'lib/search_kit/events.rb', line 33

def show(id)
  response = connection.get(id)
  body     = JSON.parse(response.body, symbolize_names: true)

  fail Errors::EventNotFound if response.status == 404

  body
end