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: "", messageBody: "", messageCode: "", relatedLinks: []) ⇒ Object (also: #submit)
- #upsert_custom_body(custom_body) ⇒ Object
Methods included from JsonHelper
Constructor Details
#initialize(url:, token:) ⇒ Samples
11 12 13 |
# File 'lib/refocus/samples.rb', line 11 def initialize(url:, token:) @http = Refocus::Http.new(url: url, token: token) end |
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
36 37 38 |
# File 'lib/refocus/samples.rb', line 36 def get(subject:, aspect:) json(http.get(URI.escape("#{subject}\|#{aspect}"))) end |
#list(limit: nil) ⇒ Object
30 31 32 33 34 |
# File 'lib/refocus/samples.rb', line 30 def list(limit: nil) params = "" params = params + "?limit=#{limit}" if limit json(http.get(params)) end |
#upsert(name:, aspect:, value: "", messageBody: "", messageCode: "", relatedLinks: []) ⇒ Object Also known as: submit
19 20 21 22 |
# File 'lib/refocus/samples.rb', line 19 def upsert(name:, aspect:, value:"", messageBody:"", messageCode:"", relatedLinks:[]) sample = format_sample(name:name, aspect: aspect, value: value, messageBody: , messageCode: , relatedLinks: ) json(http.post("upsert", body: sample, expects: 200)) end |
#upsert_custom_body(custom_body) ⇒ Object
25 26 27 28 |
# File 'lib/refocus/samples.rb', line 25 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 |