Class: Shmac::Request

Inherits:
Object
  • Object
show all
Defined in:
lib/shmac/request.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path:, method:, headers:, body: nil, content_type: nil) ⇒ Request



7
8
9
10
11
12
13
# File 'lib/shmac/request.rb', line 7

def initialize path:, method:, headers:, body: nil, content_type: nil
  @path = path
  @method = method
  self.headers = headers
  @body = body
  @content_type = content_type
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



5
6
7
# File 'lib/shmac/request.rb', line 5

def body
  @body
end

#content_typeObject (readonly)

Returns the value of attribute content_type.



5
6
7
# File 'lib/shmac/request.rb', line 5

def content_type
  @content_type
end

#headersObject

Returns the value of attribute headers.



5
6
7
# File 'lib/shmac/request.rb', line 5

def headers
  @headers
end

#methodObject (readonly)

Returns the value of attribute method.



5
6
7
# File 'lib/shmac/request.rb', line 5

def method
  @method
end

#pathObject (readonly)

Returns the value of attribute path.



5
6
7
# File 'lib/shmac/request.rb', line 5

def path
  @path
end

Instance Method Details

#api_versionObject



36
37
38
# File 'lib/shmac/request.rb', line 36

def api_version
  headers.fetch("x-authorization-version", 0).to_i
end

#authorizationObject



27
28
29
30
# File 'lib/shmac/request.rb', line 27

def authorization
  # Test for x-authorization for clients that have issues with standard headers
  headers.fetch("x-authorization") { headers["authorization"] }
end

#content_md5Object



22
23
24
25
# File 'lib/shmac/request.rb', line 22

def content_md5
  # Fallback to x-content-md5 for clients that have issues with standard headers
  headers.fetch("content-md5") { headers["x-content-md5"] }
end

#date(namespace = nil) ⇒ Object

Prefer the value of a namespaced date key if present



16
17
18
19
20
# File 'lib/shmac/request.rb', line 16

def date namespace = nil
  date_key = [namespace, "date"].compact.join("-").downcase

  headers.fetch(date_key) { headers["date"] }
end