assiname 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.rubocop.yml +23 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +38 -0
- data/Rakefile +1 -0
- data/assiname.gemspec +26 -0
- data/lib/AssinaMe/sdk.rb +162 -0
- data/lib/AssinaMe/sdk_error.rb +4 -0
- data/lib/AssinaMe/sdk_exception.rb +4 -0
- data/lib/AssinaMe/version.rb +3 -0
- data/lib/assiname.rb +8 -0
- metadata +110 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 1881ae3d4a9b2efafcd4945c0aacb6ad2e5d65ed
|
4
|
+
data.tar.gz: e4d7ff7c0973b1540dde7de631a32bad59c7e134
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 735cd9878cdff760d43a59d7f3fe9528468f9e5a39d8c36ba3045b598b6178fb9f636b9151d764d1ff34d64580e940a961ac57dda8b534533ae57c27d9880de7
|
7
|
+
data.tar.gz: ebbd92a02b37f5fd0a4452b86c0364ed59a37649a7ccdbb6ec6d7bf524aab66ad9bee41ec48c359d0d6d57553b6393fe1e1c24a40b3de07c206baf15572748bd
|
data/.rubocop.yml
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
Style/FrozenStringLiteralComment:
|
2
|
+
Enabled: false
|
3
|
+
|
4
|
+
AllCops:
|
5
|
+
Include:
|
6
|
+
- '**/Rakefile'
|
7
|
+
- '**/config.ru'
|
8
|
+
Exclude:
|
9
|
+
- 'bin/*'
|
10
|
+
- 'db/**/*'
|
11
|
+
- 'config/**/*'
|
12
|
+
- 'script/**/*'
|
13
|
+
- !ruby/regexp /old_and_unused\.rb$/
|
14
|
+
TargetRubyVersion: 2.4
|
15
|
+
|
16
|
+
Rails:
|
17
|
+
Enabled: true
|
18
|
+
|
19
|
+
Metrics/LineLength:
|
20
|
+
Max: 120
|
21
|
+
|
22
|
+
Documentation:
|
23
|
+
Enabled: false
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
assiname (0.1.0)
|
5
|
+
multi_json (~> 1.12)
|
6
|
+
rest-client (~> 2.0)
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
domain_name (0.5.20170404)
|
12
|
+
unf (>= 0.0.5, < 1.0.0)
|
13
|
+
http-cookie (1.0.3)
|
14
|
+
domain_name (~> 0.5)
|
15
|
+
mime-types (3.1)
|
16
|
+
mime-types-data (~> 3.2015)
|
17
|
+
mime-types-data (3.2016.0521)
|
18
|
+
multi_json (1.12.2)
|
19
|
+
netrc (0.11.0)
|
20
|
+
rake (10.5.0)
|
21
|
+
rest-client (2.0.2)
|
22
|
+
http-cookie (>= 1.0.2, < 2.0)
|
23
|
+
mime-types (>= 1.16, < 4.0)
|
24
|
+
netrc (~> 0.8)
|
25
|
+
unf (0.1.4)
|
26
|
+
unf_ext
|
27
|
+
unf_ext (0.0.7.4)
|
28
|
+
|
29
|
+
PLATFORMS
|
30
|
+
ruby
|
31
|
+
|
32
|
+
DEPENDENCIES
|
33
|
+
assiname!
|
34
|
+
bundler (~> 1.7)
|
35
|
+
rake (~> 10.0)
|
36
|
+
|
37
|
+
BUNDLED WITH
|
38
|
+
1.16.0
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'bundler/gem_tasks'
|
data/assiname.gemspec
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
source = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(source) unless $LOAD_PATH.include?(source)
|
4
|
+
require 'AssinaMe/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'assiname'
|
8
|
+
spec.version = AssinaMe::VERSION
|
9
|
+
spec.authors = ['Flavio Heleno']
|
10
|
+
spec.email = ['flavio@libercapital.com.br']
|
11
|
+
spec.summary = %q{Write a short summary. Required.}
|
12
|
+
spec.description = %q{Write a longer description. Optional.}
|
13
|
+
spec.homepage = 'https://www.assina.me/'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ['lib']
|
20
|
+
|
21
|
+
spec.add_development_dependency 'bundler', '~> 1.7'
|
22
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
23
|
+
|
24
|
+
spec.add_dependency 'rest-client', '~> 2.0'
|
25
|
+
spec.add_dependency 'multi_json', '~> 1.12'
|
26
|
+
end
|
data/lib/AssinaMe/sdk.rb
ADDED
@@ -0,0 +1,162 @@
|
|
1
|
+
require 'uri'
|
2
|
+
require 'rest_client'
|
3
|
+
require 'multi_json'
|
4
|
+
|
5
|
+
module AssinaMe
|
6
|
+
class SDK
|
7
|
+
attr_reader :base_url
|
8
|
+
|
9
|
+
def initialize(apikey, base_url = nil)
|
10
|
+
@apikey = apikey
|
11
|
+
|
12
|
+
@base_url = 'https://api.assina.me/v1'
|
13
|
+
|
14
|
+
@base_url = base_url unless base_url.nil?
|
15
|
+
end
|
16
|
+
|
17
|
+
def base_url=(base_url)
|
18
|
+
base_url[-1, base_url.length - 1] if base_url[-1, 1] == '/'
|
19
|
+
|
20
|
+
@base_url = base_url
|
21
|
+
end
|
22
|
+
|
23
|
+
def pdf_setup(setup)
|
24
|
+
response = send_post(
|
25
|
+
'/pdf',
|
26
|
+
nil,
|
27
|
+
setup
|
28
|
+
)
|
29
|
+
|
30
|
+
raise(AssinaMe::SDKException, 'Invalid API response format') if !response.is_a?(Hash)
|
31
|
+
|
32
|
+
raise(AssinaMe::SDKException, 'API response does not contain "document_token"') if response['document_token'].to_s.empty?
|
33
|
+
|
34
|
+
response['document_token']
|
35
|
+
end
|
36
|
+
|
37
|
+
def pdf_upload(document_token, original_file_path)
|
38
|
+
file = open(original_file_path, 'rb')
|
39
|
+
response = send_put(
|
40
|
+
"/pdf/#{document_token}/file",
|
41
|
+
nil,
|
42
|
+
file,
|
43
|
+
{ 'Content-Type': 'application/pdf' }
|
44
|
+
)
|
45
|
+
|
46
|
+
raise(AssinaMe::SDKException, 'Invalid API response format') if !response.is_a?(Hash)
|
47
|
+
end
|
48
|
+
|
49
|
+
def pdf_create(setup, original_file_path)
|
50
|
+
document_token = pdf_setup(setup)
|
51
|
+
pdf_upload(document_token, original_file_path)
|
52
|
+
|
53
|
+
document_token
|
54
|
+
end
|
55
|
+
|
56
|
+
def pdf_status(document_token)
|
57
|
+
response = send_get('/pdf/' + document_token)
|
58
|
+
|
59
|
+
raise(AssinaMe::SDKException, 'Invalid API response format') if !response.is_a?(Hash)
|
60
|
+
|
61
|
+
response
|
62
|
+
end
|
63
|
+
|
64
|
+
def pdf_download(document_token, signed_file_path)
|
65
|
+
response = send_get(
|
66
|
+
"/pdf/#{document_token}/file",
|
67
|
+
nil,
|
68
|
+
{ 'Accept': 'application/pdf' }
|
69
|
+
)
|
70
|
+
|
71
|
+
raise(AssinaMe::SDKException, 'Invalid API response') if response.empty?
|
72
|
+
|
73
|
+
open(signed_file_path, 'w:ASCII-8BIT') do |file|
|
74
|
+
file.puts(response)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
private
|
79
|
+
|
80
|
+
def send_get(uri, query = nil, headers = nil)
|
81
|
+
uri = '/' + uri if uri[0, 1] != '/'
|
82
|
+
|
83
|
+
send_request(
|
84
|
+
'GET',
|
85
|
+
uri,
|
86
|
+
query,
|
87
|
+
nil,
|
88
|
+
headers
|
89
|
+
)
|
90
|
+
end
|
91
|
+
|
92
|
+
def send_post(uri, query = nil, body = nil, headers = nil)
|
93
|
+
send_request(
|
94
|
+
'POST',
|
95
|
+
uri,
|
96
|
+
query,
|
97
|
+
body,
|
98
|
+
headers
|
99
|
+
)
|
100
|
+
end
|
101
|
+
|
102
|
+
def send_put(uri, query = nil, body = nil, headers = nil)
|
103
|
+
send_request(
|
104
|
+
'PUT',
|
105
|
+
uri,
|
106
|
+
query,
|
107
|
+
body,
|
108
|
+
headers
|
109
|
+
)
|
110
|
+
end
|
111
|
+
|
112
|
+
def send_request(method, uri, query, body, headers)
|
113
|
+
default_headers = {
|
114
|
+
'Content-Type': 'application/json; charset=utf-8',
|
115
|
+
Authorization: "Bearer #{@apikey}"
|
116
|
+
}
|
117
|
+
|
118
|
+
body = MultiJson.dump(body) if !body.nil? && body.is_a?(Hash)
|
119
|
+
|
120
|
+
default_headers.merge!(headers) if !headers.nil? && headers.is_a?(Object)
|
121
|
+
|
122
|
+
begin
|
123
|
+
response = RestClient::Request.execute(
|
124
|
+
method: method,
|
125
|
+
url: @base_url + uri,
|
126
|
+
payload: body,
|
127
|
+
open_timeout: 30,
|
128
|
+
timeout: 90,
|
129
|
+
headers: default_headers
|
130
|
+
)
|
131
|
+
rescue RestClient::Exception => exception
|
132
|
+
raise(AssinaMe::SDKError, exception.message)
|
133
|
+
end
|
134
|
+
|
135
|
+
if response.headers.key?(:content_type)
|
136
|
+
content_type = response.headers[:content_type]
|
137
|
+
|
138
|
+
if content_type[%r{^application\/json}]
|
139
|
+
begin
|
140
|
+
json = MultiJson.load(response.body)
|
141
|
+
rescue MultiJson::DecodeError
|
142
|
+
raise(AssinaMe::SDKException, 'Invalid API response format')
|
143
|
+
end
|
144
|
+
|
145
|
+
if json['status'].to_s.empty? || json['status'].to_s == 'false'
|
146
|
+
raise(AssinaMe::SDKException, json['reason']) if !json['reason'].to_s.empty?
|
147
|
+
|
148
|
+
raise(AssinaMe::SDKException, json['message']) if !json['message'].to_s.empty?
|
149
|
+
|
150
|
+
raise(AssinaMe::SDKException, 'Unknown SDK exception') if json['exception'].to_s.empty?
|
151
|
+
|
152
|
+
raise(AssinaMe::SDKException, json['exception'])
|
153
|
+
end
|
154
|
+
|
155
|
+
return json
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
159
|
+
response.body
|
160
|
+
end
|
161
|
+
end
|
162
|
+
end
|
data/lib/assiname.rb
ADDED
metadata
ADDED
@@ -0,0 +1,110 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: assiname
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Flavio Heleno
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-12-12 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.7'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.7'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rest-client
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '2.0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '2.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: multi_json
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.12'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.12'
|
69
|
+
description: Write a longer description. Optional.
|
70
|
+
email:
|
71
|
+
- flavio@libercapital.com.br
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".rubocop.yml"
|
77
|
+
- Gemfile
|
78
|
+
- Gemfile.lock
|
79
|
+
- Rakefile
|
80
|
+
- assiname.gemspec
|
81
|
+
- lib/AssinaMe/sdk.rb
|
82
|
+
- lib/AssinaMe/sdk_error.rb
|
83
|
+
- lib/AssinaMe/sdk_exception.rb
|
84
|
+
- lib/AssinaMe/version.rb
|
85
|
+
- lib/assiname.rb
|
86
|
+
homepage: https://www.assina.me/
|
87
|
+
licenses:
|
88
|
+
- MIT
|
89
|
+
metadata: {}
|
90
|
+
post_install_message:
|
91
|
+
rdoc_options: []
|
92
|
+
require_paths:
|
93
|
+
- lib
|
94
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
95
|
+
requirements:
|
96
|
+
- - ">="
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: '0'
|
99
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
requirements: []
|
105
|
+
rubyforge_project:
|
106
|
+
rubygems_version: 2.6.13
|
107
|
+
signing_key:
|
108
|
+
specification_version: 4
|
109
|
+
summary: Write a short summary. Required.
|
110
|
+
test_files: []
|