Class: ContentGateway::Request

Inherits:
Object
  • Object
show all
Defined in:
lib/content_gateway/request.rb

Instance Method Summary collapse

Constructor Details

#initialize(method, url, headers = {}, payload = {}, proxy = nil, params = {}) ⇒ Request

Returns a new instance of Request.



3
4
5
6
7
8
9
10
11
# File 'lib/content_gateway/request.rb', line 3

def initialize(method, url, headers = {}, payload = {}, proxy = nil, params = {})
  data = { method: method, url: url, proxy: proxy }.tap do |h|
    h[:payload] = payload if payload.present?
    h[:headers] = headers if headers.present?
    h = load_ssl_params(h, params) if params.has_key?(:ssl_certificate)
  end
  RestClient.proxy = proxy
  @client = RestClient::Request.new(data)
end

Instance Method Details

#executeObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/content_gateway/request.rb', line 13

def execute
  @client.execute.to_s
rescue RestClient::ResourceNotFound => e1
  raise ContentGateway::ResourceNotFound.new url, e1

rescue RestClient::Unauthorized => e2
  raise ContentGateway::UnauthorizedError.new url, e2

rescue RestClient::UnprocessableEntity => e3
  raise ContentGateway::ValidationError.new url, e3

rescue RestClient::Forbidden => e4
  raise ContentGateway::Forbidden.new url, e4

rescue RestClient::Conflict => e5
  raise ContentGateway::ConflictError.new url, e5

rescue RestClient::Exception => e6
  status_code = e6.http_code
  if status_code && status_code < 500
    raise e6
  else
    raise ContentGateway::ServerError.new url, e6, status_code
  end

rescue StandardError => e7
  raise ContentGateway::ConnectionFailure.new url, e7
end