Class: Raas::HttpClient

Inherits:
Object
  • Object
show all
Defined in:
lib/raas/http/http_client.rb

Overview

An interface for the methods that an HTTP Client must implement.

This class should not be instantiated but should be used as a base class for HTTP Client classes.

Direct Known Subclasses

FaradayClient

Instance Method Summary collapse

Instance Method Details

#convert_response(_response) ⇒ Object

Converts the HTTP Response from the client to an HttpResponse object.

Parameters:

  • The (Dynamic)

    response object received from the client.

Raises:

  • (NotImplementedError)


26
27
28
29
# File 'lib/raas/http/http_client.rb', line 26

def convert_response(_response)
  raise NotImplementedError, 'This method needs
    to be implemented in a child class.'
end

#delete(query_url, headers: {}, parameters: {}) ⇒ Object

Get a DELETE HttpRequest object.

Parameters:

  • The (String)

    URL to send the request to.

  • The (Hash, Optional)

    headers for the HTTP Request.



93
94
95
96
97
98
99
100
# File 'lib/raas/http/http_client.rb', line 93

def delete(query_url,
           headers: {},
           parameters: {})
  HttpRequest.new(HttpMethodEnum::DELETE,
                  query_url,
                  headers: headers,
                  parameters: parameters)
end

#execute_as_binary(_http_request) ⇒ Object

Execute an HttpRequest when the response is expected to be binary.

Parameters:

Raises:

  • (NotImplementedError)


19
20
21
22
# File 'lib/raas/http/http_client.rb', line 19

def execute_as_binary(_http_request)
  raise NotImplementedError, 'This method needs
    to be implemented in a child class.'
end

#execute_as_string(_http_request) ⇒ Object

Execute an HttpRequest when the response is expected to be a string.

Parameters:

Raises:

  • (NotImplementedError)


12
13
14
15
# File 'lib/raas/http/http_client.rb', line 12

def execute_as_string(_http_request)
  raise NotImplementedError, 'This method needs
    to be implemented in a child class.'
end

#get(query_url, headers: {}) ⇒ Object

Get a GET HttpRequest object.

Parameters:

  • The (String)

    URL to send the request to.

  • The (Hash, Optional)

    headers for the HTTP Request.



34
35
36
37
38
39
# File 'lib/raas/http/http_client.rb', line 34

def get(query_url,
        headers: {})
  HttpRequest.new(HttpMethodEnum::GET,
                  query_url,
                  headers: headers)
end

#head(query_url, headers: {}) ⇒ Object

Get a HEAD HttpRequest object.

Parameters:

  • The (String)

    URL to send the request to.

  • The (Hash, Optional)

    headers for the HTTP Request.



44
45
46
47
48
49
# File 'lib/raas/http/http_client.rb', line 44

def head(query_url,
         headers: {})
  HttpRequest.new(HttpMethodEnum::HEAD,
                  query_url,
                  headers: headers)
end

#patch(query_url, headers: {}, parameters: {}) ⇒ Object

Get a PATCH HttpRequest object.

Parameters:

  • The (String)

    URL to send the request to.

  • The (Hash, Optional)

    headers for the HTTP Request.

  • The (Hash, Optional)

    parameters for the HTTP Request.



81
82
83
84
85
86
87
88
# File 'lib/raas/http/http_client.rb', line 81

def patch(query_url,
          headers: {},
          parameters: {})
  HttpRequest.new(HttpMethodEnum::PATCH,
                  query_url,
                  headers: headers,
                  parameters: parameters)
end

#post(query_url, headers: {}, parameters: {}) ⇒ Object

Get a POST HttpRequest object.

Parameters:

  • The (String)

    URL to send the request to.

  • The (Hash, Optional)

    headers for the HTTP Request.

  • The (Hash, Optional)

    parameters for the HTTP Request.



55
56
57
58
59
60
61
62
# File 'lib/raas/http/http_client.rb', line 55

def post(query_url,
         headers: {},
         parameters: {})
  HttpRequest.new(HttpMethodEnum::POST,
                  query_url,
                  headers: headers,
                  parameters: parameters)
end

#put(query_url, headers: {}, parameters: {}) ⇒ Object

Get a PUT HttpRequest object.

Parameters:

  • The (String)

    URL to send the request to.

  • The (Hash, Optional)

    headers for the HTTP Request.

  • The (Hash, Optional)

    parameters for the HTTP Request.



68
69
70
71
72
73
74
75
# File 'lib/raas/http/http_client.rb', line 68

def put(query_url,
        headers: {},
        parameters: {})
  HttpRequest.new(HttpMethodEnum::PUT,
                  query_url,
                  headers: headers,
                  parameters: parameters)
end