Class: ClickSign::Signer

Inherits:
Object
  • Object
show all
Defined in:
lib/click_sign/signer.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ Signer

Returns a new instance of Signer.



6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/click_sign/signer.rb', line 6

def initialize(args)
  @raw_data = args
  @key = clean_key(args['key']) if args['key'].present?
  @email = clean_email(args['email']) if args['email'].present?
  @auths = clean_auths(args['auths']) if args['auths'].present?
  @name = clean_name(args['name']) if args['name'].present?
  @documentation = clean_documentation(args['documentation']) if args['documentation'].present?
  @birthday = clean_birthday(args['birthday']) if args['birthday'].present?
  @phone_number = clean_phone_number(args['phone_number']) if args['phone_number'].present?
  @has_documentation = clean_has_documentation(args['has_documentation']) if args['has_documentation'].present?
  @created_at = clean_created_at(args['created_at']) if args['created_at'].present?
  @updated_at = clean_updated_at(args['updated_at']) if args['updated_at'].present?
end

Instance Attribute Details

#authsObject (readonly)

Returns the value of attribute auths.



4
5
6
# File 'lib/click_sign/signer.rb', line 4

def auths
  @auths
end

#birthdayObject (readonly)

Returns the value of attribute birthday.



4
5
6
# File 'lib/click_sign/signer.rb', line 4

def birthday
  @birthday
end

#created_atObject (readonly)

Returns the value of attribute created_at.



4
5
6
# File 'lib/click_sign/signer.rb', line 4

def created_at
  @created_at
end

#documentationObject (readonly)

Returns the value of attribute documentation.



4
5
6
# File 'lib/click_sign/signer.rb', line 4

def documentation
  @documentation
end

#emailObject (readonly)

Returns the value of attribute email.



4
5
6
# File 'lib/click_sign/signer.rb', line 4

def email
  @email
end

#has_documentationObject (readonly)

Returns the value of attribute has_documentation.



4
5
6
# File 'lib/click_sign/signer.rb', line 4

def has_documentation
  @has_documentation
end

#keyObject (readonly)

Returns the value of attribute key.



4
5
6
# File 'lib/click_sign/signer.rb', line 4

def key
  @key
end

#nameObject (readonly)

Returns the value of attribute name.



4
5
6
# File 'lib/click_sign/signer.rb', line 4

def name
  @name
end

#phone_numberObject (readonly)

Returns the value of attribute phone_number.



4
5
6
# File 'lib/click_sign/signer.rb', line 4

def phone_number
  @phone_number
end

#raw_dataObject (readonly)

Returns the value of attribute raw_data.



4
5
6
# File 'lib/click_sign/signer.rb', line 4

def raw_data
  @raw_data
end

#updated_atObject (readonly)

Returns the value of attribute updated_at.



4
5
6
# File 'lib/click_sign/signer.rb', line 4

def updated_at
  @updated_at
end

Class Method Details

.build_payload(**args) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/click_sign/signer.rb', line 21

def self.build_payload(**args)
  payload = {}

  payload['email'] = parse_email(args['email']) if args['email'].present?
   payload['phone_number'] = parse_phone_number(args['phone_number']) if args['phone_number'].present?
   payload['name'] = parse_name(args['name']) if args['name'].present?
   payload['documentation'] = parse_documentation(args['documentation']) if args['documentation'].present?
   payload['birthday'] = parse_birthday(args['birthday']) if args['birthday'].present?
   payload['has_documentation'] = args['has_documentation'].present? ? parse_has_documentation(args['has_documentation']) : default_has_documentation 
   payload['auths'] = args['auths'].present? ? parse_auths(args['auths']) : default_auths
   payload['delivery'] = args['delivery'].present? ? parse_delivery(args['delivery']) : default_delivery

   {signer: payload}
end

.create(**args) ⇒ Object



48
49
50
51
52
53
54
55
56
57
# File 'lib/click_sign/signer.rb', line 48

def self.create(**args)
  payload = build_payload(args)
  response = ClickSign::Service.post(
    url: 'signers',
    payload: payload
    )
    if response.created?
      new_signer = ClickSign::Signer.new(response.body['signer'])
    end
end

.default_authsObject



44
45
46
# File 'lib/click_sign/signer.rb', line 44

def self.default_auths
  ['email']
end

.default_deliveryObject



36
37
38
# File 'lib/click_sign/signer.rb', line 36

def self.default_delivery
  ClickSign::Constants::Delivery::EMAIL
end

.default_has_documentationObject



40
41
42
# File 'lib/click_sign/signer.rb', line 40

def self.default_has_documentation
  true
end

.find(signer_key: nil) ⇒ Object



59
60
61
62
63
64
65
66
# File 'lib/click_sign/signer.rb', line 59

def self.find(signer_key: nil)
      response = ClickSign::Service.get(
url: ['signers', signer_key]
  )
  if response.success?
    signer = ClickSign::Signer.new(response.body['signer'])
  end
end

Instance Method Details

#add_to_document(document_key: nil, sign_as: nil, group: nil) ⇒ Object



70
71
72
# File 'lib/click_sign/signer.rb', line 70

def add_to_document document_key: nil, sign_as: nil, group: nil
  ClickSign::List.create document_key: document_key, signer_key: self.key, sign_as: sign_as, group: group
end

#remove_from_document(list_key: nil) ⇒ Object



74
75
76
# File 'lib/click_sign/signer.rb', line 74

def remove_from_document list_key: nil
  ClickSign::List.delete list_key: list_key
end