click_sign_rails 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a911fde98f9fd770c0e7fbbdd6246ab881304f3b
4
+ data.tar.gz: 7da7d625ccf76ffc543821e941f860ab677fb020
5
+ SHA512:
6
+ metadata.gz: cd278a56f472c2e0dd7f0144e34953c20f94faef164b9babfaab2684b569cb95a133913453fb04825b1862227b0093e99ab360e4a64d870cf4f78b35b9935f6d
7
+ data.tar.gz: 650015c9df26a4a2e4b789f84c982f41d25fe3f16745b9d8816c6e89bc3ce0ba2706fae7758b836d6b4666ea65046cd1e583b439064aa602cab393652b4bcd22
data/README.md ADDED
@@ -0,0 +1 @@
1
+ # click-sign-rails
@@ -0,0 +1,20 @@
1
+ module ClickSign
2
+ class Configuration
3
+ @base_env = "CLICK_SIGN"
4
+ @url_env = "#{@base_env}_URL"
5
+ @sandbox_url_env = "#{@base_env}_SANDBOX_URL"
6
+ @api_version_env = "#{@base_env}_API_VERSION"
7
+ @access_token_env = "#{@base_env}_ACCESS_TOKEN"
8
+
9
+ @access_token = ENV[@access_token_env]
10
+ @url = ENV[@url_env] || 'https://app.clicksign.com'
11
+ @sandbox_url = ENV[@sandbox_url_env] || 'https://sandbox.clicksign.com'
12
+ @api_version = ENV[@api_version_env] || 'v1'
13
+
14
+ @sandbox = false
15
+
16
+ class << self
17
+ attr_accessor :base_env, :url_env, :sandbox_url_env, :api_version_env, :access_token_env, :access_token, :url, :sandbox_url, :api_version, :sandbox
18
+ end
19
+ end
20
+ end
data/lib/constants.rb ADDED
@@ -0,0 +1,55 @@
1
+ module ClickSign
2
+ class Constants
3
+ class Auth
4
+ SMS = 'sms'
5
+ EMAIL = 'email'
6
+ WHATSAPP = 'whatsapp'
7
+ API = 'api'
8
+ end
9
+
10
+ class Delivery
11
+ EMAIL = 'email'
12
+ NONE = 'none'
13
+ end
14
+
15
+ class Locale
16
+ PT_BR = 'pt-BR'
17
+ EN_US = 'en-US'
18
+ end
19
+
20
+ class RemindInterval
21
+ ONE = '1'
22
+ TWO = '2'
23
+ THREE = '3'
24
+ SEVEN = '7'
25
+ FOURTEEN = '14'
26
+ end
27
+
28
+ class SignAs
29
+ SIGN = 'sign'
30
+ APPROVE = 'approve'
31
+ PARTY = 'party'
32
+ WITNESS = 'witness'
33
+ INTERVENING = 'intervening'
34
+ RECEIPT = 'receipt'
35
+ ENDORSER = 'endorser'
36
+ ENDORSEE = 'endorsee'
37
+ ADMINISTRATOR = 'administrator'
38
+ GUARANTOR = 'guarantor'
39
+ TRANSFEROR = 'transferor'
40
+ TRANSFEREE = 'transferee'
41
+ CONTRACTEE = 'contractee'
42
+ CONTRACTOR = 'contractor'
43
+ JOINT_DEBTOR = 'joint_debtor'
44
+ ISSUER = 'issuer'
45
+ MANAGER = 'manager'
46
+ BUYER = 'buyer'
47
+ SELLER = 'seller'
48
+ ATTORNEY = 'attorney'
49
+ LEGAL_REPRESENTATIVE = 'legal_representative'
50
+ CO_RESPONSIBLE = 'co_responsible'
51
+ VALIDATOR = 'validator'
52
+ RATIFY = 'ratify'
53
+ end
54
+ end
55
+ end
data/lib/document.rb ADDED
@@ -0,0 +1,153 @@
1
+ module ClickSign
2
+ class Document
3
+ require "base64"
4
+
5
+ attr_reader :key, :path, :filename, :uploaded_at, :updated_at, :finished_at, :deadline_at, :status, :auto_close, :locale, :metadata, :sequence_enabled, :signable_group, :remind_interval, :raw_data, :original_file_url
6
+
7
+ def initialize(args)
8
+ @raw_data = args
9
+ @key = args['key'] if args['key'].present?
10
+ @path = args['path'] if args['path'].present?
11
+ @filename = args['filename'] if args['filename'].present?
12
+ @uploaded_at = args['uploaded_at'] if args['uploaded_at'].present?
13
+ @updated_at = args['updated_at'] if args['updated_at'].present?
14
+ @finished_at = args['finished_at'] if args['finished_at'].present?
15
+ @deadline_at = args['deadline_at'] if args['deadline_at'].present?
16
+ @status = args['status'] if args['status'].present?
17
+ @auto_close = args['auto_close'] if args['auto_close'].present?
18
+ @locale = args['locale'] if args['locale'].present?
19
+ @metadata = args['metadata'] if args['metadata'].present?
20
+ @sequence_enabled = args['sequence_enabled'] if args['sequence_enabled'].present?
21
+ @signable_group = args['signable_group'] if args['signable_group'].present?
22
+ @remind_interval = args['remind_interval'] if args['remind_interval'].present?
23
+ @original_file_url = args['downloads']['original_file_url'] if args['downloads'].present?
24
+ end
25
+
26
+ # <CLASS METHODS>
27
+ def self.create(**args)
28
+ payload = build_payload(args)
29
+ response = ClickSign::Service.post(
30
+ url: 'documents',
31
+ payload: payload
32
+ )
33
+ if response.created?
34
+ return ClickSign::Document.new(response.body['document'])
35
+ end
36
+ end
37
+
38
+ def self.find document_key: nil
39
+ response = ClickSign::Service.get(
40
+ url: ['documents', document_key]
41
+ )
42
+ if response.success?
43
+ return ClickSign::Document.new(response.body['document'])
44
+ end
45
+ end
46
+
47
+ def self.configure(**args)
48
+ document_key = args.delete(:document_key)
49
+ payload = build_payload args
50
+ response = ClickSign::Service.patch(
51
+ url: ['documents', document_key],
52
+ payload: payload
53
+ )
54
+ if response.success?
55
+ return ClickSign::Document.new(response.body['document'])
56
+ end
57
+ end
58
+
59
+ def self.finish! document_key: nil
60
+ response = ClickSign::Service.patch(
61
+ url: ['documents', document_key, 'finish'],
62
+ )
63
+ if response.success?
64
+ return ClickSign::Document.new(response.body['document'])
65
+ end
66
+ end
67
+
68
+ def self.cancel! document_key: nil
69
+ response = ClickSign::Service.patch(
70
+ url: ['documents', document_key, 'cancel'],
71
+ )
72
+ if response.success?
73
+ return ClickSign::Document.new(response.body['document'])
74
+ end
75
+ end
76
+
77
+ def self.duplicate! document_key: nil
78
+ response = ClickSign::Service.post(
79
+ url: ['documents', document_key, 'duplicate'],
80
+ )
81
+ if response.created?
82
+ return ClickSign::Document.new(response.body['document'])
83
+ end
84
+ end
85
+
86
+ def self.delete! document_key: nil
87
+ response = ClickSign::Service.delete(
88
+ url: ['documents', document_key],
89
+ )
90
+ if response.success?
91
+ true
92
+ else
93
+ false
94
+ end
95
+ end
96
+
97
+ def self.build_payload(**args)
98
+ payload = {}
99
+
100
+ if args[:file].present?
101
+ data_type = File.extname(args[:file]).gsub('.','')
102
+ payload['content_base64'] = "data:application/#{data_type};base64,#{Base64.encode64(args[:file].read)}"
103
+ end
104
+
105
+ payload['path'] = "/#{args[:name]}" if args[:name].present?
106
+ payload['deadline_at'] = args[:deadline_at] if args[:deadline_at].present?
107
+ payload['auto_close'] = args[:auto_close] if args[:auto_close].present?
108
+ payload['locale'] = args[:locale] if args[:locale].present?
109
+ payload['sequence_enabled'] = args[:sequence_enabled] if args[:sequence_enabled].present?
110
+ payload['remind_interval'] = args[:remind_interval] if args[:remind_interval].present?
111
+
112
+ {document: payload}
113
+ end
114
+ # </CLASS METHODS>
115
+
116
+ # <INSTANCE METHODS>
117
+ def add_signer signer_key: nil, sign_as: nil, group: nil
118
+ ClickSign::List.create document_key: self.key, signer_key: signer_key, sign_as: sign_as, group: nil
119
+ end
120
+
121
+ def remove_signer list_key: nil
122
+ ClickSign::List.delete list_key: list_key
123
+ end
124
+
125
+ def edit deadline_at: nil, auto_close: nil, locale: nil, sequence_enabled: nil, remind_interval: nil
126
+ ClickSign::Document.configure(
127
+ document_key: self.key,
128
+ deadline_at: deadline_at,
129
+ auto_close: auto_close,
130
+ locale: locale,
131
+ sequence_enabled: sequence_enabled,
132
+ remind_interval: remind_interval
133
+ ).attributes
134
+ end
135
+
136
+ def finish!
137
+ ClickSign::Document.finish! document_key: self.key
138
+ end
139
+
140
+ def cancel!
141
+ ClickSign::Document.cancel! document_key: self.key
142
+ end
143
+
144
+ def duplicate!
145
+ ClickSign::Document.duplicate! document_key: self.key
146
+ end
147
+
148
+ def delete!
149
+ ClickSign::Document.delete! document_key: self.key
150
+ end
151
+ # </INSTANCE METHODS>
152
+ end
153
+ end
data/lib/list.rb ADDED
@@ -0,0 +1,58 @@
1
+ module ClickSign
2
+ class List
3
+
4
+ attr_reader :key, :request_signature_key, :document_key, :signer_key, :sign_as, :created_at, :updated_at, :url, :group, :raw_data
5
+
6
+ def initialize(args)
7
+ @raw_data = args
8
+ @key = args['key'] if args['key'].present?
9
+ @request_signature_key = args['request_signature_key'] if args['request_signature_key'].present?
10
+ @document_key = args['document_key'] if args['document_key'].present?
11
+ @signer_key = args['signer_key'] if args['signer_key'].present?
12
+ @sign_as = args['sign_as'] if args['sign_as'].present?
13
+ @created_at = args['created_at'] if args['created_at'].present?
14
+ @updated_at = args['updated_at'] if args['updated_at'].present?
15
+ @url = args['url'] if args['url'].present?
16
+ @group = args['group'] if args['group'].present?
17
+ end
18
+
19
+ # <CLASS METHODS>
20
+ def self.create(**args)
21
+ payload = build_payload(args)
22
+ response = ClickSign::Service.post(
23
+ url: 'lists',
24
+ payload: payload
25
+ )
26
+ if response.created?
27
+ new_signer = ClickSign::List.new(response.body['list'])
28
+ end
29
+ end
30
+
31
+ def self.delete! list_key: nil
32
+ response = ClickSign::Service.delete(
33
+ url: ['lists', list_key]
34
+ )
35
+ if response.success?
36
+ ap 'removido'
37
+ end
38
+ end
39
+
40
+ def self.build_payload(**args)
41
+ payload = {}
42
+ payload['document_key'] = args['document_key'] if args['document_key'].present?
43
+ payload['signer_key'] = args['signer_key'] if args['signer_key'].present?
44
+ payload['sign_as'] = args['sign_as'] if args['sign_as'].present?
45
+ payload['group'] = args['group'] if args['group'].present?
46
+
47
+ { list: payload }
48
+ end
49
+ # </CLASS METHODS>
50
+
51
+ # <INSTANCE METHODS>
52
+ def delete!
53
+ ClickSign::List.delete! self.key
54
+ end
55
+ # </INSTANCE METHODS>
56
+
57
+ end
58
+ end
data/lib/service.rb ADDED
@@ -0,0 +1,119 @@
1
+ module ClickSign
2
+ require 'rest-client'
3
+ class Service
4
+
5
+ class Response
6
+ attr_reader :status, :body
7
+
8
+ def initialize(**args)
9
+ @status_code = args[:status_code]
10
+ @body = JSON.parse(args[:body]) if args[:body].present?
11
+ end
12
+
13
+ def created?
14
+ @status_code == 201
15
+ end
16
+
17
+ def success?
18
+ @status_code == 200
19
+ end
20
+
21
+ def error?
22
+ false
23
+ end
24
+ end
25
+
26
+ class ErrorResponse < ClickSign::Service::Response
27
+ attr_reader :errors
28
+
29
+ def initialize(**args)
30
+ super
31
+ @errors = @body['errors'] if @body.present?
32
+ end
33
+
34
+ def bad_request?
35
+ @status_code == 400
36
+ end
37
+
38
+ def unauthorized?
39
+ @status_code == 401
40
+ end
41
+
42
+ def forbiden?
43
+ @status_code == 403
44
+ end
45
+
46
+ def not_found?
47
+ @status_code == 404
48
+ end
49
+
50
+ def unprocessable_entity?
51
+ @status_code == 422
52
+ end
53
+
54
+ def server_error?
55
+ @status_code == 500
56
+ end
57
+
58
+ def error?
59
+ true
60
+ end
61
+ end
62
+
63
+ # <CLASS METHODS>
64
+ def self.accept_header
65
+ { Accept: 'application/json' }
66
+ end
67
+
68
+ def self.content_type
69
+ { 'Content-Type': 'application/json'}
70
+ end
71
+
72
+ def self.api_url(*path)
73
+ url = [ClickSign::Configuration.sandbox ? ClickSign::Configuration.sandbox_url : ClickSign::Configuration.url]
74
+ url += ['api']
75
+ url += [ClickSign::Configuration.api_version]
76
+ url += path
77
+ url.join("/") + "?access_token=#{ClickSign::Configuration.access_token}"
78
+ end
79
+
80
+ def self.get url: nil, payload: nil
81
+ request method: :get, url: url, payload: payload
82
+ end
83
+
84
+ def self.post url: nil, payload: nil
85
+ request method: :post, url: url, payload: payload
86
+ end
87
+
88
+ def self.patch url: nil, payload: nil
89
+ request method: :patch, url: url, payload: payload
90
+ end
91
+
92
+ def self.delete url: nil, payload: nil
93
+ request method: :delete, url: url, payload: payload
94
+ end
95
+
96
+ def self.request method: nil, url: nil, payload: nil
97
+ begin
98
+ response = RestClient::Request.execute(
99
+ method: method,
100
+ url: api_url(url),
101
+ payload: payload,
102
+ headers: accept_header,
103
+ content_type: content_type
104
+ )
105
+ ClickSign::Service::Response.new(status_code: response.code, body: response.body)
106
+ rescue RestClient::ExceptionWithResponse => _e
107
+ ClickSign::Servive::ErrorResponse.new(status_code: _e.response.code, body: _e.response.body)
108
+ rescue RestClient::ServerBrokeConnection => _e
109
+ ap _e
110
+ rescue RestClient::SSLCertificateNotVerified => _e
111
+ ap _e
112
+ end
113
+ end
114
+ # </CLASS METHODS>
115
+
116
+ # <INSTANCE METHODS>
117
+ # </INSTANCE METHODS>
118
+ end
119
+ end
data/lib/signer.rb ADDED
@@ -0,0 +1,163 @@
1
+ module ClickSign
2
+ class Signer
3
+
4
+ attr_reader :key, :email, :auths, :name, :documentation, :birthday, :phone_number, :has_documentation, :created_at, :updated_at, :raw_data
5
+
6
+ def initialize(args)
7
+ @raw_data = args
8
+ @key = clean_key(args['key']) if args['key'].present?
9
+ @email = clean_email(args['email']) if args['email'].present?
10
+ @auths = clean_auths(args['auths']) if args['auths'].present?
11
+ @name = clean_name(args['name']) if args['name'].present?
12
+ @documentation = clean_documentation(args['documentation']) if args['documentation'].present?
13
+ @birthday = clean_birthday(args['birthday']) if args['birthday'].present?
14
+ @phone_number = clean_phone_number(args['phone_number']) if args['phone_number'].present?
15
+ @has_documentation = clean_has_documentation(args['has_documentation']) if args['has_documentation'].present?
16
+ @created_at = clean_created_at(args['created_at']) if args['created_at'].present?
17
+ @updated_at = clean_updated_at(args['updated_at']) if args['updated_at'].present?
18
+ end
19
+
20
+ # <CLASS METHODS>
21
+ def self.build_payload(**args)
22
+ payload = {}
23
+
24
+ payload['email'] = parse_email(args['email']) if args['email'].present?
25
+ payload['phone_number'] = parse_phone_number(args['phone_number']) if args['phone_number'].present?
26
+ payload['name'] = parse_name(args['name']) if args['name'].present?
27
+ payload['documentation'] = parse_documentation(args['documentation']) if args['documentation'].present?
28
+ payload['birthday'] = parse_birthday(args['birthday']) if args['birthday'].present?
29
+ payload['has_documentation'] = args['has_documentation'].present? ? parse_has_documentation(args['has_documentation']) : default_has_documentation
30
+ payload['auths'] = args['auths'].present? ? parse_auths(args['auths']) : default_auths
31
+ payload['delivery'] = args['delivery'].present? ? parse_delivery(args['delivery']) : default_delivery
32
+
33
+ {signer: payload}
34
+ end
35
+
36
+ def self.default_delivery
37
+ ClickSign::Constants::Delivery::EMAIL
38
+ end
39
+
40
+ def self.default_has_documentation
41
+ true
42
+ end
43
+
44
+ def self.default_auths
45
+ ['email']
46
+ end
47
+
48
+ def self.create(**args)
49
+ payload = build_payload(args)
50
+ response = ClickSign::Service.post(
51
+ url: 'signers',
52
+ payload: payload
53
+ )
54
+ if response.created?
55
+ new_signer = ClickSign::Signer.new(response.body['signer'])
56
+ end
57
+ end
58
+
59
+ def self.find(signer_key: nil)
60
+ response = ClickSign::Service.get(
61
+ url: ['signers', signer_key]
62
+ )
63
+ if response.success?
64
+ signer = ClickSign::Signer.new(response.body['signer'])
65
+ end
66
+ end
67
+ # </CLASS METHODS>
68
+
69
+ # <INSTANCE METHODS>
70
+ def add_to_document document_key: nil, sign_as: nil, group: nil
71
+ ClickSign::List.create document_key: document_key, signer_key: self.key, sign_as: sign_as, group: group
72
+ end
73
+
74
+ def remove_from_document list_key: nil
75
+ ClickSign::List.delete list_key: list_key
76
+ end
77
+
78
+ private
79
+ def clean_key value
80
+ value
81
+ end
82
+
83
+ def clean_email value
84
+ value
85
+ end
86
+
87
+ def clean_auths value
88
+ value
89
+ end
90
+
91
+ def clean_name value
92
+ value
93
+ end
94
+
95
+ def clean_documentation value
96
+ value
97
+ end
98
+
99
+ def clean_birthday value
100
+ value
101
+ end
102
+
103
+ def clean_phone_number value
104
+ value
105
+ end
106
+
107
+ def clean_has_documentation value
108
+ value
109
+ end
110
+
111
+ def clean_created_at value
112
+ value
113
+ end
114
+
115
+ def clean_updated_at value
116
+ value
117
+ end
118
+
119
+ def parse_key value
120
+ value
121
+ end
122
+
123
+ def parse_email value
124
+ value
125
+ end
126
+
127
+ def parse_auths value
128
+ value
129
+ end
130
+
131
+ def parse_name value
132
+ value
133
+ end
134
+
135
+ def parse_documentation value
136
+ value
137
+ end
138
+
139
+ def parse_birthday value
140
+ value
141
+ end
142
+
143
+ def parse_phone_number value
144
+ value
145
+ end
146
+
147
+ def parse_has_documentation value
148
+ value
149
+ end
150
+
151
+ def parse_created_at value
152
+ value
153
+ end
154
+
155
+ def parse_updated_at value
156
+ value
157
+ end
158
+
159
+
160
+ # </INSTANCE METHODS>
161
+
162
+ end
163
+ end
@@ -0,0 +1,14 @@
1
+ module ClickSign
2
+ module Webhooks
3
+ module Routes
4
+ end
5
+ end
6
+ end
7
+
8
+ module ActionDispatch::Routing
9
+ class Mapper
10
+ def click_sign_for
11
+ get 'test_click_sign', controller: :proposals, action: :teste
12
+ end
13
+ end
14
+ end
metadata ADDED
@@ -0,0 +1,79 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: click_sign_rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Thiago Soares de Melo
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-05-21 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '6'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rest-client
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '='
32
+ - !ruby/object:Gem::Version
33
+ version: 2.1.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '='
39
+ - !ruby/object:Gem::Version
40
+ version: 2.1.0
41
+ description:
42
+ email: thiago.soaresm19@gmail.com
43
+ executables: []
44
+ extensions: []
45
+ extra_rdoc_files: []
46
+ files:
47
+ - README.md
48
+ - lib/configuration.rb
49
+ - lib/constants.rb
50
+ - lib/document.rb
51
+ - lib/list.rb
52
+ - lib/service.rb
53
+ - lib/signer.rb
54
+ - lib/webhooks/routes.rb
55
+ homepage: https://github.com/teago19/click-sign-rails
56
+ licenses:
57
+ - MIT
58
+ metadata: {}
59
+ post_install_message:
60
+ rdoc_options: []
61
+ require_paths:
62
+ - lib
63
+ required_ruby_version: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ required_rubygems_version: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: '0'
73
+ requirements: []
74
+ rubyforge_project:
75
+ rubygems_version: 2.5.2.1
76
+ signing_key:
77
+ specification_version: 4
78
+ summary: ClickSign WebHook and Api interface for rails
79
+ test_files: []