Class: ApimaticCalculator::HttpClient

Inherits:
Object
  • Object
show all
Defined in:
lib/apimatic_calculator/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)


28
29
30
31
# File 'lib/apimatic_calculator/http/http_client.rb', line 28

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

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

Get a DELETE 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.

  • The (Hash, Optional)

    context for the HTTP Request.



112
113
114
115
116
117
118
119
120
121
# File 'lib/apimatic_calculator/http/http_client.rb', line 112

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

#execute_as_binary(_http_request) ⇒ Object

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

Parameters:

Raises:

  • (NotImplementedError)


21
22
23
24
# File 'lib/apimatic_calculator/http/http_client.rb', line 21

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)


14
15
16
17
# File 'lib/apimatic_calculator/http/http_client.rb', line 14

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

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

Get a GET HttpRequest object.

Parameters:

  • The (String)

    URL to send the request to.

  • The (Hash, Optional)

    headers for the HTTP Request.

  • The (Hash, Optional)

    context for the HTTP Request.



37
38
39
40
41
42
43
44
# File 'lib/apimatic_calculator/http/http_client.rb', line 37

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

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

Get a HEAD HttpRequest object.

Parameters:

  • The (String)

    URL to send the request to.

  • The (Hash, Optional)

    headers for the HTTP Request.

  • The (Hash, Optional)

    context for the HTTP Request.



50
51
52
53
54
55
56
57
# File 'lib/apimatic_calculator/http/http_client.rb', line 50

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

#patch(query_url, headers: {}, parameters: {}, context: {}) ⇒ 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.

  • The (Hash, Optional)

    context for the HTTP Request.



96
97
98
99
100
101
102
103
104
105
# File 'lib/apimatic_calculator/http/http_client.rb', line 96

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

#post(query_url, headers: {}, parameters: {}, context: {}) ⇒ 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.

  • The (Hash, Optional)

    context for the HTTP Request.



64
65
66
67
68
69
70
71
72
73
# File 'lib/apimatic_calculator/http/http_client.rb', line 64

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

#put(query_url, headers: {}, parameters: {}, context: {}) ⇒ 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.

  • The (Hash, Optional)

    context for the HTTP Request.



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

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