Class: Redmine::RestClient

Inherits:
Object
  • Object
show all
Defined in:
lib/redmine/rest_client.rb

Overview

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.

Instance Method Summary collapse

Constructor Details

#initialize(default_headers: {}, base_uri: nil, http: Net::HTTP.new(base_uri.host, base_uri.port)) ⇒ RestClient

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.



14
15
16
17
18
19
20
21
# 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

Instance Method Details

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

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



25
26
27
28
29
30
31
# 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