Class: GrabzIt::Client

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

Overview

This client provides access to the GrabzIt web services This API allows you to take screenshot of websites for free and convert them into images, PDF’s and tables.

Examples:

Example usage

require 'grabzit'	

grabzItClient = GrabzIt::Client.new("YOUR APPLICATION KEY", "YOUR APPLICATION SECRET")
grabzItClient.url_to_image("http://www.google.com")
grabzItClient.save("http://www.mysite.com/grabzit/handler")

See Also:

Author:

  • GrabzIt

Version:

  • 3.0

Instance Method Summary collapse

Constructor Details

#initialize(applicationKey, applicationSecret) ⇒ Client

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

Parameters:

  • applicationKey (String)

    your application key

  • applicationSecret (String)

    your application secret

See Also:



60
61
62
63
64
65
# File 'lib/grabzit/client.rb', line 60

def initialize(applicationKey, applicationSecret)
	@applicationKey = applicationKey
	@applicationSecret = applicationSecret
	@protocol = 'http'
	@proxy = Proxy.new()
end

Instance Method Details

#add_watermark(identifier, path, xpos, ypos) ⇒ Boolean

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



556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
# File 'lib/grabzit/client.rb', line 556

def add_watermark(identifier, path, xpos, ypos)
	if !File.file?(path)
		raise "File: " + path + " does not exist"
	end
	sig = encode(GrabzIt::Utility.nil_check(@applicationSecret)+"|"+GrabzIt::Utility.nil_check(identifier)+"|"+GrabzIt::Utility.nil_int_check(xpos)+
	"|"+GrabzIt::Utility.nil_int_check(ypos))

	boundary = '--------------------------'+Time.now.to_f.to_s

	url = @protocol + "://api.grabz.it/services/addwatermark"
	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 << GrabzIt::Utility.nil_check(@applicationKey)
	post_body << "\r\n--"+boundary+"\r\n"

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

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

	post_body << "Content-Disposition: form-data; name=\"ypos\"\r\n\r\n"
	post_body << GrabzIt::Utility.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
	
	caller = Net::HTTP.new(uri.host, uri.port)
	caller.use_ssl = uri.scheme == 'https'
	response = caller.start {|http| http.request(request)}	
	
	response_check(response)
	
	return (get_result_value(response.body(), "Result") == TrueString)		
end

#create_encryption_keyString

This method creates a cryptographically secure encryption key to pass to the encryption key parameter.

Returns:

  • (String)

    a encryption key



654
655
656
# File 'lib/grabzit/client.rb', line 654

def create_encryption_key()
	Base64.strict_encode64(OpenSSL::Random.random_bytes(32));
end

#decrypt(data, key) ⇒ Array<Byte>

This method will decrypt a encrypted capture, using the key you passed to the encryption key parameter.

Parameters:

  • path (String)

    the encrypted bytes

  • key (String)

    the encryption key

Returns:

  • (Array<Byte>)

    an array of decrypted bytes



674
675
676
677
678
679
680
681
682
683
684
685
686
687
# File 'lib/grabzit/client.rb', line 674

def decrypt(data, key)
	if data == nil
		return nil
	end
	iv = data[0..15]
	payload = data[16..-1]
	cipher = OpenSSL::Cipher::Cipher.new("aes-256-cbc")
	cipher.padding = 0
	cipher.key = Base64.strict_decode64(key);
	cipher.iv = iv
	decrypted = cipher.update(payload);
	decrypted << cipher.final();
	return decrypted
end

#decrypt_file(path, key) ⇒ Object

This method will decrypt a encrypted capture file, using the key you passed to the encryption key parameter.

Parameters:

  • path (String)

    the path of the encrypted capture

  • key (String)

    the encryption key



662
663
664
665
666
667
# File 'lib/grabzit/client.rb', line 662

def decrypt_file(path, key)
	data = read_file(path)
	decryptedFile = File.new(path, "wb")
	decryptedFile.write(decrypt(data, key))
	decryptedFile.close
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



512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
# File 'lib/grabzit/client.rb', line 512

def delete_cookie(name, domain)
	sig = encode(GrabzIt::Utility.nil_check(@applicationSecret)+"|"+GrabzIt::Utility.nil_check(name)+
	"|"+GrabzIt::Utility.nil_check(domain)+"|1")

	qs = "key="
	qs.concat(CGI.escape(GrabzIt::Utility.nil_check(@applicationKey)))
	qs.concat("&domain=")
	qs.concat(CGI.escape(GrabzIt::Utility.nil_check(domain)))
	qs.concat("&name=")
	qs.concat(CGI.escape(GrabzIt::Utility.nil_check(name)))
	qs.concat("&delete=1&sig=")
	qs.concat(sig)

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

#delete_watermark(identifier) ⇒ Boolean

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



615
616
617
618
619
620
621
622
623
624
625
626
# File 'lib/grabzit/client.rb', line 615

def delete_watermark(identifier)
	sig = encode(GrabzIt::Utility.nil_check(@applicationSecret)+"|"+GrabzIt::Utility.nil_check(identifier))

	qs = "key="
	qs.concat(CGI.escape(GrabzIt::Utility.nil_check(@applicationKey)))
	qs.concat("&identifier=")
	qs.concat(CGI.escape(GrabzIt::Utility.nil_check(identifier)))
	qs.concat("&sig=")
	qs.concat(sig)

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

#file_to_docx(path, options = nil) ⇒ void

This method returns an undefined value.

This method specifies a HTML file that should be converted into a DOCX

Parameters:

  • path (String)

    the file path of a HTML file to convert into a DOCX

  • options (DOCXOptions, nil) (defaults to: nil)

    a instance of the DOCXOptions class that defines any special options to use when creating the DOCX



312
313
314
# File 'lib/grabzit/client.rb', line 312

def file_to_docx(path, options = nil)		
	html_to_docx(read_file(path), options)
end

#file_to_image(path, options = nil) ⇒ void

This method returns an undefined value.

This method specifies a HTML file that should be converted into a image

Parameters:

  • path (String)

    the file path of a HTML file to convert into a image

  • options (ImageOptions, nil) (defaults to: nil)

    a instance of the ImageOptions class that defines any special options to use when creating the image



117
118
119
# File 'lib/grabzit/client.rb', line 117

def file_to_image(path, options = nil)		
	html_to_image(read_file(path), options)
end

#file_to_pdf(path, options = nil) ⇒ void

This method returns an undefined value.

This method specifies a HTML file that should be converted into a PDF

Parameters:

  • path (String)

    the file path of a HTML file to convert into a PDF

  • options (PDFOptions, nil) (defaults to: nil)

    a instance of the PDFOptions class that defines any special options to use when creating the PDF



273
274
275
# File 'lib/grabzit/client.rb', line 273

def file_to_pdf(path, options = nil)		
	html_to_pdf(read_file(path), options)
end

#file_to_rendered_html(path, options = nil) ⇒ void

This method returns an undefined value.

This method specifies a HTML file that should be converted into rendered HTML

Parameters:

  • path (String)

    the file path of a HTML file to convert into rendered HTML

  • options (HTMLOptions, nil) (defaults to: nil)

    a instance of the HTMLOptions class that defines any special options to use when creating rendered HTML



195
196
197
# File 'lib/grabzit/client.rb', line 195

def file_to_rendered_html(path, options = nil)		
	html_to_rendered_html(read_file(path), options)
end

#file_to_table(path, options = nil) ⇒ void

This method returns an undefined value.

This method specifies a HTML file that the HTML tables should be extracted from

Parameters:

  • path (String)

    the file path of a HTML file to extract HTML tables from

  • options (TableOptions, nil) (defaults to: nil)

    a instance of the TableOptions class that defines any special options to use when converting the HTML table



234
235
236
# File 'lib/grabzit/client.rb', line 234

def file_to_table(path, options = nil)		
	html_to_table(read_file(path), options)
end

#file_to_video(path, options = nil) ⇒ void

This method returns an undefined value.

This method specifies a HTML file that should be converted into a video

Parameters:

  • path (String)

    the file path of a HTML file to convert into a video

  • options (VideoOptions, nil) (defaults to: nil)

    a instance of the VideoOptions class that defines any special options to use when creating a video



156
157
158
# File 'lib/grabzit/client.rb', line 156

def file_to_video(path, options = nil)		
	html_to_video(read_file(path), options)
end

#get_cookies(domain) ⇒ Array<Cookie>

Get all the cookies that GrabzIt is using for a particular domain. This may include your user set cookies as well

Parameters:

  • domain (String)

    the domain to return cookies for

Returns:

  • (Array<Cookie>)

    an array of cookies

Raises:

  • (RuntimeError)

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



438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
# File 'lib/grabzit/client.rb', line 438

def get_cookies(domain)
	sig = encode(GrabzIt::Utility.nil_check(@applicationSecret)+"|"+GrabzIt::Utility.nil_check(domain))               

	qs = "key="
	qs.concat(CGI.escape(GrabzIt::Utility.nil_check(@applicationKey)))
	qs.concat("&domain=")
	qs.concat(CGI.escape(GrabzIt::Utility.nil_check(domain)))
	qs.concat("&sig=")
	qs.concat(sig)

	result = get(@protocol + WebServicesBaseURL + "getcookies?" + qs)

	doc = REXML::Document.new(result)

	check_for_exception(doc)

	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 = GrabzIt::Cookie.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

#get_result(id) ⇒ Object

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



425
426
427
428
429
430
431
# File 'lib/grabzit/client.rb', line 425

def get_result(id)
	if id == nil || id == ""
		return nil
	end
	
	return get(@protocol + WebServicesBaseURL + "getfile?id=" + GrabzIt::Utility.nil_check(id))
end

#get_status(id) ⇒ ScreenShotStatus

Get the current status of a GrabzIt screenshot

Parameters:

  • id (String)

    the id of the screenshot

Returns:



402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
# File 'lib/grabzit/client.rb', line 402

def get_status(id)
	
	if id == nil || id == ""
		return nil
	end			
	
	result = get(@protocol + WebServicesBaseURL + "getstatus?id=" + GrabzIt::Utility.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

#get_watermark(identifier) ⇒ WaterMark

Get your uploaded custom watermark

Parameters:

  • identifier (String, nil)

    the identifier of a particular custom watermark you want to view

Returns:

  • (WaterMark)

    the watermark with the specified identifier



532
533
534
535
536
537
538
539
# File 'lib/grabzit/client.rb', line 532

def get_watermark(identifier)
	watermarks = find_watermarks(identifier)
	if watermarks.length == 1
		return watermarks[0]
	end
	
	return nil
end

#get_watermarksArray<WaterMark>

Get your uploaded custom watermarks

Returns:

  • (Array<WaterMark>)

    an array of uploaded watermarks



544
545
546
# File 'lib/grabzit/client.rb', line 544

def get_watermarks()
	return find_watermarks(nil)
end

#html_to_docx(html, options = nil) ⇒ void

This method returns an undefined value.

This method specifies the HTML that should be converted into a DOCX

Parameters:

  • html (String)

    the HTML to convert into a DOCX

  • options (DOCXOptions, nil) (defaults to: nil)

    a instance of the DOCXOptions class that defines any special options to use when creating the DOCX



297
298
299
300
301
302
303
304
305
# File 'lib/grabzit/client.rb', line 297

def html_to_docx(html, options = nil)		

	if options == nil
		options = DOCXOptions.new()
	end

	@request = Request.new(@protocol + WebServicesBaseURL + TakeDOCX, true, options, html)
	return nil
end

#html_to_image(html, options = nil) ⇒ void

This method returns an undefined value.

This method specifies the HTML that should be converted into a image

Parameters:

  • html (String)

    the HTML to convert into a image

  • options (ImageOptions, nil) (defaults to: nil)

    a instance of the ImageOptions class that defines any special options to use when creating the image



102
103
104
105
106
107
108
109
110
# File 'lib/grabzit/client.rb', line 102

def html_to_image(html, options = nil)		

	if options == nil
		options = ImageOptions.new()
	end

	@request = Request.new(@protocol + WebServicesBaseURL + TakePicture, true, options, html)
	return nil
end

#html_to_pdf(html, options = nil) ⇒ void

This method returns an undefined value.

This method specifies the HTML that should be converted into a PDF

Parameters:

  • html (String)

    the HTML to convert into a PDF

  • options (PDFOptions, nil) (defaults to: nil)

    a instance of the PDFOptions class that defines any special options to use when creating the PDF



258
259
260
261
262
263
264
265
266
# File 'lib/grabzit/client.rb', line 258

def html_to_pdf(html, options = nil)		

	if options == nil
		options = PDFOptions.new()
	end

	@request = Request.new(@protocol + WebServicesBaseURL + TakePDF, true, options, html)
	return nil
end

#html_to_rendered_html(html, options = nil) ⇒ void

This method returns an undefined value.

This method specifies the HTML that should be converted into rendered HTML

Parameters:

  • html (String)

    the HTML to convert into rendered HTML

  • options (HTMLOptions, nil) (defaults to: nil)

    a instance of the HTMLOptions class that defines any special options to use when creating the rendered HTML



180
181
182
183
184
185
186
187
188
# File 'lib/grabzit/client.rb', line 180

def html_to_rendered_html(html, options = nil)		

	if options == nil
		options = HTMLOptions.new()
	end

	@request = Request.new(@protocol + WebServicesBaseURL + TakeHTML, true, options, html)
	return nil
end

#html_to_table(html, options = nil) ⇒ void

This method returns an undefined value.

This method specifies the HTML that the HTML tables should be extracted from

Parameters:

  • html (String)

    the HTML to extract HTML tables from

  • options (TableOptions, nil) (defaults to: nil)

    a instance of the TableOptions class that defines any special options to use when converting the HTML table



219
220
221
222
223
224
225
226
227
# File 'lib/grabzit/client.rb', line 219

def html_to_table(html, options = nil)		

	if options == nil
		options = TableOptions.new()
	end

	@request = Request.new(@protocol + WebServicesBaseURL + TakeTable, true, options, html)
	return nil
end

#html_to_video(html, options = nil) ⇒ void

This method returns an undefined value.

This method specifies the HTML that should be converted into a video

Parameters:

  • html (String)

    the HTML to convert into a video

  • options (VideoOptions, nil) (defaults to: nil)

    a instance of the VideoOptions class that defines any special options to use when creating a video



141
142
143
144
145
146
147
148
149
# File 'lib/grabzit/client.rb', line 141

def html_to_video(html, options = nil)		

	if options == nil
		options = VideoOptions.new()
	end

	@request = Request.new(@protocol + WebServicesBaseURL + TakeVideo, true, options, html)
	return nil
end

#save(callBackURL = nil) ⇒ String

Note:

This is the recommended method of saving a screenshot

Calls the GrabzIt web service to take the screenshot

The handler will be passed a URL with the following query string parameters:

  • message (is any error message associated with the screenshot)

  • customId (is a custom id you may have specified in the [AnimationOptions], [ImageOptions], [PDFOptions] or [TableOptions] classes)

  • id (is the unique id of the screenshot which can be used to retrieve the screenshot with the #get_result method)

  • filename (is the filename of the screenshot)

  • format (is the format of the screenshot)

Parameters:

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

    the handler the GrabzIt web 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 #get_result method

Raises:

  • (RuntimeError)

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



328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
# File 'lib/grabzit/client.rb', line 328

def save(callBackURL = nil)
	if @request == nil
		  raise GrabzItException.new("No parameters have been set.", GrabzItException::PARAMETER_MISSING_PARAMETERS)
	end
	
	sig = encode(@request.options()._getSignatureString(GrabzIt::Utility.nil_check(@applicationSecret), callBackURL, @request.getTargetUrl()))
	
	data = take(sig, callBackURL)
	
	if data == nil || data == ""
		data = take(sig, callBackURL)
	end

	if data == nil || data == ""
		raise GrabzItException.new("An unknown network error occurred, please try calling this method again.", GrabzItException::NETWORK_GENERAL_ERROR)
	end

	return get_result_value(data, "ID")
end

#save_to(saveToFile = nil) ⇒ Boolean

Note:

Warning, this is a SYNCHONOUS method and can take up to 5 minutes before a response

Calls the GrabzIt web service to take the screenshot and saves it to the target path provided. if no target path is provided it returns the screenshot byte data.

Examples:

Synchronously save the screenshot to test.jpg

save_to('images/test.jpg')

Parameters:

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

    the file path that the screenshot should saved to.

Returns:

  • (Boolean)

    returns the true if it is successfully saved to a file, otherwise if a target path is not provided it returns the screenshot’s byte data.

Raises:

  • (RuntimeError)

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



357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
# File 'lib/grabzit/client.rb', line 357

def save_to(saveToFile = nil)
	id = save()

	if id == nil || id == ""
		return false
	end			
	
	#Wait for it to be possibly ready
	sleep((@request.options().startDelay() / 1000) + 3)

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

		if !status.cached && !status.processing
			raise GrabzItException.new("The capture did not complete with the error: " + status.message, GrabzItException::RENDERING_ERROR)
			break
		elsif status.cached
			result = get_result(id)
			if !result
				raise GrabzItException.new("The capture could not be found on GrabzIt.", GrabzItException::RENDERING_MISSING_SCREENSHOT)
				break
			end
			
			if saveToFile == nil || saveToFile == ""
				return result
			end					

			screenshot = File.new(saveToFile, "wb")
			screenshot.write(result)
			screenshot.close

			break
		end

		sleep(3)
	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



481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
# File 'lib/grabzit/client.rb', line 481

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

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

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

#set_local_proxy(value) ⇒ Object

This method enables a local proxy server to be used for all requests

Parameters:

  • value (String)

    the URL, which can include a port if required, of the proxy. Providing a null will remove any previously set proxy



642
643
644
645
646
647
648
649
# File 'lib/grabzit/client.rb', line 642

def set_local_proxy(value)
	if value
		uri = URI.parse(value)
		@proxy = Proxy.new(uri.host, uri.port, uri.user, uri.password)
	else
		@proxy = Proxy.new()
	end
end

#url_to_animation(url, options = nil) ⇒ void

This method returns an undefined value.

This method specifies the URL of the online video that should be converted into a animated GIF

Parameters:

  • url (String)

    The URL of the video to convert into a animated GIF

  • options (AnimationOptions, nil) (defaults to: nil)

    a instance of the AnimationOptions class that defines any special options to use when creating the animated GIF



72
73
74
75
76
77
78
79
80
# File 'lib/grabzit/client.rb', line 72

def url_to_animation(url, options = nil)

	if options == nil
		options = AnimationOptions.new()
	end

	@request = Request.new(@protocol + WebServicesBaseURL + "takeanimation", false, options, url)
	return nil
end

#url_to_docx(url, options = nil) ⇒ void

This method returns an undefined value.

This method specifies the URL that should be converted into a DOCX

Parameters:

  • url (String)

    the URL to capture as a DOCX

  • options (DOCXOptions, nil) (defaults to: nil)

    a instance of the DOCXOptions class that defines any special options to use when creating the DOCX



282
283
284
285
286
287
288
289
290
# File 'lib/grabzit/client.rb', line 282

def url_to_docx(url, options = nil)

	if options == nil
		options = DOCXOptions.new()
	end

	@request = Request.new(@protocol + WebServicesBaseURL + TakeDOCX, false, options, url)
	return nil			
end

#url_to_image(url, options = nil) ⇒ void

This method returns an undefined value.

This method specifies the URL that should be converted into a image screenshot

Parameters:

  • url (String)

    the URL to capture as a screenshot

  • options (ImageOptions, nil) (defaults to: nil)

    a instance of the ImageOptions class that defines any special options to use when creating the screenshot



87
88
89
90
91
92
93
94
95
# File 'lib/grabzit/client.rb', line 87

def url_to_image(url, options = nil)		

	if options == nil
		options = ImageOptions.new()
	end

	@request = Request.new(@protocol + WebServicesBaseURL + TakePicture, false, options, url)
	return nil
end

#url_to_pdf(url, options = nil) ⇒ void

This method returns an undefined value.

This method specifies the URL that should be converted into a PDF

Parameters:

  • url (String)

    the URL to capture as a PDF

  • options (PDFOptions, nil) (defaults to: nil)

    a instance of the PDFOptions class that defines any special options to use when creating the PDF



243
244
245
246
247
248
249
250
251
# File 'lib/grabzit/client.rb', line 243

def url_to_pdf(url, options = nil)

	if options == nil
		options = PDFOptions.new()
	end

	@request = Request.new(@protocol + WebServicesBaseURL + TakePDF, false, options, url)
	return nil			
end

#url_to_rendered_html(url, options = nil) ⇒ void

This method returns an undefined value.

This method specifies the URL that should be converted into rendered HTML

Parameters:

  • url (String)

    the URL to capture as rendered HTML

  • options (HTMLOptions, nil) (defaults to: nil)

    a instance of the HTMLOptions class that defines any special options to use when creating the rendered HTML



165
166
167
168
169
170
171
172
173
# File 'lib/grabzit/client.rb', line 165

def url_to_rendered_html(url, options = nil)		

	if options == nil
		options = HTMLOptions.new()
	end

	@request = Request.new(@protocol + WebServicesBaseURL + TakeHTML, false, options, url)
	return nil
end

#url_to_table(url, options = nil) ⇒ void

This method returns an undefined value.

This method specifies the URL that the HTML tables should be extracted from

Parameters:

  • url (String)

    the URL to extract HTML tables from

  • options (TableOptions, nil) (defaults to: nil)

    a instance of the TableOptions class that defines any special options to use when converting the HTML table



204
205
206
207
208
209
210
211
212
# File 'lib/grabzit/client.rb', line 204

def url_to_table(url, options = nil)

	if options == nil
		options = TableOptions.new()
	end

	@request = Request.new(@protocol + WebServicesBaseURL + TakeTable, false, options, url)
	return nil			
end

#url_to_video(url, options = nil) ⇒ void

This method returns an undefined value.

This method specifies the URL that should be converted into a video

Parameters:

  • url (String)

    the URL to capture as a video

  • options (VideoOptions, nil) (defaults to: nil)

    a instance of the VideoOptions class that defines any special options to use when creating a video



126
127
128
129
130
131
132
133
134
# File 'lib/grabzit/client.rb', line 126

def url_to_video(url, options = nil)		

	if options == nil
		options = VideoOptions.new()
	end

	@request = Request.new(@protocol + WebServicesBaseURL + TakeVideo, false, options, url)
	return nil
end

#use_ssl(value) ⇒ Object

This method sets if requests to GrabzIt’s API should use SSL or not

Parameters:

  • value (Boolean)

    true if should use SSL



631
632
633
634
635
636
637
# File 'lib/grabzit/client.rb', line 631

def use_ssl(value)
	if value
		@protocol = 'https'
	else
		@protocol = 'http'
	end
end