Class: Cleantalk::Request
- Inherits:
-
Object
- Object
- Cleantalk::Request
- Defined in:
- lib/cleantalk/request.rb
Direct Known Subclasses
Defined Under Namespace
Classes: BadParameters
Instance Attribute Summary collapse
-
#agent ⇒ Object
required.
-
#all_headers ⇒ Object
required.
-
#allow_links ⇒ Object
required.
-
#auth_key ⇒ Object
required.
-
#example ⇒ Object
required.
-
#feedback ⇒ Object
required.
-
#js_on ⇒ Object
required.
-
#last_error_no ⇒ Object
required.
-
#last_error_text ⇒ Object
required.
-
#last_error_time ⇒ Object
required.
-
#message ⇒ Object
required.
-
#method_name ⇒ Object
required.
-
#phone ⇒ Object
required.
-
#post_info ⇒ Object
required.
-
#response_lang ⇒ Object
required.
-
#sender_email ⇒ Object
required.
-
#sender_info ⇒ Object
required.
-
#sender_ip ⇒ Object
required.
-
#sender_nickname ⇒ Object
required.
-
#stoplist_check ⇒ Object
required.
-
#submit_time ⇒ Object
required.
-
#tz ⇒ Object
required.
Instance Method Summary collapse
- #allowed? ⇒ Boolean
-
#http_request ⇒ Object
Remote Call.
- #http_request_without_parse ⇒ Object
-
#initialize(params = {}) ⇒ Request
constructor
Fill params with constructor.
- #result ⇒ Object
Constructor Details
#initialize(params = {}) ⇒ Request
Fill params with constructor
13 14 15 16 17 18 19 20 |
# File 'lib/cleantalk/request.rb', line 13 def initialize(params = {}) self.method_name, self.auth_key = params.delete(:method_name) || self.class::METHOD, nil unless params.empty? params.each do |key, value| send("#{key}=", value) end end end |
Instance Attribute Details
#agent ⇒ Object
required
5 6 7 |
# File 'lib/cleantalk/request.rb', line 5 def agent @agent end |
#all_headers ⇒ Object
required
5 6 7 |
# File 'lib/cleantalk/request.rb', line 5 def all_headers @all_headers end |
#allow_links ⇒ Object
required
5 6 7 |
# File 'lib/cleantalk/request.rb', line 5 def allow_links @allow_links end |
#auth_key ⇒ Object
required
5 6 7 |
# File 'lib/cleantalk/request.rb', line 5 def auth_key @auth_key end |
#example ⇒ Object
required
5 6 7 |
# File 'lib/cleantalk/request.rb', line 5 def example @example end |
#feedback ⇒ Object
required
5 6 7 |
# File 'lib/cleantalk/request.rb', line 5 def feedback @feedback end |
#js_on ⇒ Object
required
5 6 7 |
# File 'lib/cleantalk/request.rb', line 5 def js_on @js_on end |
#last_error_no ⇒ Object
required
5 6 7 |
# File 'lib/cleantalk/request.rb', line 5 def last_error_no @last_error_no end |
#last_error_text ⇒ Object
required
5 6 7 |
# File 'lib/cleantalk/request.rb', line 5 def last_error_text @last_error_text end |
#last_error_time ⇒ Object
required
5 6 7 |
# File 'lib/cleantalk/request.rb', line 5 def last_error_time @last_error_time end |
#message ⇒ Object
required
5 6 7 |
# File 'lib/cleantalk/request.rb', line 5 def @message end |
#method_name ⇒ Object
required
5 6 7 |
# File 'lib/cleantalk/request.rb', line 5 def method_name @method_name end |
#phone ⇒ Object
required
5 6 7 |
# File 'lib/cleantalk/request.rb', line 5 def phone @phone end |
#post_info ⇒ Object
required
5 6 7 |
# File 'lib/cleantalk/request.rb', line 5 def post_info @post_info end |
#response_lang ⇒ Object
required
5 6 7 |
# File 'lib/cleantalk/request.rb', line 5 def response_lang @response_lang end |
#sender_email ⇒ Object
required
5 6 7 |
# File 'lib/cleantalk/request.rb', line 5 def sender_email @sender_email end |
#sender_info ⇒ Object
required
5 6 7 |
# File 'lib/cleantalk/request.rb', line 5 def sender_info @sender_info end |
#sender_ip ⇒ Object
required
5 6 7 |
# File 'lib/cleantalk/request.rb', line 5 def sender_ip @sender_ip end |
#sender_nickname ⇒ Object
required
5 6 7 |
# File 'lib/cleantalk/request.rb', line 5 def sender_nickname @sender_nickname end |
#stoplist_check ⇒ Object
required
5 6 7 |
# File 'lib/cleantalk/request.rb', line 5 def stoplist_check @stoplist_check end |
#submit_time ⇒ Object
required
5 6 7 |
# File 'lib/cleantalk/request.rb', line 5 def submit_time @submit_time end |
#tz ⇒ Object
required
5 6 7 |
# File 'lib/cleantalk/request.rb', line 5 def tz @tz end |
Instance Method Details
#allowed? ⇒ Boolean
56 57 58 |
# File 'lib/cleantalk/request.rb', line 56 def allowed? self.result.allow == 1 end |
#http_request ⇒ Object
Remote Call
40 41 42 |
# File 'lib/cleantalk/request.rb', line 40 def http_request JSON.parse http_request_without_parse end |
#http_request_without_parse ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/cleantalk/request.rb', line 22 def http_request_without_parse valid? form_data = self.instance_variables.inject({}) do |params, var_name| param_key = var_name.to_s.sub('@','') params[param_key] = send(param_key) params end req = Net::HTTP::Post.new(API_URI, API_HEADERS) req.body = JSON.generate(form_data) response = Net::HTTP.start(API_URI.hostname, API_URI.port, use_ssl: true) do |http| http.request(req) end response.entity end |
#result ⇒ Object
52 53 54 |
# File 'lib/cleantalk/request.rb', line 52 def result @result ||= http_request end |