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) ⇒ Object



33
34
35
# File 'lib/exegesis/utils/http.rb', line 33

def delete url
  JSON.parse(RestClient.delete(url))
end

#escape_id(id) ⇒ Object



17
18
19
# File 'lib/exegesis/utils/http.rb', line 17

def escape_id id
  /^_design\/(.*)/ =~ id ? "_design/#{CGI.escape($1)}" : CGI.escape(id) 
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) ⇒ Object



21
22
23
# File 'lib/exegesis/utils/http.rb', line 21

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

#post(url, body = '') ⇒ Object



25
26
27
# File 'lib/exegesis/utils/http.rb', line 25

def post url, body=''
  JSON.parse(RestClient.post(url, (body || '').to_json))
end

#put(url, body = '') ⇒ Object



29
30
31
# File 'lib/exegesis/utils/http.rb', line 29

def put url, body=''
  JSON.parse(RestClient.put(url, (body || '').to_json))
end