PrexView 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 5828cf22c351b73610b82ba3d461f388ad05b573
4
+ data.tar.gz: 27c449c4354074bbbea6c5343aac23480281b268
5
+ SHA512:
6
+ metadata.gz: 98a29b3cbdc1122a9dde958ec662c7733f79a19bc168f9b9f781f767f1320563d9fb24b5ec69f4a91048f597cbe390d9e52eb4777de0fbf769e9caf4ca456316
7
+ data.tar.gz: 62d367ff67fa239c5d1dfad6c45cf5c2dc1835a2f8dabdffb4459c6ec5d536cbf9705652c68477a627901048a25d468a3a27778a33631bafcfd0fd07809b2a5f
@@ -0,0 +1,20 @@
1
+ # EditorConfig helps developers define and maintain consistent
2
+ # coding styles between different editors and IDEs
3
+ # http://editorconfig.org
4
+
5
+ root = true
6
+
7
+ [*]
8
+
9
+ # Change these settings to your own preference
10
+ indent_style = space
11
+ indent_size = 2
12
+
13
+ # We recommend you to keep these unchanged
14
+ end_of_line = lf
15
+ charset = utf-8
16
+ trim_trailing_whitespace = true
17
+ insert_final_newline = true
18
+
19
+ [*.md]
20
+ trim_trailing_whitespace = false
@@ -0,0 +1,64 @@
1
+ <<<<<<< HEAD
2
+ /.bundle/
3
+ /.yardoc
4
+ /Gemfile.lock
5
+ /_yardoc/
6
+ /coverage/
7
+ /doc/
8
+ /pkg/
9
+ /spec/reports/
10
+ /tmp/
11
+ =======
12
+ *.gem
13
+ *.rbc
14
+ /.config
15
+ /coverage/
16
+ /InstalledFiles
17
+ /pkg/
18
+ /spec/reports/
19
+ /spec/examples.txt
20
+ /test/tmp/
21
+ /test/version_tmp/
22
+ /tmp/
23
+
24
+ # Used by dotenv library to load environment variables.
25
+ # .env
26
+
27
+ ## Specific to RubyMotion:
28
+ .dat*
29
+ .repl_history
30
+ build/
31
+ *.bridgesupport
32
+ build-iPhoneOS/
33
+ build-iPhoneSimulator/
34
+
35
+ ## Specific to RubyMotion (use of CocoaPods):
36
+ #
37
+ # We recommend against adding the Pods directory to your .gitignore. However
38
+ # you should judge for yourself, the pros and cons are mentioned at:
39
+ # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
40
+ #
41
+ # vendor/Pods/
42
+
43
+ ## Documentation cache and generated files:
44
+ /.yardoc/
45
+ /_yardoc/
46
+ /doc/
47
+ /rdoc/
48
+
49
+ ## Environment normalization:
50
+ /.bundle/
51
+ /vendor/bundle
52
+ /lib/bundler/man/
53
+
54
+ # for a library or gem, you might want to ignore these files since the code is
55
+ # intended to run in multiple environments; otherwise, check them in:
56
+ # Gemfile.lock
57
+ # .ruby-version
58
+ # .ruby-gemset
59
+
60
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
61
+ .rvmrc
62
+
63
+ .DS_Store
64
+ >>>>>>> 49ad890d8ad2471bd8ee28d4a7f582e3e5bb6f93
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.1
5
+ before_install: gem install bundler -v 1.12.5
@@ -0,0 +1,49 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, and in the interest of
4
+ fostering an open and welcoming community, we pledge to respect all people who
5
+ contribute through reporting issues, posting feature requests, updating
6
+ documentation, submitting pull requests or patches, and other activities.
7
+
8
+ We are committed to making participation in this project a harassment-free
9
+ experience for everyone, regardless of level of experience, gender, gender
10
+ identity and expression, sexual orientation, disability, personal appearance,
11
+ body size, race, ethnicity, age, religion, or nationality.
12
+
13
+ Examples of unacceptable behavior by participants include:
14
+
15
+ * The use of sexualized language or imagery
16
+ * Personal attacks
17
+ * Trolling or insulting/derogatory comments
18
+ * Public or private harassment
19
+ * Publishing other's private information, such as physical or electronic
20
+ addresses, without explicit permission
21
+ * Other unethical or unprofessional conduct
22
+
23
+ Project maintainers have the right and responsibility to remove, edit, or
24
+ reject comments, commits, code, wiki edits, issues, and other contributions
25
+ that are not aligned to this Code of Conduct, or to ban temporarily or
26
+ permanently any contributor for other behaviors that they deem inappropriate,
27
+ threatening, offensive, or harmful.
28
+
29
+ By adopting this Code of Conduct, project maintainers commit themselves to
30
+ fairly and consistently applying these principles to every aspect of managing
31
+ this project. Project maintainers who do not follow or enforce the Code of
32
+ Conduct may be permanently removed from the project team.
33
+
34
+ This code of conduct applies both within project spaces and in public spaces
35
+ when an individual is representing the project or its community.
36
+
37
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
38
+ reported by contacting a project maintainer at uriel85@gmail.com. All
39
+ complaints will be reviewed and investigated and will result in a response that
40
+ is deemed necessary and appropriate to the circumstances. Maintainers are
41
+ obligated to maintain confidentiality with regard to the reporter of an
42
+ incident.
43
+
44
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
45
+ version 1.3.0, available at
46
+ [http://contributor-covenant.org/version/1/3/0/][version]
47
+
48
+ [homepage]: http://contributor-covenant.org
49
+ [version]: http://contributor-covenant.org/version/1/3/0/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in PrexView.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2017 PrexView
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Urielable
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -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 'PrexView/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "PrexView"
8
+ spec.version = PrexView::VERSION
9
+ spec.authors = ["Urielable", "prexview"]
10
+ spec.email = ["uriel85@gmail.com"]
11
+
12
+ spec.summary = "A composer library to use PrexView a fast, scalable and very friendly service for programatic HTML, PDF, PNG or JPG generation using JSON or XML data."
13
+ spec.description = "A composer library to use PrexView a fast, scalable and very friendly service for programatic HTML, PDF, PNG or JPG generation using JSON or XML data."
14
+ spec.homepage = "https://github.com/prexview/prexview-ruby"
15
+ spec.license = "MIT"
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 "minitest", "~> 5.0"
25
+ end
@@ -0,0 +1,81 @@
1
+ # PrexView
2
+
3
+ A composer library to use PrexView a fast, scalable and very friendly service for programatic HTML, PDF, PNG or JPG generation using JSON or XML data.
4
+
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ ```ruby
11
+ gem 'PrexView'
12
+ ```
13
+
14
+ And then execute:
15
+
16
+ $ bundle
17
+
18
+ Or install it yourself as:
19
+
20
+ $ gem install PrexView
21
+
22
+ ## Quick Start
23
+
24
+ Get the token key by downloading PrexView Studio, [click here for download](https://prexview.com/downloads/)
25
+
26
+ If you don't have an account create one and open the API option
27
+
28
+ ![API token](./img/api.png)
29
+
30
+ There are two ways to use the token, our recomendation and good practice is to use the default environment variable `PREXVIEW_TOKEN` :
31
+
32
+ ```bash
33
+ $ export PREXVIEW_TOKEN=<token>
34
+ ```
35
+
36
+ In your application
37
+
38
+ ```ruby
39
+ # xml example
40
+ xml = "<xml>hello world</xml>"
41
+ code, response = PrexView.send_xml(xml, {type: 'xml', design: "design-xml"})
42
+ ```
43
+
44
+ ```ruby
45
+ # json example
46
+ json = { "hello": "world" }
47
+ code, response = PrexView.send_json(json, {type: 'json', design: "design-json" })
48
+ ```
49
+
50
+ The second way is to pass the token key as a parameter
51
+
52
+ ```ruby
53
+ # xml example
54
+ xml = "<xml>hello world</xml>"
55
+ PrexView.send_xml(xml, {type: 'xml', design: "design-xml", token: "<token>" })
56
+ ```
57
+
58
+ ```ruby
59
+ # json example
60
+ json = { "hello": "world" }
61
+ code, response = PrexView.send_json(json, {type: 'json', design: "design-json", token: "<token>" })
62
+ ```
63
+
64
+ **Design:** For use design first you add a design in PrexView Studio, go to design section and create one:
65
+
66
+ ![Design](./img/design.png)
67
+
68
+ For more information please check the [documentation](https://prexview.com/docs/) or look our [examples](/examples/)
69
+
70
+ ## Contributing
71
+
72
+ Bug reports and pull requests are welcome on GitHub at https://github.com/prexview/prexview-ruby. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
73
+
74
+ ## Credits
75
+
76
+ This gem is developed and maintained by [Urielable](https://twitter.com/urielable) - [blog](http://blog.urielable.com/)
77
+
78
+ ## License
79
+
80
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
81
+
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList['test/**/*_test.rb']
8
+ end
9
+
10
+ task :default => :test
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "PrexView"
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
@@ -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,239 @@
1
+ [
2
+ {
3
+ "number":"ID-8387323",
4
+ "date_issued":"1972-01-01 13:42:24",
5
+ "currency": "USD",
6
+ "subtotal":"52330",
7
+ "tax_rate":"16",
8
+ "tax":"8372.8",
9
+ "total": "60702.8",
10
+ "bill_to": {
11
+ "name": "Daniel Osorio",
12
+ "email": "hello@prexview.com"
13
+ },
14
+ "order":[
15
+ {
16
+ "id": "3421",
17
+ "name": "Apple",
18
+ "description": "Lorem ipsum dolor si amen",
19
+ "price": "150",
20
+ "quantity": "75",
21
+ "total": "11250"
22
+ },{
23
+ "id": "8473",
24
+ "name": "Banana",
25
+ "description": "Lorem ipsum dolor si amen",
26
+ "price": "80",
27
+ "quantity": "38",
28
+ "total": "3040"
29
+ },{
30
+ "id": "7820",
31
+ "name": "Blackberry",
32
+ "description": "Lorem ipsum dolor si amen",
33
+ "price": "130",
34
+ "quantity": "32",
35
+ "total": "4160"
36
+ },{
37
+ "id": "8734",
38
+ "name": "Grape",
39
+ "description": "Lorem ipsum dolor si amen",
40
+ "price": "180",
41
+ "quantity": "49",
42
+ "total": "8820"
43
+ },{
44
+ "id": "8902",
45
+ "name": "Mango",
46
+ "description": "Lorem ipsum dolor si amen",
47
+ "price": "110",
48
+ "quantity": "28",
49
+ "total": "3080"
50
+ },{
51
+ "id": "3674",
52
+ "name": "Pineapple",
53
+ "description": "Lorem ipsum dolor si amen",
54
+ "price": "120",
55
+ "quantity": "13",
56
+ "total": "1560"
57
+ },{
58
+ "id": "8730",
59
+ "name": "Watermelon",
60
+ "description": "Lorem ipsum dolor si amen",
61
+ "price": "150",
62
+ "quantity": "120",
63
+ "total": "18000"
64
+ },{
65
+ "id": "1567",
66
+ "name": "Lemon",
67
+ "description": "Lorem ipsum dolor si amen",
68
+ "price": "30",
69
+ "quantity": "27",
70
+ "total": "810"
71
+ },{
72
+ "id": "4783",
73
+ "name": "Orange",
74
+ "description": "Lorem ipsum dolor si amen",
75
+ "price": "70",
76
+ "quantity": "23",
77
+ "total": "1610"
78
+ }
79
+ ]
80
+ },
81
+ {
82
+ "number":"ID-8387324",
83
+ "date_issued":"1972-01-01 13:42:24",
84
+ "currency": "USD",
85
+ "subtotal":"52330",
86
+ "tax_rate":"16",
87
+ "tax":"8372.8",
88
+ "total": "60702.8",
89
+ "bill_to": {
90
+ "name": "Daniel Osorio",
91
+ "email": "hello@prexview.com"
92
+ },
93
+ "order":[
94
+ {
95
+ "id": "3421",
96
+ "name": "Apple",
97
+ "description": "Lorem ipsum dolor si amen",
98
+ "price": "150",
99
+ "quantity": "75",
100
+ "total": "11250"
101
+ },{
102
+ "id": "8473",
103
+ "name": "Banana",
104
+ "description": "Lorem ipsum dolor si amen",
105
+ "price": "80",
106
+ "quantity": "38",
107
+ "total": "3040"
108
+ },{
109
+ "id": "7820",
110
+ "name": "Blackberry",
111
+ "description": "Lorem ipsum dolor si amen",
112
+ "price": "130",
113
+ "quantity": "32",
114
+ "total": "4160"
115
+ },{
116
+ "id": "8734",
117
+ "name": "Grape",
118
+ "description": "Lorem ipsum dolor si amen",
119
+ "price": "180",
120
+ "quantity": "49",
121
+ "total": "8820"
122
+ },{
123
+ "id": "8902",
124
+ "name": "Mango",
125
+ "description": "Lorem ipsum dolor si amen",
126
+ "price": "110",
127
+ "quantity": "28",
128
+ "total": "3080"
129
+ },{
130
+ "id": "3674",
131
+ "name": "Pineapple",
132
+ "description": "Lorem ipsum dolor si amen",
133
+ "price": "120",
134
+ "quantity": "13",
135
+ "total": "1560"
136
+ },{
137
+ "id": "8730",
138
+ "name": "Watermelon",
139
+ "description": "Lorem ipsum dolor si amen",
140
+ "price": "150",
141
+ "quantity": "120",
142
+ "total": "18000"
143
+ },{
144
+ "id": "1567",
145
+ "name": "Lemon",
146
+ "description": "Lorem ipsum dolor si amen",
147
+ "price": "30",
148
+ "quantity": "27",
149
+ "total": "810"
150
+ },{
151
+ "id": "4783",
152
+ "name": "Orange",
153
+ "description": "Lorem ipsum dolor si amen",
154
+ "price": "70",
155
+ "quantity": "23",
156
+ "total": "1610"
157
+ }
158
+ ]
159
+ },
160
+ {
161
+ "number":"ID-8387325",
162
+ "date_issued":"1972-01-01 13:42:24",
163
+ "currency": "USD",
164
+ "subtotal":"52330",
165
+ "tax_rate":"16",
166
+ "tax":"8372.8",
167
+ "total": "60702.8",
168
+ "bill_to": {
169
+ "name": "Daniel Osorio",
170
+ "email": "hello@prexview.com"
171
+ },
172
+ "order":[
173
+ {
174
+ "id": "3421",
175
+ "name": "Apple",
176
+ "description": "Lorem ipsum dolor si amen",
177
+ "price": "150",
178
+ "quantity": "75",
179
+ "total": "11250"
180
+ },{
181
+ "id": "8473",
182
+ "name": "Banana",
183
+ "description": "Lorem ipsum dolor si amen",
184
+ "price": "80",
185
+ "quantity": "38",
186
+ "total": "3040"
187
+ },{
188
+ "id": "7820",
189
+ "name": "Blackberry",
190
+ "description": "Lorem ipsum dolor si amen",
191
+ "price": "130",
192
+ "quantity": "32",
193
+ "total": "4160"
194
+ },{
195
+ "id": "8734",
196
+ "name": "Grape",
197
+ "description": "Lorem ipsum dolor si amen",
198
+ "price": "180",
199
+ "quantity": "49",
200
+ "total": "8820"
201
+ },{
202
+ "id": "8902",
203
+ "name": "Mango",
204
+ "description": "Lorem ipsum dolor si amen",
205
+ "price": "110",
206
+ "quantity": "28",
207
+ "total": "3080"
208
+ },{
209
+ "id": "3674",
210
+ "name": "Pineapple",
211
+ "description": "Lorem ipsum dolor si amen",
212
+ "price": "120",
213
+ "quantity": "13",
214
+ "total": "1560"
215
+ },{
216
+ "id": "8730",
217
+ "name": "Watermelon",
218
+ "description": "Lorem ipsum dolor si amen",
219
+ "price": "150",
220
+ "quantity": "120",
221
+ "total": "18000"
222
+ },{
223
+ "id": "1567",
224
+ "name": "Lemon",
225
+ "description": "Lorem ipsum dolor si amen",
226
+ "price": "30",
227
+ "quantity": "27",
228
+ "total": "810"
229
+ },{
230
+ "id": "4783",
231
+ "name": "Orange",
232
+ "description": "Lorem ipsum dolor si amen",
233
+ "price": "70",
234
+ "quantity": "23",
235
+ "total": "1610"
236
+ }
237
+ ]
238
+ }
239
+ ]
@@ -0,0 +1,79 @@
1
+ {
2
+ "number":"ID-8387323",
3
+ "date_issued":"1972-01-01 13:42:24",
4
+ "currency": "USD",
5
+ "subtotal":"52330",
6
+ "tax_rate":"16",
7
+ "tax":"8372.8",
8
+ "total": "60702.8",
9
+ "bill_to": {
10
+ "name": "Daniel Osorio",
11
+ "email": "hello@prexview.com"
12
+ },
13
+ "order":[
14
+ {
15
+ "id": "3421",
16
+ "name": "Apple",
17
+ "description": "Lorem ipsum dolor si amen",
18
+ "price": "150",
19
+ "quantity": "75",
20
+ "total": "11250"
21
+ },{
22
+ "id": "8473",
23
+ "name": "Banana",
24
+ "description": "Lorem ipsum dolor si amen",
25
+ "price": "80",
26
+ "quantity": "38",
27
+ "total": "3040"
28
+ },{
29
+ "id": "7820",
30
+ "name": "Blackberry",
31
+ "description": "Lorem ipsum dolor si amen",
32
+ "price": "130",
33
+ "quantity": "32",
34
+ "total": "4160"
35
+ },{
36
+ "id": "8734",
37
+ "name": "Grape",
38
+ "description": "Lorem ipsum dolor si amen",
39
+ "price": "180",
40
+ "quantity": "49",
41
+ "total": "8820"
42
+ },{
43
+ "id": "8902",
44
+ "name": "Mango",
45
+ "description": "Lorem ipsum dolor si amen",
46
+ "price": "110",
47
+ "quantity": "28",
48
+ "total": "3080"
49
+ },{
50
+ "id": "3674",
51
+ "name": "Pineapple",
52
+ "description": "Lorem ipsum dolor si amen",
53
+ "price": "120",
54
+ "quantity": "13",
55
+ "total": "1560"
56
+ },{
57
+ "id": "8730",
58
+ "name": "Watermelon",
59
+ "description": "Lorem ipsum dolor si amen",
60
+ "price": "150",
61
+ "quantity": "120",
62
+ "total": "18000"
63
+ },{
64
+ "id": "1567",
65
+ "name": "Lemon",
66
+ "description": "Lorem ipsum dolor si amen",
67
+ "price": "30",
68
+ "quantity": "27",
69
+ "total": "810"
70
+ },{
71
+ "id": "4783",
72
+ "name": "Orange",
73
+ "description": "Lorem ipsum dolor si amen",
74
+ "price": "70",
75
+ "quantity": "23",
76
+ "total": "1610"
77
+ }
78
+ ]
79
+ }
@@ -0,0 +1,87 @@
1
+ <invoice
2
+ number="ID-8387323"
3
+ date_issued="1972-01-01 13:42:24"
4
+ currency="USD"
5
+ subtotal="52330"
6
+ tax_rate="16"
7
+ tax="8372.8"
8
+ total="60702.8">
9
+ <bill_to
10
+ name="Daniel Osorio"
11
+ email="hello@prexview.com">
12
+ </bill_to>
13
+ <order>
14
+ <product
15
+ id="3421"
16
+ name="Apple"
17
+ description="Lorem ipsum dolor si amen"
18
+ price="150"
19
+ quantity="75"
20
+ total="11250">
21
+ </product>
22
+ <product
23
+ id="8473"
24
+ name="Banana"
25
+ description="Lorem ipsum dolor si amen"
26
+ price="80"
27
+ quantity="38"
28
+ total="3040">
29
+ </product>
30
+ <product
31
+ id="7820"
32
+ name="Blackberry"
33
+ description="Lorem ipsum dolor si amen"
34
+ price="130"
35
+ quantity="32"
36
+ total="4160">
37
+ </product>
38
+ <product
39
+ id="8734"
40
+ name="Grape"
41
+ description="Lorem ipsum dolor si amen"
42
+ price="180"
43
+ quantity="49"
44
+ total="8820">
45
+ </product>
46
+ <product
47
+ id="8902"
48
+ name="Mango"
49
+ description="Lorem ipsum dolor si amen"
50
+ price="110"
51
+ quantity="28"
52
+ total="3080">
53
+ </product>
54
+ <product
55
+ id="3674"
56
+ name="Pineapple"
57
+ description="Lorem ipsum dolor si amen"
58
+ price="120"
59
+ quantity="13"
60
+ total="1560">
61
+ </product>
62
+ <product
63
+ id="8730"
64
+ name="Watermelon"
65
+ description="Lorem ipsum dolor si amen"
66
+ price="150"
67
+ quantity="120"
68
+ total="18000">
69
+ </product>
70
+ <product
71
+ id="1567"
72
+ name="Lemon"
73
+ description="Lorem ipsum dolor si amen"
74
+ price="30"
75
+ quantity="27"
76
+ total="810">
77
+ </product>
78
+ <product
79
+ id="4783"
80
+ name="Orange"
81
+ description="Lorem ipsum dolor si amen"
82
+ price="70"
83
+ quantity="23"
84
+ total="1610">
85
+ </product>
86
+ </order>
87
+ </invoice>
@@ -0,0 +1,29 @@
1
+ require 'PrexView'
2
+ require 'json'
3
+
4
+ def send_request
5
+ array_content = JSON.parse(File.new('data/multiple-invoice.json', 'r').read)
6
+ transform = -> (json) do
7
+ code, response = PrexView.send_json(json, { type: 'json', design: "invoice-jso" })
8
+ if ("200".."299").to_a.include? code
9
+ save_in_filesystem response, "#{content["number"]}.pdf"
10
+ elsif ("400".."499").to_a.include? code
11
+ save_in_filesystem response, 'failed.txt'
12
+ end
13
+ end
14
+ array_content.map(&transform)
15
+ end
16
+
17
+ def save_in_filesystem bytes, name_pdf
18
+ directory_name = "multiple-invoice"
19
+ Dir.mkdir(directory_name) unless File.exists?(directory_name)
20
+ File.open("#{directory_name}/#{name_pdf}", 'wb') { |output|
21
+ output << bytes
22
+ }
23
+ end
24
+
25
+ def main
26
+ send_request
27
+ end
28
+
29
+ main
@@ -0,0 +1,26 @@
1
+ require 'prex_view'
2
+
3
+ def send_request
4
+ handle = File.open('data/simple-invoice.xml', 'r')
5
+ xml = handle.read
6
+
7
+ code, response = PrexView.send_xml(xml, { type: 'xml', design: "invoice-xml" })
8
+
9
+ if ("200".."299").to_a.include? code
10
+ save_in_filesystem response, 'pdf'
11
+ elsif ("400".."499").to_a.include? code
12
+ save_in_filesystem response, 'txt'
13
+ end
14
+ end
15
+
16
+ def save_in_filesystem bytes, ext
17
+ File.open("coso.#{ext}", 'wb') { |output|
18
+ output << bytes
19
+ }
20
+ end
21
+
22
+ def main
23
+ send_request
24
+ end
25
+
26
+ main
@@ -0,0 +1,23 @@
1
+ require 'PrexView'
2
+
3
+ def send_request
4
+ json = JSON.parse(File.new('data/simple-invoice.json', 'r').read)
5
+ code, response = PrexView.send_json(json, { type: 'json', design: "invoice-json" })
6
+ if ("200".."299").to_a.include? code
7
+ save_in_filesystem response, 'pdf'
8
+ elsif ("400".."499").to_a.include? code
9
+ save_in_filesystem response, 'txt'
10
+ end
11
+ end
12
+
13
+ def save_in_filesystem bytes, ext
14
+ File.open("coso.#{ext}", 'wb') { |output|
15
+ output << bytes
16
+ }
17
+ end
18
+
19
+ def main
20
+ send_request
21
+ end
22
+
23
+ main
Binary file
Binary file
@@ -0,0 +1,32 @@
1
+ require "PrexView/version"
2
+ require "PrexView/prex_view_service"
3
+
4
+ module PrexView
5
+ def self.send_xml xml, options
6
+ # Send doc to PrexView
7
+ #
8
+ # Example:
9
+ # >> PrexView.send_xml(xml, {type: "xml/json", token: "your_token"})
10
+ # => "200"
11
+ #
12
+ # Arguments:
13
+ # xml: (String or json)
14
+ # type: (String)
15
+ # token: (String)
16
+ code, content = PrexViewService::Transform.new(xml, options).send_xml
17
+ end
18
+
19
+ def self.send_json json, options
20
+ # Send doc to PrexView
21
+ #
22
+ # Example:
23
+ # >> PrexView.send_json(json, {type: "xml/json", token: "your_token"})
24
+ # => "200"
25
+ #
26
+ # Arguments:
27
+ # json: (String or json)
28
+ # type: (String)
29
+ # token: (String)
30
+ code, content = PrexViewService::Transform.new(json, options).send_json
31
+ end
32
+ end
@@ -0,0 +1,53 @@
1
+ #encoding: UTF-8
2
+ require 'net/http'
3
+ require "uri"
4
+ require "json"
5
+
6
+ module PrexViewService
7
+ class Transform
8
+ def initialize data_string, options = {}
9
+ @data_string = data_string
10
+
11
+ @uri = URI("https://api.prexview.com/v1/transform")
12
+ @token = options.fetch(:token, "#{ENV['PREXVIEW_TOKEN']}")
13
+ @type = options.fetch(:type, nil)
14
+ @design = options.fetch(:design, nil)
15
+ @output = options.fetch(:options, 'pdf')
16
+ @note = options.fetch(:note, '')
17
+ end
18
+
19
+ def send_xml
20
+ body = { "xml" => @data_string, "design" => @design, "output" => @output, "note" => @note}
21
+ _post body
22
+ end
23
+
24
+ def send_json
25
+ body = { "json" => JSON.dump(@data_string), "design" => @design, "output" => @output, "note" => @note}
26
+ _post body
27
+ end
28
+
29
+ private
30
+ def _post body
31
+ http = Net::HTTP.new(@uri.host, @uri.port)
32
+ http.use_ssl = true
33
+ request = Net::HTTP::Post.new @uri, body
34
+
35
+ request["content-type"] = 'multipart/form-data; boundary=---011000010111000001101001'
36
+ request["authorization"] = @token
37
+ response = http.request(request)
38
+ response.body
39
+
40
+ if ("200".."299").to_a.include? response.code
41
+ [response.code, response.body]
42
+ elsif ("400".."499").to_a.include? response.code
43
+ [response.code, response.body]
44
+ end
45
+ end
46
+
47
+ def save_field_in_filesystem filename, bytes
48
+ File.open(filename, 'wb') { |output|
49
+ output << bytes
50
+ }
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,3 @@
1
+ module PrexView
2
+ VERSION = "1.0.0"
3
+ end
metadata ADDED
@@ -0,0 +1,112 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: PrexView
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Urielable
8
+ - prexview
9
+ autorequire:
10
+ bindir: exe
11
+ cert_chain: []
12
+ date: 2017-04-07 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: '1.12'
21
+ type: :development
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "~>"
26
+ - !ruby/object:Gem::Version
27
+ version: '1.12'
28
+ - !ruby/object:Gem::Dependency
29
+ name: rake
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - "~>"
33
+ - !ruby/object:Gem::Version
34
+ version: '10.0'
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - "~>"
40
+ - !ruby/object:Gem::Version
41
+ version: '10.0'
42
+ - !ruby/object:Gem::Dependency
43
+ name: minitest
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - "~>"
47
+ - !ruby/object:Gem::Version
48
+ version: '5.0'
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - "~>"
54
+ - !ruby/object:Gem::Version
55
+ version: '5.0'
56
+ description: A composer library to use PrexView a fast, scalable and very friendly
57
+ service for programatic HTML, PDF, PNG or JPG generation using JSON or XML data.
58
+ email:
59
+ - uriel85@gmail.com
60
+ executables: []
61
+ extensions: []
62
+ extra_rdoc_files: []
63
+ files:
64
+ - ".editorconfig"
65
+ - ".gitignore"
66
+ - ".travis.yml"
67
+ - CODE_OF_CONDUCT.md
68
+ - Gemfile
69
+ - LICENSE
70
+ - LICENSE.txt
71
+ - PrexView.gemspec
72
+ - README.md
73
+ - Rakefile
74
+ - bin/console
75
+ - bin/setup
76
+ - examples/data/multiple-invoice.json
77
+ - examples/data/simple-invoice.json
78
+ - examples/data/simple-invoice.xml
79
+ - examples/multiple-transform.rb
80
+ - examples/simple-transform-xml.rb
81
+ - examples/simple-transform.rb
82
+ - img/api.png
83
+ - img/design.png
84
+ - lib/PrexView.rb
85
+ - lib/PrexView/prex_view_service.rb
86
+ - lib/PrexView/version.rb
87
+ homepage: https://github.com/prexview/prexview-ruby
88
+ licenses:
89
+ - MIT
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: A composer library to use PrexView a fast, scalable and very friendly service
111
+ for programatic HTML, PDF, PNG or JPG generation using JSON or XML data.
112
+ test_files: []