egree 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/egree/api_mappers/case_options_mapper.rb +13 -0
- data/lib/egree/client.rb +1 -1
- data/lib/egree/document.rb +20 -3
- data/lib/egree/serializers/case_serializer.rb +1 -0
- data/lib/egree/version.rb +1 -1
- data/spec/egree/api_mappers/case_options_mapper_spec.rb +16 -0
- data/spec/egree/client/create_case_spec.rb +9 -1
- data/spec/egree/document_spec.rb +51 -4
- data/spec/fixtures/cassettes/Egree_Client/_create_case/valid_case.yml +10 -5
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 98bec1b0ecfa88f62e76834ca60a944db74a6050
|
4
|
+
data.tar.gz: 45bb21a233e1b39a713a5028e3a62d098a80cbaf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6eed8cb22da3db1d3c632c27014b665bef0e35fe881ae47b282a6cdd7984c5513997876530c73c1947cbe4d3e4297f09d81eeb1e678d8dfdfd93bf1ae8c98900
|
7
|
+
data.tar.gz: f01926797af2159b14fdc571a8187c6aa07e05b5658f8a19c185626682cece3c4103d89493f5ab8828bb18871aab4d5e718a28da0b0544f24d52d082cab9b586
|
@@ -1,4 +1,6 @@
|
|
1
1
|
module Egree
|
2
|
+
class InvalidCaseOptionError < ArgumentError; end
|
3
|
+
|
2
4
|
module ApiMappers
|
3
5
|
module CaseOptionsMapper
|
4
6
|
def self.to_api options = {}, mappers = self.mappers
|
@@ -13,6 +15,14 @@ module Egree
|
|
13
15
|
|
14
16
|
private
|
15
17
|
|
18
|
+
LOCALES = ->(locale) {
|
19
|
+
{
|
20
|
+
"sv" => "sv-SE",
|
21
|
+
"fi" => "fi-FI",
|
22
|
+
"en" => "en-US"
|
23
|
+
}.fetch(locale) { raise Egree::InvalidCaseOptionError.new("Unknown locale: #{locale}") }
|
24
|
+
}
|
25
|
+
|
16
26
|
def self.map client_key, value, mappers = self.mappers
|
17
27
|
mapper = mappers[client_key]
|
18
28
|
|
@@ -26,6 +36,9 @@ module Egree
|
|
26
36
|
def self.mappers
|
27
37
|
{
|
28
38
|
postback_url: "CaseFinishedCallbackUrl",
|
39
|
+
locale: ->(value) {
|
40
|
+
{ "Culture" => LOCALES.call(value) }
|
41
|
+
},
|
29
42
|
continue: ->(options) {
|
30
43
|
CaseOptionsMapper.to_api options, name: "ContinueName", url: "ContinueUrl", auto: "ContinueAuto"
|
31
44
|
}
|
data/lib/egree/client.rb
CHANGED
data/lib/egree/document.rb
CHANGED
@@ -1,11 +1,16 @@
|
|
1
1
|
require "open-uri"
|
2
2
|
|
3
3
|
module Egree
|
4
|
+
class CouldNotFetchDocumentError < StandardError
|
5
|
+
end
|
6
|
+
|
4
7
|
class Document
|
5
|
-
attr_reader :path
|
8
|
+
attr_reader :path, :username, :password
|
6
9
|
|
7
|
-
def initialize path
|
10
|
+
def initialize path, username: nil, password: nil
|
8
11
|
@path = path
|
12
|
+
@username = username
|
13
|
+
@password = password
|
9
14
|
end
|
10
15
|
|
11
16
|
def filename
|
@@ -39,7 +44,19 @@ module Egree
|
|
39
44
|
end
|
40
45
|
|
41
46
|
def file
|
42
|
-
|
47
|
+
begin
|
48
|
+
open path, authentication_params
|
49
|
+
rescue OpenURI::HTTPError => error
|
50
|
+
raise Egree::CouldNotFetchDocumentError.new("Could not get url #{path} (#{error.message})")
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def authentication_params
|
55
|
+
if username && password
|
56
|
+
{ http_basic_authentication: [ username, password ] }
|
57
|
+
else
|
58
|
+
{}
|
59
|
+
end
|
43
60
|
end
|
44
61
|
end
|
45
62
|
end
|
data/lib/egree/version.rb
CHANGED
@@ -11,6 +11,22 @@ module Egree
|
|
11
11
|
})
|
12
12
|
end
|
13
13
|
|
14
|
+
describe "locale" do
|
15
|
+
it "translates locale to Culture allowing sv, fi and en" do
|
16
|
+
{ "sv" => "sv-SE", "fi" => "fi-FI", "en" => "en-US" }.each do |key, locale|
|
17
|
+
expect(CaseOptionsMapper.to_api(locale: key)).to eq({
|
18
|
+
"Culture" => locale
|
19
|
+
})
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
it "raises an InvalidCaseOptionError for unkown locales" do
|
24
|
+
expect{ CaseOptionsMapper.to_api(locale: "unknown") }.to raise_error{
|
25
|
+
Egree::InvalidCaseOptionError
|
26
|
+
}
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
14
30
|
describe "continue" do
|
15
31
|
it "translates name" do
|
16
32
|
options = { continue: { name: "The label" } }
|
@@ -36,7 +36,15 @@ module Egree
|
|
36
36
|
})
|
37
37
|
signature_case.add_document Egree::Document.new(File.join(Dir.pwd, "spec/fixtures/agreement.pdf"))
|
38
38
|
|
39
|
-
result = client.create_case
|
39
|
+
result = client.create_case(signature_case, {
|
40
|
+
postback_url: "http://example.com/postback",
|
41
|
+
continue: {
|
42
|
+
name: "Back to the site",
|
43
|
+
url: "http://example.com/thanks",
|
44
|
+
auto: true
|
45
|
+
},
|
46
|
+
locale: "sv"
|
47
|
+
})
|
40
48
|
|
41
49
|
expect(result.success?).to be true
|
42
50
|
end
|
data/spec/egree/document_spec.rb
CHANGED
@@ -30,12 +30,18 @@ module Egree
|
|
30
30
|
end
|
31
31
|
|
32
32
|
describe "#with an url" do
|
33
|
-
|
34
|
-
|
33
|
+
let :fixture_path do
|
34
|
+
File.join(Dir.pwd, "spec/fixtures/agreement.pdf")
|
35
|
+
end
|
36
|
+
|
37
|
+
let :fixture_contents do
|
38
|
+
File.read(fixture_path)
|
39
|
+
end
|
35
40
|
|
41
|
+
before do
|
36
42
|
stub_request(:get, "http://example.com/files/remote_agreement.pdf").to_return({
|
37
43
|
status: 200,
|
38
|
-
body:
|
44
|
+
body: fixture_contents
|
39
45
|
})
|
40
46
|
end
|
41
47
|
|
@@ -57,7 +63,48 @@ module Egree
|
|
57
63
|
|
58
64
|
it "has the file data encoded as base64" do
|
59
65
|
fixture_path = File.join(Dir.pwd, "spec/fixtures/agreement.pdf")
|
60
|
-
expect(document.data).to eq Base64.encode64(
|
66
|
+
expect(document.data).to eq Base64.encode64(fixture_contents)
|
67
|
+
end
|
68
|
+
|
69
|
+
describe "that is protected by basic authentication" do
|
70
|
+
describe "with valid credentials" do
|
71
|
+
let :url do
|
72
|
+
"example.com/files/protected_file.pdf"
|
73
|
+
end
|
74
|
+
|
75
|
+
before do
|
76
|
+
stub_request(:get, "test-user:secret@#{url}").to_return({
|
77
|
+
status: 200,
|
78
|
+
body: "the-body"
|
79
|
+
})
|
80
|
+
end
|
81
|
+
|
82
|
+
it "returns the document" do
|
83
|
+
document = Document.new("http://#{url}", username: "test-user", password: "secret")
|
84
|
+
|
85
|
+
expect(document.data).to eq Base64.encode64("the-body")
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
describe "with invalid credentials" do
|
90
|
+
let :url do
|
91
|
+
"http://example.com/files/protected_file.pdf"
|
92
|
+
end
|
93
|
+
|
94
|
+
before do
|
95
|
+
stub_request(:get, url).to_return({
|
96
|
+
status: [401, "Unauthorized"]
|
97
|
+
})
|
98
|
+
end
|
99
|
+
|
100
|
+
it "throws a informative error if it cannot authenticate" do
|
101
|
+
document = Document.new(url)
|
102
|
+
|
103
|
+
expect{
|
104
|
+
document.size
|
105
|
+
}.to raise_error(Egree::CouldNotFetchDocumentError, /#{url}/)
|
106
|
+
end
|
107
|
+
end
|
61
108
|
end
|
62
109
|
end
|
63
110
|
|
@@ -23,13 +23,18 @@ http_interactions:
|
|
23
23
|
{
|
24
24
|
"Name": "First Last",
|
25
25
|
"EmailAddress": "name@example.com",
|
26
|
-
"SocialSecurityNumber": "
|
26
|
+
"SocialSecurityNumber": "5212172760"
|
27
27
|
}
|
28
28
|
],
|
29
29
|
"AllowedSignatureTypes": [
|
30
30
|
"touch"
|
31
31
|
],
|
32
|
-
"CaseReferenceId": "
|
32
|
+
"CaseReferenceId": "238c0cc3-8c66-4ff4-bf75-65ee264b1001",
|
33
|
+
"CaseFinishedCallbackUrl": "http://example.com/postback",
|
34
|
+
"ContinueName": "Back to the site",
|
35
|
+
"ContinueUrl": "http://example.com/thanks",
|
36
|
+
"ContinueAuto": true,
|
37
|
+
"Culture": "sv-SE"
|
33
38
|
}
|
34
39
|
headers:
|
35
40
|
Accept:
|
@@ -52,16 +57,16 @@ http_interactions:
|
|
52
57
|
Strict-Transport-Security:
|
53
58
|
- max-age=31536000
|
54
59
|
Set-Cookie:
|
55
|
-
- ASP.NET_SessionId=
|
60
|
+
- ASP.NET_SessionId=xlsxyoeej5dfrorj3uwk2tzc; path=/; HttpOnly
|
56
61
|
X-Aspnet-Version:
|
57
62
|
- 4.0.30319
|
58
63
|
Date:
|
59
|
-
- Fri,
|
64
|
+
- Fri, 03 Oct 2014 09:12:40 GMT
|
60
65
|
Content-Length:
|
61
66
|
- '0'
|
62
67
|
body:
|
63
68
|
encoding: UTF-8
|
64
69
|
string: ''
|
65
70
|
http_version:
|
66
|
-
recorded_at: Fri,
|
71
|
+
recorded_at: Fri, 03 Oct 2014 09:13:19 GMT
|
67
72
|
recorded_with: VCR 2.9.2
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: egree
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Joel Junström
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-11-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|