grabzit 2.3.0 → 3.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.
@@ -0,0 +1,185 @@
1
+ module GrabzIt
2
+ require File.join(File.dirname(__FILE__), 'baseoptions')
3
+
4
+ # Represents all of the options available when creating an image
5
+ # @version 3.0
6
+ # @author GrabzIt
7
+ class ImageOptions < BaseOptions
8
+ def initialize()
9
+ @browserWidth = nil
10
+ @browserHeight = nil
11
+ @width = nil
12
+ @height = nil
13
+ @format = nil
14
+ @targetElement = nil
15
+ @requestAs = 0
16
+ @customWaterMarkId = nil
17
+ @quality = -1
18
+ end
19
+
20
+ # @return [Integer] the width of the browser in pixels
21
+ def browserWidth
22
+ @browserWidth
23
+ end
24
+
25
+ # Set the width of the browser in pixels
26
+ #
27
+ # @param value [Integer] the browser width
28
+ # @return [void]
29
+ def browserWidth(value)
30
+ @browserWidth = value
31
+ end
32
+
33
+ # @return [Integer] the height of the browser in pixels
34
+ def browserHeight
35
+ @browserHeight
36
+ end
37
+
38
+ # Set the height of the browser in pixels. Use -1 to screenshot the whole web page
39
+ #
40
+ # @param value [Integer] the browser height
41
+ # @return [void]
42
+ def browserHeight(value)
43
+ @browserHeight = value
44
+ end
45
+
46
+ # @return [Integer] get the width of the resulting screenshot in pixels.
47
+ def width
48
+ @width
49
+ end
50
+
51
+ # Set the width of the resulting screenshot in pixels. Use -1 to not reduce the width of the screenshot
52
+ #
53
+ # @param value [Integer] the width
54
+ # @return [void]
55
+ def width(value)
56
+ @width = value
57
+ end
58
+
59
+ # @return [Integer] get the height of the resulting screenshot in pixels
60
+ def height
61
+ @height
62
+ end
63
+
64
+ # Set the height of the resulting screenshot in pixels. Use -1 to not reduce the height of the screenshot
65
+ #
66
+ # @param value [Integer] the height
67
+ # @return [void]
68
+ def height(value)
69
+ @height = value
70
+ end
71
+
72
+ # @return [String] get the format of the screenshot image
73
+ def format
74
+ @format
75
+ end
76
+
77
+ # Set the format the screenshot should be in: bmp8, bmp16, bmp24, bmp, tiff, jpg, png
78
+ #
79
+ # @param value [String] the format
80
+ # @return [void]
81
+ def format(value)
82
+ @format = value
83
+ end
84
+
85
+ # @return [Integer] get the number of milliseconds to wait before creating the capture
86
+ def delay
87
+ @delay
88
+ end
89
+
90
+ # Set the number of milliseconds to wait before creating the capture
91
+ #
92
+ # @param value [Integer] the delay
93
+ # @return [void]
94
+ def delay(value)
95
+ @delay = value
96
+ end
97
+
98
+ # @return [String] get the id of the only HTML element in the web page to turn into a screenshot
99
+ def targetElement
100
+ @targetElement
101
+ end
102
+
103
+ # Set the id of the only HTML element in the web page to turn into a screenshot
104
+ #
105
+ # @param value [String] the target element
106
+ # @return [void]
107
+ def targetElement(value)
108
+ @targetElement = value
109
+ end
110
+
111
+ # @return [Integer] get which user agent type should be used
112
+ def requestAs
113
+ @requestAs
114
+ end
115
+
116
+ # Set which user agent type should be used: Standard Browser = 0, Mobile Browser = 1, Search Engine = 2 and Fallback Browser = 3
117
+ #
118
+ # @param value [Integer] the browser type
119
+ # @return [void]
120
+ def requestAs(value)
121
+ @requestAs = value
122
+ end
123
+
124
+ # @return [String] the custom watermark id.
125
+ def customWaterMarkId
126
+ @customWaterMarkId
127
+ end
128
+
129
+ # Set a custom watermark to add to the screenshot.
130
+ #
131
+ # @param value [String] custom watermark id
132
+ # @return [void]
133
+ def customWaterMarkId(value)
134
+ @customWaterMarkId = value
135
+ end
136
+
137
+ # @return [Integer] the quality of the screenshot.
138
+ def quality
139
+ @quality
140
+ end
141
+
142
+ # Set the quality of the screenshot where 0 is poor and 100 excellent. The default is -1 which uses the recommended quality
143
+ #
144
+ # @param value [Integer] the custom identifier
145
+ # @return [void]
146
+ def quality(value)
147
+ @quality = value
148
+ end
149
+
150
+ # @!visibility private
151
+ def _getSignatureString(applicationSecret, callBackURL, url = nil)
152
+ urlParam = ''
153
+ if (url != nil)
154
+ urlParam = GrabzIt::Utility.nil_check(url)+"|"
155
+ end
156
+
157
+ callBackURLParam = ''
158
+ if (callBackURL != nil)
159
+ callBackURLParam = GrabzIt::Utility.nil_check(callBackURL)
160
+ end
161
+
162
+ return applicationSecret+"|"+ urlParam + callBackURLParam +
163
+ "|"+GrabzIt::Utility.nil_check(@format)+"|"+GrabzIt::Utility.nil_int_check(@height)+"|"+GrabzIt::Utility.nil_int_check(@width)+"|"+GrabzIt::Utility.nil_int_check(@browserHeight)+
164
+ "|"+GrabzIt::Utility.nil_int_check(@browserWidth)+"|"+GrabzIt::Utility.nil_check(@customId)+"|"+GrabzIt::Utility.nil_int_check(@delay)+"|"+GrabzIt::Utility.nil_check(@targetElement)+
165
+ "|"+GrabzIt::Utility.nil_check(@customWaterMarkId)+"|"+GrabzIt::Utility.nil_int_check(@requestAs)+"|"+GrabzIt::Utility.nil_check(@country)+"|"+GrabzIt::Utility.nil_int_check(@quality)
166
+ end
167
+
168
+ # @!visibility private
169
+ def _getParameters(applicationKey, sig, callBackURL, dataName, dataValue)
170
+ params = createParameters(applicationKey, sig, callBackURL, dataName, dataValue)
171
+ params['width'] = GrabzIt::Utility.nil_int_check(@width)
172
+ params['height'] = GrabzIt::Utility.nil_int_check(@height)
173
+ params['format'] = GrabzIt::Utility.nil_check(@format)
174
+ params['bwidth'] = GrabzIt::Utility.nil_int_check(@browserWidth)
175
+ params['customwatermarkid'] = GrabzIt::Utility.nil_check(@customWaterMarkId)
176
+ params['bheight'] = GrabzIt::Utility.nil_int_check(@browserHeight)
177
+ params['delay'] = GrabzIt::Utility.nil_int_check(@delay)
178
+ params['target'] = GrabzIt::Utility.nil_check(@targetElement)
179
+ params['requestmobileversion'] = GrabzIt::Utility.nil_int_check(@requestAs)
180
+ params['quality'] = GrabzIt::Utility.nil_int_check(@quality)
181
+
182
+ return params
183
+ end
184
+ end
185
+ end
@@ -0,0 +1,266 @@
1
+ module GrabzIt
2
+ require File.join(File.dirname(__FILE__), 'baseoptions')
3
+
4
+ # Represents all of the options available when creating a PDF
5
+ # @version 3.0
6
+ # @author GrabzIt
7
+ class PDFOptions < BaseOptions
8
+ def initialize()
9
+ @includeBackground = true
10
+ @pagesize = 'A4'
11
+ @orientation = 'Portrait'
12
+ @includeLinks = true
13
+ @includeOutline = false
14
+ @title = nil
15
+ @coverURL = nil
16
+ @marginTop = 10
17
+ @marginLeft = 10
18
+ @marginBottom = 10
19
+ @marginRight = 10
20
+ @requestAs = 0
21
+ @templateId = nil
22
+ @customWaterMarkId = nil
23
+ @quality = -1
24
+ end
25
+
26
+ # @return [Boolean] true if the background of the web page should be included in the PDF
27
+ def includeBackground
28
+ @includeBackground
29
+ end
30
+
31
+ # Set to true if the background of the web page should be included in the PDF
32
+ #
33
+ # @param value [Boolean] include background
34
+ # @return [void]
35
+ def includeBackground(value)
36
+ @includeBackground = value
37
+ end
38
+
39
+ # @return [String] the page size of the PDF to be returned
40
+ def pagesize
41
+ @pagesize
42
+ end
43
+
44
+ # Set the page size of the PDF to be returned: 'A3', 'A4', 'A5', 'A6', 'B3', 'B4', 'B5', 'B6', 'Letter'
45
+ #
46
+ # @param value [String] page size
47
+ # @return [void]
48
+ def pagesize(value)
49
+ value = GrabzIt::Utility.nil_check(value).upcase
50
+ @pagesize = value
51
+ end
52
+
53
+ # @return [String] the orientation of the PDF to be returned
54
+ def orientation
55
+ @orientation
56
+ end
57
+
58
+ # Set the orientation of the PDF to be returned: 'Landscape' or 'Portrait'
59
+ #
60
+ # @param value [String] page orientation
61
+ # @return [void]
62
+ def orientation(value)
63
+ value = GrabzIt::Utility.nil_check(value).capitalize
64
+ @orientation = value
65
+ end
66
+
67
+ # @return [Boolean] true if the links should be included in the PDF
68
+ def includeLinks
69
+ @includeLinks
70
+ end
71
+
72
+ # Set to true if links should be included in the PDF
73
+ #
74
+ # @param value [Boolean] include links
75
+ # @return [void]
76
+ def includeLinks(value)
77
+ @includeLinks = value
78
+ end
79
+
80
+ # @return [String] a title for the PDF document
81
+ def title
82
+ @title
83
+ end
84
+
85
+ # Set a title for the PDF document
86
+ #
87
+ # @param value [String] PDF title
88
+ # @return [void]
89
+ def title(value)
90
+ @title = value
91
+ end
92
+
93
+ # @return [String] the URL of a web page that should be used as a cover page for the PDF
94
+ def coverURL
95
+ @coverURL
96
+ end
97
+
98
+ # Set the URL of a web page that should be used as a cover page for the PDF
99
+ #
100
+ # @param value [String] cover URL
101
+ # @return [void]
102
+ def coverURL(value)
103
+ @coverURL = value
104
+ end
105
+
106
+ # @return [Integer] the margin that should appear at the top of the PDF document page
107
+ def marginTop
108
+ @marginTop
109
+ end
110
+
111
+ # Set the margin that should appear at the top of the PDF document page
112
+ #
113
+ # @param value [Integer] margin top
114
+ # @return [void]
115
+ def marginTop(value)
116
+ @marginTop = value
117
+ end
118
+
119
+ # @return [Integer] the margin that should appear at the left of the PDF document page
120
+ def marginLeft
121
+ @marginLeft
122
+ end
123
+
124
+ # Set the margin that should appear at the left of the PDF document page
125
+ #
126
+ # @param value [Integer] margin left
127
+ # @return [void]
128
+ def marginLeft(value)
129
+ @marginLeft = value
130
+ end
131
+
132
+ # @return [Integer] the margin that should appear at the bottom of the PDF document page
133
+ def marginBottom
134
+ @marginBottom
135
+ end
136
+
137
+ # Set the margin that should appear at the bottom of the PDF document page
138
+ #
139
+ # @param value [Integer] margin bottom
140
+ # @return [void]
141
+ def marginBottom(value)
142
+ @marginBottom = value
143
+ end
144
+
145
+ # @return [Integer] the margin that should appear at the right of the PDF document
146
+ def marginRight
147
+ @marginRight
148
+ end
149
+
150
+ # Set the margin that should appear at the right of the PDF document
151
+ #
152
+ # @param value [Integer] margin right
153
+ # @return [void]
154
+ def marginRight(value)
155
+ @marginRight = value
156
+ end
157
+
158
+ # @return [Integer] the number of milliseconds to wait before creating the capture
159
+ def delay
160
+ @delay
161
+ end
162
+
163
+ # Set the number of milliseconds to wait before creating the capture
164
+ #
165
+ # @param value [Integer] delay
166
+ # @return [void]
167
+ def delay(value)
168
+ @delay = value
169
+ end
170
+
171
+ # @return [Integer] get which user agent type should be used
172
+ def requestAs
173
+ @requestAs
174
+ end
175
+
176
+ # Set which user agent type should be used: Standard Browser = 0, Mobile Browser = 1, Search Engine = 2 and Fallback Browser = 3
177
+ #
178
+ # @param value [Integer] the browser type
179
+ # @return [void]
180
+ def requestAs(value)
181
+ @requestAs = value
182
+ end
183
+
184
+ # @return [String] the PDF template ID that specifies the header and footer of the PDF document
185
+ def templateId
186
+ @templateId
187
+ end
188
+
189
+ # Set a PDF template ID that specifies the header and footer of the PDF document
190
+ #
191
+ # @param value [String] template id
192
+ # @return [void]
193
+ def templateId(value)
194
+ @templateId = value
195
+ end
196
+
197
+ # @return [String] the custom watermark id.
198
+ def customWaterMarkId
199
+ @customWaterMarkId
200
+ end
201
+
202
+ # Set a custom watermark to add to the PDF.
203
+ #
204
+ # @param value [String] custom watermark id
205
+ # @return [void]
206
+ def customWaterMarkId(value)
207
+ @customWaterMarkId = value
208
+ end
209
+
210
+ # @return [Integer] the quality of the PDF.
211
+ def quality
212
+ @quality
213
+ end
214
+
215
+ # Set the quality of the PDF where 0 is poor and 100 excellent. The default is -1 which uses the recommended quality
216
+ #
217
+ # @param value [Integer] quality
218
+ # @return [void]
219
+ def quality(value)
220
+ @quality = value
221
+ end
222
+
223
+ # @!visibility private
224
+ def _getSignatureString(applicationSecret, callBackURL, url = nil)
225
+ urlParam = ''
226
+ if (url != nil)
227
+ urlParam = GrabzIt::Utility.nil_check(url)+"|"
228
+ end
229
+
230
+ callBackURLParam = ''
231
+ if (callBackURL != nil)
232
+ callBackURLParam = GrabzIt::Utility.nil_check(callBackURL)
233
+ end
234
+
235
+ return applicationSecret+"|"+ urlParam + callBackURLParam +
236
+ "|"+GrabzIt::Utility.nil_check(@customId)+"|"+GrabzIt::Utility.b_to_str(@includeBackground)+"|"+@pagesize +"|"+@orientation+"|"+
237
+ GrabzIt::Utility.nil_check(@customWaterMarkId)+"|"+GrabzIt::Utility.b_to_str(@includeLinks)+"|"+GrabzIt::Utility.b_to_str(@includeOutline)+"|"+
238
+ GrabzIt::Utility.nil_check(@title)+"|"+GrabzIt::Utility.nil_check(@coverURL)+"|"+GrabzIt::Utility.nil_int_check(@marginTop)+"|"+GrabzIt::Utility.nil_int_check(@marginLeft)+
239
+ "|"+GrabzIt::Utility.nil_int_check(@marginBottom)+"|"+GrabzIt::Utility.nil_int_check(@marginRight)+"|"+GrabzIt::Utility.nil_int_check(@delay)+"|"+
240
+ GrabzIt::Utility.nil_int_check(@requestAs)+"|"+GrabzIt::Utility.nil_check(@country)+"|"+GrabzIt::Utility.nil_int_check(@quality)+"|"+GrabzIt::Utility.nil_check(@templateId)
241
+ end
242
+
243
+ # @!visibility private
244
+ def _getParameters(applicationKey, sig, callBackURL, dataName, dataValue)
245
+ params = createParameters(applicationKey, sig, callBackURL, dataName, dataValue)
246
+ params['background'] = GrabzIt::Utility.b_to_str(@includeBackground)
247
+ params['pagesize'] = @pagesize
248
+ params['orientation'] = @orientation
249
+ params['templateid'] = GrabzIt::Utility.nil_check(@templateId)
250
+ params['customwatermarkid'] = GrabzIt::Utility.nil_check(@customWaterMarkId)
251
+ params['includelinks'] = GrabzIt::Utility.b_to_str(@includeLinks)
252
+ params['includeoutline'] = GrabzIt::Utility.b_to_str(@includeOutline)
253
+ params['title'] = GrabzIt::Utility.nil_check(@title)
254
+ params['coverurl'] = GrabzIt::Utility.nil_check(@coverURL)
255
+ params['mleft'] = GrabzIt::Utility.nil_int_check(@marginLeft)
256
+ params['mright'] = GrabzIt::Utility.nil_int_check(@marginRight)
257
+ params['mtop'] = GrabzIt::Utility.nil_int_check(@marginTop)
258
+ params['mbottom'] = GrabzIt::Utility.nil_int_check(@marginBottom)
259
+ params['delay'] = GrabzIt::Utility.nil_int_check(@delay)
260
+ params['requestmobileversion'] = GrabzIt::Utility.nil_int_check(@requestAs)
261
+ params['quality'] = GrabzIt::Utility.nil_int_check(@quality)
262
+
263
+ return params;
264
+ end
265
+ end
266
+ end
@@ -0,0 +1,36 @@
1
+ module GrabzIt
2
+ # @version 3.0
3
+ # @author GrabzIt
4
+ # @!visibility private
5
+ class Request
6
+ def initialize(url, isPost, options, data = nil)
7
+ @url = url
8
+ @isPost = isPost
9
+ @options = options
10
+ @data = data
11
+ end
12
+
13
+ def url
14
+ @url
15
+ end
16
+
17
+ def isPost
18
+ @isPost
19
+ end
20
+
21
+ def options
22
+ @options
23
+ end
24
+
25
+ def data
26
+ @data
27
+ end
28
+
29
+ def getTargetUrl
30
+ if (@isPost)
31
+ return nil
32
+ end
33
+ return @data
34
+ end
35
+ end
36
+ end
@@ -1,9 +1,9 @@
1
1
  module GrabzIt
2
2
  # This class represents the screenshot status
3
- # @version 2.1
3
+ # @version 3.0
4
4
  # @author GrabzIt
5
5
  class ScreenShotStatus
6
- # @api private
6
+ # @!visibility private
7
7
  def initialize(processing = false, cached = false, expired = false, message = '')
8
8
  @Processing = processing
9
9
  @Cached = cached
@@ -0,0 +1,126 @@
1
+ module GrabzIt
2
+ require File.join(File.dirname(__FILE__), 'baseoptions')
3
+
4
+ # Represents all of the options available when extracting tabular data
5
+ # @version 3.0
6
+ # @author GrabzIt
7
+ class TableOptions < BaseOptions
8
+ def initialize()
9
+ @tableNumberToInclude = 1
10
+ @format = 'csv'
11
+ @includeHeaderNames = true
12
+ @includeAllTables = false
13
+ @targetElement = nil
14
+ @requestAs = 0
15
+ end
16
+
17
+ # @return [Integer] the index of the table to be converted
18
+ def tableNumberToInclude
19
+ @tableNumberToInclude
20
+ end
21
+
22
+ # Set the index of the table to be converted, were all tables in a web page are ordered from the top of the web page to bottom
23
+ #
24
+ # @param value [Integer] the table number
25
+ # @return [void]
26
+ def tableNumberToInclude(value)
27
+ @tableNumberToInclude = value
28
+ end
29
+
30
+ # @return [String] the format of the table should be
31
+ def format
32
+ @format
33
+ end
34
+
35
+ # Set the format the table should be in: 'csv', 'xlsx' or 'json'
36
+ #
37
+ # @param value [String] the format
38
+ # @return [void]
39
+ def format(value)
40
+ @format = value
41
+ end
42
+
43
+ # @return [Boolean] if the header names are included in the table
44
+ def includeHeaderNames
45
+ @includeHeaderNames
46
+ end
47
+
48
+ # Set to true to include header names into the table
49
+ #
50
+ # @param value [Boolean] include header names
51
+ # @return [void]
52
+ def includeHeaderNames(value)
53
+ @includeHeaderNames = value
54
+ end
55
+
56
+ # @return [Boolean] if every table on will be extracted with each table appearing in a separate spreadsheet sheet
57
+ def includeAllTables
58
+ @includeAllTables
59
+ end
60
+
61
+ # Set to true to extract every table on the web page into a separate spreadsheet sheet. Only available with the XLSX and JSON formats
62
+ #
63
+ # @param value [Boolean] include all tables
64
+ # @return [void]
65
+ def includeAllTables(value)
66
+ @includeAllTables = value
67
+ end
68
+
69
+ # @return [String] the id of the only HTML element in the web page that should be used to extract tables from
70
+ def targetElement
71
+ @targetElement
72
+ end
73
+
74
+ # Set the id of the only HTML element in the web page that should be used to extract tables from
75
+ #
76
+ # @param value [String] target
77
+ # @return [void]
78
+ def targetElement(value)
79
+ @targetElement = value
80
+ end
81
+
82
+ # @return [Integer] get which user agent type should be used
83
+ def requestAs
84
+ @requestAs
85
+ end
86
+
87
+ # Set which user agent type should be used: Standard Browser = 0, Mobile Browser = 1, Search Engine = 2 and Fallback Browser = 3
88
+ #
89
+ # @param value [Integer] the browser type
90
+ # @return [void]
91
+ def requestAs(value)
92
+ @requestAs = value
93
+ end
94
+
95
+ # @!visibility private
96
+ def _getSignatureString(applicationSecret, callBackURL, url = nil)
97
+ urlParam = ''
98
+ if (url != nil)
99
+ urlParam = GrabzIt::Utility.nil_check(url)+"|"
100
+ end
101
+
102
+ callBackURLParam = ''
103
+ if (callBackURL != nil)
104
+ callBackURLParam = GrabzIt::Utility.nil_check(callBackURL)
105
+ end
106
+
107
+ return applicationSecret+"|"+ urlParam + callBackURLParam +
108
+ "|"+GrabzIt::Utility.nil_check(@customId)+"|"+GrabzIt::Utility.nil_int_check(@tableNumberToInclude)+"|"+GrabzIt::Utility.b_to_str(@includeAllTables)+
109
+ "|"+GrabzIt::Utility.b_to_str(@includeHeaderNames)+"|"+GrabzIt::Utility.nil_check(@targetElement)+"|"+GrabzIt::Utility.nil_check(@format)+"|"+
110
+ GrabzIt::Utility.nil_int_check(@requestAs)+"|"+GrabzIt::Utility.nil_check(@country)
111
+ end
112
+
113
+ # @!visibility private
114
+ def _getParameters(applicationKey, sig, callBackURL, dataName, dataValue)
115
+ params = createParameters(applicationKey, sig, callBackURL, dataName, dataValue)
116
+ params['includeAllTables'] = GrabzIt::Utility.b_to_str(@includeAllTables)
117
+ params['includeHeaderNames'] = GrabzIt::Utility.b_to_str(@includeHeaderNames)
118
+ params['format'] = GrabzIt::Utility.nil_check(@format)
119
+ params['tableToInclude'] = GrabzIt::Utility.nil_int_check(@tableNumberToInclude)
120
+ params['target'] = GrabzIt::Utility.nil_check(@targetElement)
121
+ params['requestmobileversion'] = GrabzIt::Utility.nil_int_check(@requestAs)
122
+
123
+ return params
124
+ end
125
+ end
126
+ end
@@ -0,0 +1,31 @@
1
+ module GrabzIt
2
+ # @!visibility private
3
+ module Utility
4
+ def self.b_to_str(bValue)
5
+ if bValue
6
+ return 1.to_s
7
+ end
8
+ return 0.to_s
9
+ end
10
+
11
+ def self.nil_check(param)
12
+ if param == nil
13
+ return ""
14
+ end
15
+ return param
16
+ end
17
+
18
+ def self.nil_int_check(param)
19
+ return param.to_i.to_s
20
+ end
21
+
22
+ def self.nil_float_check(param)
23
+ val = param.to_f
24
+ if ((val % 1) == 0)
25
+ return val.to_i.to_s
26
+ end
27
+
28
+ return val.to_s
29
+ end
30
+ end
31
+ end
@@ -1,9 +1,9 @@
1
1
  module GrabzIt
2
2
  # This class represents the custom watermarks stored in GrabzIt
3
- # @version 2.1
3
+ # @version 3.0
4
4
  # @author GrabzIt
5
5
  class WaterMark
6
- # @api private
6
+ # @!visibility private
7
7
  def initialize(identifier = '', xPosition = 0, yPosition = 0, format = '')
8
8
  @Identifier = identifier
9
9
  @XPosition = xPosition