Class: Crabfarm::HttpClient
- Inherits:
-
Object
- Object
- Crabfarm::HttpClient
- Defined in:
- lib/crabfarm/http_client.rb
Defined Under Namespace
Classes: HttpRequestError, MaximumRedirectsError
Instance Attribute Summary collapse
-
#proxy_addr ⇒ Object
readonly
Returns the value of attribute proxy_addr.
-
#proxy_port ⇒ Object
readonly
Returns the value of attribute proxy_port.
Instance Method Summary collapse
- #delete(_url) ⇒ Object
- #get(_url, _query = {}, _headers = {}) ⇒ Object
-
#initialize(_proxy = nil) ⇒ HttpClient
constructor
A new instance of HttpClient.
- #post(_url, _data, _headers = {}) ⇒ Object
- #put(_url, _data, _headers = {}) ⇒ Object
Constructor Details
#initialize(_proxy = nil) ⇒ HttpClient
Returns a new instance of HttpClient.
27 28 29 30 31 32 33 34 |
# File 'lib/crabfarm/http_client.rb', line 27 def initialize(_proxy=nil) if _proxy.nil? @proxy_addr = nil @proxy_port = nil else @proxy_addr, @proxy_port = _proxy.split ':' end end |
Instance Attribute Details
#proxy_addr ⇒ Object (readonly)
Returns the value of attribute proxy_addr.
25 26 27 |
# File 'lib/crabfarm/http_client.rb', line 25 def proxy_addr @proxy_addr end |
#proxy_port ⇒ Object (readonly)
Returns the value of attribute proxy_port.
25 26 27 |
# File 'lib/crabfarm/http_client.rb', line 25 def proxy_port @proxy_port end |
Instance Method Details
#delete(_url) ⇒ Object
53 54 55 |
# File 'lib/crabfarm/http_client.rb', line 53 def delete(_url) perform_request Net::HTTP::Delete, URI(_url), _headers end |
#get(_url, _query = {}, _headers = {}) ⇒ Object
36 37 38 39 |
# File 'lib/crabfarm/http_client.rb', line 36 def get(_url, _query={}, _headers={}) uri = URI _url perform_request Net::HTTP::Get, uri, _headers end |
#post(_url, _data, _headers = {}) ⇒ Object
41 42 43 44 45 |
# File 'lib/crabfarm/http_client.rb', line 41 def post(_url, _data, _headers={}) perform_request Net::HTTP::Post, URI(_url), _headers do |req| req.body = prepare_data(_data) end end |
#put(_url, _data, _headers = {}) ⇒ Object
47 48 49 50 51 |
# File 'lib/crabfarm/http_client.rb', line 47 def put(_url, _data, _headers={}) perform_request Net::HTTP::Put, URI(_url), _headers do |req| req.body = prepare_data(_data) end end |