Class: Wavefront::CoreApi
- Inherits:
-
Object
- Object
- Wavefront::CoreApi
- Includes:
- Mixins, Validators
- Defined in:
- lib/wavefront-sdk/core/api.rb
Overview
Abstract class from which all API classes inherit. When you make any call to the Wavefront API from this SDK, you are returned an OpenStruct object.
Direct Known Subclasses
AccessPolicy, Account, Alert, ApiToken, CloudIntegration, Cluster, Dashboard, DerivedMetric, Event, ExternalLink, IngestionPolicy, Integration, MaintenanceWindow, Message, Metric, MetricsPolicy, MonitoredApplication, Notificant, Proxy, Query, Role, SavedSearch, Search, ServiceAccount, Settings, Source, SpanSamplingPolicy, Spy, Unstable::Chart, Usage, User, UserGroup, Webhook
Instance Attribute Summary collapse
-
#api ⇒ Object
readonly
Returns the value of attribute api.
-
#creds ⇒ Object
readonly
Returns the value of attribute creds.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#opts ⇒ Object
readonly
Returns the value of attribute opts.
-
#update_keys ⇒ Object
readonly
Returns the value of attribute update_keys.
Instance Method Summary collapse
-
#api_base ⇒ String
Derive the first part of the API path from the class name.
-
#api_path ⇒ Object
The API path is normally /api/v2/something, but not always.
-
#hash_for_update(old, new) ⇒ Hash
Doing a PUT to update an object requires only a certain subset of the keys returned by #describe().
-
#initialize(creds = {}, opts = {}) ⇒ Nil
constructor
Create a new API object.
- #setup_api(creds, opts) ⇒ Object
-
#time_to_ms(time) ⇒ Ingeter
Convert an epoch timestamp into epoch milliseconds.
Methods included from Mixins
#log, #parse_relative_time, #parse_time, #relative_time, #time_multiplier, #valid_relative_time?
Methods included from Validators
#uuid?, #wf_account_id?, #wf_alert_id?, #wf_alert_severity?, #wf_apitoken_id?, #wf_aws_external_id?, #wf_cloudintegration_id?, #wf_dashboard_id?, #wf_derivedmetric_id?, #wf_distribution?, #wf_distribution_count?, #wf_distribution_interval?, #wf_distribution_values?, #wf_epoch?, #wf_event_id?, #wf_granularity?, #wf_ingestionpolicy_id?, #wf_integration_id?, #wf_link_id?, #wf_link_template?, #wf_maintenance_window_id?, #wf_message_id?, #wf_metric_name?, #wf_metricspolicy_id?, #wf_monitoredapplication_id?, #wf_monitoredcluster_id?, #wf_ms_ts?, #wf_name?, #wf_notificant_id?, #wf_permission?, #wf_point?, #wf_point_tag?, #wf_point_tags?, #wf_proxy_id?, #wf_role_id?, #wf_sampling_value?, #wf_savedsearch_entity?, #wf_savedsearch_id?, #wf_serviceaccount_id?, #wf_source_id?, #wf_spansamplingpolicy_id?, #wf_string?, #wf_tag?, #wf_trace?, #wf_ts?, #wf_user_id?, #wf_usergroup_id?, #wf_value?, #wf_version?, #wf_webhook_id?
Constructor Details
#initialize(creds = {}, opts = {}) ⇒ Nil
Create a new API object. This will always be called from a class which inherits this one. If the inheriting class defines #post_initialize, that method will be called afterwards, with the same arguments.
40 41 42 43 44 45 46 47 |
# File 'lib/wavefront-sdk/core/api.rb', line 40 def initialize(creds = {}, opts = {}) @creds = creds @opts = opts @api = setup_api(creds, opts) @s_api = setup_api(creds, opts) @logger = Wavefront::Logger.new(opts) post_initialize(creds, opts) if respond_to?(:post_initialize) end |
Instance Attribute Details
#api ⇒ Object (readonly)
Returns the value of attribute api.
20 21 22 |
# File 'lib/wavefront-sdk/core/api.rb', line 20 def api @api end |
#creds ⇒ Object (readonly)
Returns the value of attribute creds.
20 21 22 |
# File 'lib/wavefront-sdk/core/api.rb', line 20 def creds @creds end |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
20 21 22 |
# File 'lib/wavefront-sdk/core/api.rb', line 20 def logger @logger end |
#opts ⇒ Object (readonly)
Returns the value of attribute opts.
20 21 22 |
# File 'lib/wavefront-sdk/core/api.rb', line 20 def opts @opts end |
#update_keys ⇒ Object (readonly)
Returns the value of attribute update_keys.
20 21 22 |
# File 'lib/wavefront-sdk/core/api.rb', line 20 def update_keys @update_keys end |
Instance Method Details
#api_base ⇒ String
Derive the first part of the API path from the class name. You can override this in your class if you wish. This method is called by the ApiCaller class.
59 60 61 |
# File 'lib/wavefront-sdk/core/api.rb', line 59 def api_base self.class.name.split('::').last.downcase end |
#api_path ⇒ Object
The API path is normally /api/v2/something, but not always. Override this method if not
66 67 68 |
# File 'lib/wavefront-sdk/core/api.rb', line 66 def api_path ['', 'api', 'v2', api_base].uri_concat end |
#hash_for_update(old, new) ⇒ Hash
Doing a PUT to update an object requires only a certain subset of the keys returned by #describe(). This method takes the existing description of an object and turns it into a new hash which can be PUT.
94 95 96 97 98 99 100 |
# File 'lib/wavefront-sdk/core/api.rb', line 94 def hash_for_update(old, new) raise ArgumentError unless old.is_a?(Hash) && new.is_a?(Hash) old.merge(new).transform_keys(&:to_sym).select do |k, _v| update_keys.include?(k) end end |
#setup_api(creds, opts) ⇒ Object
49 50 51 |
# File 'lib/wavefront-sdk/core/api.rb', line 49 def setup_api(creds, opts) Wavefront::ApiCaller.new(self, creds, opts) end |
#time_to_ms(time) ⇒ Ingeter
Convert an epoch timestamp into epoch milliseconds. If the timestamp looks like it’s already epoch milliseconds, return it as-is.
77 78 79 80 81 82 |
# File 'lib/wavefront-sdk/core/api.rb', line 77 def time_to_ms(time) return false unless time.is_a?(Integer) return time if time.to_s.size == 13 (time.to_f * 1000).round end |