Module: Visiocop

Defined in:
lib/visiocop.rb,
lib/visiocop/version.rb,
lib/visiocop/configuration.rb,
lib/visiocop/errors/configuration.rb

Defined Under Namespace

Modules: Errors Classes: Configuration

Constant Summary collapse

VERSION =
"0.3.1"

Class Method Summary collapse

Class Method Details

.check(screen1, screen2, options = {}) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/visiocop.rb', line 10

def self.check(screen1, screen2, options = {})
  response = RestClient::Request.execute(
    method: :post,
    url: configuration.url,
    timeout: 600,
    headers: { "api-key": configuration.secret_key },
    payload: {
      'options': (options || configuration.options).merge({ from_file_1: true, from_file_2: true } ),
      'image1': File.new(screen1),
      'image2': File.new(screen2)
    }
  )

  JSON.parse(response.body).dig(options[:path_to_result] || "similarity")
rescue Errno::ENOENT
  p "File not found."
rescue StandardError => e
  p e
end

.check_page(screen1, screen2, options = {}) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/visiocop.rb', line 30

def self.check_page(screen1, screen2, options = {})
  response = RestClient::Request.execute(
    method: :post,
    url: configuration.url,
    timeout: 600,
    headers: { "api-key": configuration.secret_key },
    payload: {
      'options': options || configuration.options,
      'image1': options[:from_file_1] ? File.new(screen1) : screen1,
      'image2': options[:from_file_2] ? File.new(screen2) : screen2
    }
  )

  JSON.parse(response.body).dig(options[:path_to_result] || "similarity")
rescue StandardError => e
  p e
end

.configurationObject



49
50
51
# File 'lib/visiocop.rb', line 49

def configuration
  @configuration ||= Configuration.new
end

.configure {|configuration| ... } ⇒ Object

Yields:



57
58
59
# File 'lib/visiocop.rb', line 57

def configure
  yield(configuration)
end

.resetObject



53
54
55
# File 'lib/visiocop.rb', line 53

def reset
  @configuration = Configuration.new
end