Module: Sonar::Request

Included in:
Client, RequestIterator
Defined in:
lib/sonar/request.rb

Defined Under Namespace

Classes: RequestIterator

Instance Method Summary collapse

Instance Method Details

#extract_params(params) ⇒ Object



6
7
8
9
# File 'lib/sonar/request.rb', line 6

def extract_params(params)
  # extract something from Sonar if needed
  params
end

#get(path, options = {}) ⇒ Object



11
12
13
# File 'lib/sonar/request.rb', line 11

def get(path, options = {})
  request(:get, path, options)
end

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



15
16
17
# File 'lib/sonar/request.rb', line 15

def post(path, options = {})
  request(:post, path, options)
end

#put(path, options = {}) ⇒ Object



19
20
21
# File 'lib/sonar/request.rb', line 19

def put(path, options = {})
  request(:put, path, options)
end

#request(method, path, options) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/sonar/request.rb', line 23

def request(method, path, options)
  response = connection.send(method) do |request|
    options.delete(:connection)
    case method
    when :get
      request.url(path, options)
    when :post, :put
      request.path = path
      request.body = MultiJson.encode(options) unless options.empty?
    end
  end

  response.body
end