WOLAS Channel Service

The WOLAS Channel Service creates, stores and updates channel entries for each tenant. As the table structure of this service is a key-value store, each entry into a channel can have unique fields.

Installation

Add this line to your application's Gemfile:

gem 'wolas_channel'

And then execute:

$ bundle

Or install it yourself as:

$ gem install wolas_channel

Service Overview

Data Structure

The services implements only two tables for all tenants. These tables are in their own schema and are structured as follows.

Channels Table

id channel_id tenant_id type
1 78ceb188-0090-4877-af5b-c01f2a222966 1 Communication
2 f2531651-8a74-4c2c-b655-fd8281165cc0 2 Logs
3 1e972a64-1f88-4158-891a-3483c4fbe4d9 3 Chat Room

Data Table

id channel_id entity_id key value
1 78ceb188-0090-4877-af5b-c01f2a222966 06f26d46-73ef-4c0e-9d8a-013f8862a81a author John
2 78ceb188-0090-4877-af5b-c01f2a222966 06f26d46-73ef-4c0e-9d8a-013f8862a81a message This is a message for Banjo
3 78ceb188-0090-4877-af5b-c01f2a222966 1493437a-d12b-4832-a715-b475c8b4ddd1 author Banjo
4 78ceb188-0090-4877-af5b-c01f2a222966 1493437a-d12b-4832-a715-b475c8b4ddd1 message Thanks for the message John

Permissions

Each tenant only has access to channels to which they belong, as defined in the Channels table.

If a tenant tries to access a channel to which they do not belong, the service throws a PermissionFailure error.

Methods

Instantiate Gem

require 'wolas_channel'
channel = WolasChannel.new(tenant_id)

Add Channel

The add_channel method allows a tenant to create a new channel for their tenancy. This method creates a single entry in the channels table.

args = ('Name for new channel')

channel.add_channel('Activities')
=> { channel_created: '92f02e83-b7d4-460c-90bd-f2f2b0a32a6e', channel_type: 'Activities' }

Get Entity

The get_entity method allows a tenant to return an entry from a channel, as long as they are the owner of the channel to which the entry belongs.

args = ('entity_id')

channel.get_entity('06f26d46-73ef-4c0e-9d8a-013f8862a81a')
=>  { 
        author: 'John', 
        message: 'This is a message for Banjo',
        entity_id: '06f26d46-73ef-4c0e-9d8a-013f8862a81a',
        channel_id: '78ceb188-0090-4877-af5b-c01f2a222966',
        type: 'Communication'
    }

Get Channel

The get_channel method allows a tenant to return all entries from a channel, as long as they are the owner of the channel.

args = ('channel_id')

channel.get_channel('78ceb188-0090-4877-af5b-c01f2a222966')
=>  [
        { 
            author: 'John', 
            message: 'This is a message for Banjo',
            entity_id: '06f26d46-73ef-4c0e-9d8a-013f8862a81a',
            channel_id: '78ceb188-0090-4877-af5b-c01f2a222966',
            type: 'Communication'
        },
        { 
            author: 'Banjo', 
            message: 'Thanks for the message John',
            entity_id: '1493437a-d12b-4832-a715-b475c8b4ddd1',
            channel_id: '78ceb188-0090-4877-af5b-c01f2a222966',
            type: 'Communication'
        },
    ]

Insert Entity

The insert_entity method allows a tenant to the create a new entry against a channel, as long as they are the owner of the channel to which they are trying to post the entry.

args = ('channel_id', 'insert_object')

object = { hello: 'world' }
channel.insert_entity('78ceb188-0090-4877-af5b-c01f2a222966', object)
=>  
    { 
        entity_id: '06f26d46-73ef-4c0e-9d8a-013f8862a81a', 
        insert: 'SUCCESS'
    }

Update Entity

The update_entity method allows a tenant to the create update an entry in a channel, as long as they are the owner of the channel to which the entry belongs.

This method accepts a key and value for the entry to be updated. If the entry already has a matching key to that of the update request, the value of the key is updated in the table. If however the key does not already exist for the entry, it is created instead.

args = ('channel_id', 'object_to_insert')

# Existing entity
{ 
    author: 'John', 
    message: 'This is a message for Banjo',
    entity_id: '06f26d46-73ef-4c0e-9d8a-013f8862a81a',
    channel_id: '78ceb188-0090-4877-af5b-c01f2a222966',
    type: 'Communication'
}

# Updating an existing key
channel.update_entity('06f26d46-73ef-4c0e-9d8a-013f8862a81a', 'author', 'Sarah')
=>  { 
        author: 'Sarah', 
        message: 'This is a message for Banjo',
        entity_id: '06f26d46-73ef-4c0e-9d8a-013f8862a81a',
        channel_id: '78ceb188-0090-4877-af5b-c01f2a222966',
        type: 'Communication'
    }

# Adding a new key
channel.update_entity('06f26d46-73ef-4c0e-9d8a-013f8862a81a', 'field', 'oval')
=>  { 
        author: 'Sarah', 
        message: 'This is a message for Banjo',
        field: 'oval'
        entity_id: '06f26d46-73ef-4c0e-9d8a-013f8862a81a',
        channel_id: '78ceb188-0090-4877-af5b-c01f2a222966',
        type: 'Communication'
    }