clicksign-api 0.0.1 → 0.0.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8951f7e1a735d417e2c3b1222c30d294ad1b5d7828dd58c0edc816b5f0eabce9
4
- data.tar.gz: 0713e52399d0df6a4a3220a150c9becf036ae651842a6e6564563c082aa7cffb
3
+ metadata.gz: 2777702010e8d1b6f61ea61f8071ee606402eab0e59b564ec69ae44a45b6a01f
4
+ data.tar.gz: dda577cc3c773b0cea505f5e6b5b34386a83c9bd50aba0b21b6365f4b2243b10
5
5
  SHA512:
6
- metadata.gz: 2fbca1cbd757be3603bfc71af4fac36133fd41c2556e6f7175c3cbfca654a9a5654a655b82df919f48115cde2d60899299be24b79c8d8906c349a6d1a6ba681f
7
- data.tar.gz: db8bb93dd9e9a0221bea7ef5c2a6f1543a95fcd3d054813d33c1562fa9d4a784c9c1006c22817d2c0485a34f9558ca6bd33fdad5517cf6c4a6926b298ce0a613
6
+ metadata.gz: d8e9b189731f2a2f1be1cdd1b5866ba3bc12fa06446e889aab435a224a648274beaa70353d38a686ebe6f4e9bebb006f15a8fea1347138638b6e18e4ea516e9d
7
+ data.tar.gz: aefd81b8384d2ec24910eca65f38ebdc38dc42de5e9ef284a36811f723766ca6a9e1ddffb8a8589de76a6a57e4d880c6c5e343cf466d6c23381401f8b071ffc2
data/.gitignore CHANGED
@@ -10,3 +10,4 @@
10
10
  # rspec failure tracking
11
11
  .rspec_status
12
12
  .env
13
+ .byebug_history
data/.rspec CHANGED
@@ -1,3 +1,3 @@
1
- --format documentation
1
+ --format progress
2
2
  --color
3
3
  --require spec_helper
@@ -3,5 +3,13 @@ sudo: false
3
3
  language: ruby
4
4
  cache: bundler
5
5
  rvm:
6
- - 2.4.4
6
+ - 2.5.3
7
7
  before_install: gem install bundler -v 1.16.6
8
+ before_script:
9
+ - curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
10
+ - chmod +x ./cc-test-reporter
11
+ - ./cc-test-reporter before-build
12
+ script:
13
+ - bundle exec rspec
14
+ after_script:
15
+ - ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- clicksign-api (0.0.1)
4
+ clicksign-api (0.0.2)
5
5
  faraday
6
6
 
7
7
  GEM
@@ -15,7 +15,7 @@ GEM
15
15
  diff-lcs (1.3)
16
16
  docile (1.3.1)
17
17
  dotenv (2.5.0)
18
- faraday (0.12.2)
18
+ faraday (0.15.4)
19
19
  multipart-post (>= 1.2, < 3)
20
20
  hashdiff (0.3.7)
21
21
  json (2.1.0)
@@ -62,4 +62,4 @@ DEPENDENCIES
62
62
  webmock (~> 3.0)
63
63
 
64
64
  BUNDLED WITH
65
- 1.16.6
65
+ 1.17.3
data/README.md CHANGED
@@ -1,8 +1,9 @@
1
1
  # Clicksign::Api
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/clicksign/api`. To experiment with that code, run `bin/console` for an interactive prompt.
4
-
5
- TODO: Delete this and the text above, and describe your gem
3
+ [![Gem Version](https://badge.fury.io/rb/clicksign-api.svg)](https://badge.fury.io/rb/clicksign-api)
4
+ [![Build Status](https://travis-ci.org/NexoosBR/clicksign-api.svg?branch=master)](https://travis-ci.org/NexoosBR/clicksign-api)
5
+ [![Maintainability](https://api.codeclimate.com/v1/badges/7e4c11dd4129d37ee34c/maintainability)](https://codeclimate.com/github/NexoosBR/clicksign-api/maintainability)
6
+ [![Test Coverage](https://api.codeclimate.com/v1/badges/7e4c11dd4129d37ee34c/test_coverage)](https://codeclimate.com/github/NexoosBR/clicksign-api/test_coverage)
6
7
 
7
8
  ## Installation
8
9
 
@@ -20,9 +21,67 @@ Or install it yourself as:
20
21
 
21
22
  $ gem install clicksign-api
22
23
 
23
- ## Usage
24
+ ## Setup:
25
+
26
+ By default, all requests use Clicksign's SANDBOX.
27
+
28
+ ```ruby
29
+ Clicksign::API.configure do |config|
30
+ config.access_token = ENV['CLICKSIGN_ACCESS_TOKEN']
31
+ end
32
+ ```
33
+
34
+ To use PRODUCTION environment, you have to setup:
35
+
36
+ ```ruby
37
+ Clicksign::API.configure do |config|
38
+ config.access_token = ENV['CLICKSIGN_ACCESS_TOKEN']
39
+ config.production = true
40
+ end
41
+ ```
42
+
43
+ ## Usage:
44
+
45
+ To see all available parameters, please, check the [API docs](https://developers.clicksign.com/docs/informacoes-gerais).
46
+
47
+ #### Create documents
48
+
49
+ ```ruby
50
+ response = Clicksign::API::Document.create(path: '/path/to/file.pdf', file: file)
51
+ => #<Faraday::Response ...>
52
+
53
+ response.success?
54
+ => true # false
55
+
56
+ JSON.parse(response.body)
57
+ => {:document=> {:key=> '...', :path=> '...', :status => '...', ... }
58
+ ```
59
+
60
+ #### View documents
61
+
62
+ ```ruby
63
+ response = Clicksign::API::Document.find('DOCUMENT_KEY')
64
+ => #<Faraday::Response ...>
65
+
66
+ response.success?
67
+ => true # false
24
68
 
25
- TODO: Write usage instructions here
69
+ JSON.parse(response.body)
70
+ => {:document=> {:key=> '...', :path=> '...', :status => '...', ... }
71
+ ```
72
+
73
+ #### Add signers
74
+
75
+ ```ruby
76
+ response = Clicksign::API::Signer.create('DOCUMENT_KEY', signer)
77
+ => #<Faraday::Response ...>
78
+
79
+ response.success?
80
+ => true # false
81
+
82
+ JSON.parse(response.body)
83
+ => {:document=> {:key=> '...', :path=> '...', :status => '...', ... }
84
+ ```
26
85
 
27
86
  ## Development
28
87
 
@@ -11,6 +11,8 @@ end
11
11
 
12
12
  require "clicksign/api/requests"
13
13
  require "clicksign/api/document"
14
+ require "clicksign/api/signer"
15
+ require "clicksign/api/notifier"
14
16
 
15
17
 
16
18
  module Clicksign
@@ -3,31 +3,29 @@ module Clicksign
3
3
  class Document
4
4
  extend Requests
5
5
 
6
- class << self
7
- def create(path:, file:, signers: nil, deadline_at: nil, auto_close: nil, locale: nil)
8
- content_base64 = Base64.encode64(File.read(file))
9
-
10
- body = { document: {
11
- path: path,
12
- content_base64: "data:application/pdf;base64,#{content_base64}"
13
- } }
6
+ REQUEST_PATH = '/api/v1/documents/'
7
+ ATTRIBUTES = [:path, :deadline_at, :auto_close, :locale, :signers]
14
8
 
15
- body.merge!(deadline_at: deadline_at) unless deadline_at.nil?
16
- body.merge!(auto_close: auto_close) unless auto_close.nil?
17
- body.merge!(locale: locale) unless locale.nil?
18
- body.merge!(signers: signers) unless signers.nil?
19
-
20
- request_path = '/api/v1/documents'
9
+ class << self
10
+ def create(params = {})
11
+ post(REQUEST_PATH, body(params))
12
+ end
21
13
 
22
- response = post(request_path, body)
14
+ def find(key)
15
+ get(REQUEST_PATH + key)
16
+ end
23
17
 
24
- json = JSON.parse(response.body, symbolize_names: true)
18
+ def body(params)
19
+ document = ATTRIBUTES.each.with_object({}) do |attribute, hash|
20
+ hash[attribute] = params[attribute] if params.has_key?(attribute)
21
+ end
25
22
 
26
- if response.success?
27
- json[:document]
28
- else
29
- json[:errors]
23
+ if params.has_key?(:file)
24
+ content_base64 = Base64.encode64(File.read(params[:file]))
25
+ document[:content_base64] = "data:application/pdf;base64,#{content_base64}"
30
26
  end
27
+
28
+ body = { document: document }
31
29
  end
32
30
  end
33
31
  end
@@ -0,0 +1,31 @@
1
+ module Clicksign
2
+ module API
3
+ class Notifier
4
+ extend Requests
5
+
6
+ REQUEST_PATH = '/api/v1/signers/:key/notify'
7
+ ATTRIBUTES = [:message]
8
+
9
+ class << self
10
+ def notify(document_key, params = {})
11
+ post(
12
+ path_for(document_key),
13
+ body(params)
14
+ )
15
+ end
16
+
17
+ def path_for(document_key)
18
+ REQUEST_PATH.dup.tap do |path|
19
+ path[':key'] = document_key
20
+ end
21
+ end
22
+
23
+ def body(params)
24
+ ATTRIBUTES.each.with_object({}) do |attribute, hash|
25
+ hash[attribute] = params[attribute] if params.has_key?(attribute)
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -9,6 +9,13 @@ module Clicksign
9
9
  end
10
10
  end
11
11
 
12
+ def get(request_path)
13
+ conn.get do |req|
14
+ req.url request_path, { access_token: Clicksign::API.access_token }
15
+ req.headers['Content-Type'] = 'application/json'
16
+ end
17
+ end
18
+
12
19
  def conn
13
20
  @conn ||= Faraday.new(url: Clicksign::API.url)
14
21
  end
@@ -0,0 +1,38 @@
1
+ module Clicksign
2
+ module API
3
+ class Signer
4
+ extend Requests
5
+
6
+ REQUEST_PATH = '/api/v1/documents/:key/signers/'
7
+ ATTRIBUTES = [
8
+ :email, :sign_as, :auths, :name, :documentation, :birthday,
9
+ :has_documentation, :phone_number, :send_email, :message, :url
10
+ ]
11
+
12
+ class << self
13
+ def create(document_key, *params)
14
+ post(
15
+ path_for(document_key),
16
+ body(params)
17
+ )
18
+ end
19
+
20
+ def path_for(document_key)
21
+ REQUEST_PATH.dup.tap do |path|
22
+ path[':key'] = document_key
23
+ end
24
+ end
25
+
26
+ def body(params)
27
+ signers = params.map do |signer_params|
28
+ ATTRIBUTES.each.with_object({}) do |key, hash|
29
+ hash[key] = signer_params[key] if signer_params.has_key?(key)
30
+ end
31
+ end
32
+
33
+ body = { signers: signers }
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
@@ -1,5 +1,5 @@
1
1
  module Clicksign
2
2
  module Api
3
- VERSION = "0.0.1"
3
+ VERSION = "0.0.2"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: clicksign-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Francisco Martins
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-10-24 00:00:00.000000000 Z
11
+ date: 2019-01-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -143,7 +143,6 @@ executables: []
143
143
  extensions: []
144
144
  extra_rdoc_files: []
145
145
  files:
146
- - ".byebug_history"
147
146
  - ".env.example"
148
147
  - ".gitignore"
149
148
  - ".rspec"
@@ -159,7 +158,9 @@ files:
159
158
  - clicksign-api.gemspec
160
159
  - lib/clicksign/api.rb
161
160
  - lib/clicksign/api/document.rb
161
+ - lib/clicksign/api/notifier.rb
162
162
  - lib/clicksign/api/requests.rb
163
+ - lib/clicksign/api/signer.rb
163
164
  - lib/clicksign/api/version.rb
164
165
  homepage: https://github.com/NexoosBR/clicksign-api
165
166
  licenses: []
@@ -180,7 +181,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
180
181
  version: '0'
181
182
  requirements: []
182
183
  rubyforge_project:
183
- rubygems_version: 2.7.7
184
+ rubygems_version: 2.7.6
184
185
  signing_key:
185
186
  specification_version: 4
186
187
  summary: Clicksign API ruby interface
@@ -1,162 +0,0 @@
1
- exit
2
- json[:errors]
3
- response.status
4
- response.success?
5
- response.status
6
- raise json[:errors].join(', ')
7
- json[:errors].join(', ')
8
- json
9
- json[:errors].json(', ')
10
- json
11
- response
12
- OpenStruct.new(json[:errors])
13
- OpenStruct
14
- OpenScruct.new json[:errors]
15
- json[:errors]
16
- json
17
- document = OpenStruct.new(json[:errors])
18
- json
19
- exit
20
- response.success?
21
- response.success
22
- json
23
- d.key
24
- d = OpenStruct.new(json[:document])
25
- json = JSON.parse(response.body, symbolize_names: true)
26
- JSON.parse(response.body, symbolize_names: true)
27
- response.body
28
- response
29
- exit
30
- response
31
- exit
32
- response
33
- exit
34
- response
35
- exit
36
- response
37
- exit
38
- response
39
- exit
40
- response
41
- exit
42
- nil.nil?
43
- nil.present?
44
- hash
45
- hash.merge!(foo: 'bar')
46
- hash
47
- hash.merge(foo: 'bar')
48
- hash = {}
49
- body
50
- body.merge(deadline_at: deadline_at) if deadline_at
51
- exit
52
- response
53
- respone
54
- exit
55
- end
56
- req.body = body.to_json
57
- req.headers['Content-Type'] = 'application/json'
58
- req.url request_path
59
- conn.post do |req|
60
- end
61
- req.body = body.to_json
62
- req.headers['Content-Type'] = 'application/json'
63
- req.url url
64
- conn.post do |req|
65
- body.to_json
66
- end
67
- req.body = body
68
- req.headers['Content-Type'] = 'application/json'
69
- req.url url
70
- conn.post do |req|
71
- end
72
- request.body = body
73
- request.headers['Content-Type'] = 'application/json'
74
- request.url url
75
- conn.post do |request|
76
- url
77
- exit
78
- end
79
- request.body = body
80
- request.headers['Content-Type'] = 'application/json'
81
- request.url url
82
- conn.post do |request|
83
- end
84
- request.body = body
85
- request.headers['Content-Type'] = 'application/json'
86
- request.url url
87
- conn.post do |request|
88
- conn
89
- end
90
- request.body = body
91
- headers['Content-Type'] = 'application/json'
92
- request.url url
93
- conn.post do |request|
94
- end
95
- request.body = body
96
- headers['Content-Type'] = 'application/json'
97
- request.url url
98
- conn.post do |request|
99
- end
100
- request.body = body
101
- headers['Content-Type'] = 'application/json'
102
- request.url "/api/v1/documents?access_token=#{Clicksign::API.access_token}"
103
- conn.post do |request|
104
- body
105
- exit
106
- body
107
- exit
108
- }
109
- locale: 'pt-BR',
110
- auto_close: true,
111
- deadline_at: '24/10/2018',
112
- content_base64: content_base64,
113
- path: '/teste',
114
- }body = {
115
- locale: 'pt-BR',
116
- auto_close: true,
117
- deadline_at: '24/10/2018',
118
- content_base64: content_base64,
119
- path: '/teste',
120
- body = {
121
- 1
122
- end
123
- }
124
- locale: 'pt-BR',
125
- auto_close: true,
126
- deadline_at: '24/10/2018',
127
- content_base64: content_base64,
128
- path: '/teste',
129
- request.body = {
130
- headers['Content-Type'] = 'application/json'
131
- request.url "/api/v1/documents?access_token=#{Clicksign::API.access_token}"
132
- conn.post do |request|
133
- Clicksign::API.access_token
134
- exit
135
- Clicksign::API.access_token
136
- exit
137
- Clicksign::API.access_token
138
- conn
139
- encoded_file
140
- exit
141
- Base64.decode64 encoded_file
142
- Base64.decode64encoded_file
143
- encoded_file
144
- exit
145
- Clicksign::API.url
146
- conn ||= Faraday.new(url: Clicksign::API.url)
147
- conn
148
- end
149
- @conn ||= Faraday.new(url: Clicksign::API.url)
150
- def conn
151
- conn
152
- Base64.decode64(encoded)
153
- encoded = Base64.encode64 File.read(file)conn
154
- Base64.encode64 File.read(file)
155
- File.exist? file
156
- Base64.encode64 File.open(file)
157
- Base64.encode64 File.open(path)
158
- Base64.encode64 file.open
159
- Base64.encode64 file
160
- require 'base64'
161
- block
162
- file