Class: CQ::HttpClient
- Inherits:
-
RequestClient
- Object
- RequestClient
- CQ::HttpClient
- Defined in:
- lib/cq/http_client.rb
Constant Summary collapse
- DEFAULT_OPTIONS =
{ :username => 'admin', :password => 'admin' }
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
- #basic_auth_http_conn ⇒ Object
- #http_conn(uri) ⇒ Object
-
#initialize(options) ⇒ HttpClient
constructor
A new instance of HttpClient.
- #make_request(http_method, path, body = '', headers = {}) ⇒ Object
- #uri ⇒ Object
Methods inherited from RequestClient
Constructor Details
#initialize(options) ⇒ HttpClient
15 16 17 |
# File 'lib/cq/http_client.rb', line 15 def initialize() = DEFAULT_OPTIONS.merge() end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
13 14 15 |
# File 'lib/cq/http_client.rb', line 13 def end |
Instance Method Details
#basic_auth_http_conn ⇒ Object
27 28 29 |
# File 'lib/cq/http_client.rb', line 27 def basic_auth_http_conn http_conn(uri) end |
#http_conn(uri) ⇒ Object
31 32 33 34 35 36 37 38 39 |
# File 'lib/cq/http_client.rb', line 31 def http_conn(uri) # if @options[:proxy_address] # http_class = Net::HTTP::Proxy(@options[:proxy_address], @options[:proxy_port] ? @options[:proxy_port] : 80) # else # http_class = Net::HTTP # end http_conn = Net::HTTP.new(uri.host, uri.port) http_conn end |
#make_request(http_method, path, body = '', headers = {}) ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/cq/http_client.rb', line 19 def make_request(http_method, path, body='', headers={}) request = Net::HTTP.const_get(http_method.to_s.capitalize).new(path, headers) request.body = body unless body.nil? request.basic_auth([:username], [:password]) response = basic_auth_http_conn.request(request) response end |
#uri ⇒ Object
41 42 43 |
# File 'lib/cq/http_client.rb', line 41 def uri uri = URI.parse([:site]) end |