Class: Docuseal::Model

Inherits:
Object
  • Object
show all
Defined in:
lib/docuseal/model.rb

Direct Known Subclasses

Submission, Submitter, Template

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.archive(id) ⇒ Object

Raises:



36
37
38
39
40
41
# File 'lib/docuseal/model.rb', line 36

def archive(id)
  raise Docuseal::Error, "Method not allowed" if not_allowed_to.include?(:archive)

  response = Docuseal::Client.instance.delete("#{path}/#{id}")
  new(response.body)
end

.create(path: self.path, **attrs) ⇒ Object

Raises:



4
5
6
7
8
9
10
11
12
13
# File 'lib/docuseal/model.rb', line 4

def create(path: self.path, **attrs)
  raise Docuseal::Error, "Method not allowed" if not_allowed_to.include?(:create)

  response = Docuseal::Client.instance.post(path, data: attrs)
  body = response.body

  return body.map(&self) if body.is_a?(Array)

  new(body)
end

.find(id) ⇒ Object

Raises:



15
16
17
18
19
20
# File 'lib/docuseal/model.rb', line 15

def find(id)
  raise Docuseal::Error, "Method not allowed" if not_allowed_to.include?(:find)

  response = Docuseal::Client.instance.get("#{path}/#{id}")
  new(response.body)
end

.listObject

Raises:



29
30
31
32
33
34
# File 'lib/docuseal/model.rb', line 29

def list(**)
  raise Docuseal::Error, "Method not allowed" if not_allowed_to.include?(:list)

  response = Docuseal::Client.instance.get(path, **)
  response.body["data"].map(&self)
end

.not_allowed_to(attrs = []) ⇒ Object



53
54
55
# File 'lib/docuseal/model.rb', line 53

def not_allowed_to(attrs = [])
  @not_allowed_to ||= attrs
end

.skip_coertion_for(attrs = []) ⇒ Object



49
50
51
# File 'lib/docuseal/model.rb', line 49

def skip_coertion_for(attrs = [])
  @skip_coertion_for ||= attrs
end

.to_procObject

Auxiliary methods



45
46
47
# File 'lib/docuseal/model.rb', line 45

def to_proc
  ->(attrs) { new(attrs) }
end

.update(id, **attrs) ⇒ Object

Raises:



22
23
24
25
26
27
# File 'lib/docuseal/model.rb', line 22

def update(id, **attrs)
  raise Docuseal::Error, "Method not allowed" if not_allowed_to.include?(:update)

  response = Docuseal::Client.instance.put("#{path}/#{id}", data: attrs)
  new(response.body)
end

Instance Method Details

#to_jsonObject



58
59
60
# File 'lib/docuseal/model.rb', line 58

def to_json
  @_raw.to_json
end