ScreenshotMachine
A gem to create screenshots of webpages by using the ScreenshotMachine.com API.
You will need a (free) account to get started.
Installation
Add this line to your application's Gemfile:
gem 'screenshot_machine'
And then execute:
$ bundle
Or install it yourself as:
$ gem install screenshot_machine
Usage
Using ScreenshotMachine is quite simple
require 'screenshot_machine'
ScreenshotMachine.configure do |config|
config.key = '012345abcdefg'
end
website_url = "http://google.com/?q=great+gem"
sm = ScreenshotMachine.new(website_url)
# Returns a binary stream of the file
sm.screenshot
You can also config all API Parameters
require 'screenshot_machine'
ScreenshotMachine.configure do |config|
config.key = '012345abcdefg'
config.size = 'X'
config.format = 'PNG'
config.cacheLimit = 2
config.timeout = 400
end
Exceptions
# ScreenshotMachine::Exceptions::InvalidUrl
# Raised when the website_url can not be resolved by ScreenshotMachine.com.
ScreenshotMachine.new("http://non-existing-example123.com").screenshot
# ScreenshotMachine::Exceptions::InvalidUrl: WARNING: Invalid URL
# ScreenshotMachine::Exceptions::InvalidKey
# Raised when your API key is not set or invalid.
ScreenshotMachine.new("http://non-existing-example123.com").screenshot
# ScreenshotMachine::Exceptions::InvalidKey: ERROR: Invalid API KEY
# ScreenshotMachine::Exceptions::NoCredits
# Raised when there are not sufficient credits in your ScreenshotMachine.com account.
ScreenshotMachine.new("http://example.com").screenshot
# ScreenshotMachine::Exceptions::NoCredits: ERROR: No Credits for API
# ScreenshotMachine::Exceptions::SystemError
# Raised when the API returns system_error.
ScreenshotMachine.new("http://example.com").screenshot
# ScreenshotMachine::Exceptions::SystemError: ERROR: API System Error
Contributing
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Added some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request