Class: EPC::Client::JsonClient

Inherits:
HttpClient show all
Defined in:
lib/epc/client/json_client.rb

Instance Method Summary collapse

Methods inherited from BaseClient

#initialize, #request

Constructor Details

This class inherits a constructor from EPC::Client::BaseClient

Instance Method Details

#delete(url, payload = {}) ⇒ Object



39
40
41
42
43
44
45
46
47
48
# File 'lib/epc/client/json_client.rb', line 39

def delete(url, payload = {})
  debug_request(:delete, url, payload) if @debug
  begin
    status, body, headers = super(url, payload.to_json, 'application/json')
    debug_response(status, json_parse(body), headers) if @debug
    [status, json_parse(body), headers]
  rescue JSON::ParserError
    raise BadResponse, "Invalid response received. Response status: #{status}", body
  end
end

#get(url, skip_signature = false) ⇒ Object



6
7
8
9
10
11
12
13
14
15
# File 'lib/epc/client/json_client.rb', line 6

def get(url, skip_signature = false)
  debug_request(:get, url) if @debug
  begin
    status, body, headers = super(url, 'application/json', skip_signature)
    debug_response(status, json_parse(body), headers) if @debug
    [status, json_parse(body), headers]
  rescue JSON::ParserError
    raise BadResponse, "Invalid response received. Response status: #{status}", body
  end
end

#post(url, payload = {}, skip_signature = false) ⇒ Object



17
18
19
20
21
22
23
24
25
26
# File 'lib/epc/client/json_client.rb', line 17

def post(url, payload = {}, skip_signature = false)
  debug_request(:post, url, payload) if @debug
  begin
    status, body, headers = super(url, payload.to_json, 'application/json', {}, skip_signature)
    debug_response(status, json_parse(body), headers) if @debug
    [status, json_parse(body), headers]
  rescue JSON::ParserError
    raise BadResponse, "Invalid response received. Response status: #{status}", body
  end
end

#put(url, payload = {}) ⇒ Object



28
29
30
31
32
33
34
35
36
37
# File 'lib/epc/client/json_client.rb', line 28

def put(url, payload = {})
  debug_request(:put, url, payload) if @debug
  begin
    status, body, headers = super(url, payload.to_json, 'application/json')
    debug_response(status, json_parse(body), headers) if @debug
    [status, json_parse(body), headers]
  rescue JSON::ParserError
    raise BadResponse, "Invalid response received. Response status: #{status}", body
  end
end