Class: Webstract::Screenshot

Inherits:
Object
  • Object
show all
Defined in:
lib/webstract/screenshot.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Screenshot

Returns a new instance of Screenshot.

Raises:

  • (ArgumentError)


6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/webstract/screenshot.rb', line 6

def initialize(options = {})
  @handle = Webstract::ScreenCapture.new(options)

  options.each do |k, value|
    setter = "#{k}="
    self.public_send(setter, value) if self.respond_to?(setter)
  end
  path = options[:path] || raise(ArgumentError.new('path required'))
  @basic_auth ||= {}

  raise(ArgumentError.new("basic_auth credentials must be a Hash: got #{@basic_auth.inspect}")) unless @basic_auth.is_a?(Hash)
end

Instance Attribute Details

#accept_languageObject

Returns the value of attribute accept_language.



3
4
5
# File 'lib/webstract/screenshot.rb', line 3

def accept_language
  @accept_language
end

#basic_authObject

Returns the value of attribute basic_auth.



3
4
5
# File 'lib/webstract/screenshot.rb', line 3

def basic_auth
  @basic_auth
end

#handleObject (readonly)

Returns the value of attribute handle.



4
5
6
# File 'lib/webstract/screenshot.rb', line 4

def handle
  @handle
end

#heightObject

Returns the value of attribute height.



3
4
5
# File 'lib/webstract/screenshot.rb', line 3

def height
  @height
end

#pathObject

Returns the value of attribute path.



4
5
6
# File 'lib/webstract/screenshot.rb', line 4

def path
  @path
end

#urlObject

Returns the value of attribute url.



3
4
5
# File 'lib/webstract/screenshot.rb', line 3

def url
  @url
end

#user_agentObject

Returns the value of attribute user_agent.



3
4
5
# File 'lib/webstract/screenshot.rb', line 3

def user_agent
  @user_agent
end

#widthObject

Returns the value of attribute width.



3
4
5
# File 'lib/webstract/screenshot.rb', line 3

def width
  @width
end

Instance Method Details

#captureObject



33
34
35
36
37
38
39
40
41
# File 'lib/webstract/screenshot.rb', line 33

def capture
  handle.capture(url, path,
    width: width,
    height: height,
    user_agent: user_agent,
    accept_language: accept_language,
    basic_auth: basic_auth
  )
end

#password=(password) ⇒ Object



29
30
31
# File 'lib/webstract/screenshot.rb', line 29

def password=(password)
  @basic_auth[:password] = password
end

#username=(username) ⇒ Object



25
26
27
# File 'lib/webstract/screenshot.rb', line 25

def username=(username)
  @basic_auth[:username] = username
end