Class: Paperlex::Contract

Inherits:
Base
  • Object
show all
Extended by:
ActiveSupport::Autoload
Includes:
RootObject
Defined in:
lib/paperlex/contract.rb,
lib/paperlex/contract/signers.rb,
lib/paperlex/contract/versions.rb,
lib/paperlex/contract/responses.rb,
lib/paperlex/contract/signatures.rb,
lib/paperlex/contract/review_sessions.rb

Defined Under Namespace

Classes: Responses, ReviewSessions, Signatures, Signers, Versions

Class Method Summary collapse

Instance Method Summary collapse

Methods included from RootObject

#save!

Methods inherited from Base

[], delete, get, #initialize, parse, post, put, #to_uuid

Constructor Details

This class inherits a constructor from Paperlex::Base

Class Method Details

.create(attrs = {}) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/paperlex/contract.rb', line 42

def create(attrs = {})
  attrs.symbolize_keys!
  signers = attrs.delete(:signers)
  attrs.assert_valid_keys(create_fields)
  result = new(post("contracts.json", :contract => attrs))
  if signers.present?
    signers.each do |email|
      result.create_signer(:email => email)
    end
  end
  result
end

.create_fieldsObject



34
35
36
# File 'lib/paperlex/contract.rb', line 34

def create_fields
  [*update_fields] << :slaw_id
end

.update_fieldsObject



30
31
32
# File 'lib/paperlex/contract.rb', line 30

def update_fields
  [:subject, :number_of_signers, :responses, :signature_callback_url, :body]
end

.url_nameObject



38
39
40
# File 'lib/paperlex/contract.rb', line 38

def url_name
  "contracts"
end

Instance Method Details

#at_version(version_index) ⇒ Object Also known as: version_at



168
169
170
# File 'lib/paperlex/contract.rb', line 168

def at_version(version_index)
  self.class.new(Versions[uuid].find(version_index))
end

#create_review_session(attrs = {}) ⇒ Object



108
109
110
111
112
# File 'lib/paperlex/contract.rb', line 108

def create_review_session(attrs = {})
  session = ReviewSessions[uuid].create(attrs)
  self.review_sessions << session
  session
end

#create_signature(attrs) ⇒ Object



157
158
159
160
161
# File 'lib/paperlex/contract.rb', line 157

def create_signature(attrs)
  signature = Signatures[uuid].create(attrs)
  self.signatures << signature
  signature
end

#create_signer(attrs = {}) ⇒ Object



69
70
71
72
73
# File 'lib/paperlex/contract.rb', line 69

def create_signer(attrs = {})
  signer = Signers[uuid].create(attrs)
  self.signers << signer
  signer
end

#delete_response(key) ⇒ Object



198
199
200
201
202
# File 'lib/paperlex/contract.rb', line 198

def delete_response(key)
  Responses[uuid].destroy(key)
  self.responses.delete(key)
  responses
end

#delete_review_session(review_session_uuid) ⇒ Object



133
134
135
136
# File 'lib/paperlex/contract.rb', line 133

def delete_review_session(review_session_uuid)
  remove_review_session!(review_session_uuid)
  ReviewSessions[uuid].destroy(review_session_uuid)
end

#delete_signer(signer) ⇒ Object



94
95
96
97
# File 'lib/paperlex/contract.rb', line 94

def delete_signer(signer)
  remove_signer!(signer)
  Signers[uuid].destroy(signer)
end

#fetch_response(key) ⇒ Object



186
187
188
# File 'lib/paperlex/contract.rb', line 186

def fetch_response(key)
  self.responses[key] = Responses[uuid].find(key)
end

#fetch_responsesObject



182
183
184
# File 'lib/paperlex/contract.rb', line 182

def fetch_responses
  self.responses = Responses[uuid].all
end

#fetch_review_session(review_session_uuid) ⇒ Object



119
120
121
122
123
124
# File 'lib/paperlex/contract.rb', line 119

def fetch_review_session(review_session_uuid)
  remove_review_session!(review_session_uuid)
  new_session = ReviewSessions[uuid].find(review_session_uuid)
  self.review_sessions << new_session
  new_session
end

#fetch_review_sessionsObject



114
115
116
117
# File 'lib/paperlex/contract.rb', line 114

def fetch_review_sessions
  self.review_sessions = ReviewSessions[uuid].all
  review_sessions
end

#fetch_signature(signature_uuid) ⇒ Object



150
151
152
153
154
155
# File 'lib/paperlex/contract.rb', line 150

def fetch_signature(signature_uuid)
  remove_signature!(signature_uuid)
  new_signature = Signatures[uuid].find(signature_uuid)
  self.signatures << new_signature
  new_signature
end

#fetch_signaturesObject



145
146
147
148
# File 'lib/paperlex/contract.rb', line 145

def fetch_signatures
  self.signatures = Signatures[uuid].all
  signatures
end

#fetch_signer(signer) ⇒ Object



80
81
82
83
84
85
# File 'lib/paperlex/contract.rb', line 80

def fetch_signer(signer)
  remove_signer!(signer)
  new_signer = Signers[uuid].find(signer)
  self.signers << new_signer
  new_signer
end

#fetch_signersObject



75
76
77
78
# File 'lib/paperlex/contract.rb', line 75

def fetch_signers
  self.signers = Signers[uuid].all
  signers
end

#html_urlObject



56
57
58
# File 'lib/paperlex/contract.rb', line 56

def html_url
  "#{Paperlex.base_url}/contracts/#{uuid}.html?#{{:token => Paperlex.token}.to_query}"
end

#responsesObject

Responses



178
179
180
# File 'lib/paperlex/contract.rb', line 178

def responses
  self[:responses] ||= {}
end

#revert_to_version(version_index) ⇒ Object



173
174
175
# File 'lib/paperlex/contract.rb', line 173

def revert_to_version(version_index)
  self.class.new(Versions[uuid].revert_to(version_index))
end

#review_sessionsObject



104
105
106
# File 'lib/paperlex/contract.rb', line 104

def review_sessions
  self[:review_sessions] ||= []
end

#review_sessions=(review_sessions) ⇒ Object

Review Sessions



100
101
102
# File 'lib/paperlex/contract.rb', line 100

def review_sessions=(review_sessions)
  self[:review_sessions] = review_sessions.map {|session| session.is_a?(Paperlex::ReviewSession) ? session : Paperlex::ReviewSession.new(session.merge(:contract_uuid => uuid)) }
end

#save_response(key) ⇒ Object



194
195
196
# File 'lib/paperlex/contract.rb', line 194

def save_response(key)
  Responses[uuid].update(key, responses[key])
end

#save_responsesObject



190
191
192
# File 'lib/paperlex/contract.rb', line 190

def save_responses
  Responses[uuid].update_all(responses)
end

#signatures=(signatures) ⇒ Object

Signatures Requires access to the remote signature program: api.paperlex.com/remote_signature.html



141
142
143
# File 'lib/paperlex/contract.rb', line 141

def signatures=(signatures)
  self[:signatures] = signatures.map {|signature| signature.is_a?(Paperlex::Signature) ? signature : Paperlex::Signature.new(signature.merge(:contract_uuid => uuid)) }
end

#signers=(signers) ⇒ Object

Signers



65
66
67
# File 'lib/paperlex/contract.rb', line 65

def signers=(signers)
  self[:signers] = signers.map {|signer| signer.is_a?(Paperlex::Signer) ? signer : Paperlex::Signer.new(signer.merge(:contract_uuid => uuid)) }
end

#to_htmlObject



60
61
62
# File 'lib/paperlex/contract.rb', line 60

def to_html
  RestClient.get(html_url)
end

#update_review_session(review_session_uuid, attrs) ⇒ Object



126
127
128
129
130
131
# File 'lib/paperlex/contract.rb', line 126

def update_review_session(review_session_uuid, attrs)
  remove_review_session!(review_session_uuid)
  updated_session = ReviewSessions[uuid].update(review_session_uuid, attrs)
  self.review_sessions << updated_session
  updated_session
end

#update_signer(signer, attrs) ⇒ Object



87
88
89
90
91
92
# File 'lib/paperlex/contract.rb', line 87

def update_signer(signer, attrs)
  remove_signer!(signer)
  updated_signer = Signers[uuid].update(signer, attrs)
  self.signers << updated_signer
  updated_signer
end

#versionsObject

Versions



164
165
166
# File 'lib/paperlex/contract.rb', line 164

def versions
  Versions[uuid].all.map {|version| Version.new(version) }
end