Class: Interfacets::Client::Channels::Api

Inherits:
Object
  • Object
show all
Includes:
Base
Defined in:
lib/interfacets/client/channels/api.rb

Defined Under Namespace

Classes: Builder

Instance Attribute Summary

Attributes included from Base

#id

Instance Method Summary collapse

Methods included from Base

#initialize, #type

Methods included from ActiveSupport::Concern

#append_features, #class_methods, extended, #included, #prepend_features, #prepended

Instance Method Details

#builder(stream = "default") ⇒ Object



70
71
72
# File 'lib/interfacets/client/channels/api.rb', line 70

def builder(stream = "default")
  @builder
end

#handle(event:, entity:, build_entity:) ⇒ Object



82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/interfacets/client/channels/api.rb', line 82

def handle(event:, entity:, build_entity:)
  facet_name = event.fetch("facet")
  id = event.dig(
    "payload",
    "payload",
    "attributes",
    "internal_entity_id"
  )

  entity = build_entity.(facet_name, id)

  Shared::Entities::Bus
    .new(entity:)
    .handle(
      event: event.fetch("payload")
    )
end

#prepare(entity) ⇒ Object



60
61
62
63
64
65
66
67
68
# File 'lib/interfacets/client/channels/api.rb', line 60

def prepare(entity)
  # must persist builder here
  # probably all channels need to persist their
  # builder. Because the bus calls "handle" before
  # the "prepare" call. Perhaps these should be
  # reversed?
  @builder ||= Builder.new
  @builder.entity = entity
end

#result ⇒ Object



74
75
76
77
78
79
80
# File 'lib/interfacets/client/channels/api.rb', line 74

def result
  {
    streams: {
      default: @builder.request,
    },
  }.tap { @builder.request = nil }
end