refer 0.1.1 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +17 -3
- data/app/controllers/concerns/refer/controller.rb +13 -5
- data/db/migrate/20240611180738_create_refer_referrals.rb +1 -1
- data/db/migrate/20240611183349_create_refer_referral_codes.rb +1 -1
- data/lib/generators/refer/install/USAGE +8 -0
- data/lib/generators/refer/install/install_generator.rb +7 -0
- data/lib/generators/refer/model/USAGE +3 -4
- data/lib/refer/version.rb +1 -1
- metadata +7 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c2b67d5a90aba044db91c58de5ba63120d31b89e4826545e3589388eae68922a
|
4
|
+
data.tar.gz: bccf49ec61313f94f7cf842920249d0af40bda63dd632fef70694701912b1e63
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d96dbd8d446574bf29433a558f9b342e385a0af450d2885d37db182960ef3cb1a1fe38d7be0f9eeac7ace6eeb77b7d7117c30f606eb220726764ed6b95ea7b45
|
7
|
+
data.tar.gz: 597c07e84d93b9b6ad2d487a61ad456c20f0b4e687a8fe5b2b6e5184327e11ae79b68b7426acb7d266d047b2b6259d4c9d8f3e583e6f4e97e17ea6ca630028b7
|
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,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: refer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Oliver
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-06-
|
11
|
+
date: 2024-06-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -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
|
@@ -71,8 +73,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
71
73
|
- !ruby/object:Gem::Version
|
72
74
|
version: '0'
|
73
75
|
requirements: []
|
74
|
-
rubygems_version: 3.5.
|
76
|
+
rubygems_version: 3.5.13
|
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: []
|