Class: TeBot::Court
Class Attribute Summary collapse
-
.commands ⇒ Object
readonly
Returns the value of attribute commands.
-
.wire ⇒ Object
readonly
Returns the value of attribute wire.
Instance Attribute Summary collapse
-
#message ⇒ Object
readonly
Returns the value of attribute message.
-
#params ⇒ Object
readonly
Returns the value of attribute params.
-
#wire ⇒ Object
readonly
Returns the value of attribute wire.
Class Method Summary collapse
- .access_token(token) ⇒ Object
- .command(text, &block) ⇒ Object
- .default_action(&block) ⇒ Object
- .default_command(&block) ⇒ Object
- .message_handlers(handler) ⇒ Object
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize ⇒ Court
constructor
A new instance of Court.
Methods included from Cable
Constructor Details
#initialize ⇒ Court
Returns a new instance of Court.
50 51 52 53 54 55 |
# File 'lib/te_bot/court.rb', line 50 def initialize @params = {} @message = nil @command = nil @wire = self.class.wire end |
Class Attribute Details
.commands ⇒ Object (readonly)
Returns the value of attribute commands.
11 12 13 |
# File 'lib/te_bot/court.rb', line 11 def commands @commands end |
.wire ⇒ Object (readonly)
Returns the value of attribute wire.
11 12 13 |
# File 'lib/te_bot/court.rb', line 11 def wire @wire end |
Instance Attribute Details
#message ⇒ Object (readonly)
Returns the value of attribute message.
48 49 50 |
# File 'lib/te_bot/court.rb', line 48 def @message end |
#params ⇒ Object (readonly)
Returns the value of attribute params.
48 49 50 |
# File 'lib/te_bot/court.rb', line 48 def params @params end |
#wire ⇒ Object (readonly)
Returns the value of attribute wire.
48 49 50 |
# File 'lib/te_bot/court.rb', line 48 def wire @wire end |
Class Method Details
.access_token(token) ⇒ Object
13 14 15 |
# File 'lib/te_bot/court.rb', line 13 def access_token(token) @wire = ::TeBot::Wire.new(token) end |
.command(text, &block) ⇒ Object
25 26 27 28 |
# File 'lib/te_bot/court.rb', line 25 def command(text, &block) @commands ||= {} @commands[text] = block end |
.default_action(&block) ⇒ Object
21 22 23 |
# File 'lib/te_bot/court.rb', line 21 def default_action(&block) @default_action ||= block end |
.default_command(&block) ⇒ Object
17 18 19 |
# File 'lib/te_bot/court.rb', line 17 def default_command(&block) @default_command ||= block end |
.message_handlers(handler) ⇒ Object
42 43 44 45 |
# File 'lib/te_bot/court.rb', line 42 def (handler) @message_handlers ||= {} @message_handlers[handler] end |
Instance Method Details
#call(env) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/te_bot/court.rb', line 57 def call(env) json_only(env) do |body| response = handle_request(body) case response in [Integer, Hash, Array] => rack_response rack_response in Hash => json_body [200, {"Content-Type" => "application/json"}, [JSON.generate(json_body)]] else [200, {"Content-Type" => "application/json"}, [JSON.generate({"message" => "success"})]] end end end |