Class: EaseHTTP::Connection
- Inherits:
-
Object
- Object
- EaseHTTP::Connection
- Defined in:
- lib/ease_http/connection.rb
Instance Method Summary collapse
-
#get(path, options = {}, &block) ⇒ Object
path - path to request options :headers :query.
-
#initialize(endpoint) ⇒ Connection
constructor
A new instance of Connection.
-
#post(path, options = {}, &block) ⇒ Object
path - path to request options :headers :data.
Constructor Details
#initialize(endpoint) ⇒ Connection
Returns a new instance of Connection.
7 8 9 10 11 12 13 |
# File 'lib/ease_http/connection.rb', line 7 def initialize(endpoint) @endpoint = endpoint uri = URI(endpoint) @http = Net::HTTP.new(uri.host, uri.port) @http.use_ssl = uri.scheme == 'https' end |
Instance Method Details
#get(path, options = {}, &block) ⇒ Object
path - path to request options
:headers
:query
19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/ease_http/connection.rb', line 19 def get(path, ={}, &block) uri = URI.join(@endpoint, path) headers = .delete(:headers) query = .delete(:query) if query uri.query = URI.encode_www_form(query) end @http.request_get uri.request_uri, headers, &block end |
#post(path, options = {}, &block) ⇒ Object
path - path to request options
:headers
:data
35 36 37 38 39 40 |
# File 'lib/ease_http/connection.rb', line 35 def post(path, ={}, &block) headers = .delete :headers data = .delete :data @http.request_post path, data, headers, &block end |