txtextcontrol-reportingcloud 1.0.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d69459cfc7d065e32d143d4f0448fc607a858ae5
4
+ data.tar.gz: ed780300dadb6a31f12f3785983efb806a3a70eb
5
+ SHA512:
6
+ metadata.gz: 0ec77b3c5a03931cb1068abcf690cb9156b1f7a62da9ce5770faa65fa3551006114bcbc27cc939aaecf037e93b0cb7ea3ea4bcb96f8ca6939317780765bd3841
7
+ data.tar.gz: 4c052c90eb063f0a1700257c7f9a47f44107ff4b656bcd38550907366f6177d36a43d342d269ea317033ad71c89938e5c5a8edfeffccea07d0f426e2e3801b4f
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.0
5
+ before_install: gem install bundler -v 1.12.4
@@ -0,0 +1,4 @@
1
+ // Place your settings in this file to overwrite default and user settings.
2
+ {
3
+ "editor.tabSize": 2
4
+ }
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in txtextcontrol-reportingcloud.gemspec
4
+ gemspec
data/LICENSE.md ADDED
@@ -0,0 +1,18 @@
1
+ ## Copyright © 2016, Text Control GmbH. All rights reserved.
2
+
3
+ Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
4
+ following conditions are met:
5
+
6
+ - Redistributions of source code must retain the above copyright notice, this list of conditions and the following
7
+ disclaimer.
8
+
9
+ - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following
10
+ disclaimer in the documentation and/or other materials provided with the distribution.
11
+
12
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
13
+ INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
14
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
15
+ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
16
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
17
+ WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
18
+ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
data/README.md ADDED
@@ -0,0 +1,46 @@
1
+ ![Logo](https://raw.githubusercontent.com/TextControl/txtextcontrol-reportingcloud-ruby/master/resource/rc_logo_512.png)
2
+
3
+ # ReportingCloud Ruby Wrapper
4
+
5
+ This is the official Ruby wrapper for ReportingCloud, which is authored, maintained and fully supported by [Text Control](http://www.textcontrol.com).
6
+
7
+ [http://www.reporting.cloud](http://www.reporting.cloud)
8
+
9
+ Before using ReportingCloud, please sign up to the service:
10
+
11
+ [http://api.reporting.cloud](http://api.reporting.cloud)
12
+
13
+ ## Installation
14
+
15
+ Add this line to your application's Gemfile:
16
+
17
+ ```ruby
18
+ gem 'txtextcontrol-reportingcloud'
19
+ ```
20
+
21
+ And then execute:
22
+
23
+ $ bundle
24
+
25
+ Or install it yourself as:
26
+
27
+ $ gem install txtextcontrol-reportingcloud
28
+
29
+ ## API documentation (YARD)
30
+
31
+ All the source code in this library is documented using [YARD](http://yardoc.org/).
32
+
33
+ You can read the [API documentation](https://textcontrol.github.io/txtextcontrol-reportingcloud-ruby/) online, or build it yourself, using the following command:
34
+
35
+ $ yard doc
36
+
37
+ The resultant set of HTML files will be written to `~/txtextcontrol-reportingcloud/doc`.
38
+
39
+ If you don't have YARD already installed, you can install it with RubyGems with the following command:
40
+
41
+ $ gem install yard
42
+
43
+ ## Contributing
44
+
45
+ Bug reports and pull requests are welcome on GitHub at https://github.com/TextControl/txtextcontrol-reportingcloud-ruby.
46
+
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "txtextcontrol/reportingcloud"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,28 @@
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: © 2016 Text Control GmbH
13
+
14
+ # Extensions to class String.
15
+ # @author Thorsten Kummerow (@thomerow)
16
+ class String
17
+
18
+ # Removes the first and last characters from a string and returns the
19
+ # manipulated string.
20
+ # @return [String] The string without its first and last characters.
21
+ def remove_first_and_last
22
+ if self.length == 0 then return '' end
23
+ result = self.dup
24
+ result[0] = ''
25
+ if result.length > 0 then result[result.length - 1] = '' end
26
+ return result
27
+ end
28
+ end
@@ -0,0 +1,31 @@
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: © 2016 Text Control GmbH
13
+
14
+ require "txtextcontrol/reportingcloud/version"
15
+ require_relative "./reportingcloud/reportingcloud.rb"
16
+
17
+ # The TXTextControl module.
18
+ module TXTextControl
19
+
20
+ # The ReportingCloud module.
21
+ module ReportingCloud
22
+
23
+ # Default API base url.
24
+ DEFAULT_BASE_URI = "http://api.reporting.cloud"
25
+ # Default API version.
26
+ DEFAULT_VERSION = "v1"
27
+ # Default http request timeout in seconds.
28
+ DEFAULT_TIMEOUT = 10
29
+
30
+ end
31
+ end
@@ -0,0 +1,88 @@
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: © 2016 Text Control GmbH
13
+
14
+ module TXTextControl
15
+ module ReportingCloud
16
+
17
+ # Represents ReportingCloud account settings.
18
+ # @attr_reader [String, Symbol] serial_number The serial number that is attached to the
19
+ # account. Possible values are :free, :trial and a 13 character long serial number.
20
+ # @attr_reader [Integer] created_documents The number of created documents in the
21
+ # current month.
22
+ # @attr_reader [Integer] uploaded_templates The number of uploaded templates to the
23
+ # template storage.
24
+ # @attr_reader [Integer] max_documents The maximum number of documents that can be
25
+ # created per month.
26
+ # @attr_reader [Integer] max_templates The maximum number of templates that can be
27
+ # uploaded to the template storage.
28
+ # @attr_reader [DateTime] valid_until The date until the current subscription is valid.
29
+ # Can be nil.
30
+ # @author Thorsten Kummerow (@thomerow)
31
+ class AccountSettings
32
+ attr_reader :serial_number
33
+ attr_reader :created_documents
34
+ attr_reader :uploaded_templates
35
+ attr_reader :max_documents
36
+ attr_reader :max_templates
37
+ attr_reader :valid_until
38
+
39
+ # @param [String, Symbol] serial_number The serial number that is attached to the
40
+ # account. Possible values are :free, :trial and a 13 character long serial number.
41
+ # @param [Integer] created_documents The number of created documents in the
42
+ # current month.
43
+ # @param [Integer] uploaded_templates The number of uploaded templates to the
44
+ # template storage.
45
+ # @param [Integer] max_documents The maximum number of documents that can be
46
+ # created per month.
47
+ # @param [Integer] max_templates The maximum number of templates that can be
48
+ # uploaded to the template storage.
49
+ # @param [DateTime] valid_until The date until the current subscription is valid.
50
+ # Can be nil.
51
+ def initialize(serial_number, created_documents, uploaded_templates, max_documents, max_templates, valid_until = nil)
52
+ case serial_number.downcase
53
+ when "trial"
54
+ @serial_number = :trial
55
+ when "free"
56
+ @serial_number = :free
57
+ else
58
+ @serial_number = serial_number
59
+ end
60
+ @created_documents = Integer(created_documents)
61
+ @uploaded_templates = Integer(uploaded_templates)
62
+ @max_documents = Integer(max_documents)
63
+ @max_templates = Integer(max_templates)
64
+ case valid_until
65
+ when DateTime
66
+ @valid_until = valid_until
67
+ when String
68
+ @valid_until = DateTime.iso8601(valid_until)
69
+ else
70
+ @valid_until = nil
71
+ end
72
+ end
73
+
74
+ # Creates an AccountSettings instance from a hash.
75
+ # @param [Hash] hash The hash to try and create an AccountSettings instance from.
76
+ # @return [AccountSettings] A newly created AccountSettings instance.
77
+ def self.from_camelized_hash(hash)
78
+ sn = hash["serialNumber"]
79
+ cd = hash["createdDocuments"]
80
+ ut = hash["uploadedTemplates"]
81
+ md = hash["maxDocuments"]
82
+ mt = hash["maxTemplates"]
83
+ vu = hash["validUntil"]
84
+ return AccountSettings.new(sn, cd, ut, md, mt, vu)
85
+ end
86
+ end
87
+ end
88
+ end
@@ -0,0 +1,60 @@
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: © 2016 Text Control GmbH
13
+
14
+ require "txtextcontrol/reportingcloud/merge_settings"
15
+
16
+ module TXTextControl
17
+ module ReportingCloud
18
+
19
+ # Used to pass data to the merge method.
20
+ # @attr merge_data [Array<Hash>] The merge data. Must be an array of hashes.
21
+ # @attr template [String] Base64 encoded template document.
22
+ # Supported formats are RTF, DOC, DOCX and TX.
23
+ # @attr merge_settings [MergeSettings] Merge settings to specify
24
+ # merge properties and document properties such as title and
25
+ # author.
26
+ # @author Thorsten Kummerow (@thomerow)
27
+ class MergeBody
28
+ attr_accessor :merge_data
29
+ attr_accessor :template
30
+ attr_accessor :merge_settings
31
+
32
+ # The constructor.
33
+ # @param merge_data [Array<Hash>] The merge data. Must be an array of hashes.
34
+ # @param template [String] Base64 encoded template document.
35
+ # Supported formats are RTF, DOC, DOCX and TX.
36
+ # @param merge_settings [MergeSettings] Merge settings to specify
37
+ # merge properties and document properties such as title and
38
+ # author.
39
+ def initialize(merge_data, merge_settings = nil, template = nil)
40
+ unless merge_data.kind_of?(Array) && !merge_data.empty? && merge_data[0].kind_of?(Hash)
41
+ raise ArgumentError, "Merge data must be a non empty array of hashes."
42
+ end
43
+ @merge_data = merge_data
44
+ @template = template
45
+ @merge_settings = merge_settings
46
+ end
47
+
48
+ # Converts a MergeBody instance to a hash while converting the attribute names
49
+ # from snake case to camel case.
50
+ # @return [Hash] A hash representing the MergeBody instance.
51
+ def to_camelized_hash
52
+ return {
53
+ "mergeData" => @merge_data,
54
+ "template" => @template,
55
+ "mergeSettings" => @merge_settings.nil? ? nil : merge_settings.to_camelized_hash
56
+ }
57
+ end
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,112 @@
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: © 2016 Text Control GmbH
13
+
14
+ module TXTextControl
15
+ module ReportingCloud
16
+
17
+ # Holds the merge settings needed by the merge method.
18
+ # @attr remove_empty_fields [Boolean] Specifies whether empty fields
19
+ # should be removed from the template or not.
20
+ # @attr remove_empty_blocks [Boolean] Specifies whether the content of
21
+ # empty merge blocks should be removed from the template or not.
22
+ # @attr remove_empty_images [Boolean] Specifies whether images which
23
+ # don't have merge data should be removed from the template or not.
24
+ # @attr remove_trailing_whitespace [Boolean] Specifies whether trailing
25
+ # whitespace should be removed before saving a document.
26
+ # @attr author [String] The document's author.
27
+ # @attr creation_date [DateTime] The document's creation date.
28
+ # @attr creator_application [String] The application which created the document.
29
+ # @attr document_subject [String] The document's subject.
30
+ # @attr document_title [String] The document's title.
31
+ # @attr last_modification_date [DateTime] The document's last modification date.
32
+ # @attr user_password [String] The password needed to open the document.
33
+ # @author Thorsten Kummerow (@thomerow)
34
+ class MergeSettings
35
+ attr_accessor :remove_empty_fields
36
+ attr_accessor :remove_empty_blocks
37
+ attr_accessor :remove_empty_images
38
+ attr_accessor :remove_trailing_whitespace
39
+ attr_accessor :author
40
+ attr_accessor :creator_application
41
+ attr_accessor :document_subject
42
+ attr_accessor :document_title
43
+ attr_accessor :user_password
44
+
45
+ def initialize
46
+ @remove_empty_fields = true
47
+ @remove_empty_blocks = true
48
+ @remove_empty_images = true
49
+ @remove_trailing_whitespace = true
50
+
51
+ @author = nil
52
+ @creation_date = nil
53
+ @creator_application = nil
54
+ @document_subject = nil
55
+ @document_title = nil
56
+ @last_modification_date = nil
57
+ @user_password = nil
58
+ end
59
+
60
+ def creation_date
61
+ @creation_date
62
+ end
63
+
64
+ def creation_date=(val)
65
+ case val
66
+ when nil
67
+ @creation_date = nil
68
+ when String
69
+ @creation_date = DateTime.iso8601(val)
70
+ when DateTime
71
+ @creation_date = val
72
+ else raise ArgumentError, "Value must be a string or an instance of type DateTime."
73
+ end
74
+ end
75
+
76
+ def last_modification_date
77
+ @last_modification_date
78
+ end
79
+
80
+ def last_modification_date=(val)
81
+ case val
82
+ when nil
83
+ @last_modification_date = nil
84
+ when String
85
+ @last_modification_date = DateTime.iso8601(val)
86
+ when DateTime
87
+ @last_modification_date = val
88
+ else raise ArgumentError, "Value must be a string or an instance of type DateTime."
89
+ end
90
+ end
91
+
92
+ # Converts a MergeSettings instance to a hash while converting the attribute names
93
+ # from snake case to camel case.
94
+ # @return [Hash] A hash representing the MergeSettings instance.
95
+ def to_camelized_hash
96
+ return {
97
+ "removeEmptyFields" => @remove_empty_fields,
98
+ "removeEmptyBlocks" => @remove_empty_blocks,
99
+ "removeEmptyImages" => @remove_empty_images,
100
+ "removeTrailingWhitespace" => @remove_trailing_whitespace,
101
+ "author" => @author,
102
+ "creationDate" => @creation_date.nil? ? nil : creation_date.iso8601,
103
+ "creatorApplication" => @creator_application,
104
+ "documentSubject" => @document_subject,
105
+ "documentTitle" => @document_title,
106
+ "lastModificationDate" => @last_modification_date.nil? ? nil : last_modification_date.iso8601,
107
+ "userPassword" => @user_password
108
+ }
109
+ end
110
+ end
111
+ end
112
+ end
@@ -0,0 +1,322 @@
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: © 2016 Text Control GmbH
13
+
14
+ require "uri"
15
+ require "net/http"
16
+ require "json"
17
+ require "ostruct"
18
+ require "cgi"
19
+ require 'txtextcontrol/reportingcloud/template'
20
+ require 'txtextcontrol/reportingcloud/account_settings'
21
+ require 'txtextcontrol/reportingcloud/template_name_validator'
22
+ require 'txtextcontrol/reportingcloud/template_data_validator'
23
+ require 'core_ext/string'
24
+
25
+ module TXTextControl
26
+ module ReportingCloud
27
+
28
+ # The main wrapper class.
29
+ # @attr username [String] The user name.
30
+ # @attr password [String] The password.
31
+ # @attr base_uri [String] The API base url. Is set to "http://api.reporting.cloud"
32
+ # by default.
33
+ # @attr api_version [String] The API version. Is set to "v1" by default.
34
+ # @attr read_timeout [Integer] The timeout for HTTP requests in seconds. Is set to
35
+ # 10 by default.
36
+ # @author Thorsten Kummerow (@thomerow)
37
+ class ReportingCloud
38
+ attr_accessor :username
39
+ attr_accessor :password
40
+ attr_accessor :base_uri
41
+ attr_accessor :api_version
42
+ attr_accessor :read_timeout
43
+
44
+ # @param username [String] The user name.
45
+ # @param password [String] The password.
46
+ # @param base_url [String] The API base url. Is set to "http://api.reporting.cloud"
47
+ # by default.
48
+ def initialize(username, password, base_url = nil)
49
+ base_url ||= DEFAULT_BASE_URI
50
+ @username = username
51
+ @password = password
52
+ @api_version = DEFAULT_VERSION
53
+ @read_timeout = DEFAULT_TIMEOUT
54
+ @base_uri = URI.parse(base_url)
55
+ end
56
+
57
+ # Lists all templates from the template storage.
58
+ # @return [Array<Template>] An array of Template objects.
59
+ def list_templates
60
+ res = request("/templates/list", :get)
61
+ if res.kind_of? Net::HTTPSuccess
62
+ templates = Array.new
63
+ data = JSON.parse(res.body, object_class: OpenStruct)
64
+ data.each do |elem|
65
+ templates.push(Template.new(elem.templateName, elem.modified, elem.size))
66
+ end
67
+ return templates
68
+ else
69
+ raise res.body
70
+ end
71
+ end
72
+
73
+ # Returns the number of templates in the template storage.
74
+ # @return [Integer] The number of templates in the template storage.
75
+ def get_template_count
76
+ res = request("/templates/count", :get)
77
+ if res.kind_of? Net::HTTPSuccess
78
+ return Integer(res.body)
79
+ else
80
+ raise res.body
81
+ end
82
+ end
83
+
84
+ # Merges and returns a template from the template storage or an
85
+ # uploaded template with JSON data.
86
+ # @param return_format [Symbol] The format of the created document. Possible
87
+ # values are :pdf, :rtf, :doc, :docx, :html and :tx.
88
+ # @param merge_body [MergeBody] The MergeBody object contains the datasource
89
+ # as a JSON data object and optionally, a template encoded as a Base64 string.
90
+ # @param template_name [String] The name of the template in the template storage.
91
+ # If no template name is specified, the template must be uploaded in the
92
+ # MergeBody object of this request.
93
+ # @param append [Boolean]
94
+ # @return [Array<String>] An array of the created documents as
95
+ # Base64 encoded strings.
96
+ def merge_document(merge_body, template_name = nil, return_format = :pdf, append = false)
97
+ if !template_name.to_s.empty? && !merge_body.template.nil? # .to_s.empty: check for nil or ''
98
+ raise ArgumentError, "Template name and template data must not be present at the same time."
99
+ elsif template_name.to_s.empty? && merge_body.template.nil?
100
+ raise ArgumentError, "Either a template name or template data have to be present."
101
+ end
102
+
103
+ # Create query parameters
104
+ params = {
105
+ :returnFormat => return_format,
106
+ :append => append
107
+ }
108
+ unless template_name.to_s.empty?
109
+ params[:templateName] = template_name
110
+ end
111
+
112
+ # Send request
113
+ res = request("/document/merge", :post, params, merge_body)
114
+ if res.kind_of? Net::HTTPSuccess
115
+ return JSON.parse(res.body)
116
+ else
117
+ raise res.body
118
+ end
119
+ end
120
+
121
+ # Returns the account settings.
122
+ # @return [AccountSettings] The account settings.
123
+ def get_account_settings
124
+ res = request("/account/settings", :get)
125
+ if res.kind_of? Net::HTTPSuccess
126
+ return AccountSettings.from_camelized_hash(JSON.parse(res.body))
127
+ else
128
+ raise res.body
129
+ end
130
+ end
131
+
132
+ # Returns a list of thumbnails of a specific template.
133
+ # @param template_name [String] The filename of the template in the template storage.
134
+ # @param zoom_factor [Integer] An Integer value between 1 and 400 to set the
135
+ # percentage zoom factor of the created thumbnail images.
136
+ # @param from_page [Integer] An Integer value that specifies the first page.
137
+ # @param to_page [Integer] An Integer value that specifies the last page.
138
+ # @param image_format [Symbol] Defines the image format of the returned thumbnails.
139
+ # Possible values are :png, :jpg, :gif and :bmp.
140
+ # @return [Array<String>] An array of Base64 encoded images.
141
+ def get_template_thumbnails(template_name, zoom_factor, from_page = 1, to_page = 0, image_format = :png)
142
+ # Prepare query parameters
143
+ params = {
144
+ :templateName => template_name,
145
+ :zoomFactor => zoom_factor,
146
+ :fromPage => from_page,
147
+ :toPage => to_page,
148
+ }
149
+ if image_format != :png
150
+ params[:imageFormat] = image_format
151
+ end
152
+
153
+ # Send request
154
+ res = request("/templates/thumbnails", :get, params)
155
+ if res.kind_of? Net::HTTPSuccess
156
+ return JSON.parse(res.body)
157
+ else
158
+ raise res.body
159
+ end
160
+ end
161
+
162
+ # Deletes a template from the template storage.
163
+ # @param template_name [String] The filename of the template to be deleted
164
+ # from the template storage.
165
+ # @return [void]
166
+ def delete_template(template_name)
167
+ # Parameter validation
168
+ TemplateNameValidator.validate(template_name)
169
+
170
+ res = request("/templates/delete", :delete, { :templateName => template_name })
171
+ unless res.kind_of? Net::HTTPSuccess
172
+ raise res.body
173
+ end
174
+ end
175
+
176
+ # Stores an uploaded template in the template storage (*.doc, *.docx, *.rtf and *.tx)
177
+ # @param template_name [String] The filename of the template in the template storage.
178
+ # Existing files with the same filename will be overwritten.
179
+ # @param template_data [String] A document encoded as a Base64 string.
180
+ # The supported formats are DOC, DOCX, RTF and TX.
181
+ # @return [void]
182
+ def upload_template(template_name, template_data)
183
+ # Parameter validation
184
+ TemplateNameValidator.validate(template_name)
185
+ TemplateDataValidator.validate(template_data)
186
+
187
+ res = request("/templates/upload", :post, { :templateName => template_name }, template_data)
188
+ unless res.kind_of? Net::HTTPSuccess
189
+ raise res.body
190
+ end
191
+ end
192
+
193
+ # Returns the selected template from the storage.
194
+ # @param template_name [String] The filename of the template in the template storage.
195
+ # @return [String] The template document data as a Base64 encoded string.
196
+ def download_template(template_name)
197
+ # Parameter validation
198
+ TemplateNameValidator.validate(template_name)
199
+
200
+ res = request("/templates/download", :get, { :templateName => template_name })
201
+ if res.kind_of? Net::HTTPSuccess
202
+ return res.body.remove_first_and_last
203
+ else
204
+ raise res.body
205
+ end
206
+ end
207
+
208
+ # Checks whether a template exists in the template storage.
209
+ # @param template_name [String] The filename of the template to be
210
+ # checked for availability in the template storage.
211
+ # @return [Boolean] Returns if the template with the given name exists in
212
+ # the template storage.
213
+ def template_exists?(template_name)
214
+ # Parameter validation
215
+ TemplateNameValidator.validate(template_name)
216
+
217
+ res = request("/templates/exists", :get, { :templateName => template_name })
218
+ if res.kind_of? Net::HTTPSuccess
219
+ case res.body
220
+ when "true"
221
+ return true
222
+ when "false"
223
+ return false
224
+ else raise "Unknown response value received."
225
+ end
226
+ else
227
+ raise res.body
228
+ end
229
+ end
230
+
231
+ # Returns the number of pages of a template in the template storage.
232
+ # @param template_name [String] The filename of the template in the template
233
+ # storage to retrieve the number of pages for.
234
+ # @return [Integer] The number of pages in the template.
235
+ def get_template_page_count(template_name)
236
+ # Parameter validation
237
+ TemplateNameValidator.validate(template_name)
238
+
239
+ res = request("/templates/pagecount", :get, { :templateName => template_name })
240
+ if res.kind_of? Net::HTTPSuccess
241
+ return Integer(res.body)
242
+ else
243
+ raise res.body
244
+ end
245
+ end
246
+
247
+ # Converts a document to another format.
248
+ # @param template_data [String] The source document encoded as a Base64 string.
249
+ # The supported document formats are .rtf, .doc, .docx, .html, .pdf and .tx.
250
+ # @param return_format [Symbol] The format of the created document.
251
+ # Possible values are: :pdf, :rtf, :doc, :docx, :html and :tx.
252
+ # @return [String] The created document encoded as a Base64 string.
253
+ def convert_document(template_data, return_format = :pdf)
254
+ # Parameter validation
255
+ TemplateDataValidator.validate(template_data)
256
+
257
+ res = request("/document/convert", :post, { :returnFormat => return_format }, template_data)
258
+ if res.kind_of? Net::HTTPSuccess
259
+ # Remove leading and trailing quote from string
260
+ # (inexplicably JSON.parse chokes on simple strings)
261
+ return res.body.remove_first_and_last
262
+ else
263
+ raise res.body
264
+ end
265
+ end
266
+
267
+ # Performs a HTTP request of a given type.
268
+ # @param request_type [Symbol] The type of the request. Possible values are :get,
269
+ # :post and :delete.
270
+ # @param params [Hash] The query parameters.
271
+ # @param body [Object, Hash, String]
272
+ # @return [Net::HTTPResponse] The HTTP response.
273
+ private
274
+ def request(request_uri, request_type = :get, params = nil, body = nil)
275
+ # Generate query string from given parameters
276
+ query_string = query_string_from_hash(params)
277
+
278
+ http = Net::HTTP.new(@base_uri.host, @base_uri.port)
279
+ http.read_timeout = read_timeout
280
+
281
+ # Get correct request type
282
+ req_type = nil
283
+ case request_type
284
+ when :get
285
+ req_type = Net::HTTP::Get
286
+ when :post
287
+ req_type = Net::HTTP::Post
288
+ when :delete
289
+ req_type = Net::HTTP::Delete
290
+ else raise "Unknown HTTP request type."
291
+ end
292
+
293
+ # Create HTTP request
294
+ req = req_type.new("/#{@api_version}#{request_uri}#{query_string}", initheader = { "Content-Type" => "application/json" })
295
+ req.basic_auth(@username, @password);
296
+ # If body data is present, use it directly if it is a string or
297
+ # else convert it to json
298
+ if !body.nil?
299
+ if body.kind_of? String
300
+ req.body = "\"" + body + "\""
301
+ elsif body.kind_of? Hash
302
+ req.body = body.to_json
303
+ elsif body.respond_to?(:to_camelized_hash)
304
+ req.body = body.to_camelized_hash.to_json
305
+ elsif body.respond_to?(:to_hash)
306
+ req.body = body.to_hash.to_json
307
+ end
308
+ end
309
+ # Send request
310
+ return http.request(req)
311
+ end
312
+
313
+ # Generates a query string from a hash
314
+ private
315
+ def query_string_from_hash(hash)
316
+ return "?" + hash.collect { |k, v| "#{k}=#{CGI::escape(v.to_s)}" }.join('&') unless hash.nil?
317
+ return ""
318
+ end
319
+
320
+ end
321
+ end
322
+ end
@@ -0,0 +1,40 @@
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: © 2016 Text Control GmbH
13
+
14
+ require 'date'
15
+
16
+ module TXTextControl
17
+ module ReportingCloud
18
+
19
+ # @attr_reader template_name [String] The template file name.
20
+ # @attr_reader modified [DateTime] The date and time the template file was
21
+ # last modified.
22
+ # @attr_reader size [Integer] The size of the template file in bytes.
23
+ # @author Thorsten Kummerow (@thomerow)
24
+ class Template
25
+ attr_reader :template_name
26
+ attr_reader :modified
27
+ attr_reader :size
28
+
29
+ def initialize(template_name, modified, size)
30
+ @template_name = template_name
31
+ if modified.is_a?(DateTime)
32
+ @modified = modified
33
+ else
34
+ @modified = DateTime.iso8601(modified)
35
+ end
36
+ @size = size
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,30 @@
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: © 2016 Text Control GmbH
13
+
14
+ module TXTextControl
15
+ module ReportingCloud
16
+
17
+ # Internal method parameter validator class.
18
+ # @author Thorsten Kummerow (@thomerow)
19
+ class TemplateDataValidator
20
+
21
+ # Checks if a given value is a String, is not nil and not empty.
22
+ # @param template_data [String] The string to validate.
23
+ # @return [Boolean]
24
+ def self.validate(template_data)
25
+ raise ArgumentError, "Template data must be a Base64 encoded string." if !template_data.kind_of? String
26
+ raise ArgumentError, "No template data given." if template_data.to_s.empty?
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,30 @@
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: © 2016 Text Control GmbH
13
+
14
+ module TXTextControl
15
+ module ReportingCloud
16
+
17
+ # Internal method parameter validator class.
18
+ # @author Thorsten Kummerow (@thomerow)
19
+ class TemplateNameValidator
20
+
21
+ # Checks if a given value is a String, is not nil and not empty.
22
+ # @param template_name [String] The string to validate.
23
+ # @return [Boolean]
24
+ def self.validate(template_name)
25
+ raise ArgumentError, "Template name must be a String." if !template_name.kind_of? String
26
+ raise ArgumentError, "No template name given." if template_name.to_s.empty?
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,18 @@
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: © 2016 Text Control GmbH
13
+
14
+ module TXTextControl
15
+ module ReportingCloud
16
+ VERSION = "1.0.0"
17
+ end
18
+ end
Binary file
Binary file
Binary file
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'txtextcontrol/reportingcloud/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "txtextcontrol-reportingcloud"
8
+ spec.version = TXTextControl::ReportingCloud::VERSION
9
+ spec.authors = ["Thorsten Kummerow"]
10
+ spec.email = ["thorsten@textcontrol.com"]
11
+
12
+ spec.summary = "ReportingCloud Ruby Wrapper"
13
+ spec.description = "Official wrapper (authored by Text Control GmbH, publisher of ReportingCloud) to access ReportingCloud in Ruby."
14
+ spec.homepage = "http://www.reporting.cloud"
15
+ spec.licenses = ["BSD-2-Clause"]
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.12"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ spec.add_development_dependency "rspec", "~> 3.0"
25
+ end
metadata ADDED
@@ -0,0 +1,112 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: txtextcontrol-reportingcloud
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Thorsten Kummerow
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-06-06 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.12'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.12'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
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.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ description: Official wrapper (authored by Text Control GmbH, publisher of ReportingCloud)
56
+ to access ReportingCloud in Ruby.
57
+ email:
58
+ - thorsten@textcontrol.com
59
+ executables: []
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - ".gitignore"
64
+ - ".rspec"
65
+ - ".travis.yml"
66
+ - ".vscode/settings.json"
67
+ - Gemfile
68
+ - LICENSE.md
69
+ - README.md
70
+ - Rakefile
71
+ - bin/console
72
+ - bin/setup
73
+ - lib/core_ext/string.rb
74
+ - lib/txtextcontrol/reportingcloud.rb
75
+ - lib/txtextcontrol/reportingcloud/account_settings.rb
76
+ - lib/txtextcontrol/reportingcloud/merge_body.rb
77
+ - lib/txtextcontrol/reportingcloud/merge_settings.rb
78
+ - lib/txtextcontrol/reportingcloud/reportingcloud.rb
79
+ - lib/txtextcontrol/reportingcloud/template.rb
80
+ - lib/txtextcontrol/reportingcloud/template_data_validator.rb
81
+ - lib/txtextcontrol/reportingcloud/template_name_validator.rb
82
+ - lib/txtextcontrol/reportingcloud/version.rb
83
+ - resource/rc_logo_1024.png
84
+ - resource/rc_logo_256.png
85
+ - resource/rc_logo_512.png
86
+ - txtextcontrol-reportingcloud.gemspec
87
+ homepage: http://www.reporting.cloud
88
+ licenses:
89
+ - BSD-2-Clause
90
+ metadata: {}
91
+ post_install_message:
92
+ rdoc_options: []
93
+ require_paths:
94
+ - lib
95
+ required_ruby_version: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - ">="
98
+ - !ruby/object:Gem::Version
99
+ version: '0'
100
+ required_rubygems_version: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ requirements: []
106
+ rubyforge_project:
107
+ rubygems_version: 2.5.1
108
+ signing_key:
109
+ specification_version: 4
110
+ summary: ReportingCloud Ruby Wrapper
111
+ test_files: []
112
+ has_rdoc: