refer 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d3e23e2268de377fc2bf73d90fc5ede044f1a31cd37f748e925ca68f11fcb059
|
4
|
+
data.tar.gz: 27ae4e3b9d7cca116132bcc3fb5310c6a7b82352d2330f70b52b5004c76838cf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ee9e1dae466166dd4299e39ede4e06ea492c21c03f21ea0f4f13fc8343a1eca039c8e6d2914fbf35e8ea4354b8dda9a04057699361db91ad45e56d896e98ac6a
|
7
|
+
data.tar.gz: 0e5b8663f94465cc9ce236310f1b728f011d442f8076f6184cd7a0bb5a2480bbd81205c0ecc5a5bc81dbe611e30c672a6f7015bb0153233c3c70c98def454238
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Refer
|
2
2
|
|
3
|
-
Referral codes for Ruby on Rails applications.
|
3
|
+
Referral codes and affiliate links for Ruby on Rails applications.
|
4
4
|
|
5
5
|
## 📦 Installation
|
6
6
|
Add this line to your application's Gemfile:
|
@@ -14,9 +14,15 @@ And then execute:
|
|
14
14
|
$ bundle
|
15
15
|
```
|
16
16
|
|
17
|
+
Add Refer to your controllers to store referral cookies:
|
18
|
+
```bash
|
19
|
+
bin/rails generate refer:install
|
20
|
+
```
|
21
|
+
|
17
22
|
And add Refer to your model:
|
18
23
|
```bash
|
19
24
|
bin/rails generate refer:model User
|
25
|
+
bin/rails db:migrate
|
20
26
|
```
|
21
27
|
|
22
28
|
## 🧑💻 Usage
|
@@ -42,7 +48,7 @@ user.referral_codes.create(code: "chris")
|
|
42
48
|
To customize the referral code generator:
|
43
49
|
|
44
50
|
```ruby
|
45
|
-
Refer.code_generator = ->(referrer) { [id, SecureRandom.alphanumeric(8).join("-") }
|
51
|
+
Refer.code_generator = ->(referrer) { [id, SecureRandom.alphanumeric(8)].join("-") }
|
46
52
|
#=> generates codes like "1-7frb5fUw"
|
47
53
|
```
|
48
54
|
|
@@ -54,7 +60,15 @@ To track users, we need to stash the referral code in a cookie when present. By
|
|
54
60
|
|
55
61
|
```ruby
|
56
62
|
class ApplicationController < ActionController::Base
|
57
|
-
|
63
|
+
set_referral_cookie
|
64
|
+
end
|
65
|
+
```
|
66
|
+
|
67
|
+
Move `set_referral_cookie` to specific controllers if you'd only like cookies set in certain areas like marketing pages for example.
|
68
|
+
|
69
|
+
```ruby
|
70
|
+
class MarketingController < ActionController::Base
|
71
|
+
set_referral_cookie except: [:about_us]
|
58
72
|
end
|
59
73
|
```
|
60
74
|
|
@@ -2,14 +2,22 @@ module Refer
|
|
2
2
|
module Controller
|
3
3
|
extend ActiveSupport::Concern
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
5
|
+
class_methods do
|
6
|
+
def set_referral_cookie(param_name: Refer.param_name, cookie_name: Refer.cookie_name, **options)
|
7
|
+
before_action -> { set_refer_cookie(param_name: param_name, cookie_name: cookie_name) }, **options
|
8
8
|
end
|
9
9
|
end
|
10
10
|
|
11
|
-
def refer(referee)
|
12
|
-
Refer.refer(code: cookies[
|
11
|
+
def refer(referee, cookie_name: Refer.cookie_name)
|
12
|
+
Refer.refer(code: cookies[cookie_name], referee: referee)
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def set_refer_cookie(param_name: Refer.param_name, cookie_name: Refer.cookie_name)
|
18
|
+
if (code = params[param_name])
|
19
|
+
cookies[cookie_name] = Refer.cookie(code)
|
20
|
+
end
|
13
21
|
end
|
14
22
|
end
|
15
23
|
end
|
@@ -0,0 +1,7 @@
|
|
1
|
+
class Refer::InstallGenerator < Rails::Generators::Base
|
2
|
+
source_root File.expand_path("templates", __dir__)
|
3
|
+
|
4
|
+
def add_refer
|
5
|
+
inject_into_class File.join("app", "controllers", "application_controller.rb"), "ApplicationController", " set_referral_cookie\n"
|
6
|
+
end
|
7
|
+
end
|
data/lib/refer/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: refer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Oliver
|
@@ -24,7 +24,7 @@ dependencies:
|
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: 6.1.0
|
27
|
-
description: Referral codes for Ruby on Rails apps
|
27
|
+
description: Referral codes & affiliate links for Ruby on Rails apps
|
28
28
|
email:
|
29
29
|
- excid3@gmail.com
|
30
30
|
executables: []
|
@@ -43,6 +43,8 @@ files:
|
|
43
43
|
- config/routes.rb
|
44
44
|
- db/migrate/20240611180738_create_refer_referrals.rb
|
45
45
|
- db/migrate/20240611183349_create_refer_referral_codes.rb
|
46
|
+
- lib/generators/refer/install/USAGE
|
47
|
+
- lib/generators/refer/install/install_generator.rb
|
46
48
|
- lib/generators/refer/model/USAGE
|
47
49
|
- lib/generators/refer/model/model_generator.rb
|
48
50
|
- lib/refer.rb
|
@@ -74,5 +76,5 @@ requirements: []
|
|
74
76
|
rubygems_version: 3.5.11
|
75
77
|
signing_key:
|
76
78
|
specification_version: 4
|
77
|
-
summary: Referral codes for Ruby on Rails apps
|
79
|
+
summary: Referral codes & affiliate links for Ruby on Rails apps
|
78
80
|
test_files: []
|