egree 0.0.1

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.
Files changed (44) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +20 -0
  3. data/.rspec +3 -0
  4. data/.travis.yml +13 -0
  5. data/Gemfile +5 -0
  6. data/LICENSE.txt +22 -0
  7. data/README.md +72 -0
  8. data/Rakefile +1 -0
  9. data/egree.gemspec +31 -0
  10. data/lib/egree.rb +8 -0
  11. data/lib/egree/case.rb +64 -0
  12. data/lib/egree/client.rb +103 -0
  13. data/lib/egree/document.rb +45 -0
  14. data/lib/egree/form_field.rb +3 -0
  15. data/lib/egree/party.rb +21 -0
  16. data/lib/egree/reference_id.rb +34 -0
  17. data/lib/egree/serializers/case.rb +22 -0
  18. data/lib/egree/serializers/document.rb +21 -0
  19. data/lib/egree/serializers/form_field.rb +16 -0
  20. data/lib/egree/serializers/party.rb +17 -0
  21. data/lib/egree/serializers/reference_id.rb +18 -0
  22. data/lib/egree/version.rb +3 -0
  23. data/spec/egree/case_spec.rb +74 -0
  24. data/spec/egree/client/create_case_spec.rb +62 -0
  25. data/spec/egree/client/get_case_url_spec.rb +84 -0
  26. data/spec/egree/client_spec.rb +125 -0
  27. data/spec/egree/document_spec.rb +73 -0
  28. data/spec/egree/form_field_spec.rb +18 -0
  29. data/spec/egree/party_spec.rb +35 -0
  30. data/spec/egree/reference_id_spec.rb +40 -0
  31. data/spec/egree/serializers/case_spec.rb +30 -0
  32. data/spec/egree/serializers/document_spec.rb +45 -0
  33. data/spec/egree/serializers/form_field_spec.rb +29 -0
  34. data/spec/egree/serializers/party_spec.rb +34 -0
  35. data/spec/egree/serializers/reference_id_spec.rb +28 -0
  36. data/spec/egree_spec.rb +17 -0
  37. data/spec/fixtures/agreement.pdf +0 -0
  38. data/spec/fixtures/cassettes/Egree_Client/_create_case/invalid_case.yml +58 -0
  39. data/spec/fixtures/cassettes/Egree_Client/_create_case/valid_case.yml +67 -0
  40. data/spec/fixtures/cassettes/Egree_Client/_create_case/with_an_invalid_case/includes_the_error_message.yml +66 -0
  41. data/spec/fixtures/cassettes/Egree_Client/_get_case_url/case_exists.yml +113 -0
  42. data/spec/fixtures/cassettes/Egree_Client/_get_case_url/case_missing.yml +45 -0
  43. data/spec/spec_helper.rb +38 -0
  44. metadata +219 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 287435d353b123633d8604c827611f484fe7cef5
4
+ data.tar.gz: 4f9c098c0618ba59e22f7fdb54e00675cb348384
5
+ SHA512:
6
+ metadata.gz: 35c1cf0ef2455e02360c8a1962981ab3f2319f27636450ed3c294f5c1d78f38ba1eb84f19bc3a9da3808259b1550ff3cfb30ae865aa600cb88dd09d789727222
7
+ data.tar.gz: b385eaa4872e5acafb3163ca74c5d692e7056725cbcaec488ded11794d882fd859eea601e24735aad13b71795d0c70eed3cc5f93039d124d242cc44d3918d16d
@@ -0,0 +1,20 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ .ruby-version
7
+ .env
8
+ Gemfile.lock
9
+ InstalledFiles
10
+ _yardoc
11
+ coverage
12
+ doc/
13
+ lib/bundler/man
14
+ pkg
15
+ rdoc
16
+ spec/reports
17
+ test/tmp
18
+ test/version_tmp
19
+ tmp
20
+ bin/
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --color
2
+ --warnings
3
+ --require spec_helper
@@ -0,0 +1,13 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.0
4
+ - 2.0.0
5
+ script: rspec spec
6
+ addons:
7
+ code_climate:
8
+ repo_token:
9
+ secure: Y3b1vSaq1qa9dMTbtftg1HzUrftWkx42F2yD/8ana0nUpg3b6xrvzx3LDiEPG1nLU4R7yk+KBr1dQH+skFl2LCJQpyfqwVvFhZz67S4a/8gQfYReTZDGJELMRP6HxbFbsSNisN11a3Kg3VIutBqyU9u1vSIMPx/o8ScvxVcAqHg=
10
+ env:
11
+ global:
12
+ - secure: CPu3hIqPCA4txUqh7aS90PR7hGURzyoqcMu0zJx4qvrtvzsI9eyEWKx7P8pXbvYUIgaGevw5GiWEMYH2axkH/74KMyAL9DsdpDA06aCxdZfs7iEaNfZY+l4MN3WCFb9WoLVL7fG+wqgvZXnV4RyLkn+W+vjdmvjY8RZ9G7/0HiE=
13
+ - secure: WG67hclm6kFtNQRKa/a5j2R79n4cTq7WrI+sCaxq5Nr5jvstdamaIOPtaenX7fIIakBYhX1wtGqOvlEjUzF8IpLi/fwDjn1Cb8DP8oyLhK1koeLZhegiGV3hEsne7RNiV1G8VMHfsGeJBUm2wvsWx4EdK60Ib4+ZLuw5WFMVlNg=
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in egree.gemspec
4
+ gemspec
5
+ gem "codeclimate-test-reporter", group: :test, require: nil
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Joel Junström
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,72 @@
1
+ [![Build Status](https://travis-ci.org/joeljunstrom/egree-ruby.svg?branch=master)](https://travis-ci.org/joeljunstrom/egree-ruby)
2
+ [![Code Climate](https://codeclimate.com/github/joeljunstrom/egree-ruby/badges/gpa.svg)](https://codeclimate.com/github/joeljunstrom/egree-ruby)
3
+
4
+ # Egree
5
+
6
+ Ruby client for the [Egree API](https://app.egree.com/apiv1).
7
+
8
+ Currently the only supported actions is the `createcasecommand` and `getviewcaseurlquery`.
9
+
10
+ ## Usage
11
+
12
+ ### Creating a case
13
+
14
+ ```
15
+ egree = Egree.client username, password
16
+
17
+ signature_case = Egree::Case.new "Agreement", ["touch"]
18
+ signature_case.add_party Egree::Party.new({
19
+ name: "First Last",
20
+ email: "name@example.com",
21
+ social_security_number: "1234567890"
22
+ })
23
+ signature_case.add_document Egree::Document.new "/some/path/file.pdf"
24
+
25
+ result = egree.create_case signature_case
26
+
27
+ if result.success?
28
+ puts "#{signature_case.reference_id} was created."
29
+ else
30
+ puts "There was some issues with the case"
31
+ result.errors.each do |error|
32
+ puts error
33
+ end
34
+ end
35
+ ```
36
+
37
+ ### Getting the signature url for a case
38
+
39
+ ```
40
+ egree = Egree.client username, password
41
+ result = egree.get_case_url "98d08cf5-d35d-403b-ac31-fa1ac85037a1"
42
+
43
+ if result.success?
44
+ puts "The url is: #{result.response}"
45
+ else
46
+ puts "Could not get signature url"
47
+ result.errors.each do |error|
48
+ puts error
49
+ end
50
+ end
51
+ ```
52
+
53
+
54
+
55
+ ## Contributing
56
+
57
+ 1. Fork it ( http://github.com/joeljunstrom/egree/fork )
58
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
59
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
60
+ 4. Push to the branch (`git push origin my-new-feature`)
61
+ 5. Create new Pull Request
62
+
63
+ ### Local development
64
+
65
+ Create a .env file in the root directory.
66
+
67
+ ```
68
+ EGREE_USERNAME=your-username
69
+ EGREE_PASSWORD=your-password
70
+ ```
71
+
72
+ This is used for the integration tests.
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,31 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'egree/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "egree"
8
+ spec.version = Egree::VERSION
9
+ spec.authors = ["Joel Junström"]
10
+ spec.email = ["joel.junstrom@oktavilla.se"]
11
+ spec.summary = %q{Client for the Egree API}
12
+ spec.homepage = "https://github.com/joeljunstrom/egree-ruby"
13
+ spec.license = "MIT"
14
+
15
+ spec.required_ruby_version = "~> 2.0"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0")
18
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
19
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_dependency "faraday", "~> 0.9.0"
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.5"
25
+ spec.add_development_dependency "dotenv", "~> 0.11.1"
26
+ spec.add_development_dependency "rake"
27
+ spec.add_development_dependency "rspec"
28
+ spec.add_development_dependency "webmock", "~> 1.18.0"
29
+ spec.add_development_dependency "vcr", "~> 2.9.2"
30
+ spec.add_development_dependency "luhn", "~> 0.1.1"
31
+ end
@@ -0,0 +1,8 @@
1
+ require "egree/version"
2
+ require "egree/client"
3
+
4
+ module Egree
5
+ def self.client username, password, environment = :production
6
+ Client.new username, password, environment
7
+ end
8
+ end
@@ -0,0 +1,64 @@
1
+ require "egree/reference_id"
2
+ require "egree/serializers/case"
3
+
4
+ module Egree
5
+ class Case
6
+ def self.signature_types
7
+ [ "sms", "electronicId", "touch" ]
8
+ end
9
+
10
+ def self.generate_reference_id
11
+ ReferenceId.generate
12
+ end
13
+
14
+ attr_reader :name, :signature_types
15
+
16
+ def initialize name, signature_types
17
+ @name = name
18
+ self.signature_types = signature_types
19
+ end
20
+
21
+ attr_writer :reference_id
22
+
23
+ def reference_id
24
+ @reference_id ||= self.class.generate_reference_id
25
+ end
26
+
27
+ def signature_types= signature_types
28
+ types = Array(signature_types)
29
+
30
+ unknown_types = types - Case.signature_types
31
+ if unknown_types.any?
32
+ raise unknown_signature_type_error(unknown_types)
33
+ end
34
+
35
+ @signature_types = types
36
+ end
37
+
38
+ def add_party party
39
+ self.parties << party
40
+ end
41
+
42
+ def parties
43
+ @parties ||= []
44
+ end
45
+
46
+ def add_document document
47
+ self.documents << document
48
+ end
49
+
50
+ def documents
51
+ @documents ||= []
52
+ end
53
+
54
+ def to_json
55
+ Serializers::Case.serialize self
56
+ end
57
+
58
+ private
59
+
60
+ def unknown_signature_type_error types
61
+ ArgumentError.new("Unknown signature types: #{types.join(", ")}. Valid types are: #{Case.signature_types.join(", ")}")
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,103 @@
1
+ require "json"
2
+ require "faraday"
3
+
4
+ module Egree
5
+ class Client
6
+ attr_reader :username, :password
7
+
8
+ attr_accessor :environment
9
+
10
+ def initialize username, password, environment = :production
11
+ @username = username
12
+ @password = password
13
+ self.environment = environment
14
+ end
15
+
16
+ def create_case signature_case
17
+ post "/apiv1/createcasecommand", signature_case.to_json
18
+ end
19
+
20
+ def get_case_url reference_id
21
+ post "/apiv1/getviewcaseurlquery", reference_id.to_json
22
+ end
23
+
24
+ def post api_command, body = nil
25
+ response = make_post api_command, body
26
+
27
+ if response.success?
28
+ SuccessResult.new parse_success_response(response.body)
29
+ else
30
+ ErrorResult.new parse_error_response(response.body)
31
+ end
32
+ end
33
+
34
+ def host
35
+ hosts.fetch(self.environment, hosts[:production])
36
+ end
37
+
38
+ def connection
39
+ Faraday.new "https://#{host}" do |conn|
40
+ conn.adapter :net_http
41
+ conn.headers["Accept"] = "application/json"
42
+ conn.basic_auth username, password
43
+ end
44
+ end
45
+
46
+ def headers
47
+ connection.headers
48
+ end
49
+
50
+ private
51
+
52
+ def make_post url, body
53
+ connection.post do |request|
54
+ request.url url
55
+ request.headers["Content-Type"] = "application/json; charset=utf-8"
56
+ request.body = body if body
57
+ end
58
+ end
59
+
60
+ def parse_success_response body
61
+ begin
62
+ JSON.parse body
63
+ rescue JSON::ParserError
64
+ body
65
+ end
66
+ end
67
+
68
+ def parse_error_response body
69
+ body.scan(/<p>(.*?)<\/p>/).flatten
70
+ end
71
+
72
+ def hosts
73
+ {
74
+ production: "app.egree.com",
75
+ test: "test.underskrift.se"
76
+ }
77
+ end
78
+
79
+ class SuccessResult
80
+ attr_reader :response
81
+
82
+ def initialize response
83
+ @response = response
84
+ end
85
+
86
+ def success?
87
+ true
88
+ end
89
+ end
90
+
91
+ class ErrorResult
92
+ attr_reader :errors
93
+
94
+ def initialize errors = []
95
+ @errors = Array(errors)
96
+ end
97
+
98
+ def success?
99
+ false
100
+ end
101
+ end
102
+ end
103
+ end
@@ -0,0 +1,45 @@
1
+ require "open-uri"
2
+
3
+ module Egree
4
+ class Document
5
+ attr_reader :path
6
+
7
+ def initialize path
8
+ @path = path
9
+ end
10
+
11
+ def filename
12
+ File.basename path
13
+ end
14
+
15
+ def size
16
+ file.size
17
+ end
18
+
19
+ def content_type
20
+ "application/pdf"
21
+ end
22
+
23
+ def data
24
+ Base64.encode64 file_contents
25
+ end
26
+
27
+ def add_form_field form_field
28
+ self.form_fields << form_field
29
+ end
30
+
31
+ def form_fields
32
+ @form_fields ||= []
33
+ end
34
+
35
+ private
36
+
37
+ def file_contents
38
+ file.read
39
+ end
40
+
41
+ def file
42
+ open path
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,3 @@
1
+ module Egree
2
+ FormField = Struct.new :name, :value
3
+ end
@@ -0,0 +1,21 @@
1
+ module Egree
2
+ class Party
3
+ attr_accessor :name, :email
4
+ attr_reader :social_security_number
5
+
6
+ def self.new_with_attributes attributes = {}
7
+ party = self.new
8
+
9
+ attributes.each do |name, value|
10
+ assignment_method_name = "#{name}="
11
+ party.public_send(assignment_method_name, value) if party.respond_to?(assignment_method_name)
12
+ end
13
+
14
+ party
15
+ end
16
+
17
+ def social_security_number= social_security_number
18
+ @social_security_number = social_security_number.to_s.gsub(/\D/, "")
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,34 @@
1
+ require "securerandom"
2
+ require "egree/serializers/reference_id"
3
+
4
+ module Egree
5
+ class ReferenceId
6
+ include Comparable
7
+
8
+ def self.generate
9
+ new SecureRandom.uuid
10
+ end
11
+
12
+ attr_reader :id
13
+
14
+ def initialize id
15
+ @id = id
16
+ end
17
+
18
+ def to_s
19
+ id.to_s
20
+ end
21
+
22
+ def to_json
23
+ Serializers::ReferenceId.serialize self
24
+ end
25
+
26
+ def to_api_hash
27
+ Serializers::ReferenceId.to_api_hash self
28
+ end
29
+
30
+ def <=> other
31
+ other.is_a?(self.class) && self.id <=> other.id
32
+ end
33
+ end
34
+ end