Class: AppOptics::Metrics::Annotator
- Inherits:
-
Object
- Object
- AppOptics::Metrics::Annotator
- Defined in:
- lib/appoptics/metrics/annotator.rb
Overview
Read & write annotation streams for a given client connection.
Instance Method Summary collapse
-
#add(stream, title, options = {}) ⇒ Object
Creates a new annotation on the annotation stream.
-
#client ⇒ Object
client instance used by this object.
-
#delete(stream) ⇒ Object
Delete an annotation stream.
-
#delete_event(stream, id) ⇒ Object
Delete an event from a given annotation stream.
-
#fetch(stream, options = {}) ⇒ Object
Get a list of annotation events on a given annotation stream.
-
#fetch_event(stream, id) ⇒ Object
Get properties for a given annotation stream event.
-
#initialize(options = {}) ⇒ Annotator
constructor
A new instance of Annotator.
-
#list(options = {}) ⇒ Object
List currently existing annotation streams.
-
#update_event(stream, id, options = {}) ⇒ Object
Update an event’s properties.
Constructor Details
#initialize(options = {}) ⇒ Annotator
Returns a new instance of Annotator.
7 8 9 |
# File 'lib/appoptics/metrics/annotator.rb', line 7 def initialize(={}) @client = [:client] || AppOptics::Metrics.client end |
Instance Method Details
#add(stream, title, options = {}) ⇒ Object
Creates a new annotation on the annotation stream
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/appoptics/metrics/annotator.rb', line 32 def add(stream, title, ={}) [:title] = title [:start_time] = ([:start_time] || Time.now).to_i if [:end_time] [:end_time] = [:end_time].to_i end payload = SmartJSON.write() response = connection.post("annotations/#{stream}", payload) # will raise exception if not 200 OK event = SmartJSON.read(response.body) if block_given? yield update_event stream, event['id'], end_time: Time.now.to_i # need to get updated representation event = fetch_event stream, event['id'] end event end |
#client ⇒ Object
client instance used by this object
52 53 54 |
# File 'lib/appoptics/metrics/annotator.rb', line 52 def client @client end |
#delete(stream) ⇒ Object
Delete an annotation stream
61 62 63 64 65 66 67 |
# File 'lib/appoptics/metrics/annotator.rb', line 61 def delete(stream) connection.delete do |request| request.url connection.build_url("annotations/#{stream}") end # expects 204, middleware will raise exception otherwise true end |
#delete_event(stream, id) ⇒ Object
Delete an event from a given annotation stream
74 75 76 77 78 79 80 |
# File 'lib/appoptics/metrics/annotator.rb', line 74 def delete_event(stream, id) connection.delete do |request| request.url connection.build_url("annotations/#{stream}/#{id}") end # expects 204, middleware will raise exception otherwise true end |
#fetch(stream, options = {}) ⇒ Object
Get a list of annotation events on a given annotation stream
95 96 97 98 |
# File 'lib/appoptics/metrics/annotator.rb', line 95 def fetch(stream, ={}) response = connection.get("annotations/#{stream}", ) SmartJSON.read(response.body) end |
#fetch_event(stream, id) ⇒ Object
Get properties for a given annotation stream event
105 106 107 108 |
# File 'lib/appoptics/metrics/annotator.rb', line 105 def fetch_event(stream, id) response = connection.get("annotations/#{stream}/#{id}") SmartJSON.read(response.body) end |
#list(options = {}) ⇒ Object
List currently existing annotation streams
118 119 120 121 |
# File 'lib/appoptics/metrics/annotator.rb', line 118 def list(={}) response = connection.get("annotations", ) SmartJSON.read(response.body) end |
#update_event(stream, id, options = {}) ⇒ Object
Update an event’s properties
128 129 130 131 132 133 134 135 |
# File 'lib/appoptics/metrics/annotator.rb', line 128 def update_event(stream, id, ={}) url = "annotations/#{stream}/#{id}" connection.put do |request| request.url connection.build_url(url) request.body = SmartJSON.write() end # expects 204 will raise exception otherwise end |