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) ⇒ Object
-
#initialize(config) ⇒ Client
constructor
A new instance of Client.
- #new_monitor(monitor) ⇒ DogWatch::Model::Response
- #update_monitor(monitor) ⇒ DogWatch::Model::Response
Constructor Details
#initialize(config) ⇒ Client
Returns a new instance of Client.
16 17 18 19 20 |
# File 'lib/dogwatch/model/client.rb', line 16 def initialize(config) @config = config @client = Dogapi::Client.new(@config.api_key, @config.app_key) @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) ⇒ Object
23 24 25 26 27 28 29 |
# File 'lib/dogwatch/model/client.rb', line 23 def execute(monitor) if monitor_exists?(monitor.name) update_monitor(monitor) else new_monitor(monitor) end end |
#new_monitor(monitor) ⇒ DogWatch::Model::Response
45 46 47 48 49 50 51 |
# File 'lib/dogwatch/model/client.rb', line 45 def new_monitor(monitor) = (monitor) response = @client.monitor(monitor.attributes.type, monitor.attributes.query, ) @response = DogWatch::Model::Response.new(response) end |
#update_monitor(monitor) ⇒ DogWatch::Model::Response
33 34 35 36 37 38 39 40 41 |
# File 'lib/dogwatch/model/client.rb', line 33 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]) @response = DogWatch::Model::Response.new(response, updated) end |