Class: Ribbon::Intercom::Client::SDK::Adapters::MockAdapter

Inherits:
LocalAdapter show all
Defined in:
lib/ribbon/intercom/client/sdk/adapters/mock_adapter.rb

Instance Attribute Summary collapse

Attributes inherited from LocalAdapter

#channel_secret, #channel_token, #service

Instance Method Summary collapse

Methods inherited from LocalAdapter

#connected?, #send_packet!

Methods inherited from Adapter

#call, #connected?, #dup, #headers, #initialize, #send_packet, #send_packet!

Constructor Details

This class inherits a constructor from Ribbon::Intercom::Client::SDK::Adapters::Adapter

Instance Attribute Details

#storeObject (readonly)

Returns the value of attribute store.



4
5
6
# File 'lib/ribbon/intercom/client/sdk/adapters/mock_adapter.rb', line 4

def store
  @store
end

Instance Method Details

#connect(service) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/ribbon/intercom/client/sdk/adapters/mock_adapter.rb', line 6

def connect(service)
  if service.is_a?(Class) && service < Service
    service = service.new(store: Service::Channel::Stores::MockStore.new)
  end

  unless service.is_a?(Service)
    raise ArgumentError, "Expected a service, got: #{service.inspect}"
  end

  unless service.store.is_a?(Service::Channel::Stores::MockStore)
    raise ArgumentError, "Expected service to have a MockStore, got: #{service.store.inspect}"
  end

  super(service)
  @store = service.store
end

#with_channel(token, secret) ⇒ Object



31
32
33
34
35
36
37
# File 'lib/ribbon/intercom/client/sdk/adapters/mock_adapter.rb', line 31

def with_channel(token, secret)
  token_prv, secret_prv = self.channel_token, self.channel_secret
  self.channel_token, self.channel_secret = token, secret
  yield
ensure
  self.channel_token, self.channel_secret = token_prv, secret_prv
end

#with_permissions(*perms, &block) ⇒ Object



23
24
25
26
27
28
29
# File 'lib/ribbon/intercom/client/sdk/adapters/mock_adapter.rb', line 23

def with_permissions(*perms, &block)
  channel = store.open_channel(name: 'mock channel', may: perms)
  secret = channel.rotate_secret!
  with_channel(channel.token, secret, &block)
ensure
  channel.close
end