lib/alephant/broker/call_environment.rb in alephant-broker-0.1.0 vs lib/alephant/broker/call_environment.rb in alephant-broker-0.1.1
- old
+ new
@@ -1,5 +1,7 @@
+require 'json'
+
module Alephant
module Broker
class CallEnvironment
include Logger
attr_reader :settings
@@ -7,36 +9,40 @@
def initialize(env)
@settings = env
end
def method
- @settings['REQUEST_METHOD']
+ settings['REQUEST_METHOD']
end
def post?
- @settings['REQUEST_METHOD'] == 'POST'
+ settings['REQUEST_METHOD'] == 'POST'
end
def get?
- @settings['REQUEST_METHOD'] == 'GET'
+ settings['REQUEST_METHOD'] == 'GET'
end
def query
- @settings['QUERY_STRING']
+ settings['QUERY_STRING']
end
def path
- @settings['PATH_INFO']
+ settings['PATH_INFO']
end
+ def request_type
+ path.split('/')[1]
+ end
+
def data
parse(rack_input) if post?
end
private
def rack_input
- (@settings['rack.input'].read).tap { @settings['rack.input'].rewind } # http://rack.rubyforge.org/doc/SPEC.html
+ (settings['rack.input'].read).tap { settings['rack.input'].rewind } # http://rack.rubyforge.org/doc/SPEC.html
end
def parse(json)
begin
JSON.parse(json)