Class: KaChing::ApiV1::Admin

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/ka_ching/api_v1/admin.rb

Overview

Admin Endpoint for the KaChing API V1

Instance Method Summary collapse

Constructor Details

#initialize(conn:, api_url:) ⇒ Admin

Returns a new instance of Admin.



13
14
15
16
# File 'lib/ka_ching/api_v1/admin.rb', line 13

def initialize(conn:, api_url:)
  @conn = conn
  @api_url = api_url
end

Instance Method Details

#create!(tenant_account_id:) {|Faraday::Response| ... } ⇒ Hash

creates a new tenant database

Parameters:

  • tenant_account_id (String)

    without its database namespace, e.g. ‘user_1’ instead of ‘kaching_tenant_user_1’

Yields:

  • (Faraday::Response)

    The response from the server

Returns:

  • (Hash)


44
45
46
47
48
49
50
51
# File 'lib/ka_ching/api_v1/admin.rb', line 44

def create!(tenant_account_id:)
  res = post(build_url) do |req|
    req.headers['Content-Type'] = 'application/json'
    req.body = { tenant_account_id:  }.to_json
  end
  yield res if block_given?
  JSON.parse(res.body)
end

#details(tenant_account_id:) {|Faraday::Response| ... } ⇒ Hash

gets the details of a tenant database

Parameters:

  • full (String)

    tenant_account_id with its database namespace, e.g. ‘kaching_tenant_user_1’

Yields:

  • (Faraday::Response)

    The response from the server

Returns:

  • (Hash)

    containing the details of the tenant database



26
27
28
29
30
31
32
33
# File 'lib/ka_ching/api_v1/admin.rb', line 26

def details(tenant_account_id:)
  admin_tenant_url = build_url(tenant_account_id: )
  res = get(admin_tenant_url) do |req|
    req.headers['Content-Type'] = 'application/json'
  end
  yield res if block_given?
  JSON.parse(res.body)
end

#drop!(tenant_account_id:) {|Faraday::Response| ... } ⇒ Hash

drops a tenant database

Parameters:

  • tenant_account_id (String)

    without its database namespace, e.g. ‘user_1’ instead of ‘kaching_tenant_user_1’

Yields:

  • (Faraday::Response)

    The response from the server

Returns:

  • (Hash)


78
79
80
81
82
83
84
85
# File 'lib/ka_ching/api_v1/admin.rb', line 78

def drop!(tenant_account_id:)
  res = delete(build_url) do |req|
    req.headers['Content-Type'] = 'application/json'
    req.body = { tenant_account_id:  }.to_json
  end
  yield res if block_given?
  JSON.parse(res.body)
end

#reset!(tenant_account_id:) {|res| ... } ⇒ Hash

resets a tenant database

Parameters:

  • tenant_account_id (String)

    without its database namespace

Yields:

  • (res)

Returns:

  • (Hash)

    containing the details of the response



60
61
62
63
64
65
66
67
# File 'lib/ka_ching/api_v1/admin.rb', line 60

def reset!(tenant_account_id:)
  reset_url = "#{build_url(tenant_account_id: )}/reset"
  res = post(reset_url) do |req|
    req.headers['Content-Type'] = 'application/json'
  end
  yield res if block_given?
  JSON.parse(res.body)
end