Class: ActiveDocument::MarkLogicHTTP
- Inherits:
-
Object
- Object
- ActiveDocument::MarkLogicHTTP
- Defined in:
- lib/ActiveDocument/mark_logic_http.rb
Instance Method Summary collapse
-
#initialize(uri, user_name, password) ⇒ MarkLogicHTTP
constructor
A new instance of MarkLogicHTTP.
- #send_corona_request(uri, verb = :get, body = "", post_fields = nil) ⇒ nil if there if no uri or it is an empty string. Otherwise, returns the http response
Constructor Details
#initialize(uri, user_name, password) ⇒ MarkLogicHTTP
Returns a new instance of MarkLogicHTTP.
65 66 67 68 69 |
# File 'lib/ActiveDocument/mark_logic_http.rb', line 65 def initialize(uri, user_name, password) @url = URI.parse(uri) @user_name = user_name @password = password end |
Instance Method Details
#send_corona_request(uri, verb = :get, body = "", post_fields = nil) ⇒ nil if there if no uri or it is an empty string. Otherwise, returns the http response
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/ActiveDocument/mark_logic_http.rb', line 76 def send_corona_request(uri, verb=:get, body="", post_fields=nil) return nil if uri.nil? or uri.empty? target_url = @url + URI.escape(uri) http = Net::HTTP.new(target_url.host, target_url.port) if target_url.query endpoint = target_url.path + "?" + target_url.query else endpoint = target_url.path end case verb when :post req = Net::HTTP::Post.new(endpoint) req.set_form_data(post_fields) unless post_fields.nil? #puts URI.decode_www_form(req.body) when :put req = Net::HTTP::Put.new(endpoint) when :get req = Net::HTTP::Get.new(endpoint) when :delete req = Net::HTTP::Delete.new(endpoint) else req = Net::HTTP::Get.new(endpoint) # safe default end if ((! body.nil?) and (verb == :put or verb == :post) ) then if (req.body.nil?) then req.body = body else req.body << body end end res = http.head(target_url.request_uri) #puts "body::::: #{req.body}" unless verb == :put req.digest_auth(@user_name, @password, res) res = http.request(req) case res when Net::HTTPSuccess, Net::HTTPRedirection #puts res.body res.body else #puts req.path raise res.error! end end |