Class: AppTester::Connection Abstract

Inherits:
Object
  • Object
show all
Defined in:
lib/app-tester/connection.rb

Overview

This class is abstract.

Connection object that deals with communicating with Faraday to build new connections

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#optionsAppTester::Options (readonly)

the options that the user defined when he created the framework

Returns:



6
7
8
# File 'lib/app-tester/connection.rb', line 6

def options
  @options
end

Class Method Details

.new(url = "", options = {}) ⇒ Faraday::Connection

TODO:

Implement connection retry

Build a new connection handler

Parameters:

  • url (String) (defaults to: "")

    the url that will be used to set up a new connection handler

  • options (AppTester::Options) (defaults to: {})

    the options that the user defined when he created the framework

Returns:

  • (Faraday::Connection)

    on successfull connection

Raises:

  • (OptionParser::InvalidArgument)

    if no url is specified

  • (Faraday::Error::ConnectionFailed)

    if there was a problem connecting to the url provided



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/app-tester/connection.rb', line 21

def self.new(url="", options={})
  @options = options

  # Make sure server choice makes sense
  raise OptionParser::InvalidArgument if url.nil?

  puts AppTester::Utils::Colours.dark_gray "Connecting to #{url}..."
  retries = 0
  connection = Faraday.new(:url => url, :ssl => { :verify => false }) do |builder|
    builder.request :url_encoded
    builder.adapter :net_http
    builder.response :logger if @options.log_connections
  end
  connection
  #begin
  #
  #  connection.get do |req|
  #
  #  end
  #rescue Faraday::Error::ConnectionFailed => e
  #  retries += 1
  #  if retries <= @options.connection_retries
  #    puts AppTester::Utils::Colours.dark_gray "#{AppTester::Utils::Strings::FAILED} Failed connection to #{url}, retry attempt #{retries}..."
  #    retry
  #  end
  #  raise Faraday::Error::ConnectionFailed(e.message)
  #end
end