forked from justinko/sunspot-rails-http-basic-auth
/
net_http.rb
42 lines (42 loc) · 1.2 KB
/
net_http.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# module RSolr
# module Connection
# class NetHttp
#
# def get(path, params={})
# url = build_url(path, params)
# net_http_response = basic_auth_get_request(url)
# create_http_context(net_http_response, url, path, params)
# end
#
# def post(path, data, params={}, headers={})
# url = build_url(path, params)
# net_http_response = basic_auth_post_request(url, data, headers)
# create_http_context(net_http_response, url, path, params, data, headers)
# end
#
# private
#
# def basic_auth_get_request(url)
# rails_logger "SOLR GET: #{url}"
# req = add_basic_auth(Net::HTTP::Get.new(url))
# connection.request(req)
# end
#
# def basic_auth_post_request(url, data, headers)
# rails_logger "SOLR POST: #{url}"
# req = add_basic_auth(Net::HTTP::Post.new(url, headers))
# connection.request(req, data)
# end
#
# def add_basic_auth(req)
# req.basic_auth(uri.user, uri.password) if uri.user and uri.password
# req
# end
#
# def rails_logger(text)
# Rails.logger.debug(text) if defined?(Rails)
# end
#
# end
# end
# end