Class: ZktClient::Base

Inherits:
Object
  • Object
show all
Extended by:
Helperable, Validatable
Defined in:
lib/zkt_client/models/base.rb

Overview

Base class for ZktClient module

Direct Known Subclasses

Area, Department, Device, Employee, Position, Transaction

Class Method Summary collapse

Class Method Details

.create(params) ⇒ Hash

Creates a new resource with the given parameters

Parameters:

  • params (Hash)

    the parameters for creating the resource

Returns:

  • (Hash)

    the response from the server



37
38
39
40
41
42
# File 'lib/zkt_client/models/base.rb', line 37

def create(params)
  validate_create_params!(params)
  response = HttpClient.post(url: self::URLS[:base], headers:, params:)

  build_response(response)
end

.delete(id) ⇒ Boolean

Deletes a resource by ID

Parameters:

  • id (Integer)

    the ID of the resource

Returns:

  • (Boolean)

    true if the resource was successfully deleted



60
61
62
63
64
# File 'lib/zkt_client/models/base.rb', line 60

def delete(id)
  HttpClient.delete(url: url_with_id(id), headers:)

  true
end

.list(**params) ⇒ Array<Hash>

Lists all resources with optional parameters

Parameters:

  • params (Hash)

    optional parameters for filtering the list

Returns:



27
28
29
30
31
# File 'lib/zkt_client/models/base.rb', line 27

def list(**params)
  response = HttpClient.get(url: self::URLS[:base], headers:, params:)

  build_response(response)
end

.show(id) ⇒ Hash

Shows the details of a specific resource by ID

Parameters:

  • id (Integer)

    the ID of the resource

Returns:

  • (Hash)

    the response from the server



17
18
19
20
21
# File 'lib/zkt_client/models/base.rb', line 17

def show(id)
  response = HttpClient.get(url: url_with_id(id), headers:)

  build_response(response)
end

.update(id, params) ⇒ Hash

Updates an existing resource by ID with the given parameters

Parameters:

  • id (Integer)

    the ID of the resource

  • params (Hash)

    the parameters for updating the resource

Returns:

  • (Hash)

    the response from the server



49
50
51
52
53
54
# File 'lib/zkt_client/models/base.rb', line 49

def update(id, params)
  validate_update_params!(params)
  response = HttpClient.put(url: url_with_id(id), headers:, params:)

  build_response(response)
end