Class: Refocus::Samples

Inherits:
Object
  • Object
show all
Includes:
JsonHelper
Defined in:
lib/refocus/samples.rb,
lib/refocus/samples/collector.rb

Defined Under Namespace

Classes: Collector

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from JsonHelper

#json

Constructor Details

#initialize(url:, token:) ⇒ Samples

Returns a new instance of 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

#httpObject (readonly)

Returns the value of attribute http.



9
10
11
# File 'lib/refocus/samples.rb', line 9

def http
  @http
end

Instance Method Details

#collectorObject



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_body,
                         message_code: message_code, related_links: 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