Class: Octarine::SimpleHTTP
- Inherits:
-
Object
- Object
- Octarine::SimpleHTTP
- Defined in:
- lib/octarine/simple_http.rb
Overview
SimpleHTTP is a bare-bones implementation of a simple http client, designed to be easily replaceable with another implementation.
Defined Under Namespace
Classes: Response
Instance Method Summary collapse
-
#delete(path, headers = {}) ⇒ Object
:call-seq: simple_http.delete(path, headers={}) -> response.
-
#get(path, headers = {}) ⇒ Object
:call-seq: simple_http.get(path, headers={}) -> response.
-
#head(path, headers = {}) ⇒ Object
:call-seq: simple_http.head(path, headers={}) -> response.
-
#initialize(url, options = {}) ⇒ SimpleHTTP
constructor
:call-seq: SimpleHTTP.new(url, options={}) -> simple_http SimpleHTTP.new(options) -> simple_http.
-
#post(path, body = nil, headers = {}) ⇒ Object
:call-seq: simple_http.post(path, body=nil, headers={}) -> response.
-
#put(path, body = nil, headers = {}) ⇒ Object
:call-seq: simple_http.put(path, body=nil, headers={}) -> response.
Constructor Details
#initialize(url, options = {}) ⇒ SimpleHTTP
:call-seq: SimpleHTTP.new(url, options={}) -> simple_http SimpleHTTP.new(options) -> simple_http
Create a SimpleHTTP instace with either a url and options or options with a :url key.
17 18 19 20 21 22 23 |
# File 'lib/octarine/simple_http.rb', line 17 def initialize(url, ={}) unless url.respond_to?(:to_str) = url url = [:url] end @host, @port = url.to_s.split(/:/) end |
Instance Method Details
#delete(path, headers = {}) ⇒ Object
:call-seq: simple_http.delete(path, headers={}) -> response
Perform a DELETE request, returns a response that responds to #status, #headers, and #body
70 71 72 |
# File 'lib/octarine/simple_http.rb', line 70 def delete(path, headers={}) request(Net::HTTP::Delete.new(path, headers)) end |
#get(path, headers = {}) ⇒ Object
:call-seq: simple_http.get(path, headers={}) -> response
Perform a GET request, returns a response that responds to #status, #headers, and #body
39 40 41 |
# File 'lib/octarine/simple_http.rb', line 39 def get(path, headers={}) request(Net::HTTP::Get.new(path, headers)) end |
#head(path, headers = {}) ⇒ Object
:call-seq: simple_http.head(path, headers={}) -> response
Perform a HEAD request, returns a response that responds to #status, #headers, and #body
30 31 32 |
# File 'lib/octarine/simple_http.rb', line 30 def head(path, headers={}) request(Net::HTTP::Head.new(path, headers)) end |
#post(path, body = nil, headers = {}) ⇒ Object
:call-seq: simple_http.post(path, body=nil, headers={}) -> response
Perform a POST request, returns a response that responds to #status, #headers, and #body
48 49 50 51 52 |
# File 'lib/octarine/simple_http.rb', line 48 def post(path, body=nil, headers={}) req = Net::HTTP::Post.new(path, headers) req.body = body if body request(req) end |
#put(path, body = nil, headers = {}) ⇒ Object
:call-seq: simple_http.put(path, body=nil, headers={}) -> response
Perform a PUT request, returns a response that responds to #status, #headers, and #body
59 60 61 62 63 |
# File 'lib/octarine/simple_http.rb', line 59 def put(path, body=nil, headers={}) req = Net::HTTP::Put.new(path, headers) req.body = body if body request(req) end |