userlist-rails 0.2.2 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.travis.yml +5 -5
- data/README.md +13 -7
- data/lib/userlist/rails/company.rb +9 -3
- data/lib/userlist/rails/extensions/event.rb +13 -0
- data/lib/userlist/rails/extensions/resource.rb +35 -0
- data/lib/userlist/rails/railtie.rb +5 -2
- data/lib/userlist/rails/user.rb +9 -3
- data/lib/userlist/rails/version.rb +1 -1
- data/lib/userlist/rails.rb +3 -0
- data/userlist-rails.gemspec +2 -3
- metadata +9 -29
- data/lib/userlist/rails/push.rb +0 -41
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: f4ac0764bfdecbc381ea029d3fa9e8e2b04aa7f668eff35f7f54d14b7e20d1e9
|
4
|
+
data.tar.gz: 31e4be6a0b8fe3b5a7cf172b9a07af9e6e5dac7a9edd38751b39416ddee8ad9e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3053ce85e9cc0d218dec274d0a11b5e0fb9caac714b999a2e3a0995946b17ae5f0180159fd978ecc91c890230cf8c744d3e9ddcfe67f1b035eb19c610ce49bbd
|
7
|
+
data.tar.gz: 0a426f64b71938dfea7112c62d96b97e568a47db3a8f1780571ad3612d0f7f39e8cc8c6f2511a5344b95785ad4efe18e8a5f9e912c886a9f2587601716bf2b46
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Userlist::Rails
|
1
|
+
# Userlist::Rails [![Build Status](https://travis-ci.com/userlistio/userlist-rails.svg?branch=master)](https://travis-ci.com/userlistio/userlist-rails)
|
2
2
|
|
3
3
|
This gem helps with integrating [Userlist.io](http://userlist.io) into Ruby on Rails applications.
|
4
4
|
|
@@ -57,7 +57,7 @@ end
|
|
57
57
|
|
58
58
|
#### Sending user data automatically
|
59
59
|
|
60
|
-
By default, this gem will automatically detect your `User` model and create and
|
60
|
+
By default, this gem will automatically detect your `User` model and create, update, and delete the corresponding user inside of Userlist. To customize the `identifier`, `email`, or `properties` transmitted for a user, you can overwrite the according methods in your `User` model.
|
61
61
|
|
62
62
|
```ruby
|
63
63
|
class User < ApplicationRecord
|
@@ -77,18 +77,24 @@ end
|
|
77
77
|
|
78
78
|
#### Sending user data manually
|
79
79
|
|
80
|
-
To manually send user data into Userlist, use the `Userlist::Push.
|
80
|
+
To manually send user data into Userlist, use the `Userlist::Push.users.push` method.
|
81
81
|
|
82
82
|
```ruby
|
83
|
-
Userlist::Push.
|
83
|
+
Userlist::Push.users.push(identifier: user.id, email: user.email, properties: { first_name: user.first_name, last_name: user.last_name })
|
84
|
+
```
|
85
|
+
|
86
|
+
It's also possible to delete a user from Userlist, using the `Userlist::Push.users.delete` method.
|
87
|
+
|
88
|
+
```ruby
|
89
|
+
Userlist::Push.users.delete(user.id)
|
84
90
|
```
|
85
91
|
|
86
92
|
### Tracking Events
|
87
93
|
|
88
|
-
To track custom events use the `Userlist::Push.
|
94
|
+
To track custom events use the `Userlist::Push.events.push` method.
|
89
95
|
|
90
96
|
```ruby
|
91
|
-
Userlist::Push.
|
97
|
+
Userlist::Push.events.push(name: 'project_created', user: current_user, properties: { project_name: project.name })
|
92
98
|
```
|
93
99
|
|
94
100
|
It is possible to make the `user` property optional by setting it for the entire request using an `around_action` callback in your `ApplicationController`.
|
@@ -106,7 +112,7 @@ end
|
|
106
112
|
This simplifies the tracking call for the current request.
|
107
113
|
|
108
114
|
```ruby
|
109
|
-
Userlist::Push.
|
115
|
+
Userlist::Push.events.push(name: 'project_created', properties: { project_name: project.name })
|
110
116
|
```
|
111
117
|
|
112
118
|
### Batch importing
|
@@ -7,8 +7,10 @@ module Userlist
|
|
7
7
|
extend ActiveSupport::Concern
|
8
8
|
|
9
9
|
included do
|
10
|
-
method = [:after_commit, :after_save].find { |m| respond_to?(m) }
|
11
|
-
|
10
|
+
if method = [:after_commit, :after_save].find { |m| respond_to?(m) }
|
11
|
+
public_send(method, :userlist_push, on: [:create, :update])
|
12
|
+
public_send(method, :userlist_delete, on: [:destroy])
|
13
|
+
end
|
12
14
|
end
|
13
15
|
|
14
16
|
def userlist_identifier
|
@@ -32,7 +34,11 @@ module Userlist
|
|
32
34
|
end
|
33
35
|
|
34
36
|
def userlist_push
|
35
|
-
Userlist::Push.
|
37
|
+
Userlist::Push.companies.push(userlist_payload)
|
38
|
+
end
|
39
|
+
|
40
|
+
def userlist_delete
|
41
|
+
Userlist::Push.companies.delete(userlist_identifier)
|
36
42
|
end
|
37
43
|
end
|
38
44
|
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'active_support/core_ext/hash/transform_values' if Gem::Version.new(RUBY_VERSION) < Gem::Version.new('2.5.0')
|
2
|
+
|
3
|
+
module Userlist
|
4
|
+
module Rails
|
5
|
+
module Extensions
|
6
|
+
module Resource
|
7
|
+
def initialize(payload = {})
|
8
|
+
super(transform_payload(payload))
|
9
|
+
end
|
10
|
+
|
11
|
+
private
|
12
|
+
|
13
|
+
def transform_payload(payload)
|
14
|
+
payload = transform_value(payload)
|
15
|
+
|
16
|
+
return payload unless payload.is_a?(Hash)
|
17
|
+
|
18
|
+
payload.transform_values do |value|
|
19
|
+
result = transform_value(value)
|
20
|
+
result = transform_payload(result) if result.is_a?(Hash)
|
21
|
+
result
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def transform_value(value)
|
26
|
+
if value.respond_to?(:userlist_payload)
|
27
|
+
value.send(:userlist_payload)
|
28
|
+
else
|
29
|
+
value
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -3,10 +3,12 @@ require 'rails/railtie'
|
|
3
3
|
require 'userlist'
|
4
4
|
require 'userlist/config'
|
5
5
|
require 'userlist/rails/logger'
|
6
|
-
require 'userlist/rails/push'
|
7
6
|
require 'userlist/rails/user'
|
8
7
|
require 'userlist/rails/company'
|
9
8
|
|
9
|
+
require 'userlist/rails/extensions/resource'
|
10
|
+
require 'userlist/rails/extensions/event'
|
11
|
+
|
10
12
|
module Userlist
|
11
13
|
module Rails
|
12
14
|
class Railtie < ::Rails::Railtie
|
@@ -25,7 +27,8 @@ module Userlist
|
|
25
27
|
end
|
26
28
|
|
27
29
|
initializer 'userlist.extensions' do
|
28
|
-
Userlist::Push.send(:prepend, Userlist::Rails::
|
30
|
+
Userlist::Push::Resource.send(:prepend, Userlist::Rails::Extensions::Resource)
|
31
|
+
Userlist::Push::Event.send(:prepend, Userlist::Rails::Extensions::Event)
|
29
32
|
end
|
30
33
|
|
31
34
|
initializer 'userlist.models' do
|
data/lib/userlist/rails/user.rb
CHANGED
@@ -7,8 +7,10 @@ module Userlist
|
|
7
7
|
extend ActiveSupport::Concern
|
8
8
|
|
9
9
|
included do
|
10
|
-
method = [:after_commit, :after_save].find { |m| respond_to?(m) }
|
11
|
-
|
10
|
+
if method = [:after_commit, :after_save].find { |m| respond_to?(m) }
|
11
|
+
public_send(method, :userlist_push, on: [:create, :update])
|
12
|
+
public_send(method, :userlist_delete, on: [:destroy])
|
13
|
+
end
|
12
14
|
end
|
13
15
|
|
14
16
|
def userlist_identifier
|
@@ -38,7 +40,11 @@ module Userlist
|
|
38
40
|
end
|
39
41
|
|
40
42
|
def userlist_push
|
41
|
-
Userlist::Push.
|
43
|
+
Userlist::Push.users.push(userlist_payload)
|
44
|
+
end
|
45
|
+
|
46
|
+
def userlist_delete
|
47
|
+
Userlist::Push.users.delete(userlist_identifier)
|
42
48
|
end
|
43
49
|
end
|
44
50
|
end
|
data/lib/userlist/rails.rb
CHANGED
data/userlist-rails.gemspec
CHANGED
@@ -21,11 +21,10 @@ Gem::Specification.new do |spec|
|
|
21
21
|
|
22
22
|
spec.add_dependency 'activesupport', '>= 3.0'
|
23
23
|
spec.add_dependency 'railties', '>= 3.0'
|
24
|
-
spec.add_dependency 'userlist', '~> 0.
|
24
|
+
spec.add_dependency 'userlist', '~> 0.3'
|
25
25
|
|
26
|
-
spec.add_development_dependency 'bundler', '
|
26
|
+
spec.add_development_dependency 'bundler', '>= 1.15'
|
27
27
|
spec.add_development_dependency 'rake', '~> 10.0'
|
28
28
|
spec.add_development_dependency 'rspec', '~> 3.0'
|
29
|
-
spec.add_development_dependency 'sqlite3'
|
30
29
|
spec.add_development_dependency 'webmock', '~> 1.22'
|
31
30
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: userlist-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Benedikt Deicke
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-06-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -44,32 +44,26 @@ dependencies:
|
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '0.
|
48
|
-
- - ">="
|
49
|
-
- !ruby/object:Gem::Version
|
50
|
-
version: 0.2.2
|
47
|
+
version: '0.3'
|
51
48
|
type: :runtime
|
52
49
|
prerelease: false
|
53
50
|
version_requirements: !ruby/object:Gem::Requirement
|
54
51
|
requirements:
|
55
52
|
- - "~>"
|
56
53
|
- !ruby/object:Gem::Version
|
57
|
-
version: '0.
|
58
|
-
- - ">="
|
59
|
-
- !ruby/object:Gem::Version
|
60
|
-
version: 0.2.2
|
54
|
+
version: '0.3'
|
61
55
|
- !ruby/object:Gem::Dependency
|
62
56
|
name: bundler
|
63
57
|
requirement: !ruby/object:Gem::Requirement
|
64
58
|
requirements:
|
65
|
-
- - "
|
59
|
+
- - ">="
|
66
60
|
- !ruby/object:Gem::Version
|
67
61
|
version: '1.15'
|
68
62
|
type: :development
|
69
63
|
prerelease: false
|
70
64
|
version_requirements: !ruby/object:Gem::Requirement
|
71
65
|
requirements:
|
72
|
-
- - "
|
66
|
+
- - ">="
|
73
67
|
- !ruby/object:Gem::Version
|
74
68
|
version: '1.15'
|
75
69
|
- !ruby/object:Gem::Dependency
|
@@ -100,20 +94,6 @@ dependencies:
|
|
100
94
|
- - "~>"
|
101
95
|
- !ruby/object:Gem::Version
|
102
96
|
version: '3.0'
|
103
|
-
- !ruby/object:Gem::Dependency
|
104
|
-
name: sqlite3
|
105
|
-
requirement: !ruby/object:Gem::Requirement
|
106
|
-
requirements:
|
107
|
-
- - ">="
|
108
|
-
- !ruby/object:Gem::Version
|
109
|
-
version: '0'
|
110
|
-
type: :development
|
111
|
-
prerelease: false
|
112
|
-
version_requirements: !ruby/object:Gem::Requirement
|
113
|
-
requirements:
|
114
|
-
- - ">="
|
115
|
-
- !ruby/object:Gem::Version
|
116
|
-
version: '0'
|
117
97
|
- !ruby/object:Gem::Dependency
|
118
98
|
name: webmock
|
119
99
|
requirement: !ruby/object:Gem::Requirement
|
@@ -152,9 +132,10 @@ files:
|
|
152
132
|
- lib/userlist/rails.rb
|
153
133
|
- lib/userlist/rails/company.rb
|
154
134
|
- lib/userlist/rails/config.rb
|
135
|
+
- lib/userlist/rails/extensions/event.rb
|
136
|
+
- lib/userlist/rails/extensions/resource.rb
|
155
137
|
- lib/userlist/rails/importer.rb
|
156
138
|
- lib/userlist/rails/logger.rb
|
157
|
-
- lib/userlist/rails/push.rb
|
158
139
|
- lib/userlist/rails/railtie.rb
|
159
140
|
- lib/userlist/rails/user.rb
|
160
141
|
- lib/userlist/rails/version.rb
|
@@ -178,8 +159,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
178
159
|
- !ruby/object:Gem::Version
|
179
160
|
version: '0'
|
180
161
|
requirements: []
|
181
|
-
|
182
|
-
rubygems_version: 2.4.5.2
|
162
|
+
rubygems_version: 3.0.3
|
183
163
|
signing_key:
|
184
164
|
specification_version: 4
|
185
165
|
summary: Rails integration for Userlist.io
|
data/lib/userlist/rails/push.rb
DELETED
@@ -1,41 +0,0 @@
|
|
1
|
-
require 'active_support/core_ext/hash/transform_values'
|
2
|
-
|
3
|
-
module Userlist
|
4
|
-
module Rails
|
5
|
-
module Push
|
6
|
-
def event(payload = {})
|
7
|
-
payload[:user] ||= Userlist::Rails.current_user
|
8
|
-
|
9
|
-
super(transform_payload(payload))
|
10
|
-
end
|
11
|
-
alias track event
|
12
|
-
|
13
|
-
def user(payload = {})
|
14
|
-
super(transform_payload(payload))
|
15
|
-
end
|
16
|
-
alias identify user
|
17
|
-
|
18
|
-
private
|
19
|
-
|
20
|
-
def transform_payload(payload)
|
21
|
-
payload = transform_value(payload)
|
22
|
-
|
23
|
-
return payload unless payload.is_a?(Hash)
|
24
|
-
|
25
|
-
payload.transform_values do |value|
|
26
|
-
result = transform_value(value)
|
27
|
-
result = transform_payload(result) if result.is_a?(Hash)
|
28
|
-
result
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
def transform_value(value)
|
33
|
-
if value.respond_to?(:userlist_payload)
|
34
|
-
value.send(:userlist_payload)
|
35
|
-
else
|
36
|
-
value
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|