Class: TeBot::Court

Inherits:
Object
  • Object
show all
Includes:
Cable
Defined in:
lib/te_bot/court.rb

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Cable

#chat_id, #reply

Constructor Details

#initializeCourt

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

.commandsObject (readonly)

Returns the value of attribute commands.



11
12
13
# File 'lib/te_bot/court.rb', line 11

def commands
  @commands
end

.wireObject (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

#messageObject (readonly)

Returns the value of attribute message.



48
49
50
# File 'lib/te_bot/court.rb', line 48

def message
  @message
end

#paramsObject (readonly)

Returns the value of attribute params.



48
49
50
# File 'lib/te_bot/court.rb', line 48

def params
  @params
end

#wireObject (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 message_handlers(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