class Remindrr::Server
Public Class Methods
call(env)
click to toggle source
# File lib/remindrr/server.rb, line 5 def self.call(env) new.call(env) end
Public Instance Methods
call(env)
click to toggle source
# File lib/remindrr/server.rb, line 9 def call(env) @request = Rack::Request.new(env) @response = Rack::Response.new if @request.post? receive end @response.finish end
parse_request(body)
click to toggle source
# File lib/remindrr/server.rb, line 29 def parse_request(body) JSON.parse(body) rescue JSON::ParserError raise Remindrr::BadRequest, 'Error parsing request body format' end
receive()
click to toggle source
# File lib/remindrr/server.rb, line 20 def receive body = @request.body.read body = parse_request(body) Remindrr::Reminder.receive(body) rescue Remindrr::BadRequest => error respond_with_error(error) end
respond_with_error(error)
click to toggle source
# File lib/remindrr/server.rb, line 35 def respond_with_error(error) @response.status = 400 @response.write(error.message) @response.headers['Content-Type'.freeze] = 'text/plain'.freeze end