Class: Fog::Joyent::Analytics::Real
- Inherits:
-
Object
- Object
- Fog::Joyent::Analytics::Real
- Defined in:
- lib/fog/joyent/analytics.rb,
lib/fog/joyent/requests/analytics/describe_analytics.rb,
lib/fog/joyent/requests/analytics/get_instrumentation.rb,
lib/fog/joyent/requests/analytics/list_instrumentations.rb,
lib/fog/joyent/requests/analytics/create_instrumentation.rb,
lib/fog/joyent/requests/analytics/delete_instrumentation.rb,
lib/fog/joyent/requests/analytics/get_instrumentation_value.rb
Overview
Mock
Instance Method Summary collapse
- #create_instrumentation(values = {}) ⇒ Object
- #delete_instrumentation(id) ⇒ Object
- #describe_analytics(force = false) ⇒ Object
- #get_instrumentation(id) ⇒ Object
- #get_instrumentation_value(url, requested_start_time, ndatapoints, duration) ⇒ Object
-
#initialize(options = {}) ⇒ Real
constructor
A new instance of Real.
- #list_instrumentations ⇒ Object
- #request(opts = {}) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Real
Returns a new instance of Real.
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 |
# File 'lib/fog/joyent/analytics.rb', line 146 def initialize( = {}) @mutex = Mutex.new @connection_options = [:connection_options] || {} @persistent = [:persistent] || false @joyent_url = [:joyent_url] || 'https://us-sw-1.api.joyentcloud.com' @joyent_version = [:joyent_version] || '~7' @joyent_username = [:joyent_username] unless @joyent_username raise ArgumentError, "options[:joyent_username] required" end if [:joyent_keyname] @joyent_keyname = [:joyent_keyname] @joyent_keyphrase = [:joyent_keyphrase] @key_manager = Net::SSH::Authentication::KeyManager.new(nil, { :keys_only => true, :passphrase => @joyent_keyphrase }) @header_method = method(:header_for_signature_auth) if [:joyent_keyfile] if File.exist?([:joyent_keyfile]) @joyent_keyfile = [:joyent_keyfile] @key_manager.add(@joyent_keyfile) else raise ArgumentError, "options[:joyent_keyfile] provided does not exist." end elsif [:joyent_keydata] if [:joyent_keydata].to_s.empty? raise ArgumentError, 'options[:joyent_keydata] must not be blank' else @joyent_keydata = [:joyent_keydata] @key_manager.add_key_data(@joyent_keydata) end end elsif [:joyent_password] @joyent_password = [:joyent_password] @header_method = method(:header_for_basic_auth) else raise ArgumentError, "Must provide either a joyent_password or joyent_keyname and joyent_keyfile pair" end @connection = Fog::XML::Connection.new( @joyent_url, @persistent, @connection_options ) end |
Instance Method Details
#create_instrumentation(values = {}) ⇒ Object
5 6 7 8 9 10 11 12 |
# File 'lib/fog/joyent/requests/analytics/create_instrumentation.rb', line 5 def create_instrumentation(values = {}) request( :path => "#{@joyent_username}/analytics/instrumentations", :method => "POST", :body => values, :expects => [200,201] ) end |
#delete_instrumentation(id) ⇒ Object
5 6 7 8 9 10 11 |
# File 'lib/fog/joyent/requests/analytics/delete_instrumentation.rb', line 5 def delete_instrumentation(id) request( :path => "#{@joyent_username}/analytics/instrumentations/#{id}", :method => "DELETE", :expects => 204 ) end |
#describe_analytics(force = false) ⇒ Object
5 6 7 8 9 10 11 12 13 |
# File 'lib/fog/joyent/requests/analytics/describe_analytics.rb', line 5 def describe_analytics(force = false) @describe_analytics = nil if force @describe_analytics ||= request( :path => "#{@joyent_username}/analytics", :method => "GET", :expects => 200, :idempotent => true ) end |
#get_instrumentation(id) ⇒ Object
5 6 7 8 9 10 11 12 |
# File 'lib/fog/joyent/requests/analytics/get_instrumentation.rb', line 5 def get_instrumentation(id) request( :path => "#{@joyent_username}/analytics/instrumentations/#{id}", :method => "GET", :expects => 200, :idempotent => true ) end |
#get_instrumentation_value(url, requested_start_time, ndatapoints, duration) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/fog/joyent/requests/analytics/get_instrumentation_value.rb', line 5 def get_instrumentation_value(url, requested_start_time, ndatapoints, duration) request( :path => url, :method => 'GET', :expects => 200, :idempotent => true, :query => { :ndatapoints => ndatapoints, :start_time => requested_start_time.to_i, :duration => duration } ) end |
#list_instrumentations ⇒ Object
5 6 7 8 9 10 11 12 |
# File 'lib/fog/joyent/requests/analytics/list_instrumentations.rb', line 5 def list_instrumentations request( :path => "#{@joyent_username}/analytics/instrumentations", :method => "GET", :expects => 200, :idempotent => true ) end |
#request(opts = {}) ⇒ Object
197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 |
# File 'lib/fog/joyent/analytics.rb', line 197 def request(opts = {}) opts[:headers] = { "X-Api-Version" => @joyent_version, "Content-Type" => "application/json", "Accept" => "application/json" }.merge(opts[:headers] || {}).merge(@header_method.call) if opts[:body] opts[:body] = Fog::JSON.encode(opts[:body]) end response = @connection.request(opts) if response.headers["Content-Type"] == "application/json" response.body = json_decode(response.body) end response rescue Excon::Errors::HTTPStatusError => e if e.response.headers["Content-Type"] == "application/json" e.response.body = json_decode(e.response.body) end raise_if_error!(e.request, e.response) end |