Class: FDK::Context

Inherits:
Object
  • Object
show all
Defined in:
lib/fdk/context.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(event) ⇒ Context

Returns a new instance of Context.



31
32
33
# File 'lib/fdk/context.rb', line 31

def initialize(event)
  @event = event
end

Instance Attribute Details

#eventObject (readonly)



29
30
31
# File 'lib/fdk/context.rb', line 29

def event
  @event
end

Instance Method Details

#call_idObject



44
45
46
# File 'lib/fdk/context.rb', line 44

def call_id
  cloud_event? ? event['eventID'] : event['call_id']
end

#cloud_event?Boolean

If it’s a CNCF CloudEvent

Returns:

  • (Boolean)


36
37
38
# File 'lib/fdk/context.rb', line 36

def cloud_event?
  ENV['FN_FORMAT'] == "cloudevent"
end

#configObject



40
41
42
# File 'lib/fdk/context.rb', line 40

def config
  @config ||= Config.new
end

#content_typeObject



48
49
50
# File 'lib/fdk/context.rb', line 48

def content_type
  cloud_event? ? event['contentType'] : event['content_type']
end

#protocolObject



52
53
54
# File 'lib/fdk/context.rb', line 52

def protocol
  cloud_event? ? event['extensions']['protocol'] : event['protocol']
end