class Rubytus::Request
Public Class Methods
new(env)
click to toggle source
# File lib/rubytus/request.rb, line 9 def initialize(env) @env = env end
Public Instance Methods
base_path()
click to toggle source
# File lib/rubytus/request.rb, line 53 def base_path @env['api.options'][:base_path] end
collection?()
click to toggle source
# File lib/rubytus/request.rb, line 27 def collection? path_info.chomp('/') == base_path.chomp('/') end
content_length()
click to toggle source
# File lib/rubytus/request.rb, line 77 def content_length @env['CONTENT_LENGTH'].to_i end
content_type()
click to toggle source
# File lib/rubytus/request.rb, line 73 def content_type @env['CONTENT_TYPE'] end
final_length()
click to toggle source
# File lib/rubytus/request.rb, line 45 def final_length fetch_positive_header('HTTP_FINAL_LENGTH') end
get?()
click to toggle source
# File lib/rubytus/request.rb, line 13 def get?; request_method == 'GET'; end
head?()
click to toggle source
# File lib/rubytus/request.rb, line 15 def head?; request_method == 'HEAD'; end
host_with_port()
click to toggle source
# File lib/rubytus/request.rb, line 65 def host_with_port @env['HTTP_HOST'] || "#{@env['SERVER_NAME']}:#{@env['SERVER_PORT']}" end
offset()
click to toggle source
# File lib/rubytus/request.rb, line 49 def offset fetch_positive_header('HTTP_OFFSET') end
options?()
click to toggle source
# File lib/rubytus/request.rb, line 17 def options?; request_method == 'OPTIONS'; end
patch?()
click to toggle source
# File lib/rubytus/request.rb, line 16 def patch?; request_method == 'PATCH'; end
path_info()
click to toggle source
# File lib/rubytus/request.rb, line 61 def path_info @env['PATH_INFO'] end
post?()
click to toggle source
# File lib/rubytus/request.rb, line 14 def post?; request_method == 'POST'; end
request_method()
click to toggle source
# File lib/rubytus/request.rb, line 69 def request_method @env['REQUEST_METHOD'] end
resource?()
click to toggle source
# File lib/rubytus/request.rb, line 31 def resource? !!(resource_uid =~ RESOURCE_UID_REGEX) end
resource_uid()
click to toggle source
# File lib/rubytus/request.rb, line 35 def resource_uid rpath = path_info.dup rpath.slice!(base_path) rpath end
resource_url(uid)
click to toggle source
# File lib/rubytus/request.rb, line 41 def resource_url(uid) "#{scheme}://#{host_with_port}#{base_path}#{uid}" end
resumable_content_type?()
click to toggle source
# File lib/rubytus/request.rb, line 19 def resumable_content_type? content_type == RESUMABLE_CONTENT_TYPE end
scheme()
click to toggle source
# File lib/rubytus/request.rb, line 57 def scheme @env['HTTPS'] ? 'https' : 'http' end
unknown?()
click to toggle source
# File lib/rubytus/request.rb, line 23 def unknown? !collection? && !resource? end
Protected Instance Methods
fetch_positive_header(header_name)
click to toggle source
# File lib/rubytus/request.rb, line 82 def fetch_positive_header(header_name) header_val = @env[header_name] || '' value = header_val.to_i header_orig = normalize_header_name(header_name) if header_val.empty? error!(STATUS_BAD_REQUEST, "#{header_orig} header must not be empty") end if value < 0 error!(STATUS_BAD_REQUEST, "#{header_orig} header must be > 0") end value end
normalize_header_name(header_name)
click to toggle source
# File lib/rubytus/request.rb, line 98 def normalize_header_name(header_name) header_name.gsub('HTTP_', '').split('_').map(&:capitalize).join('-') end