Class: ApiTester::Connection
- Inherits:
-
Object
- Object
- ApiTester::Connection
- Defined in:
- lib/api_tester/connection.rb
Instance Method Summary collapse
- #connection ⇒ Object
- #headers ⇒ Object
-
#initialize(endpoint, options = {}) ⇒ Connection
constructor
A new instance of Connection.
- #post(api, body) ⇒ Object
- #pretty_print(resp) ⇒ Object
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, = {}) @endpoint = endpoint end |
Instance Method Details
#connection ⇒ Object
11 12 13 14 15 16 |
# File 'lib/api_tester/connection.rb', line 11 def connection @conn ||= Faraday.new(:url => @endpoint) do |faraday| faraday.request :url_encoded faraday.adapter Faraday.default_adapter end end |
#headers ⇒ Object
18 19 20 |
# File 'lib/api_tester/connection.rb', line 18 def headers 'application/json' end |
#post(api, body) ⇒ Object
22 23 24 25 26 27 28 29 30 |
# File 'lib/api_tester/connection.rb', line 22 def post(api, body) resp = connection.post do |req| req.url api req..timeout = 3600 req..open_timeout = 3600 req.headers['Content-Type'] = headers req.body = body end end |
#pretty_print(resp) ⇒ Object
32 33 34 35 36 37 38 |
# File 'lib/api_tester/connection.rb', line 32 def pretty_print(resp) begin puts JSON.pretty_generate(JSON.parse(resp.body)) rescue puts resp.body end end |