Class: Ribbon::Intercom::Service
- Inherits:
-
Object
- Object
- Ribbon::Intercom::Service
- Defined in:
- lib/ribbon/intercom/service.rb,
lib/ribbon/intercom/service/channel.rb,
lib/ribbon/intercom/service/channel/stores/store.rb,
lib/ribbon/intercom/service/channel/stores/mock_store.rb,
lib/ribbon/intercom/service/channel/stores/redis_store.rb
Defined Under Namespace
Classes: Channel, EmptyResponse
Instance Attribute Summary collapse
-
#channel ⇒ Object
readonly
Returns the value of attribute channel.
-
#env ⇒ Object
readonly
Returns the value of attribute env.
-
#request ⇒ Object
readonly
Class methods.
-
#request_packet ⇒ Object
readonly
Returns the value of attribute request_packet.
-
#subject ⇒ Object
readonly
Returns the value of attribute subject.
Class Method Summary collapse
- ._load_store ⇒ Object
-
.call(env) ⇒ Object
The call method is needed here because Rails checks to see if a mounted Rack app can respond_to?(:call).
- .instance ⇒ Object
- .method_missing(meth, *args, &block) ⇒ Object
- .mock ⇒ Object
- .store(store_name, params = {}) ⇒ Object
Instance Method Summary collapse
- #call(env) ⇒ Object
- #call!(env) ⇒ Object
-
#initialize(opts = {}) ⇒ Service
constructor
A new instance of Service.
- #lookup_channel(token) ⇒ Object
- #open_channel(params = {}) ⇒ Object
- #rotate_secret ⇒ Object
- #store ⇒ Object
-
#sufficient_permissions?(base, intercom_method) ⇒ Boolean
Check that the channel has sufficient permissions to call the method.
Constructor Details
#initialize(opts = {}) ⇒ Service
Returns a new instance of Service.
50 51 52 |
# File 'lib/ribbon/intercom/service.rb', line 50 def initialize(opts={}) @_opts = opts.dup end |
Instance Attribute Details
#channel ⇒ Object (readonly)
Returns the value of attribute channel.
45 46 47 |
# File 'lib/ribbon/intercom/service.rb', line 45 def channel @channel end |
#env ⇒ Object (readonly)
Returns the value of attribute env.
48 49 50 |
# File 'lib/ribbon/intercom/service.rb', line 48 def env @env end |
#request ⇒ Object (readonly)
Class methods
44 45 46 |
# File 'lib/ribbon/intercom/service.rb', line 44 def request @request end |
#request_packet ⇒ Object (readonly)
Returns the value of attribute request_packet.
47 48 49 |
# File 'lib/ribbon/intercom/service.rb', line 47 def request_packet @request_packet end |
#subject ⇒ Object (readonly)
Returns the value of attribute subject.
46 47 48 |
# File 'lib/ribbon/intercom/service.rb', line 46 def subject @subject end |
Class Method Details
._load_store ⇒ Object
36 37 38 39 40 41 |
# File 'lib/ribbon/intercom/service.rb', line 36 def _load_store raise "Store name missing" unless (store_name = @_store_name.to_s) store = Utils.classify(store_name) + "Store" Intercom::Service::Channel::Stores.const_get(store).new(@_store_params) end |
.call(env) ⇒ Object
The call method is needed here because Rails checks to see if a mounted Rack app can respond_to?(:call). Without it, the Service will not mount
28 29 30 |
# File 'lib/ribbon/intercom/service.rb', line 28 def call(env) instance.call(env) end |
.instance ⇒ Object
13 14 15 |
# File 'lib/ribbon/intercom/service.rb', line 13 def instance @instance ||= new(store: _load_store) end |
.method_missing(meth, *args, &block) ⇒ Object
32 33 34 |
# File 'lib/ribbon/intercom/service.rb', line 32 def method_missing(meth, *args, &block) instance.public_send(meth, *args, &block) end |
.mock ⇒ Object
17 18 19 |
# File 'lib/ribbon/intercom/service.rb', line 17 def mock Client::MockSDK.new(self) end |
.store(store_name, params = {}) ⇒ Object
21 22 23 24 |
# File 'lib/ribbon/intercom/service.rb', line 21 def store(store_name, params={}) @_store_name = store_name @_store_params = params end |
Instance Method Details
#call(env) ⇒ Object
84 85 86 |
# File 'lib/ribbon/intercom/service.rb', line 84 def call(env) dup.call!(env) end |
#call!(env) ⇒ Object
88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/ribbon/intercom/service.rb', line 88 def call!(env) @env = env response = catch(:response) { begin _process_request rescue Exception => error _respond_with_error!(error) end } response.finish end |
#lookup_channel(token) ⇒ Object
65 66 67 |
# File 'lib/ribbon/intercom/service.rb', line 65 def lookup_channel(token) store.lookup_channel(token) end |
#open_channel(params = {}) ⇒ Object
58 59 60 61 62 63 |
# File 'lib/ribbon/intercom/service.rb', line 58 def open_channel(params={}) # Accept either an array of permissions or a string store.open_channel(params).tap { |channel| channel.may(Utils.method_identifier(self, :rotate_secret)) } end |
#rotate_secret ⇒ Object
102 103 104 |
# File 'lib/ribbon/intercom/service.rb', line 102 def rotate_secret channel.rotate_secret! end |
#store ⇒ Object
54 55 56 |
# File 'lib/ribbon/intercom/service.rb', line 54 def store @store ||= @_opts[:store] or raise Errors::MissingStoreError end |
#sufficient_permissions?(base, intercom_method) ⇒ Boolean
Check that the channel has sufficient permissions to call the method.
The ‘send` method is forbidden because it breaks the encapsulation guaranteed by intercom (i.e., private methods can’t be called).
In addition to the permissions granted to the channel, all channels have implicit permission to call public methods on basic types.
77 78 79 80 81 82 |
# File 'lib/ribbon/intercom/service.rb', line 77 def (base, intercom_method) intercom_method != :send && ( Utils.basic_type?(base) || channel.may?(Utils.method_identifier(base, intercom_method)) ) end |