affilimator 0.0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +2 -0
- data/.rvmrc +55 -0
- data/Gemfile +8 -0
- data/Gemfile.lock +24 -0
- data/README.md +2 -0
- data/affilimator.gemspec +13 -0
- data/lib/affilimator.min.js +1 -0
- data/lib/affilimator.rb +131 -0
- metadata +71 -0
data/.gitignore
ADDED
data/.rvmrc
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
#!/usr/bin/env bash
|
2
|
+
|
3
|
+
# This is an RVM Project .rvmrc file, used to automatically load the ruby
|
4
|
+
# development environment upon cd'ing into the directory
|
5
|
+
|
6
|
+
# First we specify our desired <ruby>[@<gemset>], the @gemset name is optional.
|
7
|
+
environment_id="ruby-1.9.2-p290@affilmator-gem"
|
8
|
+
|
9
|
+
#
|
10
|
+
# Uncomment following line if you want options to be set only for given project.
|
11
|
+
#
|
12
|
+
# PROJECT_JRUBY_OPTS=( --1.9 )
|
13
|
+
|
14
|
+
#
|
15
|
+
# First we attempt to load the desired environment directly from the environment
|
16
|
+
# file. This is very fast and efficient compared to running through the entire
|
17
|
+
# CLI and selector. If you want feedback on which environment was used then
|
18
|
+
# insert the word 'use' after --create as this triggers verbose mode.
|
19
|
+
#
|
20
|
+
if [[ -d "${rvm_path:-$HOME/.rvm}/environments" \
|
21
|
+
&& -s "${rvm_path:-$HOME/.rvm}/environments/$environment_id" ]]
|
22
|
+
then
|
23
|
+
\. "${rvm_path:-$HOME/.rvm}/environments/$environment_id"
|
24
|
+
|
25
|
+
if [[ -s "${rvm_path:-$HOME/.rvm}/hooks/after_use" ]]
|
26
|
+
then
|
27
|
+
. "${rvm_path:-$HOME/.rvm}/hooks/after_use"
|
28
|
+
fi
|
29
|
+
else
|
30
|
+
# If the environment file has not yet been created, use the RVM CLI to select.
|
31
|
+
if ! rvm --create use "$environment_id"
|
32
|
+
then
|
33
|
+
echo "Failed to create RVM environment '${environment_id}'."
|
34
|
+
exit 1
|
35
|
+
fi
|
36
|
+
fi
|
37
|
+
|
38
|
+
#
|
39
|
+
# If you use an RVM gemset file to install a list of gems (*.gems), you can have
|
40
|
+
# it be automatically loaded. Uncomment the following and adjust the filename if
|
41
|
+
# necessary.
|
42
|
+
#
|
43
|
+
# filename=".gems"
|
44
|
+
# if [[ -s "$filename" ]]
|
45
|
+
# then
|
46
|
+
# rvm gemset import "$filename" | grep -v already | grep -v listed | grep -v complete | sed '/^$/d'
|
47
|
+
# fi
|
48
|
+
|
49
|
+
# If you use bundler, this might be useful to you:
|
50
|
+
# if command -v bundle && [[ -s Gemfile ]]
|
51
|
+
# then
|
52
|
+
# bundle install
|
53
|
+
# fi
|
54
|
+
|
55
|
+
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
diff-lcs (1.1.3)
|
5
|
+
json_pure (1.7.5)
|
6
|
+
rack (1.4.1)
|
7
|
+
rack-test (0.6.2)
|
8
|
+
rack (>= 1.0)
|
9
|
+
rspec (2.11.0)
|
10
|
+
rspec-core (~> 2.11.0)
|
11
|
+
rspec-expectations (~> 2.11.0)
|
12
|
+
rspec-mocks (~> 2.11.0)
|
13
|
+
rspec-core (2.11.1)
|
14
|
+
rspec-expectations (2.11.3)
|
15
|
+
diff-lcs (~> 1.1.3)
|
16
|
+
rspec-mocks (2.11.3)
|
17
|
+
|
18
|
+
PLATFORMS
|
19
|
+
ruby
|
20
|
+
|
21
|
+
DEPENDENCIES
|
22
|
+
json_pure
|
23
|
+
rack-test
|
24
|
+
rspec
|
data/README.md
ADDED
data/affilimator.gemspec
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = 'affilimator'
|
3
|
+
s.version = '0.0.1.1'
|
4
|
+
s.date = '2012-11-01'
|
5
|
+
s.summary = "Affiliate Management Gem"
|
6
|
+
s.description = "A simple affilimator client gem"
|
7
|
+
s.authors = ["Carson Gross"]
|
8
|
+
s.email = 'carsongross@gmail.com'
|
9
|
+
s.files = `git ls-files`.split("\n")
|
10
|
+
s.homepage =
|
11
|
+
'http://rubygems.org/gems/affilimator'
|
12
|
+
s.add_dependency('json_pure')
|
13
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
var Affilimator=Affilimator||function(){function enc(val){return window.encodeURIComponent?encodeURIComponent(val):escape(val)}function dec(val){return window.decodeURIComponent?decodeURIComponent(val):unescape(val)}function gets(){var i,x,y,c=document.cookie.split(";");for(i=0;i<c.length;i++){x=c[i].substr(0,c[i].indexOf("=")),y=c[i].substr(c[i].indexOf("=")+1),x=x.replace(/^\s+|\s+$/g,"");if(x=="aflm_st")return dec(y)}return""}function delc(name){document.cookie=name+"=; expires=Thu, 01 Jan 1970 00:00:01 GMT;"}function aref(){var queryString=location.search.substring(1),re=/([^&=]+)=([^&]*)/g,m;while(m=re.exec(queryString)){var key=dec(m[1]);if(key=="afmc")return dec(m[2])}return""}function call(action,args){args&&(_callback=args.onFinish);var argsStr="key="+args.key;args.email&&(argsStr+="&email="+args.email),args.tags&&(argsStr+="&tags="+args.tags),args.plan&&(argsStr+="&plan="+args.plan);var afmc=aref();afmc!=""?argsStr+="&afmc="+afmc:args.afmc&&(argsStr+="&afmc="+args.afmc);var ref=findRef();ref!=""&&(argsStr+="&ref="+ref);var u=findU();u!=""&&(argsStr+="&u="+u);var s=document.createElement("script");s.type="text/javascript",s.async="async",s.src="https://js.affilimator.com/js/"+action+"?"+argsStr,document.getElementsByTagName("head")[0]?document.getElementsByTagName("head")[0].appendChild(s):document.getElementsByTagName("body")[0].appendChild(s)}function findRef(){var ref=document.referrer;return ref?enc(ref):""}function findU(){return enc([location.protocol,"//",location.host,location.pathname].join(""))}var _callback=null;return{ping:function(args){args=typeof args!="undefined"?args:{};var s=gets();s==""?call("click",args):args.onFinish&&args.onFinish()},register:function(args){args=typeof args!="undefined"?args:{};var s=gets();s==""||s=="c"?call("reg",args):args.onFinish&&args.onFinish()},finish:function(val){var last_callback=_callback;last_callback&&(last_callback(val),last_callback==_callback&&(_callback=null))},ss:function(val){var d=new Date;d.setDate(d.getDate()+36e3),document.cookie="aflm_st="+enc(val)+"; expires="+d.toUTCString()+"; path=/"},log:function(val){}}}();
|
data/lib/affilimator.rb
ADDED
@@ -0,0 +1,131 @@
|
|
1
|
+
# To use, call
|
2
|
+
# <%= Affilimator.enable(email, cookie).html_safe %>
|
3
|
+
# in the layout file(s)
|
4
|
+
#
|
5
|
+
class Affilimator
|
6
|
+
|
7
|
+
require 'json/pure'
|
8
|
+
|
9
|
+
AFFILIMATOR_CONVERT_URL = "https://api.affilimator.com/v1/convert"
|
10
|
+
AFFILIMATOR_CANCEL_URL = "https://api.affilimator.com/v1/cancel"
|
11
|
+
|
12
|
+
@@private_key = nil
|
13
|
+
@@public_key = nil
|
14
|
+
@@logging_proc = nil
|
15
|
+
@@minified_js = nil
|
16
|
+
|
17
|
+
def self.convert(email, plan)
|
18
|
+
if configured
|
19
|
+
aff_uri = URI.parse(AFFILIMATOR_CONVERT_URL)
|
20
|
+
aff_http = Net::HTTP.new(aff_uri.host, aff_uri.port)
|
21
|
+
aff_http.use_ssl = true
|
22
|
+
aff_post = Net::HTTP::Post.new(aff_uri.request_uri)
|
23
|
+
aff_post.set_form_data({"key" => aff_private_key, "email" => email, "plan" => plan})
|
24
|
+
aff_response = aff_http.request(aff_post)
|
25
|
+
log "Affilimator Convert Response: #{aff_response}"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.cancel(email)
|
30
|
+
if configured
|
31
|
+
aff_uri = URI.parse(AFFILIMATOR_CANCEL_URL)
|
32
|
+
aff_http = Net::HTTP.new(aff_uri.host, aff_uri.port)
|
33
|
+
aff_http.use_ssl = true
|
34
|
+
aff_post = Net::HTTP::Post.new(aff_uri.request_uri)
|
35
|
+
aff_post.set_form_data({"key" => aff_private_key, "email" => email})
|
36
|
+
aff_response = aff_http.request(aff_post)
|
37
|
+
puts "Affilimator Cancel Response: #{aff_response}"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def self.provision_affiliate(user_email)
|
42
|
+
if configured
|
43
|
+
aff_uri = URI.parse("https://api.affilimator.com/v1/link")
|
44
|
+
aff_http = Net::HTTP.new(aff_uri.host, aff_uri.port)
|
45
|
+
aff_http.use_ssl = true
|
46
|
+
aff_post = Net::HTTP::Post.new(aff_uri.request_uri)
|
47
|
+
aff_post.set_form_data({"key" => aff_private_key, "email" => user_email})
|
48
|
+
aff_response = aff_http.request(aff_post)
|
49
|
+
puts "Affilimator Cancel Response: #{aff_response}"
|
50
|
+
body = JSON.parse(aff_response.body)
|
51
|
+
body # return a structured object
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def self.register_js(email, cookies = nil, include_lib = true, in_script_tag = true)
|
56
|
+
if cookies and cookies[:aflm_st] == "r"
|
57
|
+
"" # user is registered, emit nothing
|
58
|
+
else
|
59
|
+
js = ""
|
60
|
+
|
61
|
+
if include_lib then
|
62
|
+
js += minified_js
|
63
|
+
end
|
64
|
+
|
65
|
+
"Affilimator.register({key: '#{aff_public_key}', email:'#{email}'})"
|
66
|
+
|
67
|
+
if in_script_tag then
|
68
|
+
js = "<script >" + js + "</script>"
|
69
|
+
end
|
70
|
+
js
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
def self.config(settings)
|
75
|
+
@@private_key = settings[:private_key]
|
76
|
+
@@public_key = settings[:public_key]
|
77
|
+
@@logging_proc = settings[:logger]
|
78
|
+
end
|
79
|
+
|
80
|
+
def self.configured
|
81
|
+
if @@private_key ||ENV['AFFILIMATOR_PRIVATE_KEY'] then
|
82
|
+
true
|
83
|
+
else
|
84
|
+
if not @@warned_on_config
|
85
|
+
puts "Affilimator is not configured for this environment. If that is not your intent, either "
|
86
|
+
puts "configure it via the Affilimator.config() call or using the AFFILIMATOR_PRIVATE_KEY and "
|
87
|
+
puts "AFFIMILATOR_PUBLIC_KEY environment variables."
|
88
|
+
@@warned_on_config = true
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
def self.aff_private_key
|
94
|
+
@@private_key || ENV['AFFILIMATOR_PRIVATE_KEY']
|
95
|
+
end
|
96
|
+
|
97
|
+
def self.aff_public_key
|
98
|
+
@@public_key || ENV['AFFILIMATOR_PUBLIC_KEY']
|
99
|
+
end
|
100
|
+
|
101
|
+
def self.log(msg)
|
102
|
+
if @@logging_proc then
|
103
|
+
@@logging_proc.call(msg)
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
def self.enable email=nil, cookies=nil
|
108
|
+
aff_elements = "<script>#{minified_js}</script>"
|
109
|
+
|
110
|
+
if !(aff_public_key.nil? || email.nil?)
|
111
|
+
aff_elements += "<script>#{register_js(email,cookies)}</script>"
|
112
|
+
end
|
113
|
+
|
114
|
+
aff_elements
|
115
|
+
end
|
116
|
+
|
117
|
+
private
|
118
|
+
|
119
|
+
def self.minified_js
|
120
|
+
if not @@minified_js then
|
121
|
+
@@minified_js = File.new("#{locate_gem('affilimator')}/lib/affilimator.min.js").read
|
122
|
+
end
|
123
|
+
@@minified_js
|
124
|
+
end
|
125
|
+
|
126
|
+
def self.locate_gem(name)
|
127
|
+
spec = Gem::Specification.find_by_name('affilimator')
|
128
|
+
spec.gem_dir
|
129
|
+
end
|
130
|
+
|
131
|
+
end
|
metadata
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: affilimator
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 0.0.1.1
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Carson Gross
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2012-11-01 00:00:00 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: json_pure
|
17
|
+
prerelease: false
|
18
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
19
|
+
none: false
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: "0"
|
24
|
+
type: :runtime
|
25
|
+
version_requirements: *id001
|
26
|
+
description: A simple affilimator client gem
|
27
|
+
email: carsongross@gmail.com
|
28
|
+
executables: []
|
29
|
+
|
30
|
+
extensions: []
|
31
|
+
|
32
|
+
extra_rdoc_files: []
|
33
|
+
|
34
|
+
files:
|
35
|
+
- .gitignore
|
36
|
+
- .rvmrc
|
37
|
+
- Gemfile
|
38
|
+
- Gemfile.lock
|
39
|
+
- README.md
|
40
|
+
- affilimator.gemspec
|
41
|
+
- lib/affilimator.min.js
|
42
|
+
- lib/affilimator.rb
|
43
|
+
homepage: http://rubygems.org/gems/affilimator
|
44
|
+
licenses: []
|
45
|
+
|
46
|
+
post_install_message:
|
47
|
+
rdoc_options: []
|
48
|
+
|
49
|
+
require_paths:
|
50
|
+
- lib
|
51
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
52
|
+
none: false
|
53
|
+
requirements:
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: "0"
|
57
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
58
|
+
none: false
|
59
|
+
requirements:
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: "0"
|
63
|
+
requirements: []
|
64
|
+
|
65
|
+
rubyforge_project:
|
66
|
+
rubygems_version: 1.8.10
|
67
|
+
signing_key:
|
68
|
+
specification_version: 3
|
69
|
+
summary: Affiliate Management Gem
|
70
|
+
test_files: []
|
71
|
+
|