Class: Fbox::HttpClient
- Inherits:
-
Object
- Object
- Fbox::HttpClient
- Defined in:
- lib/fbox/http_client.rb
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
- #http_conn(uri) ⇒ Object
-
#initialize(options) ⇒ HttpClient
constructor
A new instance of HttpClient.
- #make_request(http_method, path, body = '', headers = {}, form_params = {}) ⇒ Object
- #request(*args) ⇒ Object
- #uri ⇒ Object
Constructor Details
#initialize(options) ⇒ HttpClient
Returns a new instance of HttpClient.
32 33 34 35 36 |
# File 'lib/fbox/http_client.rb', line 32 def initialize() = .freeze = {} end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
30 31 32 |
# File 'lib/fbox/http_client.rb', line 30 def end |
Instance Method Details
#http_conn(uri) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/fbox/http_client.rb', line 49 def http_conn(uri) if [:proxy_address] http_class = Net::HTTP::Proxy([:proxy_address], [:proxy_port] ? [:proxy_port] : 80) else http_class = Net::HTTP end http_conn = http_class.new(uri.host, uri.port) http_conn.use_ssl = [:use_ssl] http_conn.verify_mode = [:ssl_verify_mode] http_conn end |
#make_request(http_method, path, body = '', headers = {}, form_params = {}) ⇒ Object
38 39 40 41 42 43 44 45 46 47 |
# File 'lib/fbox/http_client.rb', line 38 def make_request(http_method, path, body='', headers={}, form_params = {}) request = Net::HTTP.const_get(http_method.to_s.capitalize).new(path, headers) request.body = body unless body.nil? (request) if [:use_cookies] request.set_form_data(form_params) if !form_params.empty? && http_method.to_s.capitalize == 'Post' response = http_conn(uri).request(request) (response) if [:use_cookies] response end |
#request(*args) ⇒ Object
65 66 67 68 69 |
# File 'lib/fbox/http_client.rb', line 65 def request(*args) response = make_request(*args) raise HTTPError.new(response) unless response.kind_of?(Net::HTTPSuccess) response end |
#uri ⇒ Object
61 62 63 |
# File 'lib/fbox/http_client.rb', line 61 def uri URI.parse([:site]) end |