Skip to content
This repository was archived by the owner on Jan 17, 2024. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
clicksign-api (1.1.1)
clicksign-api (1.1.3.alpha)
faraday

GEM
Expand Down Expand Up @@ -56,7 +56,7 @@ GEM
rspec-mocks (3.10.2)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.10.0)
rspec-support (3.10.2)
rspec-support (3.10.3)
ruby2_keywords (0.0.5)
simplecov (0.21.2)
docile (~> 1.1)
Expand All @@ -71,7 +71,6 @@ GEM
hashdiff (>= 0.4.0, < 2.0.0)

PLATFORMS
x86_64-darwin-20
x86_64-linux

DEPENDENCIES
Expand Down
60 changes: 14 additions & 46 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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')
# => #<Faraday::Response ...>
document = Clicksign::API::Document.create( params: { path: '/path/to/file/on/clicksign.pdf', file: file }, token: "key.sandbox")
# => {"document"=> {"key"=>"00000000-0000-0000-0000-000000000000"}

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')
# => #<Faraday::Response ...>

find_document.success?
# => true # false
find_document = Clicksign::API::Document.find(params: { key: response_document['document']['key'] }, token: "key.sandbox")
# => {"document"=> {"key"=>"00000000-0000-0000-0000-000000000000"}

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')
# => #<Faraday::Response ...>

signer.success?
# => true # false
signer = Clicksign::API::Signer.create(params: { email: 'mail@email.com', auths: ['email'], delivery: 'email' }, token: "key.sandbox")
# => {"signer"=> {"key"=>"00000000-0000-0000-0000-000000000000"}

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')
# => #<Faraday::Response ...>
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")
# => {"list"=>{"key"=>"00000000-0000-0000-0000-000000000000"}

signer_document.success?
# => true # false

response_signer_document = JSON.parse(signer_document.body)
# => {:list=> {:key=> '...', ... }
```

##### Creating Documents in Batches
Expand All @@ -111,37 +91,25 @@ batch = Clicksign::API::Batch.create(
signer_key: response_signer['key'],
summary: true
},
token: 'valid_token'
token: "key.sandbox"
)
# => #<Faraday::Response ...>

batch.success?
# => true # false
# => {"batch"=>{"key"=>"00000000-0000-0000-0000-000000000000"}

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')
# => #<Faraday::Response ...>

notify.success?
# => true # false
notify = Clicksign::API::Notifier.notify(params: { request_signature_key: 'request_signature_key' }, token: "key.sandbox")
# => {:status=>202}

JSON.parse(notify.body)
# => ##<struct Faraday::Env, method=:post request_body="{\"request_signature_key\":
```

#### Notifying Signer by whatsapp

```ruby
notify = Clicksign::API::Notifier.notify(params: { request_signature_key: 'request_signature_key' }, token: 'valid_token')
# => #<Faraday::Response ...>

notify.success?
# => true # false
notify = Clicksign::API::Notifier.notify(params: { request_signature_key: 'request_signature_key' }, token: "key.sandbox")
# => {:status=>202}

## Development

Expand Down
8 changes: 5 additions & 3 deletions lib/clicksign/api/documents_signers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@ def create(token:, params: {})
)
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

Expand Down
20 changes: 17 additions & 3 deletions lib/clicksign/api/requests.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion lib/clicksign/api/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module Clicksign
module API
VERSION = "1.1.1"
VERSION = "1.1.3.alpha"
end
end
2 changes: 1 addition & 1 deletion spec/clicksign/api/batch_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions spec/clicksign/api/document_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand All @@ -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

Expand All @@ -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

Expand All @@ -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
Expand All @@ -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
46 changes: 24 additions & 22 deletions spec/clicksign/api/documents_signers_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -67,32 +67,34 @@
VCR.use_cassette('Clicksign::API::DocumentsSigners.create/batch-request') do
described_class.batch_create(
token: 'valid_token',
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'
}
]
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

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
Expand Down
2 changes: 1 addition & 1 deletion spec/clicksign/api/notifier_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
end
end

it { expect(response.status).to eq(202) }
it { expect(response[:status]).to eq(202) }
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/clicksign/api/signer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion spec/clicksign/api/whatsapp_notifier_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
end
end

it { expect(response.status).to eq(202) }
it { expect(response[:status]).to eq(202) }
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/clicksign/api_spec.rb
Original file line number Diff line number Diff line change
@@ -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.3.alpha')
end

describe '.configure' do
Expand Down