Class: Rspamd::Client
- Inherits:
-
Object
- Object
- Rspamd::Client
- Defined in:
- lib/rspamd/client.rb
Instance Attribute Summary collapse
-
#configuration ⇒ Object
readonly
Returns the value of attribute configuration.
Instance Method Summary collapse
- #add_fuzzy(message, flag: 1, weight: 1) ⇒ Object
- #check(message, headers: {}) ⇒ Object
- #delete_fuzzy(message, flag: 1) ⇒ Object
- #ham!(message) ⇒ Object
-
#initialize(**options) ⇒ Client
constructor
A new instance of Client.
- #ping ⇒ Object
- #spam!(message) ⇒ Object
Constructor Details
#initialize(**options) ⇒ Client
Returns a new instance of Client.
10 11 12 |
# File 'lib/rspamd/client.rb', line 10 def initialize(**) @configuration = Configuration.new(**) end |
Instance Attribute Details
#configuration ⇒ Object (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(, flag: 1, weight: 1) post("/fuzzyadd", , "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(, headers: {}) service.post("/checkv2", headers: headers, body: ).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(, flag: 1) post("/fuzzydel", , "Flag" => flag) end |
#ham!(message) ⇒ Object
35 36 37 |
# File 'lib/rspamd/client.rb', line 35 def ham!() learn :ham, end |
#ping ⇒ Object
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!() learn :spam, end |