Class: Codebot::Request

Inherits:
Object
  • Object
show all
Defined in:
lib/codebot/request.rb

Overview

A request which was received by the web server and can be delivered to the IRC client.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(integration, event, payload) ⇒ Request

Constructs a new request for delivery to the IRC client.

Parameters:

  • integration (Integration)

    the integration for which the request was made

  • event (Symbol)

    the event that triggered the webhook delivery

  • payload (String)

    a JSON string containing the request payload



25
26
27
28
29
# File 'lib/codebot/request.rb', line 25

def initialize(integration, event, payload)
  @integration = integration
  @event       = event
  @payload     = Payload.new payload
end

Instance Attribute Details

#eventSymbol (readonly)

Returns the event that triggered the webhook delivery.

Returns:

  • (Symbol)

    the event that triggered the webhook delivery



14
15
16
# File 'lib/codebot/request.rb', line 14

def event
  @event
end

#integrationIntegration (readonly)

Returns the integration to deliver this request to.

Returns:

  • (Integration)

    the integration to deliver this request to



11
12
13
# File 'lib/codebot/request.rb', line 11

def integration
  @integration
end

#payloadPayload (readonly)

Returns the parsed request payload.

Returns:

  • (Payload)

    the parsed request payload



17
18
19
# File 'lib/codebot/request.rb', line 17

def payload
  @payload
end

Instance Method Details

#each_network {|the, channels| ... } ⇒ Object

Invokes the given block for each network this request needs to be delivered to.

Yield Parameters:

  • the (Network)

    network

  • channels (Array<Channels>)

    that belong to the network and that a notification should be delivered to



37
38
39
40
41
# File 'lib/codebot/request.rb', line 37

def each_network
  integration.channels.group_by(&:network).each do |network, channels|
    yield network, channels
  end
end

#to_message_for(channel) ⇒ Message

Creates a message for a given channel from this request.

Parameters:

  • channel (Channel)

    the channel

Returns:

  • (Message)

    the created message



47
48
49
# File 'lib/codebot/request.rb', line 47

def to_message_for(channel)
  Message.new(channel, @event, @payload, @integration)
end