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/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

Defined Under Namespace

Classes: CLI, Publish

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeEvents

Returns a new instance of Events.



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

def initialize
  @connection = SearchKit::Client.connection
end

Instance Attribute Details

#connectionObject (readonly)

Returns the value of attribute connection.



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

def connection
  @connection
end

Instance Method Details

#complete(id) ⇒ Object



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

def complete(id)
  response = connection.delete("/api/events/#{id}")
  body     = JSON.parse(response.body, symbolize_names: true)

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

  body
end

#indexObject



25
26
27
28
29
# File 'lib/search_kit/events.rb', line 25

def index
  response = connection.get('/api/events')

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

#pending(channel) ⇒ Object



40
41
42
43
44
# File 'lib/search_kit/events.rb', line 40

def pending(channel)
  response = connection.get("/api/events?filter[channel]=#{channel}")

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

#publish(channel, payload) ⇒ Object



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

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

  action.perform
end

#show(id) ⇒ Object



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

def show(id)
  response = connection.get("/api/events/#{id}")
  body     = JSON.parse(response.body, symbolize_names: true)

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

  body
end