Class: ApiTester::Connection

Inherits:
Object
  • Object
show all
Defined in:
lib/api_tester/connection.rb

Instance Method Summary collapse

Constructor Details

#initialize(endpoint, options = {}) ⇒ Connection

Returns a new instance of Connection.



7
8
9
# File 'lib/api_tester/connection.rb', line 7

def initialize(endpoint, options = {})
  @endpoint = endpoint
end

Instance Method Details

#connectionObject



11
12
13
14
15
16
17
# File 'lib/api_tester/connection.rb', line 11

def connection
  @conn ||= Faraday.new(:url => @endpoint) do |faraday|
    faraday.request  :url_encoded
    faraday.response :logger if ApiTester.configuration.options[:verbose]
    faraday.adapter  Faraday.default_adapter
  end
end

#pretty_print(resp) ⇒ Object



31
32
33
34
35
36
37
# File 'lib/api_tester/connection.rb', line 31

def pretty_print(resp)
  begin
    puts JSON.pretty_generate(JSON.parse(resp.body))
  rescue
    puts resp.body
  end
end