ayah_integration 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "http://rubygems.org"
2
+ gem "rest-client"
3
+ gem "json"
data/README.md ADDED
@@ -0,0 +1,76 @@
1
+ # AYAH::Integration -- AreYouAHuman.com Publisher Integration
2
+
3
+ * Integrate the AreYouAHuman.com CAPTCHA-alternative human verification
4
+ into your Ruby application
5
+
6
+ AreYouAHuman.com provides a novel game-play approach to human verification;
7
+ instead of deciphering some text, you do a simple task in a fun game.
8
+ You can sign up for a free publisher key at AreYouAHuman.com to start
9
+ using it right away.
10
+
11
+ * Visit http://areyouahuman.com/ for more information on how to get started
12
+
13
+ Contact us or check out our website if you are interested in a customization.
14
+
15
+ # Supported Ruby Versions
16
+
17
+ The gem has been tested in:
18
+
19
+ * Ruby 1.8.7 / Rails 3.1.3
20
+ * Ruby 1.9.2 / Rails 3.1.3
21
+
22
+ If you are running this gem in a different environment, be sure to let us
23
+ know so we can add it to the list.
24
+
25
+ # Installation, Setup, and Integration
26
+
27
+ ## Installation
28
+
29
+ * Simply install from RubyGems:
30
+
31
+ gem install ayah_integration
32
+
33
+ ## Setup
34
+
35
+ 1. In order to use the AYAH Integration gem, you'll first need to sign up at
36
+ http://portal.areyouahuman.com/registration
37
+ 2. Next, get your 'Publisher Key' and 'Scoring Key', these will be used when
38
+ you first instantiate the AYAH::Integration class
39
+
40
+ ## Integration (Examples)
41
+
42
+ Below are the basic steps and examples needed to get the AYAH Integration gem working.
43
+ PUBLISHER_KEY and SCORING_KEY can be found in the AYAH Portal and CLIENT_IP is the IP
44
+ address of the client playing the AYAH PlayThru.
45
+
46
+ You can also register a conversion, for example, when a user passes the AYAH PlayThru
47
+ and completes an order or sign up.
48
+
49
+ 1. Get the HTML needed to be embedded in the form page (in your controller perhaps?):
50
+
51
+ ayah = AYAH::Integration.new(PUBLISHER_KEY, SCORING_KEY)
52
+ @publisher_html = ayah.get_publisher_html
53
+
54
+ 2. Handle the form submission and get score (pass/fail):
55
+
56
+ session_secret = params['session_secret'] # in this case, using Rails
57
+ ayah = AYAH::Integration.new(PUBLISHER_KEY, SCORING_KEY)
58
+ ayah_passed = ayah.score_result(session_secret, CLIENT_IP)
59
+
60
+ 3. Registering a conversion (optional):
61
+
62
+ session_secret = params['session_secret'] # or anywhere else it's stored
63
+ ayah = AYAH::Integration.new(PUBLISHER_KEY, SCORING_KEY)
64
+ @ayah_conversion_html = ayah.record_conversion(session_secret)
65
+
66
+ 4. THAT'S IT! You're Done!
67
+
68
+ # License and Distribution
69
+
70
+ This software is offered under the MIT License and is copyright (c) 2011 by AreYouAHuman.com LLC
71
+
72
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
73
+
74
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
75
+
76
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ require 'rake/testtask'
2
+
3
+ Rake::TestTask.new do |t|
4
+ t.libs << 'test'
5
+ end
6
+
7
+ desc "Run tests"
8
+ task :default => :test
@@ -0,0 +1,88 @@
1
+ require 'rest-client'
2
+ require 'json'
3
+
4
+ module AYAH
5
+
6
+ # Are You a Human Publisher Integration Rubygem
7
+
8
+ class Integration
9
+
10
+ attr_accessor :publisher_key, :scoring_key, :ayah_server
11
+ attr_reader :__score_result_status_code, :__last_error, :passed, :converted
12
+
13
+ # @attr_accessor [String] publisher_key this key can be found in the AYAH portal
14
+ # @attr_accessor [String] scoring_key this key can also be found in the AYAH portal
15
+ # @attr_accessor [String] ayah_server you shouldn't have to modify this, `ws.areyouahuman.com`
16
+
17
+ # @attr_reader [True,False,nil] passed this will be nil until a score request is made, then either true or false
18
+ # @attr_reader [True,False,nil] converted this will be nil until convert html is called for, then true
19
+ def initialize(publisher_key, scoring_key, ayah_server = 'ws.areyouahuman.com')
20
+ @publisher_key = publisher_key
21
+ @scoring_key = scoring_key
22
+ @ayah_server = ayah_server
23
+ @passed = nil
24
+ @converted = nil
25
+ end
26
+
27
+ # returns the HTML string that should be embedded into the form page to be protected
28
+ #
29
+ # @return [String] the HTML string
30
+ def get_publisher_html
31
+ "<div id='AYAH'></div><script src='https://#{@ayah_server}/ws/script/#{@publisher_key}'></script>"
32
+ end
33
+
34
+ # returns the score of the current session
35
+ #
36
+ # @param [String] session_secret the session_secret for the session to be scored
37
+ # @param [String] client_ip the ip address being used by the client
38
+ # @return [True,False] whether the session passed
39
+ def score_result(session_secret, client_ip='0.0.0.0')
40
+
41
+ # set up the url and form vars for web service submission
42
+ sr_url = "https://#{@ayah_server}/ayahwebservices/index.php/ayahwebservice/scoreGame"
43
+ payload = {:session_secret => session_secret, :client_ip => client_ip}
44
+
45
+ result = RestClient.post sr_url, payload, :content_type => 'application/x-www-form-urlencoded'
46
+
47
+ # if there was an HTTP error, fail them automatically
48
+ unless result.code == 200
49
+ log_error("ERROR: HTTP Response code: #{result.code}")
50
+ @passed = false
51
+ return @passed
52
+ end
53
+
54
+ json = JSON.parse(result)
55
+
56
+ # set the score result and see if they passed
57
+ unless json['status_code'].nil?
58
+ @__score_result_status_code = json['status_code'].to_i
59
+ @passed = (json['status_code'].to_i == 1)
60
+ return @passed
61
+ end
62
+ end
63
+
64
+ # returns the HTML to be embedded in the landing page of a completed and converted session
65
+ #
66
+ # @param [String] session_secret the session_secret for the session that converted
67
+ # @return [String] the HTML string
68
+ def record_conversion(session_secret)
69
+ @converted = true
70
+ "<iframe style='border: none;' height='0' width='0' src='https://#{@ayah_server}/ws/recordConversion/#{session_secret}\"></iframe>"
71
+ end
72
+
73
+ # returns the last error, if any, that occurred
74
+ #
75
+ # @return [String] the last error
76
+ def last_error
77
+ @__last_error
78
+ end
79
+
80
+ private
81
+ def log_error(msg)
82
+ @__last_error = msg
83
+ puts msg
84
+ end
85
+
86
+ end
87
+
88
+ end
@@ -0,0 +1,28 @@
1
+ require 'test/unit'
2
+ require 'ayah_integration'
3
+
4
+ class AYAHIntegrationTest < Test::Unit::TestCase
5
+
6
+ def setup
7
+ @pub_key = 'get_your_own_pub_key'
8
+ @score_key = 'get_this_with_the_pub_key'
9
+ @session_secret = 'shhhhhhhhhh'
10
+ @ayah = AYAH::Integration.new(@pub_key, @score_key)
11
+ end
12
+
13
+ def test_get_publisher_html
14
+ assert_equal((@ayah.get_publisher_html.size > 0), true)
15
+ end
16
+
17
+ def test_score_result_for_neg_ten
18
+ result = @ayah.score_result(@session_secret, '127.0.0.1')
19
+ assert_equal(-10, @ayah.__score_result_status_code)
20
+ assert_equal(false, @ayah.passed)
21
+ end
22
+
23
+ def test_record_conversion
24
+ assert_equal((@ayah.record_conversion('invalid_session_secret').size > 0), true)
25
+ assert_equal(@ayah.converted, true)
26
+ end
27
+
28
+ end
metadata ADDED
@@ -0,0 +1,78 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ayah_integration
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.6.0
5
+ platform: ruby
6
+ authors:
7
+ - Andrew S Herron
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2011-12-13 00:00:00 -05:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rest-client
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: json
27
+ type: :runtime
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: "0"
34
+ version:
35
+ description: Integrate the AreYouAHuman.com CAPTCHA alternative human verification into your Ruby/Rails application
36
+ email: andrew@areyouahuman.com
37
+ executables: []
38
+
39
+ extensions: []
40
+
41
+ extra_rdoc_files: []
42
+
43
+ files:
44
+ - Gemfile
45
+ - Rakefile
46
+ - README.md
47
+ - lib/ayah_integration.rb
48
+ - test/test_ayah_integration.rb
49
+ has_rdoc: true
50
+ homepage: http://rubygems.org/gems/ayah_integration
51
+ licenses: []
52
+
53
+ post_install_message:
54
+ rdoc_options: []
55
+
56
+ require_paths:
57
+ - lib
58
+ required_ruby_version: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: "0"
63
+ version:
64
+ required_rubygems_version: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: "0"
69
+ version:
70
+ requirements: []
71
+
72
+ rubyforge_project:
73
+ rubygems_version: 1.3.5
74
+ signing_key:
75
+ specification_version: 3
76
+ summary: AreYouAHuman.com CAPTCHA alternative integration library
77
+ test_files: []
78
+