Class: Refocus::Samples
- Inherits:
-
Object
- Object
- Refocus::Samples
- Includes:
- JsonHelper
- Defined in:
- lib/refocus/samples.rb,
lib/refocus/samples/collector.rb
Defined Under Namespace
Classes: Collector
Instance Attribute Summary collapse
-
#http ⇒ Object
readonly
Returns the value of attribute http.
Instance Method Summary collapse
- #collector ⇒ Object
- #get(subject:, aspect:) ⇒ Object
-
#initialize(url:, token:) ⇒ Samples
constructor
A new instance of Samples.
- #list(limit: nil) ⇒ Object
- #upsert(name:, aspect:, value: nil, message_body: nil, message_code: nil, related_links: nil) ⇒ Object (also: #submit)
- #upsert_custom_body(custom_body) ⇒ Object
Methods included from JsonHelper
Constructor Details
Instance Attribute Details
#http ⇒ Object (readonly)
Returns the value of attribute http.
9 10 11 |
# File 'lib/refocus/samples.rb', line 9 def http @http end |
Instance Method Details
#collector ⇒ Object
15 16 17 |
# File 'lib/refocus/samples.rb', line 15 def collector Collector.new(http: http) end |
#get(subject:, aspect:) ⇒ Object
37 38 39 |
# File 'lib/refocus/samples.rb', line 37 def get(subject:, aspect:) json(http.get(URI.escape("#{subject}\|#{aspect}"))) end |
#list(limit: nil) ⇒ Object
31 32 33 34 35 |
# File 'lib/refocus/samples.rb', line 31 def list(limit: nil) params = "" params = params + "?limit=#{limit}" if limit json(http.get(params)) end |
#upsert(name:, aspect:, value: nil, message_body: nil, message_code: nil, related_links: nil) ⇒ Object Also known as: submit
19 20 21 22 23 |
# File 'lib/refocus/samples.rb', line 19 def upsert(name:, aspect:, value:nil, message_body:nil, message_code:nil, related_links:nil) sample = Collector.format_sample(name:name, aspect: aspect, value: value, message_body: , message_code: , related_links: ) json(http.post("upsert", body: sample, expects: 200)) end |
#upsert_custom_body(custom_body) ⇒ Object
26 27 28 29 |
# File 'lib/refocus/samples.rb', line 26 def upsert_custom_body(custom_body) endpoint = (custom_body.is_a? Array) ? "upsert/bulk" : "upsert" json(http.post(endpoint, body: custom_body, expects: 200)) end |