Class: Http

Inherits:
Object
  • Object
show all
Defined in:
lib/vmfloaty/http.rb

Class Method Summary collapse

Class Method Details

.get_conn(verbose, url) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/vmfloaty/http.rb', line 4

def self.get_conn(verbose, url)
  if url.nil?
    STDERR.puts "The url you provided was empty"
    exit 1
  end

  conn = Faraday.new(:url => url, :ssl => {:verify => false}) do |faraday|
    faraday.request :url_encoded
    faraday.response :logger if verbose
    faraday.adapter Faraday.default_adapter
  end

  return conn
end

.get_conn_with_auth(verbose, url, user, password) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/vmfloaty/http.rb', line 19

def self.get_conn_with_auth(verbose, url, user, password)
  if url.nil?
    STDERR.puts "The url you provided was empty"
    exit 1
  end

  if user.nil?
    STDERR.puts "You did not provide a user to authenticate with"
    exit 1
  end

  conn = Faraday.new(:url => url, :ssl => {:verify => false}) do |faraday|
    faraday.request :url_encoded
    faraday.request :basic_auth, user, password
    faraday.response :logger if verbose
    faraday.adapter Faraday.default_adapter
  end

  return conn
end