Skip to content

Commit 4034b91

Browse files
author
CleanTalk
committed
Merge pull request #4 from VladCleantalk/master
added httpRequest method
2 parents 333ac6c + 5a9737e commit 4034b91

File tree

2 files changed

+34
-12
lines changed

2 files changed

+34
-12
lines changed

README.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,28 @@
11
# ruby-antispam
22
API to have CleanTalk anti-spam on Ruby
3+
4+
Example of usage:
5+
6+
require 'cleantalk.class.rb'
7+
8+
sender_info = Array.new(:cms_lang => 'en_US') #here put locale for your language
9+
10+
request = CleantalkRequest.new
11+
request.auth_key = 'your_key'
12+
request.message = 'test message' #don't use this field for registration check
13+
request.sender_email = 'stop_email@example.com
14+
request.sender_nickname = 'test nickname'
15+
request.sender_ip = '127.0.0.1'
16+
request.js_on = 1 #you should check for JavaScript by yourself
17+
request.submit_time = 11 # you should calculate time for submitting form by youself
18+
request.sender_info = sender_info
19+
20+
ct = Cleantalk.new
21+
result = ct.isAllowMessage(request) # for message checking
22+
result = ct.isAllowUser(request) # for registration checking
23+
24+
# result.allow contains our decision: 1 for allowed message, 0 for blocked
25+
# result.comment contains comment for our decision
26+
27+
28+

cleantalk.class.rb

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -341,29 +341,25 @@ class Cleantalk {
341341
# @return type
342342
#
343343
def isAllowMessage(request)
344-
uri = URI 'https://moderate.cleantalk.org/api2.0'
345-
connection = Net::HTTP.new uri.host, uri.port
346-
http_request = Net::HTTP::Post.new uri
347-
form_data = Array.new
348-
request.each_index{|elem|form_data.elem = params.at(elem)}
349-
form_data{:method_name => 'check_message'}
350-
http_request.set_form form_data, 'multipart/form-data'
351-
response = connection.request http_request
352-
return JSON.parse(response.entity)
344+
return httpRequest('check_message',request)
353345
end
354346

355347
#
356348
# Function checks whether it is possible to publish the message
357349
# @param CleantalkRequest $request
358350
# @return type
359351
#
360-
def isAllowUser(request)
361-
uri = URI 'https://moderate.cleantalk.org/api2.0'
352+
def isAllowUser(request)
353+
return httpRequest('check_newuser',request)
354+
end
355+
356+
def httpRequest(method_name, request)
357+
uri = URI 'https://moderate.cleantalk.org/api2.0'
362358
connection = Net::HTTP.new uri.host, uri.port
363359
http_request = Net::HTTP::Post.new uri
364360
form_data = Array.new
365361
request.each_index{|elem|form_data.elem = params.at(elem)}
366-
form_data{:method_name => 'check_newuser'}
362+
form_data{:method_name => method_name}
367363
http_request.set_form form_data, 'multipart/form-data'
368364
response = connection.request http_request
369365
return JSON.parse(response.entity)

0 commit comments

Comments
 (0)