GitHub Sale: sign up for any paid plan this week and pay nothing until January 1, 2009!  [ hide ]

public
Description: Spam blocking plugin with support for Akismet and Defensio.
Clone URL: git://github.com/technoweenie/viking.git
add Viking.timeout_threshold
technoweenie (author)
Wed Jun 04 21:12:13 -0700 2008
commit  a8744aafc960159bcfcd197dce4d1e98d769982a
tree    1f2752d15553c7904efdb3955a72d5458b63c340
parent  4a56ed0d4da3c3dfdd2c0cae32eada07914b0a40
...
156
157
158
159
160
161
162
163
 
164
165
166
167
168
169
170
171
172
173
174
175
176
177
 
178
179
180
181
 
 
182
183
184
...
190
191
192
 
 
 
 
 
 
193
194
195
...
156
157
158
 
 
 
 
 
159
160
161
162
163
164
165
 
 
 
 
 
 
 
 
166
167
168
169
 
170
171
172
173
174
...
180
181
182
183
184
185
186
187
188
189
190
191
0
@@ -156,29 +156,19 @@ module Viking
0
       # the server can be very telling, so please include as much information
0
       # as possible.
0
       def call_akismet(akismet_function, options={})
0
- http_post(
0
- Net::HTTP.new([options[:api_key], self.class.host].join("."), options[:proxy_host], options[:proxy_port]),
0
- akismet_function,
0
- options.update(:blog => options[:blog]).to_query
0
- )
0
+ http_post http_instance, akismet_function, options.update(:blog => options[:blog])
0
       end
0
 
0
       # Call to check and verify your API key. You may then call the
0
       # <tt>verified?</tt> method to see if your key has been validated
0
       def verify_api_key
0
         return :false if invalid_options?
0
- value = http_post(
0
- Net::HTTP.new(self.class.host, self.class.port, options[:proxy_host], options[:proxy_port]),
0
- 'verify-key',
0
- {
0
- :key => options[:api_key],
0
- :blog => options[:blog]
0
- }.to_query
0
- )
0
+ value = http_post http_instance, 'verify-key', :key => options[:api_key], :blog => options[:blog]
0
         self.verified_key = (value == "valid") ? true : :false
0
       end
0
       
0
- def http_post(http, action, data)
0
+ def http_post(http, action, options = {})
0
+ data = options.to_query
0
         resp = http.post(self.url(action), data, self.class.standard_headers)
0
         log_request(self.url(action), data, resp)
0
         resp.body
0
@@ -190,5 +180,11 @@ module Viking
0
       
0
     private
0
       attr_accessor :verified_key
0
+
0
+ def http_instance
0
+ Net::HTTP.new([options[:api_key], self.class.host].join("."), options[:proxy_host], options[:proxy_port])
0
+ http.read_timeout = http.open_timeout = Viking.timeout_threshold
0
+ http
0
+ end
0
   end
0
 end
0
\ No newline at end of file
...
349
350
351
352
353
354
355
356
357
 
 
 
358
359
360
361
362
363
364
 
 
365
366
367
...
349
350
351
 
 
 
 
 
 
352
353
354
355
356
357
 
 
 
 
358
359
360
361
362
0
@@ -349,19 +349,14 @@ module Viking
0
       end
0
       
0
       def defensio_http
0
- Net::HTTP.new(
0
- self.class.host,
0
- self.class.port,
0
- options[:proxy_host],
0
- options[:proxy_port]
0
- )
0
+ http = Net::HTTP.new self.class.host, self.class.port, options[:proxy_host], options[:proxy_port]
0
+ http.read_timeout = http.open_timeout = Viking.timeout_threshold
0
+ http
0
       end
0
       
0
       def data(params={})
0
- params.
0
- update('owner-url' => options[:blog] || options[:owner_url]).
0
- dasherize_keys.
0
- to_query
0
+ params.update('owner-url' => options[:blog] || options[:owner_url])
0
+ params.dasherize_keys.to_query
0
       end
0
       
0
     private
...
22
23
24
 
25
26
27
 
28
29
 
 
 
 
30
31
32
...
53
54
55
 
 
56
57
58
59
...
22
23
24
25
26
27
 
28
29
30
31
32
33
34
35
36
37
...
58
59
60
61
62
63
64
65
66
0
@@ -22,11 +22,16 @@ module Viking
0
   class Error < StandardError; end
0
 
0
   class << self
0
+ attr_accessor :timeout_threshold
0
     attr_accessor :logger
0
     attr_accessor :default_engine
0
- attr_accessor :connect_options
0
+ attr_writer :connect_options
0
     attr_writer :default_instance
0
 
0
+ def connect_options
0
+ @connect_options ||= {}
0
+ end
0
+
0
     def default_instance
0
       @default_instance ||= connect(default_engine, connect_options)
0
     end
0
@@ -53,6 +58,8 @@ module Viking
0
       default_instance.mark_as_spam_or_ham(is_spam, options)
0
     end
0
   end
0
+
0
+ self.timeout_threshold = 5
0
 end
0
 
0
 require 'base'
0
\ No newline at end of file

Comments

    No one has commented yet.