Module: Fog::RiakCS::Usage::Utils

Included in:
Mock, Real
Defined in:
lib/fog/riakcs/requests/usage/get_usage.rb

Constant Summary collapse

TYPES_TO_STRING =
{ :access  => 'a', :storage => 'b' }
DEFAULT_TYPES =
TYPES_TO_STRING.keys
DEFAULT_FORMAT =
:json

Instance Method Summary collapse

Instance Method Details

#format_and_types_to_path(format, types) ⇒ Object



13
14
15
16
17
18
# File 'lib/fog/riakcs/requests/usage/get_usage.rb', line 13

def format_and_types_to_path(format, types)
  format_character = format.to_s.split('').first
  type_characters  = types.map { |t| TYPES_TO_STRING[t] }.compact

  [type_characters, format_character].flatten.compact.join
end

#request_uri(access_key_id, options) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
# File 'lib/fog/riakcs/requests/usage/get_usage.rb', line 20

def request_uri(access_key_id, options)
  format        = DEFAULT_FORMAT
  types         = options[:types]       || DEFAULT_TYPES
  start_time    = options[:start_time]  || Time.now.utc - 86400
  end_time      = options[:end_time]    || Time.now.utc

  [access_key_id,
   format_and_types_to_path(format, types),
   sanitize_and_convert_time(start_time),
   sanitize_and_convert_time(end_time)].join('.')
end

#sanitize_and_convert_time(time) ⇒ Object



9
10
11
# File 'lib/fog/riakcs/requests/usage/get_usage.rb', line 9

def sanitize_and_convert_time(time)
  time.utc.iso8601.gsub(/[:-]/, '')
end