Class: GrabzItClient

Inherits:
Object
  • Object
show all
Defined in:
lib/grabzitclient.rb

Overview

The public REST API for grabz.it This API allows you to take screenshot of websites for free and convert them into images, PDF's and tables.

See Also:

Author:

Version:

Constant Summary

Instance Method Summary (collapse)

Constructor Details

- (GrabzItClient) initialize(applicationKey, applicationSecret)

Create a new instance of the GrabzItClient class in order to access the GrabzIt API.

Parameters:

  • applicationKey (String)

    your application key

  • applicationSecret (String)

    your application secret

See Also:



30
31
32
33
# File 'lib/grabzitclient.rb', line 30

def initialize(applicationKey, applicationSecret)
	@applicationKey = applicationKey
	@applicationSecret = applicationSecret
end

Instance Method Details

- (Boolean) add_watermark(identifier, path, xpos, ypos)

Add a new custom watermark.

Parameters:

  • identifier (String)

    the identifier you want to give the custom watermark. It is important that this identifier is unique.

  • path (String)

    the absolute path of the watermark on your server. For instance C:/watermark/1.png

  • xpos (Integer)

    the horizontal position you want the screenshot to appear at: Left = 0, Center = 1, Right = 2

  • ypos (Integer)

    the vertical position you want the screenshot to appear at: Top = 0, Middle = 1, Bottom = 2

Returns:

  • (Boolean)

    returns true if the watermark was successfully set

Raises:

  • (RuntimeError)

    if the GrabzIt service reports an error with the request it will be raised as a RuntimeError



278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
# File 'lib/grabzitclient.rb', line 278

def add_watermark(identifier, path, xpos, ypos)
               if !File.file?(path)
               	raise "File: " + path + " does not exist"
               end
               sig =  Digest::MD5.hexdigest(nil_check(@applicationSecret)+"|"+nil_check(identifier)+"|"+nil_int_check(xpos)+"|"+nil_int_check(ypos));
               
	boundary = '--------------------------'+Time.now.to_f.to_s

	url = WebServicesBaseURL + "addwatermark.ashx"
	uri = URI.parse(url)

	file = File.open(path, "rb")
	data = file.read

	post_body = Array.new
	post_body << "\r\n--"+boundary+"\r\n"
	post_body << "Content-Disposition: form-data; name=\"watermark\"; filename=\""+File.basename(path)+"\"\r\nContent-Type: image/jpeg\r\n\r\n"
	post_body << data
	post_body << "\r\n--"+boundary+"\r\n"
	
	post_body << "Content-Disposition: form-data; name=\"key\"\r\n\r\n"
               post_body << CGI.escape(nil_check(@applicationKey))
               post_body << "\r\n--"+boundary+"\r\n"

	post_body << "Content-Disposition: form-data; name=\"identifier\"\r\n\r\n"
               post_body << CGI.escape(nil_check(identifier))
	post_body << "\r\n--"+boundary+"\r\n"

	post_body << "Content-Disposition: form-data; name=\"xpos\"\r\n\r\n"
               post_body << nil_check(xpos)
               post_body << "\r\n--"+boundary+"\r\n"

	post_body << "Content-Disposition: form-data; name=\"ypos\"\r\n\r\n"
               post_body << nil_check(ypos)
               post_body << "\r\n--"+boundary+"\r\n"
               
              	post_body << "Content-Disposition: form-data; name=\"sig\"\r\n\r\n"
               post_body << sig
               post_body << "\r\n--"+boundary+"--\r\n"

	request = Net::HTTP::Post.new(url)
	request.content_type = "multipart/form-data, boundary="+boundary
	request.body = post_body.join

	response = Net::HTTP.new(uri.host, uri.port).start {|http| http.request(request) }	
	
	return (get_result_value(response.body(), "Result") == TrueString)		
end

Delete a custom cookie or block a global cookie from being used

Parameters:

  • name (String)

    the name of the cookie to delete

  • domain (String)

    the website the cookie belongs to

Returns:

  • (Boolean)

    returns true if the cookie was successfully set

Raises:

  • (RuntimeError)

    if the GrabzIt service reports an error with the request it will be raised as a RuntimeError



240
241
242
243
244
245
246
# File 'lib/grabzitclient.rb', line 240

def delete_cookie(name, domain)
        sig =  Digest::MD5.hexdigest(nil_check(@applicationSecret)+"|"+nil_check(name)+"|"+nil_check(domain)+"|1")

        qs = "key=" + CGI.escape(nil_check(@applicationKey))+"&domain="+CGI.escape(nil_check(domain))+"&name="+CGI.escape(nil_check(name))+"&delete=1&sig="+sig

        return (get_result_value(get(WebServicesBaseURL + "setcookie.ashx?" + qs), "Result") == TrueString)
end

- (Boolean) delete_watermark(identifier)

Delete a custom watermark.

Parameters:

  • identifier (String)

    the identifier of the custom watermark you want to delete

Returns:

  • (Boolean)

    returns true if the watermark was successfully deleted

Raises:

  • (RuntimeError)

    if the GrabzIt service reports an error with the request it will be raised as a RuntimeError



331
332
333
334
335
336
337
# File 'lib/grabzitclient.rb', line 331

def delete_watermark(identifier)
        sig =  Digest::MD5.hexdigest(nil_check(@applicationSecret)+"|"+nil_check(identifier))               

        qs = "key=" +CGI.escape(nil_check(@applicationKey))+"&identifier="+CGI.escape(nil_check(identifier))+"&sig="+sig

        return (get_result_value(get(WebServicesBaseURL + "deletewatermark.ashx?" + qs), "Result") == TrueString)
end

- (Array<GrabzItCookie>) get_cookies(domain)

An array of cookies

Parameters:

  • domain (String)

    the domain to return cookies for

Returns:

Raises:

  • (RuntimeError)

    if the GrabzIt service reports an error with the request it will be raised as a RuntimeError



186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
# File 'lib/grabzitclient.rb', line 186

def get_cookies(domain)
        sig =  Digest::MD5.hexdigest(nil_check(@applicationSecret)+"|"+nil_check(domain))               

        qs = "key=" +CGI.escape(nil_check(@applicationKey))+"&domain="+CGI.escape(nil_check(domain))+"&sig="+sig

        result = get(WebServicesBaseURL + "getcookies.ashx?" + qs)

        doc = REXML::Document.new(result)
        
        message = doc.root.elements["Message"].text()

        if message != nil
                raise message
        end

        cookies = Array.new

		xml_cookies = doc.elements.to_a("//WebResult/Cookies/Cookie")		
        xml_cookies.each do |cookie|
        	expires = nil
                if cookie.elements["Expires"] != nil                        
                	expires = cookie.elements["Expires"].text
                end                
                grabzItCookie = GrabzItCookie.new(cookie.elements["Name"].text, cookie.elements["Domain"].text, cookie.elements["Value"].text, cookie.elements["Path"].text, (cookie.elements["HttpOnly"].text == TrueString), expires, cookie.elements["Type"].text)
                cookies << grabzItCookie
        end

        return cookies
end

- (Object) get_picture(id)

Deprecated.

Use #get_result instead.

This method returns the image itself. If nothing is returned then something has gone wrong or the image is not ready yet.

Parameters:

  • id (String)

    the id of the screenshot

Returns:

  • (Object)

    returns the screenshot



382
383
384
# File 'lib/grabzitclient.rb', line 382

def get_picture(id)
	return get_result(id)
end

- (Object) get_result(id)

This method returns the screenshot itself. If nothing is returned then something has gone wrong or the screenshot is not ready yet

Parameters:

  • id (String)

    the id of the screenshot

Returns:

  • (Object)

    returns the screenshot

Raises:

  • (RuntimeError)

    if the GrabzIt service reports an error with the request it will be raised as a RuntimeError



178
179
180
# File 'lib/grabzitclient.rb', line 178

def get_result(id)
	return get(WebServicesBaseURL + "getfile.ashx?id=" + nil_check(id))
end

- (ScreenShotStatus) get_status(id)

Get the current status of a GrabzIt screenshot

Parameters:

  • id (String)

    the id of the screenshot

Returns:



161
162
163
164
165
166
167
168
169
170
171
172
# File 'lib/grabzitclient.rb', line 161

def get_status(id)
        result = get(WebServicesBaseURL + "getstatus.ashx?id=" + nil_check(id))

		doc = REXML::Document.new(result)

		processing = doc.root.elements["Processing"].text()
		cached = doc.root.elements["Cached"].text()
		expired = doc.root.elements["Expired"].text()
		message = doc.root.elements["Message"].text()

        return ScreenShotStatus.new((processing == TrueString), (cached == TrueString), (expired == TrueString), message)
end

- (Array<GrabzItWaterMark>) get_watermarks(identifier = nil)

Get your uploaded custom watermarks

Parameters:

  • identifier (String, nil) (defaults to: nil)

    the identifier of a particular custom watermark you want to view

Returns:



251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
# File 'lib/grabzitclient.rb', line 251

def get_watermarks(identifier = nil)
        sig =  Digest::MD5.hexdigest(nil_check(@applicationSecret)+"|"+nil_check(identifier))               

        qs = "key=" +CGI.escape(nil_check(@applicationKey))+"&identifier="+CGI.escape(nil_check(identifier))+"&sig="+sig

        result = get(WebServicesBaseURL + "getwatermarks.ashx?" + qs)

        doc = REXML::Document.new(result)

        watermarks = Array.new

		xml_watemarks = doc.elements.to_a("//WebResult/WaterMarks/WaterMark")		
        xml_watemarks.each do |watemark|                	
                grabzItWaterMark = GrabzItWaterMark.new(watemark.elements["Identifier"].text, watemark.elements["XPosition"].text.to_i, watemark.elements["YPosition"].text.to_i, watemark.elements["Format"].text)
                watermarks << grabzItWaterMark
        end

        return watermarks
end

- (String) save(callBackURL = nil)

Note:

This is the recommended method of saving a file

Save the result asynchronously and returns a unique identifier, which can be used to get the screenshot with the get_result method

Parameters:

  • callBackURL (String, nil) (defaults to: nil)

    the handler the GrabzIt service should call after it has completed its work

Returns:

  • (String)

    the unique identifier of the screenshot. This can be used to get the screenshot with the GetPicture method

Raises:

  • (RuntimeError)

    if the GrabzIt service reports an error with the request it will be raised as a RuntimeError



109
110
111
112
113
114
115
116
117
118
# File 'lib/grabzitclient.rb', line 109

def save(callBackURL = nil)
	if @@signaturePartOne == nil && @@signaturePartTwo == nil && @@request == nil
		  raise "No screenshot parameters have been set."
	end
	
	sig = Digest::MD5.hexdigest(@@signaturePartOne+nil_check(callBackURL)+@@signaturePartTwo)
	@@request += CGI.escape(nil_check(callBackURL))+"&sig="+sig
	
	return get_result_value(get(@@request), "ID")
end

- (Boolean) save_picture(url, saveToFile, browserWidth = nil, browserHeight = nil, width = nil, height = nil, format = nil, delay = nil, targetElement = nil)

Deprecated.

Use #set_image_options and #save_to instead.

This method takes the screenshot and then saves the result to a file. WARNING this method is synchronous.

Examples:

Synchronously save the screenshot to test.jpg

save_picture('images/test.jpg')	

Parameters:

  • url (String)

    the URL that the screenshot should be made of

  • saveToFile (String)

    the file path that the screenshot should saved to

  • browserWidth (Integer, nil) (defaults to: nil)

    the width of the browser in pixels

  • browserHeight (Integer, nil) (defaults to: nil)

    the height of the browser in pixels

  • width (Integer, nil) (defaults to: nil)

    the width of the resulting thumbnail in pixels

  • height (Integer, nil) (defaults to: nil)

    the height of the resulting thumbnail in pixels

  • format (String, nil) (defaults to: nil)

    the format the screenshot should be in: bmp8, bmp16, bmp24, bmp, gif, jpg, png

  • delay (Integer, nil) (defaults to: nil)

    the number of milliseconds to wait before taking the screenshot

  • targetElement (String, nil) (defaults to: nil)

    the id of the only HTML element in the web page to turn into a screenshot

Returns:

  • (Boolean)

    returns the true if it is successfull otherwise it throws an exception

Raises:

  • (RuntimeError)

    if the screenshot cannot be saved a RuntimeError will be raised that will contain an explanation



373
374
375
376
# File 'lib/grabzitclient.rb', line 373

def save_picture(url, saveToFile, browserWidth = nil, browserHeight = nil, width = nil, height = nil, format = nil, delay = nil, targetElement = nil)
	set_image_options(url, nil, browserWidth, browserHeight, width, height, format, delay, targetElement)	
	return save_to(saveToFile)
end

- (Boolean) save_to(saveToFile)

Note:

Warning this method is synchronous so will cause a application to pause while the result is processed.

Save the result synchronously to a file.

Examples:

Synchronously save the screenshot to test.jpg

save_to('images/test.jpg')

Parameters:

  • saveToFile (String)

    the file path that the screenshot should saved to.

Returns:

  • (Boolean)

    returns the true if it is successful otherwise it throws an exception.

Raises:

  • (RuntimeError)

    if the screenshot cannot be saved a RuntimeError will be raised that will contain an explanation



127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
# File 'lib/grabzitclient.rb', line 127

def save_to(saveToFile)
	id = save()

	#Wait for it to be ready.
	while true do
		status = get_status(id)

		if !status.cached && !status.processing
			raise "The screenshot did not complete with the error: " + status.Message
			break;
		elsif status.cached
			result = get_result(id)
			if !result
				raise "The screenshot image could not be found on GrabzIt."
				break
			end
			
			screenshot = File.new(saveToFile, "wb")
			screenshot.write(result)
			screenshot.close				

			break
		end

		sleep(1)
	end

	return true
end
Note:

This can be useful if a websites functionality is controlled by cookies

Sets a new custom cookie on GrabzIt, if the custom cookie has the same name and domain as a global cookie the global cookie is overridden

Parameters:

  • name (String)

    the name of the cookie to set

  • domain (String)

    the domain of the website to set the cookie for

  • value (String, '') (defaults to: "")

    the value of the cookie

  • path (String, '/') (defaults to: "/")

    the website path the cookie relates to

  • httponly (Boolean, false) (defaults to: false)

    is the cookie only used on HTTP

  • expires (String, '') (defaults to: "")

    when the cookie expires. Pass a nil value if it does not expire

Returns:

  • (Boolean)

    returns true if the cookie was successfully set

Raises:

  • (RuntimeError)

    if the GrabzIt service reports an error with the request it will be raised as a RuntimeError



227
228
229
230
231
232
233
# File 'lib/grabzitclient.rb', line 227

def set_cookie(name, domain, value = "", path = "/", httponly = false, expires = "")
        sig =  Digest::MD5.hexdigest(nil_check(@applicationSecret)+"|"+nil_check(name)+"|"+nil_check(domain)+"|"+nil_check(value)+"|"+nil_check(path)+"|"+b_to_str(httponly)+"|"+nil_check(expires)+"|0")

        qs = "key=" +CGI.escape(nil_check(@applicationKey))+"&domain="+CGI.escape(nil_check(domain))+"&name="+CGI.escape(nil_check(name))+"&value="+CGI.escape(nil_check(value))+"&path="+CGI.escape(nil_check(path))+"&httponly="+b_to_str(httponly)+"&expires="+nil_check(expires)+"&sig="+sig

        return (get_result_value(get(WebServicesBaseURL + "setcookie.ashx?" + qs), "Result") == TrueString)
end

- (void) set_image_options(url, customId = nil, browserWidth = nil, browserHeight = nil, width = nil, height = nil, format = nil, delay = nil, targetElement = nil, requestMobileVersion = false, customWaterMarkId = nil)

This method returns an undefined value.

Sets the parameters required to take a screenshot of a web page.

Parameters:

  • url (String)

    the URL that the screenshot should be made of

  • customId (String, nil) (defaults to: nil)

    custom identifier that you can pass through to the screenshot webservice. This will be returned with the callback URL you have specified.

  • browserWidth (Integer, nil) (defaults to: nil)

    the width of the browser in pixels

  • browserHeight (Integer, nil) (defaults to: nil)

    the height of the browser in pixels

  • width (Integer, nil) (defaults to: nil)

    the width of the resulting thumbnail in pixels

  • height (Integer, nil) (defaults to: nil)

    the height of the resulting thumbnail in pixels

  • format (String, nil) (defaults to: nil)

    the format the screenshot should be in: bmp8, bmp16, bmp24, bmp, gif, jpg, png

  • delay (Integer, nil) (defaults to: nil)

    the number of milliseconds to wait before taking the screenshot

  • targetElement (String, nil) (defaults to: nil)

    the id of the only HTML element in the web page to turn into a screenshot

  • requestMobileVersion (Boolean, false) (defaults to: false)

    request a mobile version of the target website if possible

  • customWaterMarkId (String, nil) (defaults to: nil)

    add a custom watermark to the image



48
49
50
51
52
53
54
# File 'lib/grabzitclient.rb', line 48

def set_image_options(url, customId = nil, browserWidth = nil, browserHeight = nil, width = nil, height = nil, format = nil, delay = nil, targetElement = nil, requestMobileVersion = false, customWaterMarkId = nil)
	@@request = WebServicesBaseURL + "takepicture.ashx?key="+CGI.escape(nil_check(@applicationKey))+"&url="+CGI.escape(nil_check(url))+"&width="+nil_int_check(width)+"&height="+nil_int_check(height)+"&format="+CGI.escape(nil_check(format))+"&bwidth="+nil_int_check(browserWidth)+"&bheight="+nil_int_check(browserHeight)+"&customid="+CGI.escape(nil_check(customId))+"&delay="+nil_int_check(delay)+"&target="+CGI.escape(nil_check(targetElement))+"&customwatermarkid="+CGI.escape(nil_check(customWaterMarkId))+"&requestmobileversion="+b_to_str(requestMobileVersion)+"&callback="
	@@signaturePartOne = nil_check(@applicationSecret)+"|"+nil_check(url)+"|"
	@@signaturePartTwo = "|"+nil_check(format)+"|"+nil_int_check(height)+"|"+nil_int_check(width)+"|"+nil_int_check(browserHeight)+"|"+nil_int_check(browserWidth)+"|"+nil_check(customId)+"|"+nil_int_check(delay)+"|"+nil_check(targetElement)+"|"+nil_check(customWaterMarkId)+"|"+b_to_str(requestMobileVersion)
	
	return nil
end

- (void) set_pdf_options(url, customId = nil, includeBackground = true, pagesize = 'A4', orientation = 'Portrait', includeLinks = true, includeOutline = false, title = nil, coverURL = nil, marginTop = 10, marginLeft = 10, marginBottom = 10, marginRight = 10, delay = nil, requestMobileVersion = false, customWaterMarkId = nil)

This method returns an undefined value.

Sets the parameters required to convert a web page into a PDF.

Parameters:

  • url

    url [String] the URL that the should be converted into a pdf

  • customId (String, nil) (defaults to: nil)

    a custom identifier that you can pass through to the webservice. This will be returned with the callback URL you have specified.

  • includeBackground (Boolean, true) (defaults to: true)

    if true the background of the web page should be included in the screenshot

  • pagesize (String, 'A4') (defaults to: 'A4')

    the page size of the PDF to be returned: 'A3', 'A4', 'A5', 'B3', 'B4', 'B5'.

  • orientation (String, 'Portrait') (defaults to: 'Portrait')

    the orientation of the PDF to be returned: 'Landscape' or 'Portrait'

  • includeLinks (Boolean, true) (defaults to: true)

    true if links should be included in the PDF

  • includeOutline (Boolean, false) (defaults to: false)

    True if the PDF outline should be included

  • title (String, nil) (defaults to: nil)

    provide a title to the PDF document

  • coverURL (String, nil) (defaults to: nil)

    the URL of a web page that should be used as a cover page for the PDF

  • marginTop (Integer, 10) (defaults to: 10)

    the margin that should appear at the top of the PDF document page

  • marginLeft (Integer, 10) (defaults to: 10)

    the margin that should appear at the left of the PDF document page

  • marginBottom (Integer, 10) (defaults to: 10)

    the margin that should appear at the bottom of the PDF document page

  • marginRight (Integer, 10) (defaults to: 10)

    the margin that should appear at the right of the PDF document

  • delay (Integer, nil) (defaults to: nil)

    the number of milliseconds to wait before taking the screenshot

  • requestMobileVersion (Boolean, false) (defaults to: false)

    request a mobile version of the target website if possible

  • customWaterMarkId (String, nil) (defaults to: nil)

    add a custom watermark to each page of the PDF document



92
93
94
95
96
97
98
99
100
101
102
# File 'lib/grabzitclient.rb', line 92

def set_pdf_options(url, customId = nil, includeBackground = true, pagesize = 'A4', orientation = 'Portrait', includeLinks = true, includeOutline = false, title = nil, coverURL = nil, marginTop = 10, marginLeft = 10, marginBottom = 10, marginRight = 10, delay = nil, requestMobileVersion = false, customWaterMarkId = nil)
	pagesize = nil_check(pagesize).upcase
	$orientation = nil_check(orientation).capitalize

	@@request = WebServicesBaseURL + "takepdf.ashx?key=" + CGI.escape(nil_check(@applicationKey))+"&url="+CGI.escape(nil_check(url))+"&background="+b_to_str(includeBackground)+"&pagesize="+pagesize+"&orientation="+orientation+"&customid="+CGI.escape(nil_check(customId))+"&customwatermarkid="+CGI.escape(nil_check(customWaterMarkId))+"&includelinks="+b_to_str(includeLinks)+"&includeoutline="+b_to_str(includeOutline)+"&title="+CGI.escape(nil_check(title))+"&coverurl="+CGI.escape(nil_check(coverURL))+"&mleft="+nil_int_check(marginLeft)+"&mright="+nil_int_check(marginRight)+"&mtop="+nil_int_check(marginTop)+"&mbottom="+nil_int_check(marginBottom)+"&delay="+nil_int_check(delay)+"&requestmobileversion="+b_to_str(requestMobileVersion)+"&callback="

	@@signaturePartOne = nil_check(@applicationSecret)+"|"+nil_check(url)+"|"
	@@signaturePartTwo = "|"+nil_check(customId)+"|"+b_to_str(includeBackground)+"|"+pagesize +"|"+orientation+"|"+nil_check(customWaterMarkId)+"|"+b_to_str(includeLinks)+"|"+b_to_str(includeOutline)+"|"+nil_check(title)+"|"+nil_check(coverURL)+"|"+nil_int_check(marginTop)+"|"+nil_int_check(marginLeft)+"|"+nil_int_check(marginBottom)+"|"+nil_int_check(marginRight)+"|"+nil_int_check(delay)+"|"+b_to_str(requestMobileVersion)
	
	return nil		
end

- (void) set_table_options(url, customId = nil, tableNumberToInclude = 1, format = 'csv', includeHeaderNames = true, includeAllTables = false, targetElement = nil, requestMobileVersion = false)

This method returns an undefined value.

Sets the parameters required to extract one or more tables from a web page.

Parameters:

  • url (String)

    the URL that the should be used to extract tables

  • customId (String, nil) (defaults to: nil)

    a custom identifier that you can pass through to the webservice. This will be returned with the callback URL you have specified.

  • tableNumberToInclude (Integer, 1) (defaults to: 1)

    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

  • format (String, 'csv') (defaults to: 'csv')

    the format the table should be in: csv, xlsx

  • includeHeaderNames (Boolean, true) (defaults to: true)

    if true header names will be included in the table

  • includeAllTables (Boolean, true) (defaults to: false)

    if true all table on the web page will be extracted with each table appearing in a seperate spreadsheet sheet. Only available with the XLSX format.

  • targetElement (String, nil) (defaults to: nil)

    the id of the only HTML element in the web page that should be used to extract tables from

  • requestMobileVersion (Boolean, false) (defaults to: false)

    request a mobile version of the target website if possible



66
67
68
69
70
71
72
# File 'lib/grabzitclient.rb', line 66

def set_table_options(url, customId = nil, tableNumberToInclude = 1, format = 'csv', includeHeaderNames = true, includeAllTables = false, targetElement = nil, requestMobileVersion = false)
	@@request = WebServicesBaseURL + "taketable.ashx?key=" + CGI.escape(nil_check(@applicationKey))+"&url="+CGI.escape(url)+"&includeAllTables="+b_to_str(includeAllTables)+"&includeHeaderNames="+b_to_str(includeHeaderNames)+"&format="+CGI.escape(nil_check(format))+"&tableToInclude="+nil_int_check(tableNumberToInclude)+"&customid="+CGI.escape(nil_check(customId))+"&target="+CGI.escape(nil_check(targetElement))+"&requestmobileversion="+b_to_str(requestMobileVersion)+"&callback="
	@@signaturePartOne = nil_check(@applicationSecret)+"|"+nil_check(url)+"|"
	@@signaturePartTwo = "|"+nil_check(customId)+"|"+nil_int_check(tableNumberToInclude)+"|"+b_to_str(includeAllTables)+"|"+b_to_str(includeHeaderNames)+"|"+nil_check(targetElement)+"|"+nil_check(format)+"|"+b_to_str(requestMobileVersion)
	
	return nil
end

- (String) take_picture(url, callback = nil, customId = nil, browserWidth = nil, browserHeight = nil, width = nil, height = nil, format = nil, delay = nil, targetElement = nil)

Deprecated.

Use #set_image_options and #save instead.

This method calls the GrabzIt web service to take the screenshot.

Parameters:

  • url (String)

    the URL that the screenshot should be made of

  • callback (String, nil) (defaults to: nil)

    the handler the GrabzIt web service should call after it has completed its work

  • customId (String, nil) (defaults to: nil)

    custom identifier that you can pass through to the screenshot webservice. This will be returned with the callback URL you have specified.

  • browserWidth (Integer, nil) (defaults to: nil)

    the width of the browser in pixels

  • browserHeight (Integer, nil) (defaults to: nil)

    the height of the browser in pixels

  • width (Integer, nil) (defaults to: nil)

    the width of the resulting thumbnail in pixels

  • height (Integer, nil) (defaults to: nil)

    the height of the resulting thumbnail in pixels

  • format (String, nil) (defaults to: nil)

    the format the screenshot should be in: bmp8, bmp16, bmp24, bmp, gif, jpg, png

  • delay (Integer, nil) (defaults to: nil)

    the number of milliseconds to wait before taking the screenshot

  • targetElement (String, nil) (defaults to: nil)

    the id of the only HTML element in the web page to turn into a screenshot

Returns:

  • (String)

    returns the unique identifier of the screenshot. This can be used to get the screenshot with the get_result method

Raises:

  • (RuntimeError)

    if the GrabzIt service reports an error with the request it will be raised as a RuntimeError



353
354
355
356
# File 'lib/grabzitclient.rb', line 353

def take_picture(url, callback = nil, customId = nil, browserWidth = nil, browserHeight = nil, width = nil, height = nil, format = nil, delay = nil, targetElement = nil)
	set_image_options(url, customId, browserWidth, browserHeight, width, height, format, delay, targetElement)	
	return save(callback)
end