Class: Datacentred::Request::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/datacentred/request/base.rb

Overview

Base class for all API requests.

Uses the Faraday library for HTTP interactions.

Direct Known Subclasses

Projects, Roles, Usage, Users, Versions

Class Method Summary collapse

Class Method Details

.delete(path) ⇒ nil

Access a resource via HTTP DELETE.

Parameters:

  • path (String)

    Desired server path.

Returns:

  • (nil)

    Returns nil on success.

Raises:

  • (Errors::Error)

    Raised if the server returns a non 2xx error code.



42
43
44
# File 'lib/datacentred/request/base.rb', line 42

def delete(path)
  action :delete, path
end

.get(path) ⇒ Object

Access a resource via HTTP GET.

Parameters:

  • path (String)

    Desired server path.

Returns:

  • (Object)

    Parsed server response body.

Raises:

  • (Errors::Error)

    Raised if the server returns a non 2xx error code.



13
14
15
# File 'lib/datacentred/request/base.rb', line 13

def get(path)
  action :get, path
end

.post(path, payload = nil) ⇒ Object

Access a resource via HTTP POST.

Parameters:

  • path (String)

    Desired server path.

  • payload (Object) (defaults to: nil)

    JSON serializable object.

Returns:

  • (Object)

    Parsed server response body.

Raises:

  • (Errors::Error)

    Raised if the server returns a non 2xx error code.



23
24
25
# File 'lib/datacentred/request/base.rb', line 23

def post(path, payload=nil)
  action :post, path, payload
end

.put(path, payload = nil) ⇒ Object

Access a resource via HTTP PUT.

Parameters:

  • path (String)

    Desired server path.

  • payload (Object) (defaults to: nil)

    JSON serializable object.

Returns:

  • (Object)

    Parsed server response body.

Raises:

  • (Errors::Error)

    Raised if the server returns a non 2xx error code.



33
34
35
# File 'lib/datacentred/request/base.rb', line 33

def put(path, payload=nil)
  action :put, path, payload
end