class Redmine::RestClient

Simple REST-aware HTTP client that uses Net::HTTP under the hood to make external requests. Most of its functionality comes from decorators, such as AcceptJson and HttpCaching.

Public Class Methods

new( default_headers: {}, base_uri: nil, http: Net::HTTP.new(base_uri.host, base_uri.port) ) click to toggle source

Initialize a new RestClient using default headers to be included in all requests, and optionally a customized HTTP client. If not providing a custom http option, you can provide a base_uri that will be used to create a new Net::HTTP instance.

# File lib/redmine/rest_client.rb, line 14
def initialize(
  default_headers: {},
  base_uri: nil,
  http: Net::HTTP.new(base_uri.host, base_uri.port)
)
  @http = http
  @default_headers = default_headers
end

Public Instance Methods

get(path, headers = {}) click to toggle source

Perform a GET requests to a given path, optionally with additional headers. Returns raw Net::HTTPResponse objects.

# File lib/redmine/rest_client.rb, line 25
def get(path, headers = {})
  request = Net::HTTP::Get.new(path)
  @default_headers.merge(headers).each do |key, value|
    request[key] = value
  end
  @http.request(request)
end