egree 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d312dc980ab9ce2ef80fc6dd3ff8cfe1b18ff149
4
- data.tar.gz: 76b01dd7a7d5f556dc6917df58c6dd56df7ee29a
3
+ metadata.gz: 3309501f588e8dacabdf2efe9bfe4dc04cb18fbd
4
+ data.tar.gz: d0ea6cb7fe2cc29187ccf7d7218f5523be2fd540
5
5
  SHA512:
6
- metadata.gz: 4bf175c5c2d84ede2932be4238a83c98a0e7b21af52e3e5f14f7c760078aa2f35d6b3a69dfac6ccd25b27b4d906c2c021d7308451fc2aadc3858b6a5a6c4e131
7
- data.tar.gz: f63183fa1383fd85b77c1159f53ad8cdeb8f8bc3ce87aac0cffc4100c3db738156b8810054d4a4b9aa7680905bded9cdab21dd712cb4a2facc90383b517cb90e
6
+ metadata.gz: 9bae1e3739e8f9971d0a4fab40bd03cc09ac91c89582ca60e73478b06718c967bf0a5235a186d0a1493d1339e97bb628c94ff47a97f83de0b50d6217c14edf03
7
+ data.tar.gz: 320d11f49ac518c460e3c61517198cc5c2110ae4d1bc66a8512498bd7433d7c0768db2b218bdeb44b9f4bfcc878edf5f394656912c625e99f7805fcb40ff07c7
data/README.md CHANGED
@@ -1,73 +1,78 @@
1
1
  [![Build Status](https://travis-ci.org/joeljunstrom/egree-ruby.svg?branch=master)](https://travis-ci.org/joeljunstrom/egree-ruby)
2
2
  [![Code Climate](https://codeclimate.com/github/joeljunstrom/egree-ruby/badges/gpa.svg)](https://codeclimate.com/github/joeljunstrom/egree-ruby)
3
3
  [![Test Coverage](https://codeclimate.com/github/joeljunstrom/egree-ruby/badges/coverage.svg)](https://codeclimate.com/github/joeljunstrom/egree-ruby)
4
+ [![Gem Version](https://badge.fury.io/rb/egree.svg)](http://badge.fury.io/rb/egree)
4
5
 
5
6
  # Egree
6
7
 
7
8
  Ruby client for the [Egree API](https://app.egree.com/apiv1).
8
9
 
9
- Currently the only supported actions is the `createcasecommand` and `getviewcaseurlquery`.
10
+ Currently the only supported api calls is `createcasecommand` and `getviewcaseurlquery`.
10
11
 
11
12
  ## Usage
12
13
 
13
14
  ### Creating a case
14
15
 
15
- ```
16
- egree = Egree.client username, password
17
-
18
- signature_case = Egree::Case.new "Agreement", ["touch"]
19
- signature_case.add_party Egree::Party.new({
20
- name: "First Last",
21
- email: "name@example.com",
22
- social_security_number: "1234567890"
23
- })
24
- signature_case.add_document Egree::Document.new "/some/path/file.pdf"
25
-
26
- result = egree.create_case signature_case
27
-
28
- if result.success?
29
- puts "#{signature_case.reference_id} was created."
30
- else
31
- puts "There was some issues with the case"
32
- result.errors.each do |error|
33
- puts error
34
- end
16
+ ```ruby
17
+ egree = Egree.client username, password
18
+
19
+ signature_case = Egree::Case.new "Agreement", ["touch"]
20
+ signature_case.add_party Egree::Party.new_with_attributes({
21
+ name: "First Last",
22
+ email: "name@example.com",
23
+ social_security_number: "1234567890"
24
+ })
25
+ signature_case.add_document Egree::Document.new "/some/path/file.pdf"
26
+
27
+ result = egree.create_case(signature_case, {
28
+ postback_url: "https://example.com/my-endpoint",
29
+ continue: {
30
+ url: "http://example.com/user-endpoint",
31
+ auto: true
32
+ }
33
+ })
34
+
35
+ if result.success?
36
+ puts "#{signature_case.reference_id} was created."
37
+ else
38
+ puts "There was some issues with the case"
39
+ result.errors.each do |error|
40
+ puts error
35
41
  end
42
+ end
36
43
  ```
37
44
 
38
45
  ### Getting the signature url for a case
39
46
 
40
- ```
41
- egree = Egree.client username, password
42
- result = egree.get_case_url "98d08cf5-d35d-403b-ac31-fa1ac85037a1"
43
-
44
- if result.success?
45
- puts "The url is: #{result.response}"
46
- else
47
- puts "Could not get signature url"
48
- result.errors.each do |error|
49
- puts error
50
- end
47
+ ```ruby
48
+ egree = Egree.client username, password
49
+ result = egree.get_case_url "98d08cf5-d35d-403b-ac31-fa1ac85037a1"
50
+
51
+ if result.success?
52
+ puts "The url is: #{result.response}"
53
+ else
54
+ puts "Could not get signature url"
55
+ result.errors.each do |error|
56
+ puts error
51
57
  end
58
+ end
52
59
  ```
53
60
 
54
61
 
55
62
 
56
63
  ## Contributing
57
64
 
58
- 1. Fork it ( http://github.com/joeljunstrom/egree/fork )
59
- 2. Create your feature branch (`git checkout -b my-new-feature`)
60
- 3. Commit your changes (`git commit -am 'Add some feature'`)
61
- 4. Push to the branch (`git push origin my-new-feature`)
62
- 5. Create new Pull Request
65
+ Contributions is more than welcome!
66
+
67
+ Just create a fork and submit a pull request.
68
+
69
+ Please adhere to the coding standards used in the project and add tests.
63
70
 
64
71
  ### Local development
65
72
 
66
- Create a .env file in the root directory.
73
+ Create a .env file in the root directory to run the integration tests against your Egree environment.
67
74
 
68
- ```
75
+ ```yaml
69
76
  EGREE_USERNAME=your-username
70
77
  EGREE_PASSWORD=your-password
71
78
  ```
72
-
73
- This is used for the integration tests.
@@ -0,0 +1,36 @@
1
+ module Egree
2
+ module ApiMappers
3
+ module CaseOptionsMapper
4
+ def self.to_api options = {}, mappers = self.mappers
5
+ options.reduce({}) do |api_hash, (client_key, value)|
6
+ if mappers.key?(client_key)
7
+ api_hash.merge(self.map(client_key, value, mappers))
8
+ else
9
+ api_hash
10
+ end
11
+ end || {}
12
+ end
13
+
14
+ private
15
+
16
+ def self.map client_key, value, mappers = self.mappers
17
+ mapper = mappers[client_key]
18
+
19
+ if mapper.respond_to?(:call)
20
+ mapper.call value
21
+ else
22
+ { mapper => value }
23
+ end
24
+ end
25
+
26
+ def self.mappers
27
+ {
28
+ postback_url: "CaseFinishedCallbackUrl",
29
+ continue: ->(options) {
30
+ CaseOptionsMapper.to_api options, name: "ContinueName", url: "ContinueUrl", auto: "ContinueAuto"
31
+ }
32
+ }
33
+ end
34
+ end
35
+ end
36
+ end
@@ -16,8 +16,8 @@ module Egree
16
16
  self.environment = environment
17
17
  end
18
18
 
19
- def create_case signature_case
20
- signature_case_json = Egree::Serializers::CaseSerializer.serialize signature_case
19
+ def create_case signature_case, options = {}
20
+ signature_case_json = Egree::Serializers::CaseSerializer.serialize signature_case, options
21
21
  post "/apiv1/createcasecommand", signature_case_json
22
22
  end
23
23
 
@@ -4,8 +4,10 @@ require "egree/api_mappers/case_mapper"
4
4
  module Egree
5
5
  module Serializers
6
6
  module CaseSerializer
7
- def self.serialize signature_case
8
- JSON.pretty_generate Egree::ApiMappers::CaseMapper.to_api(signature_case)
7
+ def self.serialize signature_case, options = {}
8
+ signature_case_api_hash = Egree::ApiMappers::CaseMapper.to_api signature_case
9
+ options_api_hash = Egree::ApiMappers::CaseOptionsMapper.to_api options
10
+ JSON.pretty_generate signature_case_api_hash.merge(options_api_hash)
9
11
  end
10
12
  end
11
13
  end
@@ -1,3 +1,3 @@
1
1
  module Egree
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -0,0 +1,51 @@
1
+ require "spec_helper"
2
+ require "egree/api_mappers/case_options_mapper"
3
+
4
+ module Egree
5
+ module ApiMappers
6
+ RSpec.describe CaseOptionsMapper do
7
+ describe "#to_api" do
8
+ it "translates postback_url to CaseFinishedCallbackUrl" do
9
+ expect(CaseOptionsMapper.to_api(postback_url: "http://example.com")).to eq({
10
+ "CaseFinishedCallbackUrl" => "http://example.com"
11
+ })
12
+ end
13
+
14
+ describe "continue" do
15
+ it "translates name" do
16
+ options = { continue: { name: "The label" } }
17
+
18
+ expect(CaseOptionsMapper.to_api(options)).to eq({
19
+ "ContinueName" => "The label"
20
+ })
21
+ end
22
+
23
+ it "translates url" do
24
+ options = { continue: { url: "http://example.com/where-to-go" } }
25
+
26
+ expect(CaseOptionsMapper.to_api(options)).to eq({
27
+ "ContinueUrl" => "http://example.com/where-to-go"
28
+ })
29
+ end
30
+
31
+ it "translates auto" do
32
+ options = { continue: { auto: true } }
33
+
34
+ expect(CaseOptionsMapper.to_api(options)).to eq({
35
+ "ContinueAuto" => true
36
+ })
37
+ end
38
+ end
39
+
40
+ it "ignores unknown keys" do
41
+ expect(CaseOptionsMapper.to_api({
42
+ postback_url: "http://example.com",
43
+ unknown: "Some value"
44
+ })).to eq({
45
+ "CaseFinishedCallbackUrl" => "http://example.com"
46
+ })
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
@@ -12,7 +12,6 @@ module Egree
12
12
  expect(ReferenceIdMapper.to_api(reference_id)).to eq({
13
13
  "CaseReferenceId" => "123"
14
14
  })
15
-
16
15
  end
17
16
  end
18
17
  end
@@ -17,10 +17,11 @@ module Egree
17
17
  allow(client).to receive :post
18
18
 
19
19
  signature_case = double "Case"
20
+ options = { postback_url: "http://example.com/postback" }
20
21
 
21
- expect(Egree::Serializers::CaseSerializer).to receive(:serialize).with(signature_case).and_return "case-json"
22
+ expect(Egree::Serializers::CaseSerializer).to receive(:serialize).with(signature_case, options).and_return "case-json"
22
23
 
23
- client.create_case signature_case
24
+ client.create_case signature_case, options
24
25
 
25
26
  expect(client).to have_received(:post).with "/apiv1/createcasecommand", "case-json"
26
27
  end
@@ -15,6 +15,18 @@ module Egree
15
15
 
16
16
  expect(CaseSerializer.serialize(signature_case)).to eq JSON.pretty_generate(api_hash)
17
17
  end
18
+
19
+ it "takes options for how to handle the user" do
20
+ signature_case = double "Egree::Case"
21
+ api_hash = { "The" => "Case" }
22
+ options = { postback_url: "http://example.com" }
23
+ options_hash = { "CaseFinishedCallbackUrl" => "http://example.com" }
24
+
25
+ expect(Egree::ApiMappers::CaseMapper).to receive(:to_api).with(signature_case).and_return api_hash
26
+ expect(Egree::ApiMappers::CaseOptionsMapper).to receive(:to_api).with(options).and_return options_hash
27
+
28
+ expect(CaseSerializer.serialize(signature_case, options)).to eq JSON.pretty_generate(api_hash.merge(options_hash))
29
+ end
18
30
  end
19
31
  end
20
32
  end
@@ -3,7 +3,7 @@ require "egree"
3
3
 
4
4
  RSpec.describe Egree do
5
5
  describe ".client" do
6
- it "creates a Egree::Client" do
6
+ it "returns a Egree::Client" do
7
7
  expect(Egree.client("admin", "secret")).to be_kind_of Egree::Client
8
8
  end
9
9
 
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.2
4
+ version: 0.0.3
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-09-18 00:00:00.000000000 Z
11
+ date: 2014-10-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -139,6 +139,7 @@ files:
139
139
  - egree.gemspec
140
140
  - lib/egree.rb
141
141
  - lib/egree/api_mappers/case_mapper.rb
142
+ - lib/egree/api_mappers/case_options_mapper.rb
142
143
  - lib/egree/api_mappers/document_mapper.rb
143
144
  - lib/egree/api_mappers/form_field_mapper.rb
144
145
  - lib/egree/api_mappers/party_mapper.rb
@@ -153,6 +154,7 @@ files:
153
154
  - lib/egree/serializers/reference_id_serializer.rb
154
155
  - lib/egree/version.rb
155
156
  - spec/egree/api_mappers/case_mapper_spec.rb
157
+ - spec/egree/api_mappers/case_options_mapper_spec.rb
156
158
  - spec/egree/api_mappers/document_mapper_spec.rb
157
159
  - spec/egree/api_mappers/form_field_mapper_spec.rb
158
160
  - spec/egree/api_mappers/party_mapper_spec.rb
@@ -201,6 +203,7 @@ specification_version: 4
201
203
  summary: Client for the Egree API
202
204
  test_files:
203
205
  - spec/egree/api_mappers/case_mapper_spec.rb
206
+ - spec/egree/api_mappers/case_options_mapper_spec.rb
204
207
  - spec/egree/api_mappers/document_mapper_spec.rb
205
208
  - spec/egree/api_mappers/form_field_mapper_spec.rb
206
209
  - spec/egree/api_mappers/party_mapper_spec.rb