Skip to content
This repository has been archived by the owner on Nov 9, 2022. It is now read-only.

Commit

Permalink
Merge pull request #386 from grtjn/365-howto-help
Browse files Browse the repository at this point in the history
Fixed #365: added howto help based on wiki pages
  • Loading branch information
dmcassel committed Mar 31, 2015
2 parents 70df03b + dc0b9eb commit f7fc1cb
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 9 deletions.
3 changes: 2 additions & 1 deletion deploy/lib/MLClient.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def build_request_params(url, verb)
}
end

def go(url, verb, headers = {}, params = nil, body = nil)
def go(url, verb, headers = {}, params = nil, body = nil, xcc = false)
logger.debug(%Q{[#{verb.upcase}]\t#{url}})
password_prompt
request_params = build_request_params(url, verb)
Expand All @@ -97,6 +97,7 @@ def go(url, verb, headers = {}, params = nil, body = nil)
request_params[:request].body = body
end

request_params[:request].use_xcc(xcc)
response = get_http.request request_params
response.value
response
Expand Down
3 changes: 2 additions & 1 deletion deploy/lib/RoxyHttp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def set_path(path)
@path = path
end
end

module HTTPHeader
@@nonce_count = -1
CNONCE = Digest::MD5.hexdigest "%x" % (Time.now.to_i + rand(65535))
Expand Down Expand Up @@ -318,6 +318,7 @@ def start(request_params)
@http.ca_file = ca_file
end
end

# open connection
@http.start
end
Expand Down
52 changes: 52 additions & 0 deletions deploy/lib/server_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,58 @@ def self.build_element_index
end
end

def self.howto
begin
optional_require 'open-uri'
optional_require 'nokogiri'

search = ARGV.first

doc = Nokogiri::HTML(open("https://github.com/marklogic/roxy/wiki/_pages"))

pages = doc.css('.content').select do |page|
search == nil or page.text.downcase().include? search
end

selected = 1

if pages.length > 1
count = 0
pages.each do |page|
count = count + 1
puts "#{count} - #{page.text}\n\thttps://github.com/#{page.xpath('a/@href').text}"
end

print "Select a page: "
selected = STDIN.gets.chomp().to_i
if selected == 0
return
end

if selected > pages.length
selected = pages.length
end
end

count = 0
pages.each do |page|
count = count + 1
if count == selected

puts "\n#{page.text}\n\thttps://github.com/#{page.xpath('a/@href').text}"

uri = "https://github.com/#{page.xpath('a/@href').text}"
doc = Nokogiri::HTML(open(uri))

puts doc.css('.markdown-body').text.gsub(/\n\n\n+/, "\n\n")

end
end
rescue NameError => e
puts "Missing library: #{e}"
end
end

def execute_query(query, properties = {})
r = nil
if @server_version == 4
Expand Down
7 changes: 7 additions & 0 deletions deploy/lib/util.rb
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,13 @@ def present?
def to_b
present? && ['true', 'TRUE', 'yes', 'YES', 'y', 'Y', 't', 'T'].include?(self)
end

def optional_require(feature)
begin
require feature
rescue LoadError
end
end
end

def parse_json(body)
Expand Down
24 changes: 17 additions & 7 deletions deploy/lib/xcc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,24 @@ class HTTPGenericRequest
def set_path(path)
@path = path
end


alias_method :original_write_header, :write_header

def use_xcc(bool)
@use_xcc = bool
end

def write_header(sock, ver, path)
buf = "#{@method} #{path} XDBC/1.0\r\n"
each_capitalized do |k,v|
buf << "#{k}: #{v}\r\n"
if @use_xcc
buf = "#{@method} #{path} XDBC/1.0\r\n"
each_capitalized do |k,v|
buf << "#{k}: #{v}\r\n"
end
buf << "\r\n"
sock.write buf
else
original_write_header(sock, ver, path)
end
buf << "\r\n"
sock.write buf
end
end

Expand Down Expand Up @@ -152,7 +162,7 @@ def load_buffer(uri, buffer, options)

def go(url, verb, headers = {}, params = nil, body = nil)
headers['User-Agent'] = "Roxy RubyXCC/#{RUBY_XCC_VERSION} MarkXDBC/#{XCC_VERSION}"
super(url, verb, headers, params, body)
super(url, verb, headers, params, body, true)
end

def get_files(path, options = {}, data = [])
Expand Down

0 comments on commit f7fc1cb

Please sign in to comment.