Module: Hope::Server::Helpers

Defined in:
lib/hope/server.rb

Instance Method Summary collapse

Instance Method Details

#bodyObject

Request…



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

def body
  @body ||= JSON.parse request.body.read rescue {}
end

#engineObject



15
16
17
18
# File 'lib/hope/server.rb', line 15

def engine
  engine_id = params[:engine_id] || params[:id]
  Hope::Engine.get(engine_id) or not_found
end

#error_with(message, code = 400) ⇒ Object



27
28
29
# File 'lib/hope/server.rb', line 27

def error_with message, code=400
  respond_with({ :error => message.to_s }, code)
end

#respond_with(d, code = 200) ⇒ Object

Response…



21
22
23
24
25
# File 'lib/hope/server.rb', line 21

def respond_with d, code=200
  content_type :json
  status code
  d.to_json
end

#statementObject

Getters…



10
11
12
13
# File 'lib/hope/server.rb', line 10

def statement
  statement_id = params[:statement_id] || params[:id]
  engine.statement(statement_id) or not_found
end