Class: GSolr::Connection::NetHttp
- Inherits:
-
Object
- Object
- GSolr::Connection::NetHttp
- Includes:
- Requestable
- Defined in:
- lib/gsolr/connection/net_http.rb
Instance Attribute Summary
Attributes included from Requestable
Instance Method Summary collapse
-
#build_url(path, params = {}) ⇒ Object
accepts a path/string and optional hash of query params.
- #connection ⇒ Object
- #create_http_context(net_http_response, url, path, params, data = nil, headers = {}) ⇒ Object
- #get(path, params = {}) ⇒ Object
- #post(path, data, params = {}, headers = {}) ⇒ Object
Methods included from Requestable
Methods included from Utils
#build_param, #bytesize, #encode_utf8, #escape, #hash_to_query
Instance Method Details
#build_url(path, params = {}) ⇒ Object
accepts a path/string and optional hash of query params
48 49 50 51 52 |
# File 'lib/gsolr/connection/net_http.rb', line 48 def build_url(path, params={}) full_path = @uri.path + path super full_path, params, @uri.query end |
#connection ⇒ Object
12 13 14 |
# File 'lib/gsolr/connection/net_http.rb', line 12 def connection @connection ||= Net::HTTP.new(@uri.host, @uri.port) end |
#create_http_context(net_http_response, url, path, params, data = nil, headers = {}) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/gsolr/connection/net_http.rb', line 28 def create_http_context(net_http_response, url, path, params, data=nil, headers={}) full_url = "#{@uri.scheme}://#{@uri.host}" full_url += ":#{@uri.port}" if @uri.port full_url += url return { :status_code => net_http_response.code.to_i, :url => full_url, :body => encode_utf8(net_http_response.body), :path => path, :params => params, :data => data, :headers => headers, :message => net_http_response. } end |
#get(path, params = {}) ⇒ Object
16 17 18 19 20 |
# File 'lib/gsolr/connection/net_http.rb', line 16 def get(path, params={}) url = self.build_url path, params net_http_response = self.connection.get url create_http_context net_http_response, url, path, params end |
#post(path, data, params = {}, headers = {}) ⇒ Object
22 23 24 25 26 |
# File 'lib/gsolr/connection/net_http.rb', line 22 def post(path, data, params={}, headers={}) url = self.build_url path, params net_http_response = self.connection.post url, data, headers create_http_context net_http_response, url, path, params, data, headers end |