egree 0.0.3 → 0.0.4

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
  SHA1:
3
- metadata.gz: 3309501f588e8dacabdf2efe9bfe4dc04cb18fbd
4
- data.tar.gz: d0ea6cb7fe2cc29187ccf7d7218f5523be2fd540
3
+ metadata.gz: 98bec1b0ecfa88f62e76834ca60a944db74a6050
4
+ data.tar.gz: 45bb21a233e1b39a713a5028e3a62d098a80cbaf
5
5
  SHA512:
6
- metadata.gz: 9bae1e3739e8f9971d0a4fab40bd03cc09ac91c89582ca60e73478b06718c967bf0a5235a186d0a1493d1339e97bb628c94ff47a97f83de0b50d6217c14edf03
7
- data.tar.gz: 320d11f49ac518c460e3c61517198cc5c2110ae4d1bc66a8512498bd7433d7c0768db2b218bdeb44b9f4bfcc878edf5f394656912c625e99f7805fcb40ff07c7
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
  }
@@ -44,9 +44,9 @@ module Egree
44
44
 
45
45
  def connection
46
46
  Faraday.new "https://#{host}" do |conn|
47
- conn.adapter :net_http
48
47
  conn.headers["Accept"] = "application/json"
49
48
  conn.basic_auth username, password
49
+ conn.adapter :net_http
50
50
  end
51
51
  end
52
52
 
@@ -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
- open path
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
@@ -1,5 +1,6 @@
1
1
  require "json"
2
2
  require "egree/api_mappers/case_mapper"
3
+ require "egree/api_mappers/case_options_mapper"
3
4
 
4
5
  module Egree
5
6
  module Serializers
@@ -1,3 +1,3 @@
1
1
  module Egree
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -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 signature_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
@@ -30,12 +30,18 @@ module Egree
30
30
  end
31
31
 
32
32
  describe "#with an url" do
33
- before do
34
- fixture_path = File.join(Dir.pwd, "spec/fixtures/agreement.pdf")
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: File.read(fixture_path)
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(File.open(fixture_path).read)
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": "4503089239"
26
+ "SocialSecurityNumber": "5212172760"
27
27
  }
28
28
  ],
29
29
  "AllowedSignatureTypes": [
30
30
  "touch"
31
31
  ],
32
- "CaseReferenceId": "6c99f997-6115-4524-af93-791fe4e626dd"
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=ondwcvli0qi5bildy5olrlvh; path=/; HttpOnly
60
+ - ASP.NET_SessionId=xlsxyoeej5dfrorj3uwk2tzc; path=/; HttpOnly
56
61
  X-Aspnet-Version:
57
62
  - 4.0.30319
58
63
  Date:
59
- - Fri, 12 Sep 2014 10:06:24 GMT
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, 12 Sep 2014 10:06:26 GMT
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.3
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-10-02 00:00:00.000000000 Z
11
+ date: 2014-11-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday