lib/geet/gitlab/api_interface.rb in geet-0.1.12 vs lib/geet/gitlab/api_interface.rb in geet-0.2.0

- old
+ new

@@ -26,10 +26,11 @@ end # Send a request. # # Returns the parsed response, or an Array, in case of multipage. + # Where no body is present in the response, nil is returned. # # params: # :api_path: api path, will be appended to the API URL. # for root path, prepend a `/`: # - use `/gists` for `https://api.github.com/gists` @@ -37,22 +38,23 @@ # - use `issues` for `https://api.github.com/myowner/myproject/repos/issues` # :params: (Hash) # :data: (Hash) if present, will generate a POST request, otherwise, a GET # :multipage: set true for paged Github responses (eg. issues); it will make the method # return an array, with the concatenated (parsed) responses - # :http_method: :get, :patch, :post and :put are accepted, but only :patch/:put are meaningful, - # since the others are automatically inferred by :data. + # :http_method: symbol format of the method (:get, :patch, :post, :put and :delete) + # :get and :post are automatically inferred by the present of :data; the other + # cases must be specified. # def send_request(api_path, params: nil, data: nil, multipage: false, http_method: nil) address = api_url(api_path) # filled only on :multipage parsed_responses = [] loop do response = send_http_request(address, params: params, data: data, http_method: http_method) - parsed_response = JSON.parse(response.body) + parsed_response = JSON.parse(response.body) if response.body if error?(response) formatted_error = decode_and_format_error(parsed_response) raise(formatted_error) end @@ -124,15 +126,17 @@ http_method ||= data ? :post : :get case http_method when :get Net::HTTP::Get + when :delete + Net::HTTP::Delete when :patch Net::HTTP::Patch - when :put - Net::HTTP::Put when :post Net::HTTP::Post + when :put + Net::HTTP::Put else raise "Unsupported HTTP method: #{http_method.inspect}" end end end