Module: Gerry::Api::Request

Included in:
Client
Defined in:
lib/gerry/api/request.rb

Overview

:nodoc:

Defined Under Namespace

Classes: RequestError

Instance Method Summary collapse

Instance Method Details

#auth_url(url) ⇒ Object



27
28
29
# File 'lib/gerry/api/request.rb', line 27

def auth_url(url)
  (@username && @password) ? "/a#{url}" : url
end

#delete(url) ⇒ Object



41
42
43
44
# File 'lib/gerry/api/request.rb', line 41

def delete(url)
  response = perform_request(:delete, auth_url(url))
  parse(response)
end

#get(url) ⇒ Object



22
23
24
25
# File 'lib/gerry/api/request.rb', line 22

def get(url)
  response = perform_request(:get, auth_url(url))
  parse(response)
end

#map_options(options) ⇒ String

Get the mapped options.

Parameters:

  • or (Array)

    [Hash] options the query parameters.

Returns:

  • (String)

    the mapped options.



13
14
15
16
17
18
19
20
# File 'lib/gerry/api/request.rb', line 13

def map_options(options)
  if options.is_a?(Array)
    options.map { |v| "#{v}" }.join('&')
  elsif options.is_a?(Hash)
    # Gerrit expects repeated parameters (o=A&o=B), never a comma-joined list.
    options.flat_map { |k, v| Array(v).map { |value| "#{k}=#{value}" } }.join('&')
  end
end

#post(url, body, is_json = true) ⇒ Object



36
37
38
39
# File 'lib/gerry/api/request.rb', line 36

def post(url, body, is_json = true)
  response = perform_request(:post, auth_url(url), body, is_json)
  parse(response)
end

#put(url, body = nil, is_json = true) ⇒ Object



31
32
33
34
# File 'lib/gerry/api/request.rb', line 31

def put(url, body = nil, is_json = true)
  response = perform_request(:put, auth_url(url), body, is_json)
  parse(response)
end