txtextcontrol-reportingcloud 1.0.1 → 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/LICENSE.md +1 -1
- data/lib/core_ext/string.rb +1 -1
- data/lib/txtextcontrol/reportingcloud.rb +1 -1
- data/lib/txtextcontrol/reportingcloud/account_settings.rb +1 -1
- data/lib/txtextcontrol/reportingcloud/find_and_replace_body.rb +91 -0
- data/lib/txtextcontrol/reportingcloud/merge_block.rb +61 -0
- data/lib/txtextcontrol/reportingcloud/merge_body.rb +1 -1
- data/lib/txtextcontrol/reportingcloud/merge_field.rb +78 -0
- data/lib/txtextcontrol/reportingcloud/merge_settings.rb +1 -1
- data/lib/txtextcontrol/reportingcloud/reportingcloud.rb +81 -5
- data/lib/txtextcontrol/reportingcloud/template.rb +1 -1
- data/lib/txtextcontrol/reportingcloud/template_data_validator.rb +1 -1
- data/lib/txtextcontrol/reportingcloud/template_info.rb +67 -0
- data/lib/txtextcontrol/reportingcloud/template_name_validator.rb +1 -1
- data/lib/txtextcontrol/reportingcloud/version.rb +2 -2
- metadata +7 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f5b632e12313e22c5615fa25a61e07f66f196851
|
4
|
+
data.tar.gz: b23b146e8e07c8bdc8cc515973ec4251777c1f21
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 90750efc45ace03aacd6756765e075a75a6942561dfdf54377a208d07ab2b3c658baceb00ee4843cb03c3fbe7678e3e45235604c37be8b80bb5121f1a9156854
|
7
|
+
data.tar.gz: adcb08b8b1fc36a76d4be92392397eb2d760bab9639e7be673b8f204a24b2066ab04cd7746b9bd5d3946c53f20fc61eff54f65583651d7633a081c0ecf082b79
|
data/LICENSE.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
## Copyright ©
|
1
|
+
## Copyright © 2017, Text Control GmbH. All rights reserved.
|
2
2
|
|
3
3
|
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
|
4
4
|
following conditions are met:
|
data/lib/core_ext/string.rb
CHANGED
@@ -9,7 +9,7 @@
|
|
9
9
|
#
|
10
10
|
# License: https://raw.githubusercontent.com/TextControl/txtextcontrol-reportingcloud-ruby/master/LICENSE.md
|
11
11
|
#
|
12
|
-
# Copyright: ©
|
12
|
+
# Copyright: © 2017 Text Control GmbH
|
13
13
|
|
14
14
|
# Extensions to class String.
|
15
15
|
# @author Thorsten Kummerow (@thomerow)
|
@@ -9,7 +9,7 @@
|
|
9
9
|
#
|
10
10
|
# License: https://raw.githubusercontent.com/TextControl/txtextcontrol-reportingcloud-ruby/master/LICENSE.md
|
11
11
|
#
|
12
|
-
# Copyright: ©
|
12
|
+
# Copyright: © 2017 Text Control GmbH
|
13
13
|
|
14
14
|
require "txtextcontrol/reportingcloud/version"
|
15
15
|
require_relative "./reportingcloud/reportingcloud.rb"
|
@@ -0,0 +1,91 @@
|
|
1
|
+
# ReportingCloud Ruby Wrapper
|
2
|
+
#
|
3
|
+
# Official wrapper (authored by Text Control GmbH, publisher of ReportingCloud) to access
|
4
|
+
# ReportingCloud in Ruby.
|
5
|
+
#
|
6
|
+
# Go to http://www.reporting.cloud to learn more about ReportingCloud
|
7
|
+
# Go to https://github.com/TextControl/txtextcontrol-reportingcloud-ruby for the
|
8
|
+
# canonical source repository.
|
9
|
+
#
|
10
|
+
# License: https://raw.githubusercontent.com/TextControl/txtextcontrol-reportingcloud-ruby/master/LICENSE.md
|
11
|
+
#
|
12
|
+
# Copyright: © 2017 Text Control GmbH
|
13
|
+
|
14
|
+
require "txtextcontrol/reportingcloud/merge_settings"
|
15
|
+
|
16
|
+
module TXTextControl
|
17
|
+
module ReportingCloud
|
18
|
+
|
19
|
+
# The request body of requests to the endpoint "/document/findandreplace". Contains
|
20
|
+
# an array of string arrays, a template encoded as a Base64 string and a ReportingCloud
|
21
|
+
# MergeSettings object.
|
22
|
+
# @attr find_and_replace_data [Array<Array<String>>] The find and replace
|
23
|
+
# pair values as an array of string arrays.
|
24
|
+
# @attr merge_settings [MergeSettings] Merge settings to specify merge
|
25
|
+
# properties and document properties such as title and author.
|
26
|
+
# @attr template [String] The source document encoded as a Base64 string.
|
27
|
+
class FindAndReplaceBody
|
28
|
+
attr_accessor :find_and_replace_data
|
29
|
+
attr_accessor :merge_settings
|
30
|
+
attr_accessor :template
|
31
|
+
|
32
|
+
# @param find_and_replace_data [Array<Array<String>>] The find and replace
|
33
|
+
# pair values as an array of string arrays.
|
34
|
+
# @param template [String] The source document encoded as a Base64 string.
|
35
|
+
# The supported document formats are +.rtf+, +.doc+, +.docx+, and +.tx+.
|
36
|
+
# @param merge_settings [MergeSettings] Merge settings to specify merge
|
37
|
+
# properties and document properties such as title and author.
|
38
|
+
def initialize(find_and_replace_data, template = nil, merge_settings = nil)
|
39
|
+
self.find_and_replace_data = find_and_replace_data
|
40
|
+
self.template = template
|
41
|
+
self.merge_settings = merge_settings
|
42
|
+
end
|
43
|
+
|
44
|
+
def find_and_replace_data
|
45
|
+
@find_and_replace_data
|
46
|
+
end
|
47
|
+
|
48
|
+
def find_and_replace_data=(val)
|
49
|
+
unless !val.nil? && (val.kind_of? Array) && !val.empty? && (val.all? { |elem| elem.kind_of? Array }) &&
|
50
|
+
(val.all? { |elem| (elem.length == 2) && (elem[0].kind_of? String) && (elem[1].kind_of? String) })
|
51
|
+
raise ArgumentError, "Find and replace data must be a non empty array of string arrays containing two strings each."
|
52
|
+
end
|
53
|
+
@find_and_replace_data = val
|
54
|
+
end
|
55
|
+
|
56
|
+
def merge_settings
|
57
|
+
@merge_settings
|
58
|
+
end
|
59
|
+
|
60
|
+
def merge_settings=(val)
|
61
|
+
unless val.nil? || (val.kind_of? MergeSettings)
|
62
|
+
raise ArgumentError, "Merge settings must be of type MergeSettings."
|
63
|
+
end
|
64
|
+
@merge_settings = val
|
65
|
+
end
|
66
|
+
|
67
|
+
def template
|
68
|
+
@template
|
69
|
+
end
|
70
|
+
|
71
|
+
def template=(val)
|
72
|
+
unless val.nil? || ((val.kind_of? String) && !val.to_s.empty?)
|
73
|
+
raise ArgumentError, "Template data must be a non empty string."
|
74
|
+
end
|
75
|
+
@template = val
|
76
|
+
end
|
77
|
+
|
78
|
+
# Converts a FindAndReplaceBody instance to a hash while converting the attribute names
|
79
|
+
# from snake case to camel case.
|
80
|
+
# @return [Hash] A hash representing the FindAndReplaceBody instance.
|
81
|
+
def to_camelized_hash
|
82
|
+
return {
|
83
|
+
"findAndReplaceData" => @find_and_replace_data,
|
84
|
+
"template" => @template,
|
85
|
+
"mergeSettings" => @merge_settings
|
86
|
+
}
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
@@ -0,0 +1,61 @@
|
|
1
|
+
# ReportingCloud Ruby Wrapper
|
2
|
+
#
|
3
|
+
# Official wrapper (authored by Text Control GmbH, publisher of ReportingCloud) to access
|
4
|
+
# ReportingCloud in Ruby.
|
5
|
+
#
|
6
|
+
# Go to http://www.reporting.cloud to learn more about ReportingCloud
|
7
|
+
# Go to https://github.com/TextControl/txtextcontrol-reportingcloud-ruby for the
|
8
|
+
# canonical source repository.
|
9
|
+
#
|
10
|
+
# License: https://raw.githubusercontent.com/TextControl/txtextcontrol-reportingcloud-ruby/master/LICENSE.md
|
11
|
+
#
|
12
|
+
# Copyright: © 2017 Text Control GmbH
|
13
|
+
|
14
|
+
require 'txtextcontrol/reportingcloud/merge_field'
|
15
|
+
|
16
|
+
module TXTextControl
|
17
|
+
module ReportingCloud
|
18
|
+
|
19
|
+
# Represents a merge block in a document template.
|
20
|
+
# @attr_reader [String] name The merge block's' name.
|
21
|
+
# @attr_reader [Array<MergeBlock>] merge_blocks The merge blocks nested
|
22
|
+
# inside the merge block.
|
23
|
+
# @attr_reader [Array<MergeField>] merge_fields The merge fields inside
|
24
|
+
# the merge block.
|
25
|
+
class MergeBlock
|
26
|
+
attr_reader :name
|
27
|
+
attr_reader :merge_blocks
|
28
|
+
attr_reader :merge_fields
|
29
|
+
|
30
|
+
def initialize(name, merge_blocks, merge_fields)
|
31
|
+
# Parameter validation
|
32
|
+
raise ArgumentError, "Block name must be a string." if !name.kind_of? String
|
33
|
+
raise ArgumentError, "Parameter merge_blocks must be an array." if !merge_blocks.kind_of? Array
|
34
|
+
raise ArgumentError, "Parameter merge_fields must be an array." if !merge_fields.kind_of? Array
|
35
|
+
|
36
|
+
@name = name
|
37
|
+
@merge_blocks = merge_blocks
|
38
|
+
@merge_fields = merge_fields
|
39
|
+
end
|
40
|
+
|
41
|
+
# Creates an MergeBlock instance from a hash.
|
42
|
+
# @param [Hash] hash The hash to try and create an MergeBlock instance from.
|
43
|
+
# @return [MergeBlock] A newly created MergeBlock instance.
|
44
|
+
def self.from_camelized_hash(hash)
|
45
|
+
# Parameter validation
|
46
|
+
raise ArgumentError, "Parameter must be a Hash." if !hash.kind_of? Hash
|
47
|
+
|
48
|
+
name = hash["name"]
|
49
|
+
blocks = Array.new
|
50
|
+
hash["mergeBlocks"].each do |elem|
|
51
|
+
blocks.push(MergeBlock.from_camelized_hash(elem))
|
52
|
+
end
|
53
|
+
fields = Array.new
|
54
|
+
hash["mergeFields"].each do |elem|
|
55
|
+
fields.push(MergeField.from_camelized_hash(elem))
|
56
|
+
end
|
57
|
+
return MergeBlock.new(name, blocks, fields)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -9,7 +9,7 @@
|
|
9
9
|
#
|
10
10
|
# License: https://raw.githubusercontent.com/TextControl/txtextcontrol-reportingcloud-ruby/master/LICENSE.md
|
11
11
|
#
|
12
|
-
# Copyright: ©
|
12
|
+
# Copyright: © 2017 Text Control GmbH
|
13
13
|
|
14
14
|
require "txtextcontrol/reportingcloud/merge_settings"
|
15
15
|
|
@@ -0,0 +1,78 @@
|
|
1
|
+
# ReportingCloud Ruby Wrapper
|
2
|
+
#
|
3
|
+
# Official wrapper (authored by Text Control GmbH, publisher of ReportingCloud) to access
|
4
|
+
# ReportingCloud in Ruby.
|
5
|
+
#
|
6
|
+
# Go to http://www.reporting.cloud to learn more about ReportingCloud
|
7
|
+
# Go to https://github.com/TextControl/txtextcontrol-reportingcloud-ruby for the
|
8
|
+
# canonical source repository.
|
9
|
+
#
|
10
|
+
# License: https://raw.githubusercontent.com/TextControl/txtextcontrol-reportingcloud-ruby/master/LICENSE.md
|
11
|
+
#
|
12
|
+
# Copyright: © 2017 Text Control GmbH
|
13
|
+
|
14
|
+
module TXTextControl
|
15
|
+
module ReportingCloud
|
16
|
+
|
17
|
+
# Represents a merge field in a document template.
|
18
|
+
# @attr_reader [String] date_time_format The format which is applied to
|
19
|
+
# date / time values.
|
20
|
+
# @attr_reader [String] name The name of the field.
|
21
|
+
# @attr_reader [String] numeric_format The format which is applied to
|
22
|
+
# numeric values.
|
23
|
+
# @attr_reader [Boolean] preserve_formatting Specifies whether formatting is
|
24
|
+
# preserved.
|
25
|
+
# @attr_reader [String] text The field text.
|
26
|
+
# @attr_reader [String] text_after The text after the field.
|
27
|
+
# @attr_reader [String] text_before The text before the field.
|
28
|
+
class MergeField
|
29
|
+
attr_reader :date_time_format
|
30
|
+
attr_reader :name
|
31
|
+
attr_reader :numeric_format
|
32
|
+
attr_reader :preserve_formatting
|
33
|
+
attr_reader :text
|
34
|
+
attr_reader :text_after
|
35
|
+
attr_reader :text_before
|
36
|
+
|
37
|
+
def initialize(date_time_format, name, numeric_format, preserve_formatting, text, text_after, text_before)
|
38
|
+
# Parameter validation
|
39
|
+
unless date_time_format.nil? || (date_time_format.kind_of? String)
|
40
|
+
raise ArgumentError, "Date / time format must be a string."
|
41
|
+
end
|
42
|
+
raise ArgumentError, "Field name must be a string." if !name.kind_of? String
|
43
|
+
unless numeric_format.nil? || (numeric_format.kind_of? String)
|
44
|
+
raise ArgumentError, "Numeric format must be a string"
|
45
|
+
end
|
46
|
+
raise ArgumentError, "Preserve formatting parameter must be a boolean value." if !!preserve_formatting != preserve_formatting
|
47
|
+
raise ArgumentError, "Field text must be a string." if !text.kind_of? String
|
48
|
+
raise ArgumentError, "Text after must be a string." if !text_after.nil? && (!text_after.kind_of? String)
|
49
|
+
raise ArgumentError, "Text before must be a string." if !text_before.nil? && (!text_before.kind_of? String)
|
50
|
+
|
51
|
+
@date_time_format = date_time_format
|
52
|
+
@name = name
|
53
|
+
@numeric_format = numeric_format
|
54
|
+
@preserve_formatting = preserve_formatting
|
55
|
+
@text = text
|
56
|
+
@text_after = text_after
|
57
|
+
@text_before = text_before
|
58
|
+
end
|
59
|
+
|
60
|
+
# Creates an MergeField instance from a hash.
|
61
|
+
# @param [Hash] hash The hash to try and create an MergeField instance from.
|
62
|
+
# @return [MergeField] A newly created MergeField instance.
|
63
|
+
def self.from_camelized_hash(hash)
|
64
|
+
# Parameter validation
|
65
|
+
raise ArgumentError, "Parameter must be a Hash." if !hash.kind_of? Hash
|
66
|
+
|
67
|
+
date_time_format = hash["dateTimeFormat"]
|
68
|
+
name = hash["name"]
|
69
|
+
numeric_format = hash["numericFormat"]
|
70
|
+
preserve_formatting = hash["preserveFormatting"]
|
71
|
+
text = hash["text"]
|
72
|
+
text_after = hash["textAfter"]
|
73
|
+
text_before = hash["textBefore"]
|
74
|
+
return MergeField.new(date_time_format, name, numeric_format, preserve_formatting, text, text_after, text_before)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
@@ -9,7 +9,7 @@
|
|
9
9
|
#
|
10
10
|
# License: https://raw.githubusercontent.com/TextControl/txtextcontrol-reportingcloud-ruby/master/LICENSE.md
|
11
11
|
#
|
12
|
-
# Copyright: ©
|
12
|
+
# Copyright: © 2017 Text Control GmbH
|
13
13
|
|
14
14
|
require "uri"
|
15
15
|
require "net/http"
|
@@ -17,7 +17,9 @@ require "json"
|
|
17
17
|
require "ostruct"
|
18
18
|
require "cgi"
|
19
19
|
require 'txtextcontrol/reportingcloud/template'
|
20
|
+
require 'txtextcontrol/reportingcloud/template_info'
|
20
21
|
require 'txtextcontrol/reportingcloud/account_settings'
|
22
|
+
require 'txtextcontrol/reportingcloud/find_and_replace_body'
|
21
23
|
require 'txtextcontrol/reportingcloud/template_name_validator'
|
22
24
|
require 'txtextcontrol/reportingcloud/template_data_validator'
|
23
25
|
require 'core_ext/string'
|
@@ -92,9 +94,11 @@ module TXTextControl
|
|
92
94
|
# MergeBody object of this request.
|
93
95
|
# @param append [Boolean] Specifies whether the documents should be appened
|
94
96
|
# to one resulting document when more than 1 data row is passed.
|
97
|
+
# @param test [Boolean] Specifies whether it is a test run or not. A test run is
|
98
|
+
# not counted against the quota and created documents contain a watermark.
|
95
99
|
# @return [Array<String>] An array of the created documents as
|
96
100
|
# Base64 encoded strings.
|
97
|
-
def merge_document(merge_body, template_name = nil, return_format = :pdf, append = false)
|
101
|
+
def merge_document(merge_body, template_name = nil, return_format = :pdf, append = false, test = false)
|
98
102
|
if !template_name.to_s.empty? && !merge_body.template.nil? # .to_s.empty: check for nil or ''
|
99
103
|
raise ArgumentError, "Template name and template data must not be present at the same time."
|
100
104
|
elsif template_name.to_s.empty? && merge_body.template.nil?
|
@@ -104,7 +108,8 @@ module TXTextControl
|
|
104
108
|
# Create query parameters
|
105
109
|
params = {
|
106
110
|
:returnFormat => return_format,
|
107
|
-
:append => append
|
111
|
+
:append => append,
|
112
|
+
:test => test
|
108
113
|
}
|
109
114
|
unless template_name.to_s.empty?
|
110
115
|
params[:templateName] = template_name
|
@@ -250,12 +255,20 @@ module TXTextControl
|
|
250
255
|
# The supported document formats are +.rtf+, +.doc+, +.docx+, +.html+, +.pdf+ and +.tx+.
|
251
256
|
# @param return_format [Symbol] The format of the created document.
|
252
257
|
# Possible values are: +:pdf+, +:rtf+, +:doc+, +:docx+, +:html+ and +:tx+.
|
258
|
+
# @param test [Boolean] Specifies whether it is a test run or not. A test run is not
|
259
|
+
# counted against the quota and created documents contain a watermark.
|
253
260
|
# @return [String] The created document encoded as a Base64 string.
|
254
|
-
def convert_document(template_data, return_format = :pdf)
|
261
|
+
def convert_document(template_data, return_format = :pdf, test = false)
|
255
262
|
# Parameter validation
|
256
263
|
TemplateDataValidator.validate(template_data)
|
257
264
|
|
258
|
-
|
265
|
+
# Create query parameters
|
266
|
+
params = {
|
267
|
+
:returnFormat => return_format,
|
268
|
+
:test => test
|
269
|
+
}
|
270
|
+
|
271
|
+
res = request("/document/convert", :post, params, template_data)
|
259
272
|
if res.kind_of? Net::HTTPSuccess
|
260
273
|
# Remove leading and trailing quote from string
|
261
274
|
# (inexplicably JSON.parse chokes on simple strings)
|
@@ -265,6 +278,69 @@ module TXTextControl
|
|
265
278
|
end
|
266
279
|
end
|
267
280
|
|
281
|
+
# Returns information about a template including merge fields and merge blocks.
|
282
|
+
# @param template_name [String] The filename of the template in the template
|
283
|
+
# storage to retrieve the information for.
|
284
|
+
# @return [TemplateInfo] The template information.
|
285
|
+
def get_template_info(template_name)
|
286
|
+
# Parameter validation
|
287
|
+
TemplateNameValidator.validate(template_name)
|
288
|
+
|
289
|
+
res = request("/templates/info", :get, { :templateName => template_name })
|
290
|
+
if res.kind_of? Net::HTTPSuccess
|
291
|
+
return TemplateInfo.from_camelized_hash(JSON.parse(res.body))
|
292
|
+
else
|
293
|
+
raise res.body
|
294
|
+
end
|
295
|
+
end
|
296
|
+
|
297
|
+
# Executes a find and replace on a template.
|
298
|
+
# @param find_and_replace_body [FindAndReplaceBody] The request body.
|
299
|
+
# @param template_name [String] The name of the template in the template storage.
|
300
|
+
# If no template is specified, the template must be included in the FindAndReplaceBody
|
301
|
+
# object of this request.
|
302
|
+
# @param return_format [Symbol] The format of the created document.
|
303
|
+
# Possible values are: +:pdf+, +:rtf+, +:doc+, +:docx+, +:html+ and +:tx+.
|
304
|
+
# @param test [Boolean] Specifies whether it is a test run or not. A test run is not
|
305
|
+
# counted against the quota and created documents contain a watermark.
|
306
|
+
# @return [String] The created document encoded as a Base64 string.
|
307
|
+
def find_and_replace(find_and_replace_body, template_name = nil, return_format = :pdf, test = false)
|
308
|
+
# Parameter validation
|
309
|
+
unless !find_and_replace_body.nil? && (find_and_replace_body.kind_of? FindAndReplaceBody)
|
310
|
+
raise ArgumentError, "Request body must be of type FindAndReplaceBody."
|
311
|
+
end
|
312
|
+
unless template_name.nil? || !template_name.to_s.empty?
|
313
|
+
raise ArgumentError, "Template name must be a non empty string."
|
314
|
+
end
|
315
|
+
|
316
|
+
# Create query parameters
|
317
|
+
params = {
|
318
|
+
:returnFormat => return_format,
|
319
|
+
:templateName => template_name,
|
320
|
+
:test => test
|
321
|
+
}
|
322
|
+
|
323
|
+
res = request("/document/findandreplace", :post, params, find_and_replace_body)
|
324
|
+
if res.kind_of? Net::HTTPSuccess
|
325
|
+
# Remove leading and trailing quote from string
|
326
|
+
# (inexplicably JSON.parse chokes on simple strings)
|
327
|
+
return res.body.remove_first_and_last
|
328
|
+
else
|
329
|
+
raise res.body
|
330
|
+
end
|
331
|
+
end
|
332
|
+
|
333
|
+
# Lists all available fonts.
|
334
|
+
# @return [Array<String>] An array containing the names of all available fonts.
|
335
|
+
def list_fonts
|
336
|
+
res = request("/fonts/list", :get)
|
337
|
+
if res.kind_of? Net::HTTPSuccess
|
338
|
+
return JSON.parse(res.body)
|
339
|
+
else
|
340
|
+
raise res.body
|
341
|
+
end
|
342
|
+
end
|
343
|
+
|
268
344
|
# Performs a HTTP request of a given type.
|
269
345
|
# @param request_type [Symbol] The type of the request. Possible values are +:get+,
|
270
346
|
# +:post+ and +:delete+.
|
@@ -0,0 +1,67 @@
|
|
1
|
+
# ReportingCloud Ruby Wrapper
|
2
|
+
#
|
3
|
+
# Official wrapper (authored by Text Control GmbH, publisher of ReportingCloud) to access
|
4
|
+
# ReportingCloud in Ruby.
|
5
|
+
#
|
6
|
+
# Go to http://www.reporting.cloud to learn more about ReportingCloud
|
7
|
+
# Go to https://github.com/TextControl/txtextcontrol-reportingcloud-ruby for the
|
8
|
+
# canonical source repository.
|
9
|
+
#
|
10
|
+
# License: https://raw.githubusercontent.com/TextControl/txtextcontrol-reportingcloud-ruby/master/LICENSE.md
|
11
|
+
#
|
12
|
+
# Copyright: © 2017 Text Control GmbH
|
13
|
+
|
14
|
+
require 'txtextcontrol/reportingcloud/merge_field'
|
15
|
+
require 'txtextcontrol/reportingcloud/merge_block'
|
16
|
+
|
17
|
+
module TXTextControl
|
18
|
+
module ReportingCloud
|
19
|
+
|
20
|
+
# Holds information about the merge blocks and merge fields in a template
|
21
|
+
# in the template storage.
|
22
|
+
# @attr_reader template_name [String] The template file name.
|
23
|
+
# @attr_reader merge_blocks [Array<MergeBlock>] Contains all top level merge
|
24
|
+
# blocks in the template.
|
25
|
+
# @attr_reader merge_fields [Array<MergeField>] Contains all top level merge
|
26
|
+
# fields in the template.
|
27
|
+
# @author Thorsten Kummerow (@thomerow)
|
28
|
+
class TemplateInfo
|
29
|
+
attr_reader :template_name
|
30
|
+
attr_reader :merge_blocks
|
31
|
+
attr_reader :merge_fields
|
32
|
+
|
33
|
+
# @param template_name [String] The template file name.
|
34
|
+
# @param merge_blocks [Array<MergeBlock>] The top level merge blocks in the template.
|
35
|
+
# @param merge_fields [Array<MergeField>] The top level merge fields in the template.
|
36
|
+
def initialize(template_name, merge_blocks, merge_fields)
|
37
|
+
# Parameter validation
|
38
|
+
raise ArgumentError, "Block name must be a string." if !template_name.kind_of? String
|
39
|
+
raise ArgumentError, "Parameter merge_blocks must be an array." if !merge_blocks.kind_of? Array
|
40
|
+
raise ArgumentError, "Parameter merge_fields must be an array." if !merge_fields.kind_of? Array
|
41
|
+
|
42
|
+
@template_name = template_name
|
43
|
+
@merge_blocks = merge_blocks
|
44
|
+
@merge_fields = merge_fields
|
45
|
+
end
|
46
|
+
|
47
|
+
# Creates a TemplateInfo instance from a hash.
|
48
|
+
# @param hash [Hash] The hash to try and create a TemplateInfo instance from.
|
49
|
+
# @return [TemplateInfo] A newly created TemplateInfo instance.
|
50
|
+
def self.from_camelized_hash(hash)
|
51
|
+
# Parameter validation
|
52
|
+
raise ArgumentError, "Parameter must be a Hash." if !hash.kind_of? Hash
|
53
|
+
|
54
|
+
name = hash["templateName"]
|
55
|
+
blocks = Array.new
|
56
|
+
hash["mergeBlocks"].each do |elem|
|
57
|
+
blocks.push(MergeBlock.from_camelized_hash(elem))
|
58
|
+
end
|
59
|
+
fields = Array.new
|
60
|
+
hash["mergeFields"].each do |elem|
|
61
|
+
fields.push(MergeField.from_camelized_hash(elem))
|
62
|
+
end
|
63
|
+
return TemplateInfo.new(name, blocks, fields)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -9,10 +9,10 @@
|
|
9
9
|
#
|
10
10
|
# License: https://raw.githubusercontent.com/TextControl/txtextcontrol-reportingcloud-ruby/master/LICENSE.md
|
11
11
|
#
|
12
|
-
# Copyright: ©
|
12
|
+
# Copyright: © 2017 Text Control GmbH
|
13
13
|
|
14
14
|
module TXTextControl
|
15
15
|
module ReportingCloud
|
16
|
-
VERSION = "1.0.
|
16
|
+
VERSION = "1.0.3"
|
17
17
|
end
|
18
18
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: txtextcontrol-reportingcloud
|
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
|
- Thorsten Kummerow
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-03-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -71,11 +71,15 @@ files:
|
|
71
71
|
- lib/core_ext/string.rb
|
72
72
|
- lib/txtextcontrol/reportingcloud.rb
|
73
73
|
- lib/txtextcontrol/reportingcloud/account_settings.rb
|
74
|
+
- lib/txtextcontrol/reportingcloud/find_and_replace_body.rb
|
75
|
+
- lib/txtextcontrol/reportingcloud/merge_block.rb
|
74
76
|
- lib/txtextcontrol/reportingcloud/merge_body.rb
|
77
|
+
- lib/txtextcontrol/reportingcloud/merge_field.rb
|
75
78
|
- lib/txtextcontrol/reportingcloud/merge_settings.rb
|
76
79
|
- lib/txtextcontrol/reportingcloud/reportingcloud.rb
|
77
80
|
- lib/txtextcontrol/reportingcloud/template.rb
|
78
81
|
- lib/txtextcontrol/reportingcloud/template_data_validator.rb
|
82
|
+
- lib/txtextcontrol/reportingcloud/template_info.rb
|
79
83
|
- lib/txtextcontrol/reportingcloud/template_name_validator.rb
|
80
84
|
- lib/txtextcontrol/reportingcloud/version.rb
|
81
85
|
- resource/rc_logo_1024.png
|
@@ -102,9 +106,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
102
106
|
version: '0'
|
103
107
|
requirements: []
|
104
108
|
rubyforge_project:
|
105
|
-
rubygems_version: 2.5.
|
109
|
+
rubygems_version: 2.5.2
|
106
110
|
signing_key:
|
107
111
|
specification_version: 4
|
108
112
|
summary: ReportingCloud Ruby Wrapper
|
109
113
|
test_files: []
|
110
|
-
has_rdoc:
|