web_merge 1.0.2 → 1.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -0
- data/lib/web_merge/api.rb +6 -2
- data/lib/web_merge/constants.rb +4 -2
- data/lib/web_merge/document.rb +12 -7
- data/lib/web_merge/version.rb +1 -1
- data/spec/api_spec.rb +22 -0
- data/spec/document_spec.rb +112 -0
- data/spec/spec_helper.rb +2 -0
- data/web_merge.gemspec +2 -0
- metadata +38 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bc7a10e1ae74d9250ab19f76d480191409df2a53
|
4
|
+
data.tar.gz: ffe5b449a036bc8efdc7b3d44ee028b098d4a68c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 537cc6e7452062a6342393c1ab6d063e41e0b21a7e82ef4f371741cc1b2f82c1710acf70abe0d7e08f54596c65cb84b19c5f10a0f921ec5739ce5a28d9833938
|
7
|
+
data.tar.gz: 4926a32d64c0b0924fb4aeaceb83b289a2bcce78cbab708abc5f28e53b5eb0657be337eb6e6c945a8461738d7c78a87d4dc84a5198e6929c2d944d29958cbeeb
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,11 @@
|
|
1
|
+
## 1.0.3
|
2
|
+
|
3
|
+
* Increased test coverage.
|
4
|
+
* Added support for more document types.
|
5
|
+
* Added support for the document file API endpoint.
|
6
|
+
* Added support for JSON payload.
|
7
|
+
* Raises an error if a document didn't save on WebMerge.
|
8
|
+
|
1
9
|
## 1.0.2
|
2
10
|
|
3
11
|
* Update regex for single line match.
|
data/lib/web_merge/api.rb
CHANGED
@@ -35,6 +35,10 @@ module WebMerge
|
|
35
35
|
get("#{WebMerge::Constants::DOCUMENTS}/#{doc_id}/fields", &block)
|
36
36
|
end
|
37
37
|
|
38
|
+
def get_document_file(doc_id, &block)
|
39
|
+
get("#{WebMerge::Constants::DOCUMENTS}/#{doc_id}/file", &block)
|
40
|
+
end
|
41
|
+
|
38
42
|
# doc_id The Document ID
|
39
43
|
# example: 436346
|
40
44
|
# doc_key The Document Key
|
@@ -98,9 +102,9 @@ module WebMerge
|
|
98
102
|
uri = URI.parse(url_string)
|
99
103
|
Net::HTTP.start(uri.host, uri.port, use_ssl: uri.scheme == 'https') do |http|
|
100
104
|
action_klass = "Net::HTTP::#{verb.camelize}".constantize
|
101
|
-
request = action_klass.new(uri.request_uri)
|
105
|
+
request = action_klass.new(uri.request_uri, 'Content-Type' => 'application/json')
|
102
106
|
request.basic_auth(@api_key, @api_secret)
|
103
|
-
request.
|
107
|
+
request.body = form_data.to_json if form_data.present?
|
104
108
|
http.request(request) do |response|
|
105
109
|
if block_given?
|
106
110
|
return block.call(response)
|
data/lib/web_merge/constants.rb
CHANGED
@@ -20,13 +20,15 @@ module WebMerge
|
|
20
20
|
HTML = 'html'
|
21
21
|
DOCX = 'docx'
|
22
22
|
EMAIL = 'email'
|
23
|
+
PPTX = 'pptx'
|
24
|
+
XLSX = 'xlsx'
|
23
25
|
|
24
26
|
SECURITY_LEVEL_LOW = 'low'
|
25
27
|
SECURITY_LEVEL_MEDIUM = 'medium'
|
26
28
|
SECURITY_LEVEL_HIGH = 'high'
|
27
29
|
|
28
|
-
SUPPORTED_TYPES = [HTML, PDF, DOCX]
|
29
|
-
SUPPORTED_OUTPUTS = [PDF, DOCX, EMAIL]
|
30
|
+
SUPPORTED_TYPES = [HTML, PDF, DOCX, PPTX, XLSX]
|
31
|
+
SUPPORTED_OUTPUTS = [PDF, DOCX, EMAIL, PPTX, XLSX]
|
30
32
|
|
31
33
|
SECURITY_LEVELS = [SECURITY_LEVEL_LOW, SECURITY_LEVEL_MEDIUM, SECURITY_LEVEL_HIGH]
|
32
34
|
end
|
data/lib/web_merge/document.rb
CHANGED
@@ -1,4 +1,7 @@
|
|
1
|
+
|
1
2
|
module WebMerge
|
3
|
+
class DocumentError < RuntimeError; end;
|
4
|
+
|
2
5
|
class Document
|
3
6
|
include ::ActiveModel::Validations
|
4
7
|
|
@@ -21,8 +24,8 @@ module WebMerge
|
|
21
24
|
@size_height = options[:size_height]
|
22
25
|
end
|
23
26
|
|
24
|
-
def self.find(doc_id)
|
25
|
-
instance = empty_instance
|
27
|
+
def self.find(doc_id, client: required(:client))
|
28
|
+
instance = empty_instance(client)
|
26
29
|
instance.send(:id=, doc_id)
|
27
30
|
instance.reload
|
28
31
|
end
|
@@ -33,9 +36,9 @@ module WebMerge
|
|
33
36
|
end
|
34
37
|
end
|
35
38
|
|
36
|
-
def self.all
|
37
|
-
|
38
|
-
instance = empty_instance
|
39
|
+
def self.all(client: required(:client))
|
40
|
+
client.get_documents.map do |doc_hash|
|
41
|
+
instance = empty_instance(client)
|
39
42
|
instance.send(:update_instance, doc_hash)
|
40
43
|
instance
|
41
44
|
end
|
@@ -56,6 +59,8 @@ module WebMerge
|
|
56
59
|
else
|
57
60
|
@client.update_document(id, as_form_data)
|
58
61
|
end
|
62
|
+
raise WebMerge::DocumentError.new(response['error']) if response['error'].present?
|
63
|
+
|
59
64
|
update_instance(response.symbolize_keys)
|
60
65
|
true
|
61
66
|
end
|
@@ -112,8 +117,8 @@ module WebMerge
|
|
112
117
|
private
|
113
118
|
attr_writer :id, :key, :size, :active, :url
|
114
119
|
|
115
|
-
def self.empty_instance
|
116
|
-
new(name: "", type: "", output: "")
|
120
|
+
def self.empty_instance(client)
|
121
|
+
new(client: client, name: "", type: "", output: "")
|
117
122
|
end
|
118
123
|
|
119
124
|
def update_instance(response)
|
data/lib/web_merge/version.rb
CHANGED
data/spec/api_spec.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require_relative '../lib/web_merge/constants'
|
3
|
+
require_relative '../lib/web_merge/api'
|
4
|
+
|
5
|
+
describe WebMerge::API do
|
6
|
+
let(:api) { described_class.new(secret: 'foo', key: 'bar', force_test_mode: true) }
|
7
|
+
let(:document) do
|
8
|
+
double(:document, id: 123, type: 'pdf', contents: 'things', updated_at: Time.now)
|
9
|
+
end
|
10
|
+
|
11
|
+
describe '#get_document_file' do
|
12
|
+
|
13
|
+
let(:url_string) { "#{WebMerge::Constants::DOCUMENTS}/#{document.id}/file" }
|
14
|
+
let(:response) do
|
15
|
+
{ 'type' => document.type, 'last_update' => document.updated_at, 'contents' => document.contents }
|
16
|
+
end
|
17
|
+
it 'makes a get request' do
|
18
|
+
expect(api).to receive(:get).with(url_string).and_return(response)
|
19
|
+
expect(api.get_document_file(document.id)).to eq(response)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,112 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require_relative '../lib/web_merge/constants'
|
3
|
+
require_relative '../lib/web_merge/document'
|
4
|
+
|
5
|
+
describe WebMerge::Document do
|
6
|
+
describe '.find' do
|
7
|
+
let(:document) do
|
8
|
+
described_class.new(client: 'foo', name: 'foo', type: 'foo').tap do |document|
|
9
|
+
document.send(:id=, rand(1..10))
|
10
|
+
end
|
11
|
+
end
|
12
|
+
let(:client) { double(:client, get_document: response ) }
|
13
|
+
let(:response) { { foo: 'irrelevant' } }
|
14
|
+
|
15
|
+
it 'returns a document' do
|
16
|
+
finder = described_class.find(document.id, client: client)
|
17
|
+
expect(finder).to be_kind_of(described_class)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe '.all' do
|
22
|
+
let(:client) { double(:client, get_documents: response ) }
|
23
|
+
let(:response) { [ first_document: 'foo', second_document: 'bar' ] }
|
24
|
+
|
25
|
+
it 'returns a collection of documents' do
|
26
|
+
finder = described_class.all(client: client)
|
27
|
+
|
28
|
+
finder.each do |doc|
|
29
|
+
expect(doc).to be_kind_of(described_class)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
describe '#save' do
|
35
|
+
let(:client) { double(:client, create_document: response ) }
|
36
|
+
context 'document is valid' do
|
37
|
+
let(:response) do
|
38
|
+
{
|
39
|
+
"id":"234543",
|
40
|
+
"key":"firm3",
|
41
|
+
"type":"html",
|
42
|
+
"name":"1040 EZ",
|
43
|
+
"output":"pdf",
|
44
|
+
"size":"",
|
45
|
+
"size_width":"8.5",
|
46
|
+
"size_height":"11",
|
47
|
+
"active":"1",
|
48
|
+
"url":"https://www.webmerge.me/merge/234543/firm3",
|
49
|
+
"fields":[
|
50
|
+
{"key":"aflekjf409t3j4mg30m409m", "name":"FirstName"},
|
51
|
+
{"key":"3to3igj3g3gt94j9304jfqw", "name":"LastName"},
|
52
|
+
{"key":"t43j0grjaslkfje304vj9we", "name":"Email"}
|
53
|
+
]
|
54
|
+
}
|
55
|
+
end
|
56
|
+
|
57
|
+
let(:valid_document) do
|
58
|
+
described_class.new(client: client, name: 'foo', type: 'docx')
|
59
|
+
end
|
60
|
+
|
61
|
+
it 'returns true' do
|
62
|
+
expect(valid_document.save).to eq(true)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
describe '#save!' do
|
68
|
+
let(:client) { double(:client, create_document: response ) }
|
69
|
+
context 'document is valid' do
|
70
|
+
let(:response) do
|
71
|
+
{
|
72
|
+
"id":"234543",
|
73
|
+
"key":"firm3",
|
74
|
+
"type":"html",
|
75
|
+
"name":"1040 EZ",
|
76
|
+
"output":"pdf",
|
77
|
+
"size":"",
|
78
|
+
"size_width":"8.5",
|
79
|
+
"size_height":"11",
|
80
|
+
"active":"1",
|
81
|
+
"url":"https://www.webmerge.me/merge/234543/firm3",
|
82
|
+
"fields":[
|
83
|
+
{"key":"aflekjf409t3j4mg30m409m", "name":"FirstName"},
|
84
|
+
{"key":"3to3igj3g3gt94j9304jfqw", "name":"LastName"},
|
85
|
+
{"key":"t43j0grjaslkfje304vj9we", "name":"Email"}
|
86
|
+
]
|
87
|
+
}
|
88
|
+
end
|
89
|
+
|
90
|
+
let(:valid_document) do
|
91
|
+
described_class.new(client: client, name: 'foo', type: 'docx')
|
92
|
+
end
|
93
|
+
|
94
|
+
it 'returns nil' do
|
95
|
+
expect(valid_document.save!).to be_nil
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
context 'document has merge field errors' do
|
100
|
+
let(:response) do
|
101
|
+
{ 'error' => 'Error merging document: Syntax error in template...' }
|
102
|
+
end
|
103
|
+
let(:document_with_merge_field_errors) do
|
104
|
+
described_class.new(client: client, name: 'foo', type: 'docx')
|
105
|
+
end
|
106
|
+
|
107
|
+
it 'raises an error upon document save error' do
|
108
|
+
expect { document_with_merge_field_errors.save! }.to raise_error(WebMerge::DocumentError)
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
data/spec/spec_helper.rb
ADDED
data/web_merge.gemspec
CHANGED
@@ -20,5 +20,7 @@ Gem::Specification.new do |spec|
|
|
20
20
|
|
21
21
|
spec.add_development_dependency "bundler", "~> 1.7"
|
22
22
|
spec.add_development_dependency "rake", "~> 10.0"
|
23
|
+
spec.add_development_dependency "rspec", "~> 3.4"
|
24
|
+
spec.add_development_dependency "pry", "~> 0.10"
|
23
25
|
spec.add_development_dependency "activemodel", ">= 3.0"
|
24
26
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: web_merge
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jeremy Clarke
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-07-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -38,6 +38,34 @@ dependencies:
|
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.4'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.4'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: pry
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0.10'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0.10'
|
41
69
|
- !ruby/object:Gem::Dependency
|
42
70
|
name: activemodel
|
43
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -71,6 +99,9 @@ files:
|
|
71
99
|
- lib/web_merge/document.rb
|
72
100
|
- lib/web_merge/notification.rb
|
73
101
|
- lib/web_merge/version.rb
|
102
|
+
- spec/api_spec.rb
|
103
|
+
- spec/document_spec.rb
|
104
|
+
- spec/spec_helper.rb
|
74
105
|
- web_merge.gemspec
|
75
106
|
homepage: http://www.webmerge.me
|
76
107
|
licenses:
|
@@ -92,8 +123,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
92
123
|
version: '0'
|
93
124
|
requirements: []
|
94
125
|
rubyforge_project:
|
95
|
-
rubygems_version: 2.
|
126
|
+
rubygems_version: 2.6.11
|
96
127
|
signing_key:
|
97
128
|
specification_version: 4
|
98
129
|
summary: WebMerge REST API Wrapper
|
99
|
-
test_files:
|
130
|
+
test_files:
|
131
|
+
- spec/api_spec.rb
|
132
|
+
- spec/document_spec.rb
|
133
|
+
- spec/spec_helper.rb
|