Class: ScreenshotMachine::Generator
- Inherits:
-
Object
- Object
- ScreenshotMachine::Generator
- Defined in:
- lib/screenshot_machine/generator.rb
Instance Method Summary collapse
-
#initialize(url, options = {}) ⇒ Generator
constructor
A new instance of Generator.
- #screenshot ⇒ Object
Constructor Details
#initialize(url, options = {}) ⇒ Generator
Returns a new instance of Generator.
6 7 8 9 10 11 12 13 |
# File 'lib/screenshot_machine/generator.rb', line 6 def initialize(url, ={}) = ScreenshotMachine.. merge({ :url => url }). merge() Configuration::VALID_PARAMS_KEYS.each do |key| send("#{key}=", [key]) end end |
Instance Method Details
#screenshot ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/screenshot_machine/generator.rb', line 15 def screenshot @screenshot ||= begin response = open(screenshot_url) case response.["x-screenshotmachine-response"] when "invalid_url" raise Exceptions::InvalidUrl, "WARNING: Invalid URL" when "invalid_key" raise Exceptions::InvalidKey, "ERROR: Invalid API KEY" when "no_credits" raise Exceptions::NoCredits, "ERROR: No Credits for API" when "system_error" raise Exceptions::SystemError, "ERROR: API System Error" end response.read end end |