Skip to content

Commit

Permalink
Finished Ruby upgrade for animated GIF
Browse files Browse the repository at this point in the history
  • Loading branch information
oi.u.sms@gmail.com committed Aug 12, 2014
1 parent d83180c commit debe3bf
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 9 deletions.
4 changes: 2 additions & 2 deletions ruby/GrabzIt/grabzit.gemspec
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
Gem::Specification.new do |s|
s.name = 'grabzit'
s.version = '2.1.3'
s.version = '2.2.0'
s.date = Date.today.to_s
s.summary = "GrabzIt Ruby Client"
s.description = "Automatically create screenshots of website for free, with GrabzIt. Screenshots can be output in a variety of formats including: JPEG, PNG, TIFF, BMP, PDF, CSV and XLSX."
s.description = "Automatically create screenshots of website for free, with GrabzIt. Screenshots can be output in a variety of formats including: JPEG, PNG, TIFF, BMP, PDF, CSV and XLSX. Additionally GrabzIt allows you to convert online videos into animated GIF's."
s.authors = ["GrabzIt"]
s.require_paths = ["lib"]
s.email = 'support@grabz.it'
Expand Down
35 changes: 35 additions & 0 deletions ruby/GrabzIt/lib/grabzit/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,31 @@ def initialize(applicationKey, applicationSecret)
@applicationSecret = applicationSecret
end

# This method sets the parameters required to turn a online video into a animated GIF
#
# @param url [String] the URL of the online video
# @param customId [String, nil] custom identifier that you can pass through to the screenshot webservice. This will be returned with the callback URL you have specified
# @param width [Integer, 0] the width of the resulting animated GIF in pixels
# @param height [Integer, 0] the height of the resulting animated GIF in pixels
# @param start [Integer, 0] the starting position of the video that should be converted into a animated GIF
# @param duration [Integer, 0] the length in seconds of the video that should be converted into a animated GIF
# @param speed [Float, 0] the speed of the animated GIF from 0.2 to 10 times the original speed
# @param framesPerSecond [Float, 0] the number of frames per second that should be captured from the video. From a minimum of 0.2 to a maximum of 60
# @param repeat [Integer, 0] the number of times to loop the animated GIF. If 0 it will loop forever
# @param reverse [Boolean, false] if true the frames of the animated GIF are reversed
# @param customWaterMarkId [String, nil] add a custom watermark to the animated GIF
# @param quality [Integer, -1] the quality of the image where 0 is poor and 100 excellent. The default is -1 which uses the recommended quality
# @param country [String, nil] request the screenshot from different countries: Default, UK or US
# @return [void]
def set_animation_options(url, customId = nil, width = 0, height = 0, start = 0, duration = 0, speed = 0, framesPerSecond = 0, repeat = 0, reverse = false, customWaterMarkId = '', quality = -1, country = '')
@@startDelay = 0;
@@request = WebServicesBaseURL + "takeanimation.ashx?key=" + CGI.escape(nil_check(@applicationKey))+"&url="+CGI.escape(nil_check(url))+"&width="+nil_int_check(width)+"&height="+nil_int_check(height)+"&duration="+nil_int_check(duration)+"&speed="+nil_float_check(speed)+"&start="+nil_int_check(start)+"&customid="+CGI.escape(nil_check(customId))+"&fps="+nil_float_check(framesPerSecond)+"&repeat="+nil_int_check(repeat)+"&customwatermarkid="+CGI.escape(nil_check(customWaterMarkId))+"&reverse="+b_to_str(reverse)+"&country="+CGI.escape(nil_check(country))+"&quality="+nil_int_check(quality)+"&callback="
@@signaturePartOne = @applicationSecret+"|"+nil_check(url)+"|"
@@signaturePartTwo = "|"+nil_int_check(height)+"|"+nil_int_check(width)+"|"+nil_check(customId)+"|"+nil_float_check(framesPerSecond)+"|"+nil_float_check(speed)+"|"+nil_int_check(duration)+"|"+nil_int_check(repeat)+"|"+b_to_str(reverse)+"|"+nil_int_check(start)+"|"+nil_check(customWaterMarkId)+"|"+nil_check(country)+"|"+nil_int_check(quality)
return nil
end


# Sets the parameters required to take a screenshot of a web page.
#
# @param url [String] the URL that the screenshot should be made of
Expand Down Expand Up @@ -510,6 +535,16 @@ def nil_check(param)
def nil_int_check(param)
return param.to_i.to_s
end

private
def nil_float_check(param)
val = param.to_f
if ((val % 1) == 0)
return val.to_i.to_s
end

return val.to_s
end

private
def check_for_exception(doc)
Expand Down
9 changes: 9 additions & 0 deletions ruby/GrabzIt/lib/grabzit/exception.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,15 @@ class GrabzItException < Exception
PARAMETER_MISSING_PARAMETERS = 143
PARAMETER_QUALITY_TOO_LARGE = 144
PARAMETER_QUALITY_TOO_SMALL = 145
PARAMETER_REPEAT_TOO_SMALL = 149
PARAMETER_INVALID_REVERSE = 150
PARAMETER_FPS_TOO_LARGE = 151
PARAMETER_FPS_TOO_SMALL = 152
PARAMETER_SPEED_TOO_FAST = 153
PARAMETER_SPEED_TOO_SLOW = 154
PARAMETER_INVALID_DURATION_FPS_WIDTH_HEIGHT_COMBINATION = 155
PARAMETER_START_TOO_SMALL = 156
PARAMETER_DURATION_TOO_LARGE = 157
NETWORK_SERVER_OFFLINE = 200
NETWORK_GENERAL_ERROR = 201
NETWORK_DDOS_ATTACK = 202
Expand Down
30 changes: 25 additions & 5 deletions ruby/GrabzIt/test/test_grabzit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ class GrabzItTest < Test::Unit::TestCase
Screenshot_Path = "test/tmp.jpg"

def setup
@applicationKey = ""
@applicationSecret = ""
@applicationKey = "c3VwcG9ydEBncmFiei5pdA=="
@applicationSecret = "AD8/aT8/Pz8/Tz8/PwJ3Pz9sVSs/Pz8/Pz9DOzJodoi="
#Set to true if the account is subscribed
@isSubscribedAccount = false
@isSubscribedAccount = true
end

def test_application_key
Expand Down Expand Up @@ -58,6 +58,14 @@ def test_save_picture
File.delete(Screenshot_Path)
end

def test_save_animation
assert_nothing_raised "An error occured when trying to take a animation" do
grabzItClient = GrabzIt::Client.new(@applicationKey, @applicationSecret)
grabzItClient.set_animation_options("http://www.youtube.com");
assert_not_equal(false, grabzItClient.save(), "Animation not taken")
end
end

def test_save_to_bytes
assert_nothing_raised "An error occured when trying to take a image screenshot" do
grabzItClient = GrabzIt::Client.new(@applicationKey, @applicationSecret)
Expand Down Expand Up @@ -90,7 +98,9 @@ def test_add_cookie
grabzItClient.set_cookie(Cookie_Name, Cookie_Domain)
end
return
end
end

sleep(4)

assert(find_cookie(grabzItClient), "Set cookie has not been found!")
end
Expand All @@ -108,10 +118,14 @@ def test_delete_cookie
return
end

sleep(4)

assert_equal(true, find_cookie(grabzItClient), "Test cookie not found!")

grabzItClient.delete_cookie(Cookie_Name, Cookie_Domain)

sleep(4)

assert_equal(false, find_cookie(grabzItClient), "Failed to delete cookie!")
end
end
Expand All @@ -133,10 +147,14 @@ def test_delete_watermark
return
end

sleep(5)

assert_equal(true, find_watermark(grabzItClient), "Test watermark not found!")

grabzItClient.delete_watermark(WaterMark_Identifier)

sleep(5)

assert_equal(false, find_watermark(grabzItClient), "Failed to delete watermark!")
end
end
Expand All @@ -155,7 +173,9 @@ def test_add_watermark
grabzItClient.add_watermark(WaterMark_Identifier, WaterMark_Path, 2, 2)
end
return
end
end

sleep(4)

assert(find_watermark(grabzItClient), "Set watermark has not been found!")
end
Expand Down
4 changes: 2 additions & 2 deletions ruby/readme.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
GrabzIt 2.1
GrabzIt 2.2
===========

This software allows you to programmatically take screenshots of websites.
This library allows you to programmatically convert web pages into images, PDF's, CSV's and spreadsheets. Additionally GrabzIt allows you to convert online videos into animated GIF's.

Its usually best to place these files in thier own directory.

Expand Down

0 comments on commit debe3bf

Please sign in to comment.