Module: Applitools::Connectivity::ServerConnector

Extended by:
ServerConnector
Included in:
ServerConnector
Defined in:
lib/applitools/connectivity/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

Instance Attribute Details

#api_keyObject

Returns the value of attribute api_key.



23
24
25
# File 'lib/applitools/connectivity/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/connectivity/server_connector.rb', line 24

def endpoint_url
  @endpoint_url
end

#proxyObject

Returns the value of attribute proxy.



25
26
27
# File 'lib/applitools/connectivity/server_connector.rb', line 25

def proxy
  @proxy
end

#server_urlObject

Returns the value of attribute server_url.



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

def server_url
  @server_url
end

Instance Method Details

#match_window(session, data) ⇒ Object

Raises:

  • (Applitools::EyesError)


48
49
50
51
52
53
54
55
56
57
# File 'lib/applitools/connectivity/server_connector.rb', line 48

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 json_data
  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} #{res.headers}") unless res.success?
  Applitools::MatchResult.new Oj.load(res.body)
end

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



36
37
38
# File 'lib/applitools/connectivity/server_connector.rb', line 36

def set_proxy(uri, user = nil, password = nil)
  self.proxy = Proxy.new uri, user, password
end

#start_session(session_start_info) ⇒ Object

Raises:

  • (Applitools::EyesError)


59
60
61
62
63
64
65
66
# File 'lib/applitools/connectivity/server_connector.rb', line 59

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} #{res.body}") unless res.success?

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

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

Raises:

  • (Applitools::EyesError)


68
69
70
71
72
73
74
# File 'lib/applitools/connectivity/server_connector.rb', line 68

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::TestResults.new(response)
end