esignatur 1.0.0 → 1.1.0
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 +5 -5
- data/Gemfile +4 -2
- data/Gemfile.lock +1 -1
- data/README.md +12 -5
- data/lib/esignatur/api.rb +8 -2
- data/lib/esignatur/api/request_info.rb +16 -0
- data/lib/esignatur/api/response.rb +26 -2
- data/lib/esignatur/api_resource.rb +35 -0
- data/lib/esignatur/client.rb +2 -1
- data/lib/esignatur/error.rb +14 -1
- data/lib/esignatur/order.rb +22 -12
- data/lib/esignatur/orders.rb +13 -5
- data/lib/esignatur/pades.rb +12 -7
- data/lib/esignatur/status.rb +24 -0
- data/lib/esignatur/version.rb +1 -1
- metadata +6 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 5fe073d133639d410eb843518fad63d14a9bfe3f
|
4
|
+
data.tar.gz: 438fd000077e43b71082a46017d261d707179b40
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 80e43b37d1de91a249452513c7acc9b405b80b809dce37f076d0cb11e9a05e94e7c8ee317a7dcf17fd0100621c0595f29bf17a86d1e49741048e7e239c1d053f
|
7
|
+
data.tar.gz: a51c8865f60775672d5d27a4fb3fedab46a454074d8a0fc046a775b72f84f16127c252c7fcffa837e32b29304228033e20599c5450e7834df639cd34ad4af1bd
|
data/Gemfile
CHANGED
@@ -1,6 +1,8 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
3
|
+
source 'https://rubygems.org'
|
4
|
+
|
5
|
+
git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
|
4
6
|
|
5
7
|
# Specify your gem's dependencies in esignatur.gemspec
|
6
8
|
gemspec
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -1,5 +1,10 @@
|
|
1
1
|
# Esignatur
|
2
2
|
|
3
|
+
|
4
|
+
[](https://travis-ci.org/samesystem/esignatur)
|
5
|
+
[](https://codecov.io/gh/samesystem/esignatur)
|
6
|
+
[](https://samesystem.github.io/esignatur)
|
7
|
+
|
3
8
|
https://api.esignatur.dk api ruby client
|
4
9
|
|
5
10
|
## Installation
|
@@ -22,15 +27,17 @@ Or install it yourself as:
|
|
22
27
|
|
23
28
|
```ruby
|
24
29
|
esignatur = Esignatur::Client.new(api_key: your_api_key)
|
25
|
-
|
30
|
+
|
26
31
|
esignatur.orders.where(modified_since: Date.new(2000, 1, 1))
|
27
32
|
|
28
33
|
order = esignatur.orders.find(1)
|
29
|
-
order.
|
30
|
-
order.
|
31
|
-
|
34
|
+
order.create(some_order_params) # creates order on esignatur side
|
35
|
+
order.status # returns Status object
|
36
|
+
order.cancel # => true/false
|
32
37
|
|
33
|
-
|
38
|
+
pades = order.pades
|
39
|
+
pades.document_data # decoded body of the document
|
40
|
+
```
|
34
41
|
|
35
42
|
## Development
|
36
43
|
|
data/lib/esignatur/api.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'esignatur/api/response'
|
4
|
+
require 'esignatur/api/request_info'
|
4
5
|
|
5
6
|
module Esignatur
|
6
7
|
# all raw http requests are made using Api instance
|
@@ -31,11 +32,16 @@ module Esignatur
|
|
31
32
|
|
32
33
|
headers = default_headers.merge(extra_headers)
|
33
34
|
raw_response = Faraday.public_send(http_method, url, data&.to_json, headers)
|
34
|
-
|
35
|
+
request = RequestInfo.new(http_method, url, headers)
|
36
|
+
Esignatur::Api::Response.new(raw_response, request: request)
|
35
37
|
end
|
36
38
|
|
37
39
|
def default_headers
|
38
|
-
{
|
40
|
+
{
|
41
|
+
'X-eSignatur-Id' => api_key,
|
42
|
+
'Accept' => 'application/json',
|
43
|
+
'Content-Type' => 'application/json'
|
44
|
+
}
|
39
45
|
end
|
40
46
|
end
|
41
47
|
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Esignatur
|
4
|
+
class Api
|
5
|
+
# api response wrapper
|
6
|
+
class RequestInfo
|
7
|
+
attr_reader :url, :headers, :http_method
|
8
|
+
|
9
|
+
def initialize(http_method, url, headers)
|
10
|
+
@url = url
|
11
|
+
@headers = headers
|
12
|
+
@http_method = http_method
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -1,21 +1,43 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'esignatur/error'
|
4
|
+
|
3
5
|
module Esignatur
|
4
6
|
class Api
|
5
7
|
# api response wrapper
|
6
8
|
class Response
|
7
|
-
attr_reader :
|
9
|
+
attr_reader :request
|
8
10
|
|
9
|
-
def initialize(original_response)
|
11
|
+
def initialize(original_response, request:)
|
10
12
|
@original_response = original_response
|
13
|
+
@request = request
|
11
14
|
end
|
12
15
|
|
13
16
|
def body
|
14
17
|
original_response.body
|
15
18
|
end
|
16
19
|
|
20
|
+
def status_code
|
21
|
+
original_response.status
|
22
|
+
end
|
23
|
+
|
24
|
+
def headers
|
25
|
+
original_response.headers
|
26
|
+
end
|
27
|
+
|
28
|
+
def success?
|
29
|
+
original_response.success?
|
30
|
+
end
|
31
|
+
|
32
|
+
def failed?
|
33
|
+
!success?
|
34
|
+
end
|
35
|
+
|
17
36
|
def json_body
|
18
37
|
JSON.parse(body)
|
38
|
+
rescue JSON::ParserError => error
|
39
|
+
error.extend(Esignatur::ParsingError)
|
40
|
+
raise error
|
19
41
|
end
|
20
42
|
|
21
43
|
def method_missing(method_name, *args)
|
@@ -28,6 +50,8 @@ module Esignatur
|
|
28
50
|
|
29
51
|
private
|
30
52
|
|
53
|
+
attr_reader :original_response
|
54
|
+
|
31
55
|
def original_respond_to?(method_name, *args)
|
32
56
|
original_response.respond_to?(method_name, *args)
|
33
57
|
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Esignatur
|
4
|
+
# add methods that are shared for all api resources
|
5
|
+
module ApiResource
|
6
|
+
def errors
|
7
|
+
@errors || []
|
8
|
+
end
|
9
|
+
|
10
|
+
def last_response
|
11
|
+
@last_response
|
12
|
+
end
|
13
|
+
|
14
|
+
protected
|
15
|
+
|
16
|
+
def api_post(relative_url, data)
|
17
|
+
make_api_request(:post, relative_url, data: data)
|
18
|
+
end
|
19
|
+
|
20
|
+
def api_get(relative_url, **options)
|
21
|
+
make_api_request(:get, relative_url, **options)
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def make_api_request(http_method, relative_url, **options)
|
27
|
+
@last_response = api.public_send(http_method, relative_url, **options).tap do |response|
|
28
|
+
@errors = []
|
29
|
+
@errors << response.headers['x-esignatur-error']
|
30
|
+
@errors << "Request failed with HTTP status: #{response.status_code}" if response.failed?
|
31
|
+
@errors = @errors.reject(&:nil?)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
data/lib/esignatur/client.rb
CHANGED
@@ -1,8 +1,9 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Esignatur
|
4
|
+
# main API class
|
4
5
|
class Client
|
5
|
-
DEFAULT_BASE_URL = 'https://api.esignatur.dk'
|
6
|
+
DEFAULT_BASE_URL = 'https://api.esignatur.dk'
|
6
7
|
|
7
8
|
def initialize(api_key:, base_url: DEFAULT_BASE_URL)
|
8
9
|
@api = Esignatur::Api.new(api_key: api_key, base_url: base_url)
|
data/lib/esignatur/error.rb
CHANGED
@@ -1,3 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Esignatur
|
2
|
-
|
4
|
+
# base error
|
5
|
+
module Error; end
|
6
|
+
|
7
|
+
# indicates that body is not parsable
|
8
|
+
module ParsingError
|
9
|
+
include Error
|
10
|
+
end
|
11
|
+
|
12
|
+
# indicates that some mandatory attribute is not given
|
13
|
+
class MissingAttributeError < StandardError
|
14
|
+
include Esignatur::Error
|
15
|
+
end
|
3
16
|
end
|
data/lib/esignatur/order.rb
CHANGED
@@ -1,36 +1,46 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'esignatur/api_resource'
|
3
4
|
require 'esignatur/pades'
|
5
|
+
require 'esignatur/status'
|
4
6
|
require 'active_support/core_ext/string/inflections'
|
5
7
|
|
6
8
|
module Esignatur
|
7
9
|
# esignatur order representation
|
8
10
|
# More info: https://api.esignatur.dk/Documentation/Order
|
9
11
|
class Order
|
10
|
-
|
12
|
+
include ApiResource
|
11
13
|
|
12
|
-
|
13
|
-
response = api.post('Order/Create', data: attributes)
|
14
|
-
body = response.json_body
|
15
|
-
new(body.fetch('OrderId'), response_body: response.body, api: api)
|
16
|
-
end
|
14
|
+
attr_reader :attributes
|
17
15
|
|
18
|
-
def initialize(
|
19
|
-
@
|
20
|
-
@response_body = response_body
|
16
|
+
def initialize(attributes: {}, api:)
|
17
|
+
@attributes = attributes
|
21
18
|
@api = api
|
22
19
|
end
|
23
20
|
|
21
|
+
def create(attributes)
|
22
|
+
response = api_post('Order/Create', attributes)
|
23
|
+
if errors.empty?
|
24
|
+
body = response.json_body
|
25
|
+
@attributes = attributes.merge(id: body.fetch('OrderId')).merge(body)
|
26
|
+
end
|
27
|
+
self
|
28
|
+
end
|
29
|
+
|
30
|
+
def id
|
31
|
+
attributes[:id]
|
32
|
+
end
|
33
|
+
|
24
34
|
def status
|
25
|
-
api.
|
35
|
+
@status ||= Esignatur::Status.new(order: self, api: api).tap(&:fetch)
|
26
36
|
end
|
27
37
|
|
28
38
|
def cancel
|
29
|
-
|
39
|
+
api_get("Order/Cancel/#{id}").success?
|
30
40
|
end
|
31
41
|
|
32
42
|
def pades
|
33
|
-
Pades.new(order: self, api: api)
|
43
|
+
Esignatur::Pades.new(order: self, api: api)
|
34
44
|
end
|
35
45
|
|
36
46
|
private
|
data/lib/esignatur/orders.rb
CHANGED
@@ -1,9 +1,12 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'esignatur/api_resource'
|
4
|
+
|
3
5
|
module Esignatur
|
4
6
|
# esignatur order info collection representation.
|
5
7
|
# more info: https://api.esignatur.dk/Documentation/OrderInfo
|
6
8
|
class Orders
|
9
|
+
include ::Esignatur::ApiResource
|
7
10
|
include Enumerable
|
8
11
|
|
9
12
|
def initialize(scope: {}, api:)
|
@@ -12,7 +15,11 @@ module Esignatur
|
|
12
15
|
end
|
13
16
|
|
14
17
|
def create(attributes)
|
15
|
-
|
18
|
+
build.create(attributes)
|
19
|
+
end
|
20
|
+
|
21
|
+
def build
|
22
|
+
Esignatur::Order.new(api: api)
|
16
23
|
end
|
17
24
|
|
18
25
|
def where(new_scope)
|
@@ -21,9 +28,10 @@ module Esignatur
|
|
21
28
|
|
22
29
|
def all
|
23
30
|
@all ||= begin
|
24
|
-
response =
|
31
|
+
response = api_get("OrderInfo/OrdersForAdministrator/#{creator_id}", headers: headers_for_all_query)
|
25
32
|
response.json_body.fetch('SignOrders').map do |raw_order|
|
26
|
-
|
33
|
+
order_attributes = raw_order.merge(id: raw_order.fetch('SignOrderId'))
|
34
|
+
Esignatur::Order.new(attributes: order_attributes, api: api)
|
27
35
|
end
|
28
36
|
end
|
29
37
|
end
|
@@ -33,7 +41,7 @@ module Esignatur
|
|
33
41
|
end
|
34
42
|
|
35
43
|
def find(id)
|
36
|
-
Order.new(id, api: api)
|
44
|
+
Esignatur::Order.new(attributes: { id: id }, api: api)
|
37
45
|
end
|
38
46
|
|
39
47
|
private
|
@@ -48,7 +56,7 @@ module Esignatur
|
|
48
56
|
def creator_id
|
49
57
|
scope.fetch(:creator_id) do
|
50
58
|
raise(
|
51
|
-
Esignatur::
|
59
|
+
Esignatur::MissingAttributeError,
|
52
60
|
'You need to specify creator_id in order to fech orders. ' \
|
53
61
|
'You can do this with `esignatur.orders.where(creator_id: 123)`'
|
54
62
|
)
|
data/lib/esignatur/pades.rb
CHANGED
@@ -1,27 +1,32 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'esignatur/api_resource'
|
4
|
+
|
3
5
|
module Esignatur
|
4
6
|
# esignature PAdES document representation.
|
5
7
|
# More info: https://api.esignatur.dk/Documentation/Pades
|
6
8
|
class Pades
|
7
|
-
|
9
|
+
include ApiResource
|
10
|
+
|
11
|
+
attr_reader :attributes, :order
|
8
12
|
|
9
13
|
def initialize(order:, api:)
|
14
|
+
@attributes = {}
|
10
15
|
@order = order
|
11
16
|
@api = api
|
12
17
|
end
|
13
18
|
|
14
19
|
def document_data
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
def response_body
|
19
|
-
@response_body ||= \
|
20
|
-
api.post('Pades/Download', data: { 'Id' => order.id, 'DocumentIndex' => 0 }).json_body
|
20
|
+
fetch if attributes.empty?
|
21
|
+
Base64.decode64(attributes.fetch('DocumentData'))
|
21
22
|
end
|
22
23
|
|
23
24
|
private
|
24
25
|
|
25
26
|
attr_reader :api
|
27
|
+
|
28
|
+
def fetch
|
29
|
+
@attributes = api_post('Pades/Download', 'Id' => order.id, 'DocumentIndex' => 0).json_body
|
30
|
+
end
|
26
31
|
end
|
27
32
|
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'esignatur/api_resource'
|
4
|
+
|
5
|
+
module Esignatur
|
6
|
+
# esignatur status representation
|
7
|
+
# More info: https://api.esignatur.dk/Documentation/Status
|
8
|
+
class Status
|
9
|
+
include ApiResource
|
10
|
+
|
11
|
+
attr_reader :attributes, :order, :api
|
12
|
+
|
13
|
+
def initialize(order:, attributes: {}, api:)
|
14
|
+
@attributes = attributes
|
15
|
+
@order = order
|
16
|
+
@api = api
|
17
|
+
end
|
18
|
+
|
19
|
+
def fetch
|
20
|
+
@attributes = api_get("status/get/#{order.id}").json_body
|
21
|
+
self
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
data/lib/esignatur/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: esignatur
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Povilas Jurcys
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-10-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -188,12 +188,15 @@ files:
|
|
188
188
|
- esignatur.gemspec
|
189
189
|
- lib/esignatur.rb
|
190
190
|
- lib/esignatur/api.rb
|
191
|
+
- lib/esignatur/api/request_info.rb
|
191
192
|
- lib/esignatur/api/response.rb
|
193
|
+
- lib/esignatur/api_resource.rb
|
192
194
|
- lib/esignatur/client.rb
|
193
195
|
- lib/esignatur/error.rb
|
194
196
|
- lib/esignatur/order.rb
|
195
197
|
- lib/esignatur/orders.rb
|
196
198
|
- lib/esignatur/pades.rb
|
199
|
+
- lib/esignatur/status.rb
|
197
200
|
- lib/esignatur/version.rb
|
198
201
|
homepage: https://github.com/samesystem/esignatur
|
199
202
|
licenses:
|
@@ -215,7 +218,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
215
218
|
version: '0'
|
216
219
|
requirements: []
|
217
220
|
rubyforge_project:
|
218
|
-
rubygems_version: 2.
|
221
|
+
rubygems_version: 2.6.14.1
|
219
222
|
signing_key:
|
220
223
|
specification_version: 4
|
221
224
|
summary: ruby API client for esignatur.dk
|