Class: TeBot::Court

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

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Class Attribute Details

.commandsObject (readonly)

Returns the value of attribute commands.



9
10
11
# File 'lib/te_bot/court.rb', line 9

def commands
  @commands
end

.wireObject (readonly)

Returns the value of attribute wire.



9
10
11
# File 'lib/te_bot/court.rb', line 9

def wire
  @wire
end

Class Method Details

.access_token(token) ⇒ Object



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

def access_token(token)
  @wire = ::TeBot::Wire.new(token)
end

.command(text, &block) ⇒ Object



23
24
25
26
# File 'lib/te_bot/court.rb', line 23

def command(text, &block)
  @commands ||= {}
  @commands[text] = block
end

.default_action(&block) ⇒ Object



19
20
21
# File 'lib/te_bot/court.rb', line 19

def default_action(&block)
  @default_action ||= block
end

.default_command(&block) ⇒ Object



15
16
17
# File 'lib/te_bot/court.rb', line 15

def default_command(&block)
  @default_command ||= block
end

Instance Method Details

#call(env) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/te_bot/court.rb', line 36

def call(env)
  json_only(env) do |body|
    response = handle_request(body)

    if response.is_a?(Array)
      status, headers, body = response
      [status, headers, body]
    else
      [200, {"Content-Type" => "application/json"}, [JSON.generate({"message" => "success"})]]
    end
  end
end