Class: PiholeApi::Client

Inherits:
Object
  • Object
show all
Includes:
AuthorisedEndpoints, AuthorisedFormEndpoints, Constants, UnauthorisedEndpoints
Defined in:
lib/pihole-api/client.rb

Constant Summary

Constants included from Constants

PiholeApi::Constants::API_PATH, PiholeApi::Constants::INDEX_PATH, PiholeApi::Constants::LOGIN_PATH, PiholeApi::Constants::TELEPORTER_PATH, PiholeApi::Constants::TOKEN_REGEX, PiholeApi::Constants::TOKEN_SEPERATOR

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from AuthorisedEndpoints

#disable, #enable, #get_all_queries, #get_forward_destinations, #get_query_sources, #get_query_types, #over_time_data_10_mins, #recent_blocked, #summary, #summary_raw, #top_clients, #top_items

Methods included from UnauthorisedEndpoints

#type, #version

Constructor Details

#initialize(base_path:, password:, port: 80) ⇒ Client

Returns a new instance of Client.



12
13
14
15
16
17
18
# File 'lib/pihole-api/client.rb', line 12

def initialize(base_path:, password:, port: 80)
  @password = password
  @api_token = PiholeApi::Client.hash_password(password)

  @base_path = base_path
  @port = port
end

Instance Attribute Details

#api_tokenObject (readonly)

Returns the value of attribute api_token.



10
11
12
# File 'lib/pihole-api/client.rb', line 10

def api_token
  @api_token
end

#base_pathObject (readonly)

Returns the value of attribute base_path.



10
11
12
# File 'lib/pihole-api/client.rb', line 10

def base_path
  @base_path
end

Returns the value of attribute cookie.



10
11
12
# File 'lib/pihole-api/client.rb', line 10

def cookie
  @cookie
end

#form_tokenObject (readonly)

Returns the value of attribute form_token.



10
11
12
# File 'lib/pihole-api/client.rb', line 10

def form_token
  @form_token
end

#passwordObject (readonly)

Returns the value of attribute password.



10
11
12
# File 'lib/pihole-api/client.rb', line 10

def password
  @password
end

#portObject (readonly)

Returns the value of attribute port.



10
11
12
# File 'lib/pihole-api/client.rb', line 10

def port
  @port
end

Class Method Details

.api_versionObject

This is the version of the API docs this client was built off-of



25
26
27
# File 'lib/pihole-api/client.rb', line 25

def self.api_version
  'v2 2023-01-21'
end

.compatible_api_versionObject



20
21
22
# File 'lib/pihole-api/client.rb', line 20

def self.compatible_api_version
  'v3'
end

.hash_password(password) ⇒ Object



29
30
31
32
33
34
# File 'lib/pihole-api/client.rb', line 29

def self.hash_password(password)
  require 'digest'

  hash1 = Digest::SHA256.hexdigest(password)
  Digest::SHA256.hexdigest(hash1) # Use as hash password for client
end