Class: BackchatClient::Stream
- Inherits:
-
Object
- Object
- BackchatClient::Stream
- Includes:
- BackchatLogger, HttpClient
- Defined in:
- lib/backchat_client/stream.rb
Overview
A Backchat Stream allows to define a set of channels with filters
Constant Summary collapse
- URI_PATH =
http uri to handle streams
"streams"
Instance Method Summary collapse
-
#create(name, description, filters = []) ⇒ Object
This method POST a request to create a new stream on behalf of the authenticated application.
-
#destroy(name) ⇒ Object
Delete a defined stream.
-
#find(name) ⇒ Object
Retrieves a stream.
-
#initialize(api_key, endpoint) ⇒ Stream
constructor
A new instance of Stream.
- #update(slug, params) ⇒ Object
Methods included from BackchatLogger
#debug, #error, included, #logger
Methods included from HttpClient
#delete, #get, #post, #put, #response_handler
Constructor Details
#initialize(api_key, endpoint) ⇒ Stream
Returns a new instance of Stream.
19 20 21 22 |
# File 'lib/backchat_client/stream.rb', line 19 def initialize(api_key, endpoint) @api_key = api_key @endpoint = endpoint end |
Instance Method Details
#create(name, description, filters = []) ⇒ Object
This method POST a request to create a new stream on behalf of the authenticated application
31 32 33 34 35 36 37 38 39 |
# File 'lib/backchat_client/stream.rb', line 31 def create(name, description, filters = []) begin data = post("", {:name => name, :description => description, :channel_filters => filters}) ActiveSupport::JSON.decode(data) rescue Error::ClientError => ex logger.error ActiveSupport::JSON.decode(ex.response.body) raise ex end end |
#destroy(name) ⇒ Object
Delete a defined stream
61 62 63 64 65 66 67 68 69 |
# File 'lib/backchat_client/stream.rb', line 61 def destroy(name) begin delete(name) true rescue Error::ClientError => ex logger.error ex.errors false end end |
#find(name) ⇒ Object
Retrieves a stream
44 45 46 47 48 49 50 51 52 |
# File 'lib/backchat_client/stream.rb', line 44 def find(name) name.nil? and name = "index.json" begin ActiveSupport::JSON.decode(get(name)) rescue Error::ClientError => ex logger.error(ex.errors) return nil end end |
#update(slug, params) ⇒ Object
54 55 56 |
# File 'lib/backchat_client/stream.rb', line 54 def update(slug, params) ActiveSupport::JSON.decode(put(slug, params)) end |