From 074752f219da2a0d0c85d55577b48e77a9d8c779 Mon Sep 17 00:00:00 2001 From: "renan.proenca" Date: Tue, 9 Nov 2021 18:54:46 -0300 Subject: [PATCH 1/8] [WIP] Batch Create --- lib/clicksign/api/documents_signers.rb | 19 +++++++++++++++---- spec/clicksign/api/documents_signers_spec.rb | 10 +++++----- spec/clicksign/api_spec.rb | 2 +- 3 files changed, 21 insertions(+), 10 deletions(-) diff --git a/lib/clicksign/api/documents_signers.rb b/lib/clicksign/api/documents_signers.rb index ee8be04..f891c38 100644 --- a/lib/clicksign/api/documents_signers.rb +++ b/lib/clicksign/api/documents_signers.rb @@ -10,16 +10,19 @@ class DocumentsSigners class << self def create(token:, params: {}) - post( + response = post( REQUEST_PATH, body(params), token ) + parse(response) end - def batch_create(token:, batch:) - batch.map do |params| - create(token: token, params: params) + def batch_create(token:, params:) + params = params.transform_keys(&:to_sym) + + params[:batch].map do |single_params| + create(token: token, params: single_params) end end @@ -32,6 +35,14 @@ def body(params) body = { list: list } end + + def parse(response) + if !response.body.empty? + JSON.parse(response.body, symbolize_keys: true).merge(status: response.status) + else + { status: response.status } + end + end end end end diff --git a/spec/clicksign/api/documents_signers_spec.rb b/spec/clicksign/api/documents_signers_spec.rb index 6476339..7c100b1 100644 --- a/spec/clicksign/api/documents_signers_spec.rb +++ b/spec/clicksign/api/documents_signers_spec.rb @@ -55,7 +55,7 @@ end end - it { expect(json[:list][:key]).to eq('721ff97f-83d7-44c8-92a0-7c7f287f73f6') } + it { expect(response['list']['key']).to eq('721ff97f-83d7-44c8-92a0-7c7f287f73f6') } end end end @@ -67,7 +67,7 @@ VCR.use_cassette('Clicksign::API::DocumentsSigners.create/batch-request') do described_class.batch_create( token: 'valid_token', - batch: + params: [ { document_key: '28343efd-dccb-4e7a-9989-49e792b3c266', @@ -90,9 +90,9 @@ end it do - expect(JSON.parse(response[0].body)["list"]["key"]).to eq('8c5cf01d-09d2-474c-b9a1-b4ef6bc1b603') - expect(JSON.parse(response[1].body)["list"]["key"]).to eq('4add9d39-54cb-44f3-88be-fb67ab45b0be') - expect(JSON.parse(response[2].body)["list"]["key"]).to eq('bb1a4b55-cd16-4778-b2dc-9184160026b8') + expect((response[0])['list']['key']).to eq('8c5cf01d-09d2-474c-b9a1-b4ef6bc1b603') + expect((response[1])['list']['key']).to eq('4add9d39-54cb-44f3-88be-fb67ab45b0be') + expect((response[2])['list']['key']).to eq('bb1a4b55-cd16-4778-b2dc-9184160026b8') end end end diff --git a/spec/clicksign/api_spec.rb b/spec/clicksign/api_spec.rb index 9f7ab23..6dc1043 100644 --- a/spec/clicksign/api_spec.rb +++ b/spec/clicksign/api_spec.rb @@ -1,6 +1,6 @@ RSpec.describe Clicksign::API do it 'has a version number' do - expect(Clicksign::API::VERSION).to eq('1.1.0.alpha2') + expect(Clicksign::API::VERSION).to eq('1.1.1') end describe '.configure' do From 42d2bae8f85fcedfaa61c39d6840ffb9c382b90d Mon Sep 17 00:00:00 2001 From: "renan.proenca" Date: Wed, 10 Nov 2021 12:39:49 -0300 Subject: [PATCH 2/8] Refactor of Farady response to Hash Class & Edit README.md, Unit Tests refactored --- README.md | 60 +++++--------------- lib/clicksign/api/documents_signers.rb | 15 +---- lib/clicksign/api/requests.rb | 20 ++++++- spec/clicksign/api/batch_spec.rb | 2 +- spec/clicksign/api/document_spec.rb | 12 ++-- spec/clicksign/api/documents_signers_spec.rb | 38 +++++++------ spec/clicksign/api/notifier_spec.rb | 2 +- spec/clicksign/api/signer_spec.rb | 2 +- spec/clicksign/api/whatsapp_notifier_spec.rb | 2 +- 9 files changed, 62 insertions(+), 91 deletions(-) diff --git a/README.md b/README.md index 62c71b9..6bd7877 100644 --- a/README.md +++ b/README.md @@ -54,52 +54,32 @@ To see all available parameters, please, check the [API docs](https://developers ```ruby file = File.open('/path/to/file/local/file.pdf', 'r') -document = Clicksign::API::Document.create( params: { path: '/path/to/file/on/clicksign.pdf', file: file }, token: 'valid_token') -# => # +document = Clicksign::API::Document.create( params: { path: '/path/to/file/on/clicksign.pdf', file: file }, token: "key.sandbox") +# Class Hash => {"document"=> {"key"=>"key"} -document.success? -# => true # false - -response_document = JSON.parse(document.body) -# => {:document=> {:key=> '...', :path=> '...', :status => '...', ... } ``` #### View documents ```ruby -find_document = Clicksign::API::Document.find(params: { key: response_document['document']['key'] }, token: 'valid_token') -# => # - -find_document.success? -# => true # false +find_document = Clicksign::API::Document.find(params: { key: response_document['document']['key'] }, token: "key.sandbox") +# Class Hash => {"document"=> {"key"=>"key"} -JSON.parse(find_document.body) -# => {:document=> {:key=> '...', :path=> '...', :status => '...', ... } ``` #### Create Signers ```ruby -signer = Clicksign::API::Signer.create(params: { email: 'mail@email.com', auths: ['email'], delivery: 'email' }, token: 'valid_token') -# => # - -signer.success? -# => true # false +signer = Clicksign::API::Signer.create(params: { email: 'mail@email.com', auths: ['email'], delivery: 'email' }, token: "key.sandbox") +# Class Hash => {"signer"=> {"key"=>"key"} -response_signer = JSON.parse(signer.body) -# => {:signer=> {:key=> '...', :email=> '...', ... } ``` #### Add Signers to Document ```ruby -signer_document = Clicksign::API::DocumentsSigners.create(params: { document_key: response_document['document']['key'], signer_key: response_signer['key'], sign_as: 'sign_as' }, token: 'valid_token') -# => # +signer_document = Clicksign::API::DocumentsSigners.create(params: { document_key: response_document['document']['key'], signer_key: response_signer['key'], sign_as: 'sign_as' }, token: "key.sandbox") +# Class Hash => {"list"=>{"key"=>"cc222eb2-238b-4d53-9c2f-4ff0b03912f2"} -signer_document.success? -# => true # false - -response_signer_document = JSON.parse(signer_document.body) -# => {:list=> {:key=> '...', ... } ``` ##### Creating Documents in Batches @@ -111,37 +91,25 @@ batch = Clicksign::API::Batch.create( signer_key: response_signer['key'], summary: true }, - token: 'valid_token' + token: "key.sandbox" ) -# => # -batch.success? -# => true # false +# Class Hash => {"batch"=>{"key"=>"a5060ae8-f957-4da1-b260-956338695a96"} -rseponse_batch = JSON.parse(batch.body) -# => #{"batch"=> {"key"=>"..." ``` #### Notifying Signer by e-mail ```ruby -notify = Clicksign::API::Notifier.notify(params: { request_signature_key: 'request_signature_key' }, token: 'valid_token') -# => # - -notify.success? -# => true # false +notify = Clicksign::API::Notifier.notify(params: { request_signature_key: 'request_signature_key' }, token: "key.sandbox") +# Class Hash => {:status=>202} -JSON.parse(notify.body) -# => ## # - -notify.success? -# => true # false +notify = Clicksign::API::Notifier.notify(params: { request_signature_key: 'request_signature_key' }, token: "key.sandbox") +# Class Hash => {:status=>202} ## Development diff --git a/lib/clicksign/api/documents_signers.rb b/lib/clicksign/api/documents_signers.rb index f891c38..b0eba36 100644 --- a/lib/clicksign/api/documents_signers.rb +++ b/lib/clicksign/api/documents_signers.rb @@ -10,39 +10,26 @@ class DocumentsSigners class << self def create(token:, params: {}) - response = post( + post( REQUEST_PATH, body(params), token ) - parse(response) end def batch_create(token:, params:) - params = params.transform_keys(&:to_sym) - params[:batch].map do |single_params| create(token: token, params: single_params) end end def body(params) - params = params.transform_keys(&:to_sym) - list = ATTRIBUTES.each.with_object({}) do |key, hash| hash[key] = params[key] if params.has_key?(key) end body = { list: list } end - - def parse(response) - if !response.body.empty? - JSON.parse(response.body, symbolize_keys: true).merge(status: response.status) - else - { status: response.status } - end - end end end end diff --git a/lib/clicksign/api/requests.rb b/lib/clicksign/api/requests.rb index abfabf7..2e3804f 100644 --- a/lib/clicksign/api/requests.rb +++ b/lib/clicksign/api/requests.rb @@ -2,23 +2,37 @@ module Clicksign module API module Requests def post(request_path, body, token) - conn.post do |req| + response = conn.post do |req| req.url request_path, { access_token: Clicksign::API.credentials[token] } req.headers['Content-Type'] = 'application/json' req.body = body.to_json end + + parse(response) end def get(request_path, token) - conn.get do |req| + response = conn.get do |req| req.url request_path, { access_token: Clicksign::API.credentials[token] } req.headers['Content-Type'] = 'application/json' end + + parse(response) end + + private def conn @conn ||= Faraday.new(url: Clicksign::API.url) end + + def parse(response) + if !response.body.empty? + JSON.parse(response.body, symbolize_keys: true).merge(status: response.status) + else + { status: response.status } + end + end end end -end +end \ No newline at end of file diff --git a/spec/clicksign/api/batch_spec.rb b/spec/clicksign/api/batch_spec.rb index ef1b100..abd832e 100644 --- a/spec/clicksign/api/batch_spec.rb +++ b/spec/clicksign/api/batch_spec.rb @@ -58,7 +58,7 @@ end end - it { expect(json[:batch][:key]).to eq('d98c9561-3750-4dab-a7a2-46676a148afd') } + it { expect(response['batch']['key']).to eq('d98c9561-3750-4dab-a7a2-46676a148afd') } end end end diff --git a/spec/clicksign/api/document_spec.rb b/spec/clicksign/api/document_spec.rb index d7eec76..1c682ac 100644 --- a/spec/clicksign/api/document_spec.rb +++ b/spec/clicksign/api/document_spec.rb @@ -18,7 +18,7 @@ end end - it { expect(json[:document][:key]).to eq('ae7618d4-3958-4d7d-ade3-59def0d1288d') } + it { expect(response['document']['key']).to eq('ae7618d4-3958-4d7d-ade3-59def0d1288d') } end context 'with all available parameters' do @@ -37,7 +37,7 @@ end end - it { expect(json[:document][:key]).to eq('28343efd-dccb-4e7a-9989-49e792b3c266') } + it { expect(response['document']['key']).to eq('28343efd-dccb-4e7a-9989-49e792b3c266') } end end @@ -55,7 +55,7 @@ end end - it { expect(json[:errors]).to eq(['Nome do arquivo não contém mimetype válido']) } + it { expect(response['errors']).to eq(['Nome do arquivo não contém mimetype válido']) } end end @@ -72,7 +72,7 @@ end end - it { expect(json[:errors]).to eq(['Access Token inválido']) } + it { expect(response['errors']).to eq(['Access Token inválido']) } end end @@ -89,7 +89,7 @@ end end - it { expect(json[:document][:key]).to eq('28343efd-dccb-4e7a-9989-49e792b3c266') } + it { expect(response['document']['key']).to eq('28343efd-dccb-4e7a-9989-49e792b3c266') } end context 'invalid key' do @@ -104,7 +104,7 @@ end end - it { expect(json[:errors]).to eq(['Documento não encontrado']) } + it { expect(response['errors']).to eq(['Documento não encontrado']) } end end end diff --git a/spec/clicksign/api/documents_signers_spec.rb b/spec/clicksign/api/documents_signers_spec.rb index 7c100b1..05f6251 100644 --- a/spec/clicksign/api/documents_signers_spec.rb +++ b/spec/clicksign/api/documents_signers_spec.rb @@ -67,24 +67,26 @@ VCR.use_cassette('Clicksign::API::DocumentsSigners.create/batch-request') do described_class.batch_create( token: 'valid_token', - params: - [ - { - document_key: '28343efd-dccb-4e7a-9989-49e792b3c266', - signer_key: '6fa5fc10-dcbe-4bae-a361-0350ea44fb5d', - sign_as: 'transferor' - }, - { - document_key: '28343efd-dccb-4e7a-9989-49e792b3c266', - signer_key: '6fa5fc10-dcbe-4bae-a361-0350ea44fb5d', - sign_as: 'transferee' - }, - { - document_key: '28343efd-dccb-4e7a-9989-49e792b3c266', - signer_key: '6fa5fc10-dcbe-4bae-a361-0350ea44fb5d', - sign_as: 'contractee' - } - ] + params: { + batch: + [ + { + document_key: '28343efd-dccb-4e7a-9989-49e792b3c266', + signer_key: '6fa5fc10-dcbe-4bae-a361-0350ea44fb5d', + sign_as: 'transferor' + }, + { + document_key: '28343efd-dccb-4e7a-9989-49e792b3c266', + signer_key: '6fa5fc10-dcbe-4bae-a361-0350ea44fb5d', + sign_as: 'transferee' + }, + { + document_key: '28343efd-dccb-4e7a-9989-49e792b3c266', + signer_key: '6fa5fc10-dcbe-4bae-a361-0350ea44fb5d', + sign_as: 'contractee' + } + ] + } ) end end diff --git a/spec/clicksign/api/notifier_spec.rb b/spec/clicksign/api/notifier_spec.rb index c117737..b76ada5 100644 --- a/spec/clicksign/api/notifier_spec.rb +++ b/spec/clicksign/api/notifier_spec.rb @@ -49,7 +49,7 @@ end end - it { expect(response.status).to eq(202) } + it { expect(response[:status]).to eq(202) } end end end diff --git a/spec/clicksign/api/signer_spec.rb b/spec/clicksign/api/signer_spec.rb index a71e2cc..907d883 100644 --- a/spec/clicksign/api/signer_spec.rb +++ b/spec/clicksign/api/signer_spec.rb @@ -57,7 +57,7 @@ end end - it { expect(json[:signer][:key]).to eq('6fa5fc10-dcbe-4bae-a361-0350ea44fb5d') } + it { expect(response['signer']['key']).to eq('6fa5fc10-dcbe-4bae-a361-0350ea44fb5d') } end end end diff --git a/spec/clicksign/api/whatsapp_notifier_spec.rb b/spec/clicksign/api/whatsapp_notifier_spec.rb index 819019b..02b4adf 100644 --- a/spec/clicksign/api/whatsapp_notifier_spec.rb +++ b/spec/clicksign/api/whatsapp_notifier_spec.rb @@ -47,7 +47,7 @@ end end - it { expect(response.status).to eq(202) } + it { expect(response[:status]).to eq(202) } end end end From 5bcb188c7fcdf0e3a02a42f7cf38ddd0a0aa7c21 Mon Sep 17 00:00:00 2001 From: "renan.proenca" Date: Wed, 10 Nov 2021 12:49:29 -0300 Subject: [PATCH 3/8] bump version --- lib/clicksign/api/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/clicksign/api/version.rb b/lib/clicksign/api/version.rb index f8fc8df..0917184 100644 --- a/lib/clicksign/api/version.rb +++ b/lib/clicksign/api/version.rb @@ -1,5 +1,5 @@ module Clicksign module API - VERSION = "1.1.1" + VERSION = "1.1.2" end end From 11d0b2e124a3541a43c4e3ff4b0b947fbac2787d Mon Sep 17 00:00:00 2001 From: "renan.proenca" Date: Tue, 16 Nov 2021 15:53:09 -0300 Subject: [PATCH 4/8] adjust README --- README.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 6bd7877..aded805 100644 --- a/README.md +++ b/README.md @@ -55,7 +55,7 @@ To see all available parameters, please, check the [API docs](https://developers ```ruby file = File.open('/path/to/file/local/file.pdf', 'r') document = Clicksign::API::Document.create( params: { path: '/path/to/file/on/clicksign.pdf', file: file }, token: "key.sandbox") -# Class Hash => {"document"=> {"key"=>"key"} +# => {"document"=> {"key"=>"00000000-0000-0000-0000-000000000000"} ``` @@ -63,7 +63,7 @@ document = Clicksign::API::Document.create( params: { path: '/path/to/file/on/cl ```ruby find_document = Clicksign::API::Document.find(params: { key: response_document['document']['key'] }, token: "key.sandbox") -# Class Hash => {"document"=> {"key"=>"key"} +# => {"document"=> {"key"=>"00000000-0000-0000-0000-000000000000"} ``` @@ -71,14 +71,14 @@ find_document = Clicksign::API::Document.find(params: { key: response_document[' ```ruby signer = Clicksign::API::Signer.create(params: { email: 'mail@email.com', auths: ['email'], delivery: 'email' }, token: "key.sandbox") -# Class Hash => {"signer"=> {"key"=>"key"} +# => {"signer"=> {"key"=>"00000000-0000-0000-0000-000000000000"} ``` #### Add Signers to Document ```ruby signer_document = Clicksign::API::DocumentsSigners.create(params: { document_key: response_document['document']['key'], signer_key: response_signer['key'], sign_as: 'sign_as' }, token: "key.sandbox") -# Class Hash => {"list"=>{"key"=>"cc222eb2-238b-4d53-9c2f-4ff0b03912f2"} +# => {"list"=>{"key"=>"00000000-0000-0000-0000-000000000000"} ``` @@ -94,7 +94,7 @@ batch = Clicksign::API::Batch.create( token: "key.sandbox" ) -# Class Hash => {"batch"=>{"key"=>"a5060ae8-f957-4da1-b260-956338695a96"} +# => {"batch"=>{"key"=>"00000000-0000-0000-0000-000000000000"} ``` #### Notifying Signer by e-mail From 2e59446f99dab1eb172d6dcc9470e16b7773e4eb Mon Sep 17 00:00:00 2001 From: "renan.proenca" Date: Tue, 16 Nov 2021 15:56:44 -0300 Subject: [PATCH 5/8] adjust README --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index aded805..41735c6 100644 --- a/README.md +++ b/README.md @@ -101,7 +101,7 @@ batch = Clicksign::API::Batch.create( ```ruby notify = Clicksign::API::Notifier.notify(params: { request_signature_key: 'request_signature_key' }, token: "key.sandbox") -# Class Hash => {:status=>202} +# => {:status=>202} ``` @@ -109,7 +109,7 @@ notify = Clicksign::API::Notifier.notify(params: { request_signature_key: 'reque ```ruby notify = Clicksign::API::Notifier.notify(params: { request_signature_key: 'request_signature_key' }, token: "key.sandbox") -# Class Hash => {:status=>202} +# => {:status=>202} ## Development From 70d5ce21e088bd163562631104436eb91b14dedd Mon Sep 17 00:00:00 2001 From: Lucas Garcia Date: Tue, 16 Nov 2021 18:55:26 -0300 Subject: [PATCH 6/8] Release 1.1.2.alpha --- Gemfile.lock | 2 +- lib/clicksign/api/version.rb | 2 +- spec/clicksign/api_spec.rb | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index fcf8f30..17281ed 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - clicksign-api (1.1.1) + clicksign-api (1.1.2.alpha) faraday GEM diff --git a/lib/clicksign/api/version.rb b/lib/clicksign/api/version.rb index 0917184..c4a58d3 100644 --- a/lib/clicksign/api/version.rb +++ b/lib/clicksign/api/version.rb @@ -1,5 +1,5 @@ module Clicksign module API - VERSION = "1.1.2" + VERSION = "1.1.2.alpha" end end diff --git a/spec/clicksign/api_spec.rb b/spec/clicksign/api_spec.rb index 6dc1043..3afeec0 100644 --- a/spec/clicksign/api_spec.rb +++ b/spec/clicksign/api_spec.rb @@ -1,6 +1,6 @@ RSpec.describe Clicksign::API do it 'has a version number' do - expect(Clicksign::API::VERSION).to eq('1.1.1') + expect(Clicksign::API::VERSION).to eq('1.1.2.alpha') end describe '.configure' do From 090806787367162e16a53156b2ca1385658d1adc Mon Sep 17 00:00:00 2001 From: "renan.proenca" Date: Thu, 25 Nov 2021 15:19:57 -0300 Subject: [PATCH 7/8] JSON Signer --- Gemfile.lock | 2 +- lib/clicksign/api/documents_signers.rb | 4 ++++ spec/clicksign/api_spec.rb | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index fcf8f30..ff0d0b6 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - clicksign-api (1.1.1) + clicksign-api (1.1.2) faraday GEM diff --git a/lib/clicksign/api/documents_signers.rb b/lib/clicksign/api/documents_signers.rb index b0eba36..0fb24e3 100644 --- a/lib/clicksign/api/documents_signers.rb +++ b/lib/clicksign/api/documents_signers.rb @@ -18,12 +18,16 @@ def create(token:, params: {}) end def batch_create(token:, params:) + params = params.transform_keys(&:to_sym) + params[:batch].map do |single_params| create(token: token, params: single_params) end end def body(params) + params = params.transform_keys(&:to_sym) + list = ATTRIBUTES.each.with_object({}) do |key, hash| hash[key] = params[key] if params.has_key?(key) end diff --git a/spec/clicksign/api_spec.rb b/spec/clicksign/api_spec.rb index 6dc1043..c5b0b19 100644 --- a/spec/clicksign/api_spec.rb +++ b/spec/clicksign/api_spec.rb @@ -1,6 +1,6 @@ RSpec.describe Clicksign::API do it 'has a version number' do - expect(Clicksign::API::VERSION).to eq('1.1.1') + expect(Clicksign::API::VERSION).to eq('1.1.2') end describe '.configure' do From 1a55ba5c480b7bdb724fc3c542520a5d9556232d Mon Sep 17 00:00:00 2001 From: Lucas Garcia Date: Thu, 9 Dec 2021 11:12:13 -0300 Subject: [PATCH 8/8] Release 1.1.3.alpha --- Gemfile.lock | 2 +- lib/clicksign/api/version.rb | 2 +- spec/clicksign/api_spec.rb | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 2cd6609..473866d 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - clicksign-api (1.1.2.alpha) + clicksign-api (1.1.3.alpha) faraday GEM diff --git a/lib/clicksign/api/version.rb b/lib/clicksign/api/version.rb index c4a58d3..fd5ae11 100644 --- a/lib/clicksign/api/version.rb +++ b/lib/clicksign/api/version.rb @@ -1,5 +1,5 @@ module Clicksign module API - VERSION = "1.1.2.alpha" + VERSION = "1.1.3.alpha" end end diff --git a/spec/clicksign/api_spec.rb b/spec/clicksign/api_spec.rb index 3afeec0..516a347 100644 --- a/spec/clicksign/api_spec.rb +++ b/spec/clicksign/api_spec.rb @@ -1,6 +1,6 @@ RSpec.describe Clicksign::API do it 'has a version number' do - expect(Clicksign::API::VERSION).to eq('1.1.2.alpha') + expect(Clicksign::API::VERSION).to eq('1.1.3.alpha') end describe '.configure' do