Module: Connfu

Includes:
ConnfuLogger
Defined in:
lib/connfu.rb,
lib/connfu/dsl.rb,
lib/connfu/events.rb,
lib/connfu/message.rb,
lib/connfu/version.rb,
lib/connfu/listener.rb,
lib/connfu/dispatcher.rb,
lib/connfu/provisioning.rb,
lib/connfu/cli/generator.rb,
lib/connfu/connfu_logger.rb,
lib/connfu/connfu_stream.rb,
lib/connfu/listener_channel.rb,
lib/connfu/provisioning/rss.rb,
lib/connfu/provisioning/base.rb,
lib/connfu/provisioning/dtmf.rb,
lib/connfu/provisioning/phone.rb,
lib/connfu/provisioning/voice.rb,
lib/connfu/provisioning/channel.rb,
lib/connfu/provisioning/twitter.rb,
lib/connfu/provisioning/whitelist.rb,
lib/connfu/connfu_message_formatter.rb,
lib/connfu/provisioning/application.rb,
lib/connfu/provisioning/whitelist_user.rb

Defined Under Namespace

Modules: Cli, ConnfuLogger, DSL, Provisioning Classes: ConnfuMessageFormatter, ConnfuStream, Dispatcher, Events, Listener, ListenerChannel, Message

Constant Summary collapse

CONNFU_ENDPOINT =

connFu provisioning API endpoint

"https://api.connfu.com/v1"
STREAM_ENDPOINT =

connFu HTTP streaming API endpoint

"https://stream.connfu.com/"
VERSION =

Current connFu DSL version

"0.1.3"

Class Attribute Summary collapse

Class Method Summary collapse

Methods included from ConnfuLogger

included, #logger

Class Attribute Details

.app_channelsObject (readonly)

Hash that keeps information about the connFu application channels



38
39
40
# File 'lib/connfu.rb', line 38

def app_channels
  @app_channels
end

.dispatcherObject

events dispatcher handler



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

def dispatcher
  @dispatcher
end

.listenerObject

events listener. It gets incoming events and forward them to the dispatcher layer



44
45
46
# File 'lib/connfu.rb', line 44

def listener
  @listener
end

.listener_channelsObject (readonly)

Hash that keeps information about the blocks to be executed when a new event is thrown



35
36
37
# File 'lib/connfu.rb', line 35

def listener_channels
  @listener_channels
end

.tokenObject (readonly)

The token defines the application that is using the connFu platform. Get a valid one using connfu portal



32
33
34
# File 'lib/connfu.rb', line 32

def token
  @token
end

Class Method Details

.application(token, endpoint = CONNFU_ENDPOINT, stream_endpoint = STREAM_ENDPOINT) ⇒ Object

This method is used to start a connFu application. Check the examples folder to find some code snippets.

Parameters

  • token valid application token got from connfu

  • endpoint connFu endpoint (valid provisioning API endpoint)

  • stream_endpoint connFu streaming endpoint



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/connfu.rb', line 55

def application(token, endpoint = CONNFU_ENDPOINT, stream_endpoint = STREAM_ENDPOINT)
  @token = token
  @listener_channels = {}
  @app_channels = []
  @endpoint = endpoint
  
  # set the log level to DEBUG if we are in debug mode
  $DEBUG and self.log_level=Logger::DEBUG

  logger.info("Starting application with token #{token}")

  # stop if invalid token
  stream = nil
  begin
    app_info = prov_client.get_info
  rescue RestClient::Unauthorized => ex
    logger.error("Invalid token provided")
    logger.error(ex.inspect)
    raise "Token is invalid"
  rescue Exception => ex
    logger.error("Error retrieving application info")
    logger.error(ex.inspect)
    raise "Token is invalid"
  end

  app_info.nil? and raise "Unable to find application data"

  app_stream = app_info.stream_name

  channels = prov_client.get_channels

  # Get the interesting channel data using the channel specific method to_hash
  @app_channels = channels.map { |channel| channel.to_hash }

  # Duplicate voice channels to sms channels
  sms = channels.select { |channel| channel.type.eql?("voice") }
  sms.map!{|channel| channel.type = "sms"; channel.to_hash}

  sms.each{|channel|
    @app_channels << channel
  }

  logger.debug "The application #{app_info.name} has these channels: #{@app_channels}"

  if block_given?

    # Load the listening channels defined using the DSL
    @listener_channels = DSL.run &Proc.new
    
    # This Queue will be used by the listener to put events
    # and by the dispatcher to handle them
    events = Connfu::Events.new
    
    # Start the dispatcher
    @dispatcher = Connfu::Dispatcher.new(events, self.listener_channels, self.app_channels)
    @dispatcher.start

    # Start the listener
    @listener = Connfu::Listener.new(events, app_stream, token, stream_endpoint)
    @listener.start
    
    @listener.join # wait for incoming events
    @dispatcher.join
  end

  # Return the module
  self
end