Class: Rubytus::Request
Constant Summary
Constants included
from Constants
Constants::BASE_PATH_REGEX, Constants::COMMON_HEADERS, Constants::DEFAULT_BASE_PATH, Constants::DEFAULT_DATA_DIR, Constants::DEFAULT_MAX_SIZE, Constants::DEFAULT_STORAGE, Constants::ENV_BASE_PATH, Constants::ENV_DATA_DIR, Constants::ENV_MAX_SIZE, Constants::ENV_STORAGE, Constants::RESOURCE_UID_REGEX, Constants::RESUMABLE_CONTENT_TYPE, Constants::STATUS_BAD_REQUEST, Constants::STATUS_CREATED, Constants::STATUS_FORBIDDEN, Constants::STATUS_INTERNAL_ERROR, Constants::STATUS_NOT_ALLOWED, Constants::STATUS_NOT_FOUND, Constants::STATUS_OK
Instance Method Summary
collapse
Methods included from Common
#error!, #generate_uid
Constructor Details
#initialize(env) ⇒ Request
Returns a new instance of Request.
9
10
11
|
# File 'lib/rubytus/request.rb', line 9
def initialize(env)
@env = env
end
|
Instance Method Details
#base_path ⇒ Object
53
54
55
|
# File 'lib/rubytus/request.rb', line 53
def base_path
@env['api.options'][:base_path]
end
|
#collection? ⇒ Boolean
27
28
29
|
# File 'lib/rubytus/request.rb', line 27
def collection?
path_info.chomp('/') == base_path.chomp('/')
end
|
#content_length ⇒ Object
77
78
79
|
# File 'lib/rubytus/request.rb', line 77
def content_length
@env['CONTENT_LENGTH'].to_i
end
|
#content_type ⇒ Object
73
74
75
|
# File 'lib/rubytus/request.rb', line 73
def content_type
@env['CONTENT_TYPE']
end
|
#final_length ⇒ Object
45
46
47
|
# File 'lib/rubytus/request.rb', line 45
def final_length
('HTTP_FINAL_LENGTH')
end
|
#get? ⇒ Boolean
13
|
# File 'lib/rubytus/request.rb', line 13
def get?; request_method == 'GET'; end
|
#head? ⇒ Boolean
15
|
# File 'lib/rubytus/request.rb', line 15
def head?; request_method == 'HEAD'; end
|
#host_with_port ⇒ Object
65
66
67
|
# File 'lib/rubytus/request.rb', line 65
def host_with_port
@env['HTTP_HOST'] || "#{@env['SERVER_NAME']}:#{@env['SERVER_PORT']}"
end
|
#offset ⇒ Object
49
50
51
|
# File 'lib/rubytus/request.rb', line 49
def offset
('HTTP_OFFSET')
end
|
#options? ⇒ Boolean
17
|
# File 'lib/rubytus/request.rb', line 17
def options?; request_method == 'OPTIONS'; end
|
#patch? ⇒ Boolean
16
|
# File 'lib/rubytus/request.rb', line 16
def patch?; request_method == 'PATCH'; end
|
#path_info ⇒ Object
61
62
63
|
# File 'lib/rubytus/request.rb', line 61
def path_info
@env['PATH_INFO']
end
|
#post? ⇒ Boolean
14
|
# File 'lib/rubytus/request.rb', line 14
def post?; request_method == 'POST'; end
|
#request_method ⇒ Object
69
70
71
|
# File 'lib/rubytus/request.rb', line 69
def request_method
@env['REQUEST_METHOD']
end
|
#resource? ⇒ Boolean
31
32
33
|
# File 'lib/rubytus/request.rb', line 31
def resource?
!!(resource_uid =~ RESOURCE_UID_REGEX)
end
|
#resource_uid ⇒ Object
35
36
37
38
39
|
# File 'lib/rubytus/request.rb', line 35
def resource_uid
rpath = path_info.dup
rpath.slice!(base_path)
rpath
end
|
#resource_url(uid) ⇒ Object
41
42
43
|
# File 'lib/rubytus/request.rb', line 41
def resource_url(uid)
"#{scheme}://#{host_with_port}#{base_path}#{uid}"
end
|
#resumable_content_type? ⇒ Boolean
19
20
21
|
# File 'lib/rubytus/request.rb', line 19
def resumable_content_type?
content_type == RESUMABLE_CONTENT_TYPE
end
|
#scheme ⇒ Object
57
58
59
|
# File 'lib/rubytus/request.rb', line 57
def scheme
@env['HTTPS'] ? 'https' : 'http'
end
|
#unknown? ⇒ Boolean
23
24
25
|
# File 'lib/rubytus/request.rb', line 23
def unknown?
!collection? && !resource?
end
|