aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorGibheer <gibheer@gmail.com>2012-11-15 06:43:40 +0100
committerGibheer <gibheer@gmail.com>2012-11-15 06:43:40 +0100
commit8f5486700bc5a61d2c62a52a6200f5ea049e0f00 (patch)
treef9c962da64e158cd62997d9894807a728b8fb671 /lib
parent721e1e61d9bbb8b4d6ebd60023f36bd649d6d729 (diff)
added Client to the request
Diffstat (limited to 'lib')
-rw-r--r--lib/zero/request.rb5
-rw-r--r--lib/zero/request/client.rb31
2 files changed, 36 insertions, 0 deletions
diff --git a/lib/zero/request.rb b/lib/zero/request.rb
index 30e891e..f3d40d6 100644
--- a/lib/zero/request.rb
+++ b/lib/zero/request.rb
@@ -1,4 +1,5 @@
require_relative 'request/accept'
+require_relative 'request/client'
require_relative 'request/parameter'
module Zero
@@ -19,6 +20,10 @@ module Zero
@path ||= @env[CONST_PATH_INFO]
end
+ def client
+ @client ||= Request::Client.new(@env)
+ end
+
# get an object representing the parameters of the request
# @return [Parameter] object having all parameters
def params
diff --git a/lib/zero/request/client.rb b/lib/zero/request/client.rb
new file mode 100644
index 0000000..2a27cb7
--- /dev/null
+++ b/lib/zero/request/client.rb
@@ -0,0 +1,31 @@
+module Zero
+ class Request
+ # This class represents all information about the client of a request.
+ class Client
+ # the key for the ip of the client
+ KEY_REMOTE_ADDR = 'REMOTE_ADDR'
+ # the key for the hostname
+ KEY_REMOTE_HOST = 'REMOTE_HOST'
+ # the key for the user agent
+ KEY_USER_AGENT = 'HTTP_USER_AGENT'
+
+ # creates a new client with the data of the request environment
+ # @param environment a hash representation of the request
+ def initialize(environment)
+ @address = environment[KEY_REMOTE_ADDR]
+ @hostname = environment[KEY_REMOTE_HOST]
+ @user_agent = environment[KEY_USER_AGENT]
+ end
+
+ # the ip address of the client
+ # @return [String] the address of the client
+ attr_reader :address
+ # the hostname of the client
+ # @return [String] the hostname of the client
+ attr_reader :hostname
+ # the user agent of the client
+ # @return [String] the user agent of the client
+ attr_reader :user_agent
+ end
+ end
+end