Class: Matterhorn::Endpoint::Security
- Inherits:
-
Matterhorn::Endpoint
- Object
- Matterhorn::Endpoint
- Matterhorn::Endpoint::Security
- Defined in:
- lib/matterhorn/endpoint/security.rb
Overview
Matterhorn::Endpoint::Security ===
Instance Attribute Summary
Attributes inherited from Matterhorn::Endpoint
#response_body, #response_code
Instance Method Summary collapse
-
#sign(url, valid_until = nil, valid_source = nil) ⇒ Object
Create a signed url.
Methods inherited from Matterhorn::Endpoint
#close, create, #error_code, #error_msg, #error_occurred?, #initialize, open
Constructor Details
This class inherits a constructor from Matterhorn::Endpoint
Instance Method Details
#sign(url, valid_until = nil, valid_source = nil) ⇒ Object
Create a signed url.
-
url: the url which should be signed
-
valid_until: The date and time until the signed url is valid
-
valid_source: The IP address from which the request is allowed
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/matterhorn/endpoint/security.rb', line 17 def sign(url, valid_until = nil, valid_source = nil) signed_url = nil begin params = {} params['url'] = url.to_s if !valid_until.nil? && (valid_until.kind_of?(DateTime) || valid_until.kind_of?(Time)) params['valid_until'] = valid_until.xmlschema elsif !valid_until.nil? && valid_until.respond_to?(:to_s) params['valid_until'] = valid_until.to_s end if !valid_source.nil? && valid_source.respond_to?(:to_s) params['valid_source'] = ivalid_source.to_s end split_response http_endpoint_client.post( "api/security/sign", params ) signed_url = JSON.parse(response_body)['url'] rescue => ex exception_handler('create', ex, { 401 => "The caller is not authorized to have the link signed!" } ) end signed_url end |