Class: AYAH::Integration
- Inherits:
-
Object
- Object
- AYAH::Integration
- Defined in:
- lib/ayah_integration.rb
Overview
Are You a Human Publisher Integration Rubygem
Instance Attribute Summary collapse
-
#__last_error ⇒ Object
readonly
Returns the value of attribute __last_error.
-
#__score_result_status_code ⇒ Object
readonly
Returns the value of attribute __score_result_status_code.
-
#ayah_server ⇒ Object
Returns the value of attribute ayah_server.
-
#converted ⇒ Object
readonly
Returns the value of attribute converted.
-
#passed ⇒ Object
readonly
Returns the value of attribute passed.
-
#publisher_key ⇒ Object
Returns the value of attribute publisher_key.
-
#scoring_key ⇒ Object
Returns the value of attribute scoring_key.
Instance Method Summary collapse
-
#get_publisher_html ⇒ String
returns the HTML string that should be embedded into the form page to be protected.
-
#initialize(publisher_key, scoring_key, ayah_server = 'ws.areyouahuman.com') ⇒ Integration
constructor
A new instance of Integration.
-
#last_error ⇒ String
returns the last error, if any, that occurred.
-
#record_conversion(session_secret) ⇒ String
returns the HTML to be embedded in the landing page of a completed and converted session.
-
#score_result(session_secret, client_ip = '0.0.0.0') ⇒ True, False
returns the score of the current session.
Constructor Details
#initialize(publisher_key, scoring_key, ayah_server = 'ws.areyouahuman.com') ⇒ Integration
Returns a new instance of Integration.
19 20 21 22 23 24 25 |
# File 'lib/ayah_integration.rb', line 19 def initialize(publisher_key, scoring_key, ayah_server = 'ws.areyouahuman.com') @publisher_key = publisher_key @scoring_key = scoring_key @ayah_server = ayah_server @passed = nil @converted = nil end |
Instance Attribute Details
#__last_error ⇒ Object (readonly)
Returns the value of attribute __last_error.
11 12 13 |
# File 'lib/ayah_integration.rb', line 11 def __last_error @__last_error end |
#__score_result_status_code ⇒ Object (readonly)
Returns the value of attribute __score_result_status_code.
11 12 13 |
# File 'lib/ayah_integration.rb', line 11 def __score_result_status_code @__score_result_status_code end |
#ayah_server ⇒ Object
Returns the value of attribute ayah_server.
10 11 12 |
# File 'lib/ayah_integration.rb', line 10 def ayah_server @ayah_server end |
#converted ⇒ Object (readonly)
Returns the value of attribute converted.
11 12 13 |
# File 'lib/ayah_integration.rb', line 11 def converted @converted end |
#passed ⇒ Object (readonly)
Returns the value of attribute passed.
11 12 13 |
# File 'lib/ayah_integration.rb', line 11 def passed @passed end |
#publisher_key ⇒ Object
Returns the value of attribute publisher_key.
10 11 12 |
# File 'lib/ayah_integration.rb', line 10 def publisher_key @publisher_key end |
#scoring_key ⇒ Object
Returns the value of attribute scoring_key.
10 11 12 |
# File 'lib/ayah_integration.rb', line 10 def scoring_key @scoring_key end |
Instance Method Details
#get_publisher_html ⇒ String
returns the HTML string that should be embedded into the form page to be protected
30 31 32 |
# File 'lib/ayah_integration.rb', line 30 def get_publisher_html "<div id='AYAH'></div><script src='https://#{@ayah_server}/ws/script/#{@publisher_key}' type='text/javascript' language='JavaScript'></script>" end |
#last_error ⇒ String
returns the last error, if any, that occurred
76 77 78 |
# File 'lib/ayah_integration.rb', line 76 def last_error @__last_error end |
#record_conversion(session_secret) ⇒ String
returns the HTML to be embedded in the landing page of a completed and converted session
68 69 70 71 |
# File 'lib/ayah_integration.rb', line 68 def record_conversion(session_secret) @converted = true "<iframe style='border: none;' height='0' width='0' src='https://#{@ayah_server}/ws/recordConversion/#{session_secret}\"></iframe>" end |
#score_result(session_secret, client_ip = '0.0.0.0') ⇒ True, False
returns the score of the current session
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/ayah_integration.rb', line 39 def score_result(session_secret, client_ip='0.0.0.0') # set up the url and form vars for web service submission sr_url = "https://#{@ayah_server}/ayahwebservices/index.php/ayahwebservice/scoreGame" payload = {:session_secret => session_secret, :client_ip => client_ip} result = RestClient.post sr_url, payload, :content_type => 'application/x-www-form-urlencoded' # if there was an HTTP error, fail them automatically unless result.code == 200 log_error("ERROR: HTTP Response code: #{result.code}") @passed = false return @passed end json = JSON.parse(result) # set the score result and see if they passed unless json['status_code'].nil? @__score_result_status_code = json['status_code'].to_i @passed = (json['status_code'].to_i == 1) return @passed end end |