Class: Served::Backends::HTTParty

Inherits:
Base
  • Object
show all
Defined in:
lib/served/backends/httparty.rb

Overview

HTTParty Backend uses the HTTParty client

Instance Method Summary collapse

Methods inherited from Base

#initialize, #serialize_response

Constructor Details

This class inherits a constructor from Served::Backends::Base

Instance Method Details

#delete(endpoint, id, params = {}) ⇒ Object



38
39
40
41
42
43
44
45
46
# File 'lib/served/backends/httparty.rb', line 38

def delete(endpoint, id, params = {})
  ::HTTParty.delete(template.expand(id:       id,
                                    query:    params,
                                    resource: endpoint).to_s,
                    headers: headers,
                    timeout: timeout)
rescue Errno::ECONNREFUSED
  raise Served::HTTPClient::ConnectionFailed.new(resource)
end

#get(endpoint, id, params = {}) ⇒ Object



8
9
10
11
12
13
14
15
16
# File 'lib/served/backends/httparty.rb', line 8

def get(endpoint, id, params = {})
  ::HTTParty.get(template.expand(id:       id,
                                 query:    params,
                                 resource: endpoint).to_s,
                 headers: headers,
                 timeout: timeout)
rescue Errno::ECONNREFUSED
  raise Served::HTTPClient::ConnectionFailed.new(resource)
end

#post(endpoint, body, params = {}) ⇒ Object



29
30
31
32
33
34
35
36
# File 'lib/served/backends/httparty.rb', line 29

def post(endpoint, body, params = {})
  ::HTTParty.post(template.expand(query: params, resource: endpoint).to_s,
                  body: body,
                  headers: headers,
                  timeout: timeout)
rescue Errno::ECONNREFUSED
  raise Served::HTTPClient::ConnectionFailed.new(resource)
end

#put(endpoint, id, body, params = {}) ⇒ Object



18
19
20
21
22
23
24
25
26
27
# File 'lib/served/backends/httparty.rb', line 18

def put(endpoint, id, body, params = {})
  ::HTTParty.put(template.expand(id:       id,
                                 query:    params,
                                 resource: endpoint).to_s,
                 body:    body,
                 headers: headers,
                 timeout: timeout)
rescue Errno::ECONNREFUSED
  raise Served::HTTPClient::ConnectionFailed.new(resource)
end