Class: BackchatClient::Channel

Inherits:
Object
  • Object
show all
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

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.

Parameters:

  • *api_key*

    application identifier

  • *endpoint*

    Backchat endpoint



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

Parameters:

  • uri

    valid Backchat URI, i.e. twitter://username

Returns:

  • response body



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

Parameters:

  • *name*

    valid channel URI

  • *force*

    delete even if it is being used by a stream

Returns:

  • true|false



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

#findObject

This method sends a GET request to retrieve all the user channels There is no way to retrieve a specific channel

Returns:

  • response body



41
42
43
# File 'lib/backchat_client/channel.rb', line 41

def find
  ActiveSupport::JSON.decode(get("index.json"))
end