Class: ScreenshotMachine::Generator

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

Instance Method Summary collapse

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, options={})
  merged_options = ScreenshotMachine.options.
    merge({ :url => url }).
    merge(options)
  Configuration::VALID_PARAMS_KEYS.each do |key|
    send("#{key}=", merged_options[key])
  end
end

Instance Method Details

#screenshotObject



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.meta["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