Module: Applitools::Base::ServerConnector

Extended by:
ServerConnector
Includes:
MethodTracer
Included in:
ServerConnector
Defined in:
lib/applitools/base/server_connector.rb

Constant Summary collapse

DEFAULT_SERVER_URL =
'https://eyessdk.applitools.com'.freeze
SSL_CERT =
File.join(File.dirname(File.expand_path(__FILE__)), '../../../certs/cacert.pem').to_s.freeze
DEFAULT_TIMEOUT =
300
API_SESSIONS_RUNNING =
'/api/sessions/running/'.freeze
HTTP_STATUS_CODES =
{
  created: 201,
  accepted: 202
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from MethodTracer

included

Instance Attribute Details

#api_keyObject

Returns the value of attribute api_key.



23
24
25
# File 'lib/applitools/base/server_connector.rb', line 23

def api_key
  @api_key
end

#endpoint_urlObject (readonly)

Returns the value of attribute endpoint_url.



24
25
26
# File 'lib/applitools/base/server_connector.rb', line 24

def endpoint_url
  @endpoint_url
end

#server_urlObject

Returns the value of attribute server_url.



23
24
25
# File 'lib/applitools/base/server_connector.rb', line 23

def server_url
  @server_url
end

Instance Method Details

#match_window(session, data) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/applitools/base/server_connector.rb', line 39

def match_window(session, data)
  # Notice that this does not include the screenshot.
  json_data = Oj.dump(Applitools::Utils.camelcase_hash_keys(data.to_hash)).force_encoding('BINARY')
  body = [json_data.length].pack('L>') + json_data + data.screenshot
  Applitools::EyesLogger.debug 'Sending match data...'

  res = post(URI.join(endpoint_url, session.id.to_s), content_type: 'application/octet-stream', body: body)
  raise Applitools::EyesError.new("Request failed: #{res.status}") unless res.success?

  Oj.load(res.body)['asExpected'].tap do |as_expected|
    Applitools::EyesLogger.debug "Got response! #{as_expected}"
  end
end

#set_proxy(uri, user = nil, password = nil) ⇒ Object



31
32
33
34
35
36
37
# File 'lib/applitools/base/server_connector.rb', line 31

def set_proxy(uri, user = nil, password = nil)
  @proxy = {
    uri: uri,
    user: user,
    password: password
  }
end

#start_session(session_start_info) ⇒ Object



53
54
55
56
57
58
59
60
# File 'lib/applitools/base/server_connector.rb', line 53

def start_session(session_start_info)
  res = post(endpoint_url, body: Oj.dump(startInfo:
    Applitools::Utils.camelcase_hash_keys(session_start_info.to_hash)))
  raise Applitools::EyesError.new("Request failed: #{res.status}") unless res.success?

  response = Oj.load(res.body)
  Applitools::Base::Session.new(response['id'], response['url'], res.status == HTTP_STATUS_CODES[:created])
end

#stop_session(session, aborted = nil, save = false) ⇒ Object



62
63
64
65
66
67
68
# File 'lib/applitools/base/server_connector.rb', line 62

def stop_session(session, aborted = nil, save = false)
  res = long_delete(URI.join(endpoint_url, session.id.to_s), query: { aborted: aborted, updateBaseline: save })
  raise Applitools::EyesError.new("Request failed: #{res.status}") unless res.success?

  response = Oj.load(res.body)
  Applitools::Base::TestResults.new(response)
end