adcopy 0.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +1 -0
- data/LICENSE +20 -0
- data/README.rdoc +55 -0
- data/Rakefile +26 -0
- data/VERSION +1 -0
- data/init.rb +10 -0
- data/install.rb +4 -0
- data/lib/adcopy.rb +20 -0
- data/lib/controller_methods.rb +52 -0
- data/lib/view_methods.rb +44 -0
- data/tasks/adcopy_tasks.rake +17 -0
- data/uninstall.rb +0 -0
- metadata +67 -0
data/.gitignore
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
doc
|
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2010 Eddie Siegel
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
= AdCopy
|
2
|
+
|
3
|
+
Author:: Eddie Siegel
|
4
|
+
Info:: http://www.adcopy.com
|
5
|
+
Documentation:: http://rdoc.info/projects/atomon/adcopy
|
6
|
+
|
7
|
+
== Installation
|
8
|
+
|
9
|
+
Currently AdCopy can only be installed as a rails plugin (gem coming soon):
|
10
|
+
|
11
|
+
script/plugin install git://github.com/atomon/adcopy.git
|
12
|
+
|
13
|
+
== API Keys
|
14
|
+
|
15
|
+
Your AdCopy API keys should be stored in <tt>config/adcopy_config.yml</tt>, which can be generated by running
|
16
|
+
|
17
|
+
rake adcopy:setup
|
18
|
+
|
19
|
+
== Adding An AdCopy Puzzle To A View
|
20
|
+
|
21
|
+
Displaying an AdCopy Puzzle is as simple as calling +adcopy_puzzle+ inside a form within your view. For example:
|
22
|
+
|
23
|
+
<% form_for(@user) do |f| %>
|
24
|
+
# ...
|
25
|
+
<p>
|
26
|
+
<%= adcopy_puzzle %>
|
27
|
+
</p>
|
28
|
+
# ...
|
29
|
+
<% end %>
|
30
|
+
|
31
|
+
The appearance of the puzzle can be adjusted by passing options to +adcopy_puzzle+. For a full list of options, see the documentation.
|
32
|
+
|
33
|
+
== Verifying The Input To An AdCopy Puzzle In A Controller
|
34
|
+
|
35
|
+
The +verify_adcopy_puzzle+ method verifies the user's input and returns +true+ if the user provided the correct input. In the simplest case, verification could be performed as follows:
|
36
|
+
|
37
|
+
respond_to do |format|
|
38
|
+
if verify_adcopy_puzzle && @user.save
|
39
|
+
# ...
|
40
|
+
else
|
41
|
+
# ...
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
+verify_adcopy_puzzle+ can also be used to add an error to a model object if the verification fails:
|
46
|
+
|
47
|
+
respond_to do |format|
|
48
|
+
if verify_adcopy_puzzle(:model => @user, :error_message => 'AdCopy puzzle input is invalid') && @user.save
|
49
|
+
# ...
|
50
|
+
else
|
51
|
+
# ...
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
See the documentation for a full list of options accepted by +verify_adcopy_puzzle+.
|
data/Rakefile
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'rake'
|
2
|
+
require 'rake/rdoctask'
|
3
|
+
|
4
|
+
desc 'Generate documentation for the adcopy plugin.'
|
5
|
+
Rake::RDocTask.new(:rdoc) do |rdoc|
|
6
|
+
rdoc.rdoc_dir = 'rdoc'
|
7
|
+
rdoc.title = 'Adcopy'
|
8
|
+
rdoc.options << '--line-numbers' << '--inline-source'
|
9
|
+
rdoc.rdoc_files.include('README')
|
10
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
11
|
+
end
|
12
|
+
|
13
|
+
begin
|
14
|
+
require 'jeweler'
|
15
|
+
Jeweler::Tasks.new do |gem|
|
16
|
+
gem.name = "adcopy"
|
17
|
+
gem.summary = "Simplifies the use of AdCopy puzzles within rails applications"
|
18
|
+
gem.description = "Simplifies the use of AdCopy puzzles within rails applications"
|
19
|
+
gem.email = "atomon@gmail.com"
|
20
|
+
gem.homepage = "http://github.com/atomon/adcopy"
|
21
|
+
gem.authors = ["Eddie Siegel"]
|
22
|
+
end
|
23
|
+
Jeweler::GemcutterTasks.new
|
24
|
+
rescue LoadError
|
25
|
+
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
26
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.0
|
data/init.rb
ADDED
data/install.rb
ADDED
data/lib/adcopy.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# Adcopy
|
2
|
+
require 'view_methods'
|
3
|
+
require 'controller_methods'
|
4
|
+
|
5
|
+
module AdCopy
|
6
|
+
CONFIG_FILE = "#{RAILS_ROOT}/config/adcopy_config.yml"
|
7
|
+
CONFIG = YAML.load_file(CONFIG_FILE) if File.exist?(CONFIG_FILE)
|
8
|
+
VERIFY_SERVER = 'http://verify.adcopy.com'
|
9
|
+
API_SERVER = 'http://api.adcopy.com'
|
10
|
+
SIGNUP_URL = 'http://portal.adcopy.com/portal/public/signup'
|
11
|
+
|
12
|
+
class AdCopyError < StandardError
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.check_for_keys!
|
16
|
+
if !File.exist?(CONFIG_FILE) || CONFIG.nil? || CONFIG['C_KEY'].nil? || CONFIG['V_KEY'].nil? || CONFIG['H_KEY'].nil?
|
17
|
+
raise AdCopyError, "AdCopy API keys not found. Keys can be obtained at #{SIGNUP_URL}"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
module AdCopy
|
2
|
+
|
3
|
+
# Methods within this module will be included in ActionController::Base
|
4
|
+
module ControllerMethods
|
5
|
+
|
6
|
+
# Sends a POST request to the AdCopy server in order to verify the user's input.
|
7
|
+
# Returns +true+ if the user's input is valid, +false+ otherwise
|
8
|
+
#
|
9
|
+
# Options:
|
10
|
+
# <tt>:validate_response</tt>:: Whether or not the AdCopy authenticator should be used to validate the server's response. If this is set to +true+ and the validation fails, an AdCopyError is raised.
|
11
|
+
# <tt>:timeout</tt>:: The amount of time in seconds before the request should timeout. If the request times out, a Timeout::Error is raised.
|
12
|
+
# <tt>:model</tt>:: An ActiveRecord model. If verification fails, an error will be added to this model.
|
13
|
+
# <tt>:error_message</tt>:: A custom error message (to be used in conjunction with <tt>:model</tt>) to be used if verification fails.
|
14
|
+
def verify_adcopy_puzzle(options = {})
|
15
|
+
AdCopy::check_for_keys!
|
16
|
+
options = { :validate_response => true,
|
17
|
+
:timeout => 5,
|
18
|
+
:model => nil,
|
19
|
+
:error_message => nil
|
20
|
+
}.merge(options)
|
21
|
+
|
22
|
+
#Send POST to AdCopy
|
23
|
+
response = nil
|
24
|
+
Timeout::timeout(options[:timeout]) do
|
25
|
+
response = Net::HTTP.post_form URI.parse("#{AdCopy::VERIFY_SERVER}/papi/verify"), {
|
26
|
+
"privatekey" => AdCopy::CONFIG['V_KEY'],
|
27
|
+
"challenge" => params[:adcopy_challenge],
|
28
|
+
"response" => params[:adcopy_response],
|
29
|
+
"remoteip" => request.remote_ip
|
30
|
+
}
|
31
|
+
end
|
32
|
+
answer, error, authenticator = response.body.split("\n")
|
33
|
+
|
34
|
+
#validate the response
|
35
|
+
if options[:validate_response] && authenticator != Digest::SHA1.hexdigest("#{answer}#{params[:adcopy_challenge]}#{AdCopy::CONFIG['H_KEY']}")
|
36
|
+
raise AdCopyError, "AdCopy Error: Unable to Validate Response"
|
37
|
+
end
|
38
|
+
|
39
|
+
if answer.downcase == "true"
|
40
|
+
return true
|
41
|
+
else
|
42
|
+
#Add error to the model
|
43
|
+
if options[:model]
|
44
|
+
options[:model].valid?
|
45
|
+
options[:model].errors.add_to_base options[:error_message] || "AdCopy Puzzle: #{error}"
|
46
|
+
end
|
47
|
+
|
48
|
+
return false
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
data/lib/view_methods.rb
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
module AdCopy
|
2
|
+
|
3
|
+
# Methods within this module will be included in ActionView::Base
|
4
|
+
module ViewMethods
|
5
|
+
|
6
|
+
# Returns the HTML for an AdCopy puzzle
|
7
|
+
#
|
8
|
+
# Options:
|
9
|
+
# <tt>tabindex</tt>:: The tab index of the text field within the puzzle (defaults to <tt>nil</tt>)
|
10
|
+
# <tt>theme</tt>:: The theme applied to the puzzle (defaults to <tt>'purple'</tt>)
|
11
|
+
# <tt>lang</tt>:: The language of the puzzle (defaults to <tt>'en'</tt>)
|
12
|
+
def adcopy_puzzle(options = {})
|
13
|
+
AdCopy::check_for_keys!
|
14
|
+
options = { :tabindex => nil,
|
15
|
+
:theme => 'purple',
|
16
|
+
:lang => 'en'
|
17
|
+
}.merge(options)
|
18
|
+
|
19
|
+
output = ""
|
20
|
+
|
21
|
+
output << %{<script type="text/javascript">\n}
|
22
|
+
output << " var ACPuzzleOptions = {\n"
|
23
|
+
output << %{ tabindex: #{options[:tabindex]},\n} unless options[:tabindex].nil?
|
24
|
+
output << %{ theme: '#{options[:theme]}',\n}
|
25
|
+
output << %{ lang: '#{options[:lang]}'\n}
|
26
|
+
output << " };\n"
|
27
|
+
output << %{</script>\n}
|
28
|
+
|
29
|
+
output << %{<script type="text/javascript"}
|
30
|
+
output << %{ src="#{AdCopy::API_SERVER}/papi/challenge.script?k=#{AdCopy::CONFIG['C_KEY']}">}
|
31
|
+
output << %{</script>}
|
32
|
+
|
33
|
+
output << %{<noscript>}
|
34
|
+
output << %{ <iframe src="#{AdCopy::API_SERVER}/papi/challenge.noscript?k=#{AdCopy::CONFIG['C_KEY']}"}
|
35
|
+
output << %{ height="300" width="500" frameborder="0"></iframe><br/>}
|
36
|
+
output << %{ <textarea name="adcopy_challenge" rows="3" cols="40">}
|
37
|
+
output << %{ </textarea>}
|
38
|
+
output << %{ <input type="hidden" name="adcopy_response"}
|
39
|
+
output << %{ value="manual_challenge"/>}
|
40
|
+
output << %{</noscript>}
|
41
|
+
return output
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
namespace :adcopy do
|
2
|
+
desc "Creates YAML file for API keys"
|
3
|
+
task :setup do
|
4
|
+
file_loc = "#{RAILS_ROOT}/config/adcopy_config.yml"
|
5
|
+
|
6
|
+
if File.exist?(file_loc)
|
7
|
+
puts "#{file_loc} exists. Nothing to do."
|
8
|
+
else
|
9
|
+
puts "Creating #{file_loc}"
|
10
|
+
file = File.new(file_loc, 'w')
|
11
|
+
file.puts "C_KEY: your_c_key_here"
|
12
|
+
file.puts "V_KEY: your_V_key_here"
|
13
|
+
file.puts "H_KEY: your_H_key_here"
|
14
|
+
puts "Don't forget to put your own API keys in adcopy_config.yml"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/uninstall.rb
ADDED
File without changes
|
metadata
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: adcopy
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Eddie Siegel
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2010-01-20 00:00:00 -05:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: Simplifies the use of AdCopy puzzles within rails applications
|
17
|
+
email: atomon@gmail.com
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files:
|
23
|
+
- LICENSE
|
24
|
+
- README.rdoc
|
25
|
+
files:
|
26
|
+
- .gitignore
|
27
|
+
- LICENSE
|
28
|
+
- README.rdoc
|
29
|
+
- Rakefile
|
30
|
+
- VERSION
|
31
|
+
- init.rb
|
32
|
+
- install.rb
|
33
|
+
- lib/adcopy.rb
|
34
|
+
- lib/controller_methods.rb
|
35
|
+
- lib/view_methods.rb
|
36
|
+
- tasks/adcopy_tasks.rake
|
37
|
+
- uninstall.rb
|
38
|
+
has_rdoc: true
|
39
|
+
homepage: http://github.com/atomon/adcopy
|
40
|
+
licenses: []
|
41
|
+
|
42
|
+
post_install_message:
|
43
|
+
rdoc_options:
|
44
|
+
- --charset=UTF-8
|
45
|
+
require_paths:
|
46
|
+
- lib
|
47
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
48
|
+
requirements:
|
49
|
+
- - ">="
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
version: "0"
|
52
|
+
version:
|
53
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: "0"
|
58
|
+
version:
|
59
|
+
requirements: []
|
60
|
+
|
61
|
+
rubyforge_project:
|
62
|
+
rubygems_version: 1.3.5
|
63
|
+
signing_key:
|
64
|
+
specification_version: 3
|
65
|
+
summary: Simplifies the use of AdCopy puzzles within rails applications
|
66
|
+
test_files: []
|
67
|
+
|