Class: ApiAuth::RequestDrivers::RestClientRequest

Inherits:
Object
  • Object
show all
Includes:
Helpers
Defined in:
lib/api_auth/request_drivers/rest_client.rb

Overview

:nodoc:

Instance Method Summary collapse

Methods included from Helpers

#b64_encode, #capitalize_keys, #md5_base64digest

Constructor Details

#initialize(request) ⇒ RestClientRequest

Returns a new instance of RestClientRequest.



12
13
14
15
16
# File 'lib/api_auth/request_drivers/rest_client.rb', line 12

def initialize(request)
  @request = request
  @headers = fetch_headers
  true
end

Instance Method Details

#authorization_headerObject



75
76
77
# File 'lib/api_auth/request_drivers/rest_client.rb', line 75

def authorization_header
  find_header %w(Authorization AUTHORIZATION HTTP_AUTHORIZATION)
end

#calculated_md5Object



24
25
26
27
28
29
30
31
32
# File 'lib/api_auth/request_drivers/rest_client.rb', line 24

def calculated_md5
  if @request.payload
    body = @request.payload.read
    @request.payload.instance_variable_get(:@stream).seek(0)
  else
    body = ''
  end
  md5_base64digest(body)
end

#content_md5Object



57
58
59
60
# File 'lib/api_auth/request_drivers/rest_client.rb', line 57

def content_md5
  value = find_header(%w(CONTENT-MD5 CONTENT_MD5))
  value.nil? ? "" : value
end

#content_typeObject



52
53
54
55
# File 'lib/api_auth/request_drivers/rest_client.rb', line 52

def content_type
  value = find_header(%w(CONTENT-TYPE CONTENT_TYPE HTTP_CONTENT_TYPE))
  value.nil? ? "": value
end

#fetch_headersObject



48
49
50
# File 'lib/api_auth/request_drivers/rest_client.rb', line 48

def fetch_headers
  capitalize_keys @request.processed_headers
end

#md5_mismatch?Boolean

Returns:

  • (Boolean)


40
41
42
43
44
45
46
# File 'lib/api_auth/request_drivers/rest_client.rb', line 40

def md5_mismatch?
  if [:post, :put].include?(@request.method)
    calculated_md5 != content_md5
  else
    false
  end
end

#populate_content_md5Object



34
35
36
37
38
# File 'lib/api_auth/request_drivers/rest_client.rb', line 34

def populate_content_md5
  if [:post, :put].include?(@request.method)
    @request.headers["Content-MD5"] = calculated_md5
  end
end

#request_uriObject



62
63
64
# File 'lib/api_auth/request_drivers/rest_client.rb', line 62

def request_uri
  @request.url
end

#set_auth_header(header) ⇒ Object



18
19
20
21
22
# File 'lib/api_auth/request_drivers/rest_client.rb', line 18

def set_auth_header(header)
  @request.headers.merge!({ "Authorization" => header })
  save_headers # enforce update of processed_headers based on last updated headers
  @request
end

#set_dateObject



66
67
68
# File 'lib/api_auth/request_drivers/rest_client.rb', line 66

def set_date
  @request.headers.merge!({ "DATE" => Time.now.utc.httpdate })
end

#timestampObject



70
71
72
73
# File 'lib/api_auth/request_drivers/rest_client.rb', line 70

def timestamp
  value = find_header(%w(DATE HTTP_DATE))
  value.nil? ? "" : value
end