module Openstack::Helpers::CacheableBody
cache-friendly response body.
Public Instance Methods
body_to_cache()
click to toggle source
# File lib/openstack/helpers/cacheable_body.rb, line 7 def body_to_cache # We cache JSON rather than ruby object. Simple object. { headers: headers, token: token, expires_at: expires_at, code: Integer(code), message: message, body: body_as_hash }.to_json end
Private Instance Methods
body_as_hash()
click to toggle source
# File lib/openstack/helpers/cacheable_body.rb, line 35 def body_as_hash JSON.parse(body) rescue JSON::ParserError {} end
expires_at()
click to toggle source
# File lib/openstack/helpers/cacheable_body.rb, line 29 def expires_at Time.parse(body_as_hash.dig('token', 'expires_at')) rescue TypeError nil end
headers()
click to toggle source
# File lib/openstack/helpers/cacheable_body.rb, line 21 def headers each_header.to_h end
token()
click to toggle source
# File lib/openstack/helpers/cacheable_body.rb, line 25 def token header.fetch('X-Subject-Token') { nil } end