Module: Exegesis::Http

Extended by:
Http
Included in:
Http, Server
Defined in:
lib/exegesis/utils/http.rb

Instance Method Summary collapse

Instance Method Details

#delete(url, headers = {}) ⇒ Object



39
40
41
# File 'lib/exegesis/utils/http.rb', line 39

def delete url, headers={}
  JSON.parse(RestClient.delete(url, headers))
end

#escape_id(id) ⇒ Object



17
18
19
20
21
22
23
24
25
# File 'lib/exegesis/utils/http.rb', line 17

def escape_id id
  if %r{^_design/(.*)/_view/(.*)} =~ id
    "_design/#{CGI.escape($1)}/_view/#{CGI.escape($2)}"
  elsif /^_design\/(.*)/ =~ id
    "_design/#{CGI.escape($1)}"
  else 
    CGI.escape(id)
  end
end

#format_url(url, params = {}) ⇒ Object



6
7
8
9
10
11
12
13
14
15
# File 'lib/exegesis/utils/http.rb', line 6

def format_url url, params={}
  if params && !params.empty?
    query = params.map do |key, value|
      value = value.to_json if [:key, :startkey, :endkey, :keys].include?(key)
      "#{key}=#{CGI.escape(value.to_s)}"
    end.join('&')
    url = "#{url}?#{query}"
  end
  url
end

#get(url, headers = {}) ⇒ Object



27
28
29
# File 'lib/exegesis/utils/http.rb', line 27

def get url, headers={}
  JSON.parse(RestClient.get(url, headers), :max_nesting => false)
end

#post(url, body = '', headers = {}) ⇒ Object



31
32
33
# File 'lib/exegesis/utils/http.rb', line 31

def post url, body='', headers={}
  JSON.parse(RestClient.post(url, body, headers))
end

#put(url, body = '', headers = {}) ⇒ Object



35
36
37
# File 'lib/exegesis/utils/http.rb', line 35

def put url, body='', headers={}
  JSON.parse(RestClient.put(url, body, headers))
end