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 35 36 37 |
# File 'lib/crabfarm/http_client.rb', line 27 def initialize(_proxy=nil) if Crabfarm.live? @proxy_addr = '127.0.0.1' @proxy_port = Crabfarm.live.proxy_port elsif _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
56 57 58 |
# File 'lib/crabfarm/http_client.rb', line 56 def delete(_url) perform_request Net::HTTP::Delete, URI(_url), _headers end |
#get(_url, _query = {}, _headers = {}) ⇒ Object
39 40 41 42 |
# File 'lib/crabfarm/http_client.rb', line 39 def get(_url, _query={}, _headers={}) uri = URI _url perform_request Net::HTTP::Get, uri, _headers end |
#post(_url, _data, _headers = {}) ⇒ Object
44 45 46 47 48 |
# File 'lib/crabfarm/http_client.rb', line 44 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
50 51 52 53 54 |
# File 'lib/crabfarm/http_client.rb', line 50 def put(_url, _data, _headers={}) perform_request Net::HTTP::Put, URI(_url), _headers do |req| req.body = prepare_data(_data) end end |