Module: Backend::ConnectionHelper
- Included in:
- Api::BuildResults::Binaries, Api::BuildResults::Status, Api::BuildResults::Worker, Api::Published, Api::Search, Api::Server
- Defined in:
- connection_helper.rb
Overview
Module that holds the wrapping methods for http requests, are mainly used for simplify the calculation of urls.
The methods get, put, post and delete always will return the body of the response encoded in UTF-8.
Parameters
All the methods need a valid endpoint to connect to, and it
can be provided in two different ways:
-
As a single string. No processing is performed.
-
As an array. In this case the first element needs to be a string with placeholders that will be replaced in the order provided starting with the second element of the array. The placeholders have the same style as ruby symbols.
get(["/build/:project/:package/_result", "Apache", "apache2"]) # => HTTP GET "/build/Apache/apache2/_result"
The options hash is used for providing the params and other
options available.
:params-
Hash with the parameters to be sent as part of the query in the url.
get("/source/Apache/_meta", params: { revision: 42 })
# => HTTP GET "/source/Apache/_meta?revision=42"
:defaults-
Hash with the default parameters values that will be merged with
options[:params].
get("/source/Apache", defaults: { cmd: :copy, revision: 1 }, params: { revision: 42, target: Nginx })
# => HTTP GET "/source/Apache?cmd=copy&revision=42&target=Nginx"
:rename-
Hash with the pairs of params keys to rename before converting the url.
get("/source/Apache/_meta", params: { revision: 42 }, rename: { revision: :rev})
# => HTTP GET "/source/Apache/_meta?rev=42"
:accepted-
Array with the whitelist of keys for the params.
get("/source/Apache/_meta", params: { revision: 42, fake: 2 }, accepted: [:revision, :comment])
# => HTTP GET "/source/Apache/_meta?revision=42"
:expand-
Array of keys to expand using the same name (no [] are used).
get("/source/Apache/_meta", params: { revision: 42, package: ['pack1', 'pack2'] }, expand: [:package])
# => HTTP GET "/source/Apache/_meta?revision=42&package=pack1&package=pack2"
:data-
In the case of
putorpostrequests is the data that will be sent. :headers-
Hash with the headers that will be added to the request.