Module: MangoApi::HttpClient

Defined in:
lib/mangopay/api/http_client.rb

Overview

Handles HTTP communication.

Constant Summary collapse

LOG =
MangoPay::LogProvider.provide(self)

Class Method Summary collapse

Class Method Details

.api_headersObject

Provides a hash containing necessary headers for API calls.



94
95
96
97
# File 'lib/mangopay/api/http_client.rb', line 94

def api_headers
  initialize_headers unless @default_headers
  @default_headers
end

.get(uri, filter_request = nil) ⇒ Hash

Launches a self-configuring GET request, with headers required by the API. Applies filters if provided.

Parameters:

  • +uri+ (URI)

    request URI

  • +filters+ (FilterRequest)

    response entity filtering object

Returns:

  • (Hash)

    hashed request response JSON body



74
75
76
77
78
79
# File 'lib/mangopay/api/http_client.rb', line 74

def get(uri, filter_request = nil)
  request proc { |ury, &block| get_raw(ury, &block) },
          uri,
          nil,
          filter_request
end

.get_raw(uri, &block) ⇒ Hash

Launches a fully customizable GET request. Expects to be given a block to which it yields the request object before execution to be configured.

Parameters:

  • +uri+ (URI)

    request URI

Returns:

  • (Hash)

    hashed request response JSON body



87
88
89
90
91
# File 'lib/mangopay/api/http_client.rb', line 87

def get_raw(uri, &block)
  request_raw Net::HTTP::Get,
              uri,
              &block
end

.post(uri, entity, id_key = nil) ⇒ Hash

Launches a self-configuring POST request, with headers required by the API.

Parameters:

  • +uri+ (String)

    request URI

  • +entity+ (Object)

    object to be JSON-serialized and sent as body Must include Jsonifier.

  • +id_key+ (String)

    idempotency key for future response replication

Returns:

  • (Hash)

    hashed request response JSON body



22
23
24
25
26
27
28
# File 'lib/mangopay/api/http_client.rb', line 22

def post(uri, entity, id_key = nil)
  request proc { |ury, &block| post_raw(ury, &block) },
          uri,
          entity,
          nil,
          id_key
end

.post_raw(uri, &block) ⇒ Hash

Launches a fully customizable POST request. Expects to be given a block to which it yields the request object before execution to be configured.

Parameters:

  • +uri+ (String)

    request URI

Returns:

  • (Hash)

    hashed request response JSON body



36
37
38
39
40
# File 'lib/mangopay/api/http_client.rb', line 36

def post_raw(uri, &block)
  request_raw Net::HTTP::Post,
              uri,
              &block
end

.put(uri, entity = nil) ⇒ Hash

Launches a self-configuring PUT request, with headers required by the API.

Parameters:

  • +uri+ (URI)

    request URI

  • +entity+ (Object)

    object to be JSON-serialized and sent as body Must include Jsonifier.

Returns:

  • (Hash)

    hashed request response JSON body



49
50
51
52
53
# File 'lib/mangopay/api/http_client.rb', line 49

def put(uri, entity = nil)
  request proc { |ury, &block| put_raw(ury, &block) },
          uri,
          entity
end

.put_raw(uri, &block) ⇒ Hash

Launches a fully customizable PUT request. Expects to be given a block to which it yields the request object before execution to be configured.

Parameters:

  • +uri+ (String)

    request URI

Returns:

  • (Hash)

    hashed request response JSON body



61
62
63
64
65
# File 'lib/mangopay/api/http_client.rb', line 61

def put_raw(uri, &block)
  request_raw Net::HTTP::Put,
              uri,
              &block
end