Module: Addressable::Rest

Defined in:
lib/addressable/rest.rb,
lib/addressable/rest/version.rb

Constant Summary collapse

VERSION =
"0.0.3"

Instance Method Summary collapse

Instance Method Details

#get(options = {}) ⇒ Object



9
10
11
12
13
14
15
16
17
18
# File 'lib/addressable/rest.rb', line 9

def get(options = {})
  url = dup.normalize
  response = Net::HTTP.start(url.host, url.port) do |request|
    request.get(url.request_uri)
  end

  decode_options = {}
  decode_options[:symbolize_keys] = true if options[:symbolize_keys]
  MultiJson.decode(response.body, decode_options)
end

#post(data, options = {}) ⇒ Object



20
21
22
23
24
25
26
27
28
29
# File 'lib/addressable/rest.rb', line 20

def post(data, options = {})
  url = dup.normalize
  response = Net::HTTP.start(url.host, url.port) do |request|
    request.post(url.request_uri, data.to_query)
  end

  decode_options = {}
  decode_options[:symbolize_keys] = true if options[:symbolize_keys]
  MultiJson.decode(response.body, decode_options)
end