Class: Keypic::Proxy
- Inherits:
-
Object
- Object
- Keypic::Proxy
- Defined in:
- lib/keypic/proxy.rb
Instance Attribute Summary collapse
-
#env ⇒ Object
readonly
Returns the value of attribute env.
Instance Method Summary collapse
- #check! ⇒ Object
- #clear! ⇒ Object
- #client_params ⇒ Object
- #fetch_rank(options = {}) ⇒ Object
-
#initialize(env) ⇒ Proxy
constructor
A new instance of Proxy.
- #session ⇒ Object
- #spam?(options = {}, rank = 80) ⇒ Boolean
- #token ⇒ Object
- #valid?(options = {}, rank = 80) ⇒ Boolean
Constructor Details
#initialize(env) ⇒ Proxy
Returns a new instance of Proxy.
5 6 7 |
# File 'lib/keypic/proxy.rb', line 5 def initialize(env) @env = env end |
Instance Attribute Details
#env ⇒ Object (readonly)
Returns the value of attribute env.
3 4 5 |
# File 'lib/keypic/proxy.rb', line 3 def env @env end |
Instance Method Details
#check! ⇒ Object
47 48 49 50 51 52 53 |
# File 'lib/keypic/proxy.rb', line 47 def check! body = Keypic::Client.new(:check_form).invoke if body && body["status"] == 'response' body["report"] end end |
#clear! ⇒ Object
55 56 57 58 |
# File 'lib/keypic/proxy.rb', line 55 def clear! session.delete("keypic.token") @token = nil end |
#client_params ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/keypic/proxy.rb', line 34 def client_params { 'ServerName' => env['SERVER_NAME'], 'ClientIP' => env['REMOTE_ADDR'], 'ClientUserAgent' => env['HTTP_USER_AGENT'], 'ClientAccept' => env['HTTP_ACCEPT'], 'ClientAcceptEncoding' => env['HTTP_ACCEPT_ENCODING'], 'ClientAcceptLanguage' => env['HTTP_ACCEPT_LANGUAGE'], 'ClientAcceptCharset' => env['HTTP_ACCEPT_CHARSET'], 'ClientHttpReferer' => env['HTTP_REFERER'] } end |
#fetch_rank(options = {}) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/keypic/proxy.rb', line 21 def fetch_rank( = {}) params = () params = { 'Token' => token }.merge(client_params).merge(params) body = Keypic::Client.new(:validate).invoke(params) if body && body["status"] == 'response' body["spam"].to_f else 0.0 end end |
#session ⇒ Object
60 61 62 |
# File 'lib/keypic/proxy.rb', line 60 def session env["rack.session"] || {} end |
#spam?(options = {}, rank = 80) ⇒ Boolean
17 18 19 |
# File 'lib/keypic/proxy.rb', line 17 def spam?( = {}, rank = 80) !valid?(, rank) end |
#token ⇒ Object
9 10 11 |
# File 'lib/keypic/proxy.rb', line 9 def token @token ||= (fetch_token_from_session || fetch_token_form_server) end |
#valid?(options = {}, rank = 80) ⇒ Boolean
13 14 15 |
# File 'lib/keypic/proxy.rb', line 13 def valid?( = {}, rank = 80) fetch_rank() >= rank.to_f end |