Class: DogWatch::Model::Client
- Inherits:
-
Object
- Object
- DogWatch::Model::Client
- Defined in:
- lib/dogwatch/model/client.rb
Overview
Client interface for the DataDog API
Instance Attribute Summary collapse
-
#client ⇒ Object
Returns the value of attribute client.
-
#config ⇒ Object
writeonly
Sets the attribute config.
-
#response ⇒ Object
readonly
Returns the value of attribute response.
Instance Method Summary collapse
- #execute(monitor) ⇒ DogWatch::Model::Response
-
#initialize(config) ⇒ Client
constructor
A new instance of Client.
- #new_monitor(monitor) ⇒ DogWatch::Model::Response
- #update_monitor(monitor) ⇒ DogWatch::Model::Response
- #validate(monitor) ⇒ Dogwatch::Model::Response
Constructor Details
#initialize(config) ⇒ Client
Returns a new instance of Client.
16 17 18 19 20 21 |
# File 'lib/dogwatch/model/client.rb', line 16 def initialize(config) @config = config @client = Dogapi::Client.new(@config.api_key, @config.app_key, nil, nil, true, @config.timeout) @all_monitors = all_monitors end |
Instance Attribute Details
#client ⇒ Object
Returns the value of attribute client.
11 12 13 |
# File 'lib/dogwatch/model/client.rb', line 11 def client @client end |
#config=(value) ⇒ Object
Sets the attribute config
12 13 14 |
# File 'lib/dogwatch/model/client.rb', line 12 def config=(value) @config = value end |
#response ⇒ Object (readonly)
Returns the value of attribute response.
13 14 15 |
# File 'lib/dogwatch/model/client.rb', line 13 def response @response end |
Instance Method Details
#execute(monitor) ⇒ DogWatch::Model::Response
25 26 27 28 29 30 31 |
# File 'lib/dogwatch/model/client.rb', line 25 def execute(monitor) if monitor_exists?(monitor.name) update_monitor(monitor) else new_monitor(monitor) end end |
#new_monitor(monitor) ⇒ DogWatch::Model::Response
47 48 49 50 51 52 53 |
# File 'lib/dogwatch/model/client.rb', line 47 def new_monitor(monitor) = (monitor) response = @client.monitor(monitor.attributes.type, monitor.attributes.query, ) DogWatch::Model::Response.new(response, [:name]) end |
#update_monitor(monitor) ⇒ DogWatch::Model::Response
35 36 37 38 39 40 41 42 43 |
# File 'lib/dogwatch/model/client.rb', line 35 def update_monitor(monitor) = (monitor) existing_monitor = get_monitor(monitor.name) response = @client.update_monitor(existing_monitor['id'], monitor.attributes.query, ) updated = %w(200 202).include?(response[0]) DogWatch::Model::Response.new(response, [:name], updated) end |
#validate(monitor) ⇒ Dogwatch::Model::Response
57 58 59 60 61 62 63 |
# File 'lib/dogwatch/model/client.rb', line 57 def validate(monitor) validation = monitor.validate return validation if validation.status == :error # If no validation errors return a valid Response DogWatch::Model::Response.new(['200', {}], 'valid') end |