Class: Fog::Radosgw::Usage::Real
- Inherits:
-
Object
- Object
- Fog::Radosgw::Usage::Real
- Includes:
- Utils
- Defined in:
- lib/fog/radosgw/usage.rb,
lib/fog/radosgw/requests/usage/get_usage.rb
Instance Method Summary collapse
- #get_usage(access_key_id, options = {}) ⇒ Object
-
#initialize(options = {}) ⇒ Real
constructor
A new instance of Real.
Methods included from Utils
Constructor Details
#initialize(options = {}) ⇒ Real
Returns a new instance of Real.
41 42 43 44 45 46 47 |
# File 'lib/fog/radosgw/usage.rb', line 41 def initialize( = {}) () @radosgw_access_key_id = [:radosgw_access_key_id] @radosgw_secret_access_key = [:radosgw_secret_access_key] = [:connection_options] || {} @persistent = [:persistent] || false end |
Instance Method Details
#get_usage(access_key_id, options = {}) ⇒ Object
16 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 |
# File 'lib/fog/radosgw/requests/usage/get_usage.rb', line 16 def get_usage(access_key_id, = {}) path = "admin/usage" t_now = Fog::Time.now start_time = sanitize_and_convert_time([:start_time] || t_now - 86400) end_time = sanitize_and_convert_time([:end_time] || t_now) query = "?format=json&start=#{start_time}&end=#{end_time}" params = { :method => 'GET', :path => path, } begin response = Excon.get("#{@scheme}://#{@host}/#{path}#{query}", :headers => signed_headers(params)) if !response.body.empty? case response.headers['Content-Type'] when 'application/json' response.body = Fog::JSON.decode(response.body) end end response rescue Excon::Errors::BadRequest => e raise Fog::Radosgw::Provisioning::ServiceUnavailable.new end end |