Class: Rspamd::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/rspamd/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**options) ⇒ Client

Returns a new instance of Client.



10
11
12
# File 'lib/rspamd/client.rb', line 10

def initialize(**options)
  @configuration = Configuration.new(**options)
end

Instance Attribute Details

#configurationObject (readonly)

Returns the value of attribute configuration.



8
9
10
# File 'lib/rspamd/client.rb', line 8

def configuration
  @configuration
end

Instance Method Details

#add_fuzzy(message, flag: 1, weight: 1) ⇒ Object



39
40
41
# File 'lib/rspamd/client.rb', line 39

def add_fuzzy(message, flag: 1, weight: 1)
  post("/fuzzyadd", message, "Flag" => flag, "Weight" => weight)
end

#check(message, headers: {}) ⇒ Object



21
22
23
24
25
26
27
28
29
# File 'lib/rspamd/client.rb', line 21

def check(message, headers: {})
  service.post("/checkv2", headers: headers, body: message).then do |response|
    if response.is_a?(Net::HTTPOK)
      Check::Result.parse(response.body)
    else
      raise InvalidResponse, "Received invalid response from Rspamd: expected 200 OK, got #{response.code} #{response.message}".strip
    end
  end
end

#delete_fuzzy(message, flag: 1) ⇒ Object



43
44
45
# File 'lib/rspamd/client.rb', line 43

def delete_fuzzy(message, flag: 1)
  post("/fuzzydel", message, "Flag" => flag)
end

#ham!(message) ⇒ Object



35
36
37
# File 'lib/rspamd/client.rb', line 35

def ham!(message)
  learn :ham, message
end

#pingObject



14
15
16
17
18
19
# File 'lib/rspamd/client.rb', line 14

def ping
  service.get("/ping")
    .then { |response| response.is_a?(Net::HTTPOK) && response.body.match?(/\Apong(\r?\n)?\z/) }
rescue Net::OpenTimeout, Net::ReadTimeout, IOError, SystemCallError
  false
end

#spam!(message) ⇒ Object



31
32
33
# File 'lib/rspamd/client.rb', line 31

def spam!(message)
  learn :spam, message
end