Class: CommandTower::Messaging::Endpoints::Revoke

Inherits:
Object
  • Object
show all
Defined in:
app/services/command_tower/messaging/endpoints/revoke.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(owner_user_id:, endpoint_id:) ⇒ Revoke

Returns a new instance of Revoke.



11
12
13
14
# File 'app/services/command_tower/messaging/endpoints/revoke.rb', line 11

def initialize(owner_user_id:, endpoint_id:)
  @owner_user_id = owner_user_id
  @endpoint_id = endpoint_id
end

Class Method Details

.call(owner_user_id:, endpoint_id:) ⇒ Object



7
8
9
# File 'app/services/command_tower/messaging/endpoints/revoke.rb', line 7

def self.call(owner_user_id:, endpoint_id:)
  new(owner_user_id:, endpoint_id:).call
end

Instance Method Details

#callObject

Raises:



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'app/services/command_tower/messaging/endpoints/revoke.rb', line 16

def call
  record = Endpoint.for_owner(@owner_user_id).find_by(id: @endpoint_id)
  raise NotFoundError, "endpoint not found" if record.nil?

  ChannelGate.assert_record_supported!(record)

  case record.lifecycle_state
  when "revoked", "retired"
    return SafeView.from_record(record)
  when "invalid"
    Lifecycle.apply!(record, to: "retired")
    record.save!
    return SafeView.from_record(record)
  when "active"
    Lifecycle.apply!(record, to: "revoked")
    record.save!
    SafeView.from_record(record)
  else
    raise InvalidTransitionError, "cannot revoke from #{record.lifecycle_state.inspect}"
  end
end