referthis 0.2.5 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/mailers/mailer.rb +2 -2
- data/lib/referee.rb +2 -0
- data/lib/referral.rb +9 -9
- data/lib/referthis.rb +16 -0
- data/lib/sms.rb +2 -3
- metadata +2 -2
- data/lib/initializers/smtp_settings.rb +0 -8
data/lib/mailers/mailer.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# http://stackoverflow.com/questions/6021372/best-way-to-create-unique-token-in-rails
|
2
2
|
class Mailer < ActionMailer::Base
|
3
|
-
def send_referral(referral)
|
4
|
-
mail(:to => Referee.find(referral.referee_id).endpoint, :
|
3
|
+
def send_referral(referral, url, referrer_name, app_name)
|
4
|
+
mail(:to => Referee.find(referral.referee_id).endpoint, :subject => app_name, :body => referrer_name + ' has referred you to ' + app_name + '. You might be interested in checking out the following: ' + url + '/' + Base64::encode64(referral.id.to_s).chop + '.')
|
5
5
|
end
|
6
6
|
end
|
data/lib/referee.rb
CHANGED
data/lib/referral.rb
CHANGED
@@ -1,6 +1,9 @@
|
|
1
|
+
require 'active_record'
|
2
|
+
require 'mailers/mailer'
|
3
|
+
require 'sms'
|
1
4
|
class Referral < ActiveRecord::Base
|
2
5
|
attr_accessible :referee_id, :user_id
|
3
|
-
|
6
|
+
|
4
7
|
def self.construct(referee_id)
|
5
8
|
referral = Referral.new
|
6
9
|
referral.referee_id = referee_id
|
@@ -8,17 +11,16 @@ class Referral < ActiveRecord::Base
|
|
8
11
|
referral.save
|
9
12
|
return referral
|
10
13
|
end
|
11
|
-
|
12
|
-
def self.generate_referral(endpoints, user_current_id)
|
14
|
+
def self.generate_referral(endpoints, user_current_id, url, referrer_name, app_name)
|
13
15
|
threads = []
|
14
16
|
@user_current_id = user_current_id
|
15
17
|
if endpoints[:phone_number] != ''
|
16
18
|
threads << Thread.new('sms'){
|
17
19
|
phone_number = SMS.sieve(endpoints[:phone_number])
|
18
20
|
if Referee.exists?(:endpoint => phone_number)
|
19
|
-
SMS.send_referral(self.construct(Referee.find_by_endpoint(phone_number.to_s).id))
|
21
|
+
SMS.send_referral(self.construct(Referee.find_by_endpoint(phone_number.to_s).id), url, referrer_name, app_name)
|
20
22
|
else
|
21
|
-
SMS.send_referral(self.construct(Referee.construct(phone_number.to_s).id))
|
23
|
+
SMS.send_referral(self.construct(Referee.construct(phone_number.to_s).id), url, referrer_name, app_name)
|
22
24
|
end
|
23
25
|
}
|
24
26
|
end
|
@@ -27,9 +29,9 @@ class Referral < ActiveRecord::Base
|
|
27
29
|
email_address = endpoints[:email_address]
|
28
30
|
begin
|
29
31
|
if Referee.exists?(:endpoint => email_address)
|
30
|
-
Mailer.send_referral(self.construct(Referee.find_by_endpoint(email_address).id)).deliver
|
32
|
+
Mailer.send_referral(self.construct(Referee.find_by_endpoint(email_address).id), url, referrer_name, app_name).deliver
|
31
33
|
else
|
32
|
-
Mailer.send_referral(self.construct(Referee.construct(email_address).id)).deliver
|
34
|
+
Mailer.send_referral(self.construct(Referee.construct(email_address).id), url, referrer_name, app_name).deliver
|
33
35
|
end
|
34
36
|
rescue Net::SMTPSyntaxError
|
35
37
|
puts 'Hello'
|
@@ -38,7 +40,6 @@ class Referral < ActiveRecord::Base
|
|
38
40
|
end
|
39
41
|
threads.each {|thread| thread.join}
|
40
42
|
end
|
41
|
-
|
42
43
|
def self.percent_clicked_through(email=nil, sms=nil)
|
43
44
|
if email || sms
|
44
45
|
referrals = Referral.all
|
@@ -69,7 +70,6 @@ class Referral < ActiveRecord::Base
|
|
69
70
|
end
|
70
71
|
end
|
71
72
|
end
|
72
|
-
|
73
73
|
def self.resolve_token(token)
|
74
74
|
referral_id = Base64::decode64(token)
|
75
75
|
if self.exists?(:id => referral_id)
|
data/lib/referthis.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
# http://ruby-doc.org/core-1.9.3/File.html#method-c-dirname
|
2
|
+
# http://www.google.com/search?sugexp=chrome,mod=4&sourceid=chrome&ie=UTF-8&q=path+of+current+file+ruby
|
3
|
+
# http://www.rubyist.net/~slagell/ruby/inheritance.html
|
4
|
+
# http://stackoverflow.com/questions/3724487/rails-root-directory-path
|
5
|
+
# http://stackoverflow.com/questions/3539148/how-do-i-access-the-name-of-the-rails-3-application-object
|
6
|
+
require 'referral'
|
7
|
+
require 'referee'
|
8
|
+
class ReferThis < Referral
|
9
|
+
def self.setup
|
10
|
+
system('cp -r ' + File.dirname(File.absolute_path(__FILE__)) + '/db/migrate/* ' + "'" + Rails.root.to_s.split('app/').first + "/db/migrate/'")
|
11
|
+
system('rake db:migrate')
|
12
|
+
end
|
13
|
+
def self.url(endpoints, user_current_id, url, referrer_name, app_name=Rails.application.class.to_s.split("::").first)
|
14
|
+
self.generate_referral(endpoints, user_current_id, url, referrer_name, app_name)
|
15
|
+
end
|
16
|
+
end
|
data/lib/sms.rb
CHANGED
@@ -7,8 +7,7 @@ class SMS
|
|
7
7
|
def self.sieve(number)
|
8
8
|
return number.to_s.gsub(/\D/, '')
|
9
9
|
end
|
10
|
-
|
11
|
-
|
12
|
-
@@account.sms.messages.create(:from => '+18599030353', :to => Referee.find(referral.referee_id).endpoint, :body => '<user_name> has referred you to <app_name>. You might be interested in checking out the following: <url>' + Base64::encode64(referral.id.to_s).chop + '.')
|
10
|
+
def self.send_referral(referral, url, referrer_name, app_name)
|
11
|
+
@@account.sms.messages.create(:from => '+18599030353', :to => Referee.find(referral.referee_id).endpoint, :body => referrer_name + ' has referred you to ' + app_name + '. You might be interested in checking out the following: ' + url + '/' + Base64::encode64(referral.id.to_s).chop + '.')
|
13
12
|
end
|
14
13
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: referthis
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -23,8 +23,8 @@ files:
|
|
23
23
|
- lib/db/migrate/20120621004835_create_referrals.rb
|
24
24
|
- lib/db/migrate/20120621004904_create_referees.rb
|
25
25
|
- lib/db/migrate/20120621215402_add_keys.rb
|
26
|
-
- lib/initializers/smtp_settings.rb
|
27
26
|
- lib/mailers/mailer.rb
|
27
|
+
- lib/referthis.rb
|
28
28
|
homepage: http://github.com/ahcarpenter/referthis
|
29
29
|
licenses: []
|
30
30
|
post_install_message:
|