cleantalk 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/lib/cleantalk.rb +54 -0
  3. metadata +72 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 023627ab25949a050d5ecf967503261f3643698e
4
+ data.tar.gz: ee19c974e4f91eead37a688bb6470d8dc582e26a
5
+ SHA512:
6
+ metadata.gz: 4ef7d507a1002406a8ffa498ec6ffc42f617272bf6f2254152590c16f88931394b62c5dfff84072c8e85b66079b93cf0dcf425c776b9d82f9f183da325f5fba6
7
+ data.tar.gz: 298a42c598ec3949a87a78f1926f0cc9401f6069568d29aeadc6e9cc1248fa9521904114d65d67b9fe3bef297e32b9150658629534b0398daea8f33276a025b5
@@ -0,0 +1,54 @@
1
+ require 'net/http'
2
+ require 'json'
3
+
4
+ class Cleantalk
5
+ class Request
6
+ attr_accessor :all_headers, :last_error_no, :last_error_time, \
7
+ :last_error_text, :message, :example, :auth_key, :agent, \
8
+ :stoplist_check, :response_lang, :sender_ip, :sender_email, \
9
+ :sender_nickname, :sender_info, :post_info, :allow_links, \
10
+ :submit_time, :js_on, :tz, :feedback, :phone
11
+
12
+ # Fill params with constructor
13
+ def initialize(params = nil)
14
+ unless params.nil?
15
+ params.each do |key, value|
16
+ instance_variable_set("@#{key}", value)
17
+ end
18
+ end
19
+ end
20
+ end
21
+
22
+ #
23
+ # Function checks whether it is possible to publish the message
24
+ # @param CleantalkRequest $request
25
+ # @return type
26
+ #
27
+ def is_allowed_message(request)
28
+ return http_request('check_message', request)
29
+ end
30
+
31
+ #
32
+ # Function checks whether it is possible to publish the message
33
+ # @param CleantalkRequest $request
34
+ # @return type
35
+ #
36
+ def is_allowed_user(request)
37
+ return http_request('check_newuser', request)
38
+ end
39
+
40
+ def http_request(method_name, request)
41
+ uri = URI 'https://moderate.cleantalk.org/api2.0'
42
+
43
+ form_data = {method_name: method_name}
44
+ attrs = request.instance_variables
45
+ attrs.each {|elem| form_data[elem.to_s.sub('@','')] = request.instance_variable_get(elem) }
46
+
47
+ req = Net::HTTP::Post.new(uri, {'Content-Type' =>'application/json'})
48
+ req.body = form_data.to_json
49
+ response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) do |http|
50
+ http.request(req)
51
+ end
52
+ return JSON.parse(response.entity)
53
+ end
54
+ end
metadata ADDED
@@ -0,0 +1,72 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cleantalk
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - ''
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-06-05 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rspec
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '3.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '3.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: webmock
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '3.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '3.0'
41
+ description: ''
42
+ email: ''
43
+ executables: []
44
+ extensions: []
45
+ extra_rdoc_files: []
46
+ files:
47
+ - lib/cleantalk.rb
48
+ homepage: https://github.com/francois2metz/ruby-antispam
49
+ licenses:
50
+ - MIT
51
+ metadata: {}
52
+ post_install_message:
53
+ rdoc_options: []
54
+ require_paths:
55
+ - lib
56
+ required_ruby_version: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ required_rubygems_version: !ruby/object:Gem::Requirement
62
+ requirements:
63
+ - - ">="
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ requirements: []
67
+ rubyforge_project:
68
+ rubygems_version: 2.6.11
69
+ signing_key:
70
+ specification_version: 4
71
+ summary: Talk to cleantalk.org API for antispam
72
+ test_files: []