Module: Poms::Api::Client

Extended by:
Drivers::NetHttp
Defined in:
lib/poms/api/client.rb

Overview

The Client module isolates all HTTP interactions, regardless of the driver module to implement the actual operations. Use the Client module to build signed requests and execute them.

See Also:

Constant Summary

Constants included from Drivers::NetHttp

Drivers::NetHttp::NET_HTTP_ERRORS

Class Method Summary collapse

Methods included from Drivers::NetHttp

execute

Class Method Details

.get(uri, credentials, headers = {}) ⇒ Object



18
19
20
21
22
23
24
25
26
27
# File 'lib/poms/api/client.rb', line 18

def get(uri, credentials, headers = {})
  handle_response(
    execute(
      Auth.sign(
        prepare_get(uri, headers),
        credentials
      )
    )
  )
end

.handle_response(response) ⇒ Object



40
41
42
43
44
45
46
47
# File 'lib/poms/api/client.rb', line 40

def handle_response(response)
  case response.code
  when 400..499 then raise Errors::HttpMissingError, response.code
  when 500..599 then raise Errors::HttpServerError, response.code
  else
    response
  end
end

.post(uri, body, credentials, headers = {}) ⇒ Object



29
30
31
32
33
34
35
36
37
38
# File 'lib/poms/api/client.rb', line 29

def post(uri, body, credentials, headers = {})
  handle_response(
    execute(
      Auth.sign(
        prepare_post(uri, body, headers),
        credentials
      )
    )
  )
end

.prepare_get(uri, headers = {}) ⇒ Object



49
50
51
# File 'lib/poms/api/client.rb', line 49

def prepare_get(uri, headers = {})
  Request.get(uri, nil, headers)
end

.prepare_post(uri, body, headers = {}) ⇒ Object



53
54
55
# File 'lib/poms/api/client.rb', line 53

def prepare_post(uri, body, headers = {})
  Request.post(uri, body, headers)
end