Class: BackchatClient::Channel
- Inherits:
-
Object
- Object
- BackchatClient::Channel
- Includes:
- BackchatLogger, HttpClient
- Defined in:
- lib/backchat_client/channel.rb
Overview
A Backchat Channel allows to define an external resource to fetch events using Backchat infrastructure
Constant Summary collapse
- URI_PATH =
http uri to handle channels
"channels"
Instance Method Summary collapse
-
#create(uri) ⇒ Object
This method POST a request to create a new channel on behalf of the authenticated application.
-
#destroy(name, force = false) ⇒ Object
Delete an application channel.
-
#find ⇒ Object
This method sends a GET request to retrieve all the user channels There is no way to retrieve a specific channel.
-
#initialize(api_key, endpoint) ⇒ Channel
constructor
A new instance of Channel.
Methods included from BackchatLogger
#debug, #error, included, #logger
Methods included from HttpClient
#delete, #get, #post, #put, #response_handler
Constructor Details
#initialize(api_key, endpoint) ⇒ Channel
Returns a new instance of Channel.
19 20 21 22 |
# File 'lib/backchat_client/channel.rb', line 19 def initialize(api_key, endpoint) @api_key = api_key @endpoint = endpoint end |
Instance Method Details
#create(uri) ⇒ Object
This method POST a request to create a new channel on behalf of the authenticated application
28 29 30 31 32 33 34 35 36 |
# File 'lib/backchat_client/channel.rb', line 28 def create(uri) begin data = post("index.json", {:channel => uri}) ActiveSupport::JSON.decode(data) rescue Error::ClientError => ex logger.error ex.errors raise ex end end |
#destroy(name, force = false) ⇒ Object
Delete an application channel
49 50 51 52 53 54 55 56 57 |
# File 'lib/backchat_client/channel.rb', line 49 def destroy(name, force = false) begin ActiveSupport::JSON.decode(delete("", {:channel => name, :force => force})) true rescue Error::ClientError => ex logger.error ex.errors false end end |
#find ⇒ Object
This method sends a GET request to retrieve all the user channels There is no way to retrieve a specific channel
41 42 43 |
# File 'lib/backchat_client/channel.rb', line 41 def find ActiveSupport::JSON.decode(get("index.json")) end |