Module: Contentful::Management::HTTPClient

Included in:
Client
Defined in:
lib/contentful/management/http_client.rb

Overview

Thin HTTP Client with Restful Operations

Instance Method Summary collapse

Instance Method Details

#delete_http(url, params, headers = {}, proxy = {}) ⇒ HTTP::Response

Delete Request

Parameters:

  • url (String)
  • params (Hash)
  • headers (Hash) (defaults to: {})

Returns:

  • (HTTP::Response)


34
35
36
# File 'lib/contentful/management/http_client.rb', line 34

def delete_http(url, params, headers = {}, proxy = {})
  http_send(:delete, url, { params: params }, headers, proxy)
end

#get_http(url, query, headers = {}, proxy = {}) ⇒ HTTP::Response

Get Request

Parameters:

  • url (String)
  • query (Hash)
  • headers (Hash) (defaults to: {})

Returns:

  • (HTTP::Response)


12
13
14
# File 'lib/contentful/management/http_client.rb', line 12

def get_http(url, query, headers = {}, proxy = {})
  http_send(:get, url, { params: query }, headers, proxy)
end

#http_send(type, url, params, headers, proxy) ⇒ HTTP::Response

HTTP Helper Abtracts the Proxy/No-Proxy logic

Parameters:

  • type (Symbol)
  • url (String)
  • params (Hash)
  • headers (Hash)
  • proxy (Hash)

Returns:

  • (HTTP::Response)


77
78
79
80
# File 'lib/contentful/management/http_client.rb', line 77

def http_send(type, url, params, headers, proxy)
  return proxy_send(type, url, params, headers, proxy) unless proxy[:host].nil?
  HTTP[headers].public_send(type, url, params)
end

#post_http(url, params, headers = {}, proxy = {}) ⇒ HTTP::Response

Post Request

Parameters:

  • url (String)
  • params (Hash)
  • headers (Hash) (defaults to: {})

Returns:

  • (HTTP::Response)


23
24
25
# File 'lib/contentful/management/http_client.rb', line 23

def post_http(url, params, headers = {}, proxy = {})
  http_send(:post, url, { json: params }, headers, proxy)
end

#proxy_send(type, url, params, headers, proxy) ⇒ HTTP::Response

Proxy Helper

Parameters:

  • type (Symbol)
  • url (String)
  • params (Hash)
  • headers (Hash)
  • proxy (Hash)

Returns:

  • (HTTP::Response)


58
59
60
61
62
63
64
65
# File 'lib/contentful/management/http_client.rb', line 58

def proxy_send(type, url, params, headers, proxy)
  HTTP[headers].via(
    proxy[:host],
    proxy[:port],
    proxy[:username],
    proxy[:password]
  ).public_send(type, url, params)
end

#put_http(url, params, headers = {}, proxy = {}) ⇒ HTTP::Response

Put Request

Parameters:

  • url (String)
  • params (Hash)
  • headers (Hash) (defaults to: {})

Returns:

  • (HTTP::Response)


45
46
47
# File 'lib/contentful/management/http_client.rb', line 45

def put_http(url, params, headers = {}, proxy = {})
  http_send(:put, url, { json: params }, headers, proxy)
end