Class: Refocus::Subjects

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from PathHelper

#parent_and_name

Methods included from JsonHelper

#json

Constructor Details

#initialize(url:, token:) ⇒ Subjects

Returns a new instance of Subjects.



12
13
14
# File 'lib/refocus/subjects.rb', line 12

def initialize(url:, token:)
  @http = Refocus::Http.new(url: url, token: token)
end

Instance Attribute Details

#httpObject (readonly)

Returns the value of attribute http.



10
11
12
# File 'lib/refocus/subjects.rb', line 10

def http
  @http
end

Instance Method Details

#allObject



16
17
18
# File 'lib/refocus/subjects.rb', line 16

def all
  json(http.get(""))
end

#create(name:, options: {}) ⇒ Object



20
21
22
23
24
25
# File 'lib/refocus/subjects.rb', line 20

def create(name:, options: {})
  parent, child = parent_and_name(name)
  path = parent ? "#{parent}/child" : ""
  body = options.merge({"name" => child})
  json(http.post(path, body: body))
end

#delete(name:) ⇒ Object



27
28
29
# File 'lib/refocus/subjects.rb', line 27

def delete(name:)
  json(http.delete(name))
end

#get(name:) ⇒ Object



35
36
37
# File 'lib/refocus/subjects.rb', line 35

def get(name:)
  json(http.get(name))
end

#update(name:, options:) ⇒ Object



31
32
33
# File 'lib/refocus/subjects.rb', line 31

def update(name:, options:)
  json(http.patch(name, body: options))
end