hertz-courier-intercom 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/README.md +102 -0
- data/Rakefile +30 -0
- data/app/jobs/hertz/courier/intercom/notification_delivery_job.rb +41 -0
- data/lib/generators/hertz/courier/intercom/install_generator.rb +14 -0
- data/lib/generators/hertz/courier/intercom/templates/initializer.rb +14 -0
- data/lib/hertz/courier/intercom.rb +27 -0
- data/lib/hertz/courier/intercom/engine.rb +10 -0
- data/lib/hertz/courier/intercom/version.rb +8 -0
- metadata +221 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 996572459beab3e6ec731087f5043447c8adc086
|
4
|
+
data.tar.gz: 909ef496dc0ce9326f8b5ac9dc3dcd0b3cbd0966
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 49c6c1684dd11c9af5e7660fb8511e126b2e685a65d2bbe69e85dec82ac2a09e4d120df546f1c6a72560d1078c2da035e3a1d338664acda4af2bb4ee485fee6b
|
7
|
+
data.tar.gz: 8be561a496b89400c9155b4a25d53b0c20849fbde93ee19b199f0ec37e08e67db33216af72dd5304229e7644be82679991355950e0cf692083a637c78ae140a2
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2016 Alessandro Desantis
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,102 @@
|
|
1
|
+
# Hertz::Courier::Intercom
|
2
|
+
|
3
|
+
[](https://gemnasium.com/github.com/alessandro1997/hertz-courier-intercom)
|
4
|
+
[](https://codeclimate.com/github/alessandro1997/hertz-courier-intercom)
|
5
|
+
|
6
|
+
This is a [Hertz](https://github.com/alessandro1997/hertz) courier for sending
|
7
|
+
notifications to your users as [Intercom](https://www.intercom.io) conversations.
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
Add this line to your application's Gemfile:
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
gem 'hertz-courier-intercom'
|
15
|
+
```
|
16
|
+
|
17
|
+
And then execute:
|
18
|
+
|
19
|
+
```console
|
20
|
+
$ bundle
|
21
|
+
```
|
22
|
+
|
23
|
+
Or install it yourself as:
|
24
|
+
|
25
|
+
```console
|
26
|
+
$ gem install hertz-courier-intercom
|
27
|
+
```
|
28
|
+
|
29
|
+
Then, run the installer generator:
|
30
|
+
|
31
|
+
```console
|
32
|
+
$ rails g hertz:courier:intercom:install
|
33
|
+
```
|
34
|
+
|
35
|
+
You will also need to expose the `hertz_intercom_id` method in your receiver
|
36
|
+
class:
|
37
|
+
|
38
|
+
```ruby
|
39
|
+
class User < ActiveRecord::Base
|
40
|
+
include Hertz::Notifiable
|
41
|
+
|
42
|
+
def hertz_intercom_id
|
43
|
+
id
|
44
|
+
end
|
45
|
+
end
|
46
|
+
```
|
47
|
+
|
48
|
+
If `#hertz_intercom_id` returns an empty value (i.e. `false`, `nil` or an
|
49
|
+
empty string) at the time the job is executed, the notification will not be
|
50
|
+
delivered. This allows you to programmatically enable/disable email
|
51
|
+
notifications for a user:
|
52
|
+
|
53
|
+
```ruby
|
54
|
+
class User
|
55
|
+
include Hertz::Notifiable
|
56
|
+
|
57
|
+
def hertz_intercom_id
|
58
|
+
id if send_through_intercom?
|
59
|
+
end
|
60
|
+
end
|
61
|
+
```
|
62
|
+
|
63
|
+
## Usage
|
64
|
+
|
65
|
+
In order to use this courier, add `:intercom` to `deliver_by` in the
|
66
|
+
notification model(s):
|
67
|
+
|
68
|
+
```ruby
|
69
|
+
class CommentNotification < Hertz::Notification
|
70
|
+
deliver_by :intercom
|
71
|
+
end
|
72
|
+
```
|
73
|
+
|
74
|
+
Now, add the `intercom_subject` and `intercom_body` methods in your notification
|
75
|
+
class:
|
76
|
+
|
77
|
+
```ruby
|
78
|
+
class CommentNotification < Hertz::Notification
|
79
|
+
def intercom_subject
|
80
|
+
'You have a new comment!'
|
81
|
+
end
|
82
|
+
|
83
|
+
def intercom_body
|
84
|
+
'Hey man, you got a new comment waiting for you!'
|
85
|
+
end
|
86
|
+
end
|
87
|
+
```
|
88
|
+
|
89
|
+
## Contributing
|
90
|
+
|
91
|
+
Bug reports and pull requests are welcome on GitHub at
|
92
|
+
https://github.com/alessandro1997/hertz-courier-intercom.
|
93
|
+
|
94
|
+
## License
|
95
|
+
|
96
|
+
The gem is available as open source under the terms of the
|
97
|
+
[MIT License](http://opensource.org/licenses/MIT).
|
98
|
+
|
99
|
+
# To do
|
100
|
+
|
101
|
+
- [ ] Allow changing the job's queue
|
102
|
+
- [ ] Store notification delivery in the DB to avoid resending
|
data/Rakefile
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
begin
|
2
|
+
require 'bundler/setup'
|
3
|
+
rescue LoadError
|
4
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
5
|
+
end
|
6
|
+
|
7
|
+
require 'rdoc/task'
|
8
|
+
|
9
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
10
|
+
rdoc.rdoc_dir = 'rdoc'
|
11
|
+
rdoc.title = 'Hertz'
|
12
|
+
rdoc.options << '--line-numbers'
|
13
|
+
rdoc.rdoc_files.include('README.rdoc')
|
14
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
15
|
+
end
|
16
|
+
|
17
|
+
APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__)
|
18
|
+
load 'rails/tasks/engine.rake'
|
19
|
+
load 'rails/tasks/statistics.rake'
|
20
|
+
|
21
|
+
Bundler::GemHelper.install_tasks
|
22
|
+
|
23
|
+
Rake::TestTask.new(:spec) do |t|
|
24
|
+
t.libs << 'lib'
|
25
|
+
t.libs << 'spec'
|
26
|
+
t.pattern = 'spec/**/*_spec.rb'
|
27
|
+
t.verbose = false
|
28
|
+
end
|
29
|
+
|
30
|
+
task default: :spec
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module Hertz
|
3
|
+
module Courier
|
4
|
+
module Intercom
|
5
|
+
class NotificationDeliveryJob < ActiveJob::Base
|
6
|
+
queue_as :default
|
7
|
+
|
8
|
+
def perform(notification)
|
9
|
+
return if notification.delivered_with?(:intercom)
|
10
|
+
return unless notification.receiver.hertz_intercom_id.present?
|
11
|
+
|
12
|
+
intercom_client.messages.create(
|
13
|
+
message_type: 'email',
|
14
|
+
subject: notification.intercom_subject,
|
15
|
+
body: notification.intercom_body,
|
16
|
+
template: ::Hertz::Courier::Intercom.email_template,
|
17
|
+
from: {
|
18
|
+
type: 'admin',
|
19
|
+
id: ::Hertz::Courier::Intercom.admin_id
|
20
|
+
},
|
21
|
+
to: {
|
22
|
+
type: 'user',
|
23
|
+
user_id: notification.receiver.hertz_intercom_id
|
24
|
+
}
|
25
|
+
)
|
26
|
+
|
27
|
+
notification.mark_delivered_with(:intercom)
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def intercom_client
|
33
|
+
@intercom ||= ::Intercom::Client.new(
|
34
|
+
app_id: ::Hertz::Courier::Intercom.intercom_app_id,
|
35
|
+
api_key: ::Hertz::Courier::Intercom.intercom_api_key
|
36
|
+
)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module Hertz
|
3
|
+
module Courier
|
4
|
+
module Intercom
|
5
|
+
class InstallGenerator < Rails::Generators::Base
|
6
|
+
source_root File.expand_path('../templates', __FILE__)
|
7
|
+
|
8
|
+
def copy_initializer_file
|
9
|
+
copy_file 'initializer.rb', 'config/initializers/hertz_intercom.rb'
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
Hertz::Courier::Intercom.configure do |config|
|
3
|
+
# Your Intercom app ID.
|
4
|
+
config.intercom_app_id = 'YourAppID'
|
5
|
+
|
6
|
+
# Your Intercom API key.
|
7
|
+
config.intercom_api_key = 'YourAPIKey'
|
8
|
+
|
9
|
+
# The template to use for emails ("plain" or "personal").
|
10
|
+
config.email_template = 'plain'
|
11
|
+
|
12
|
+
# The initiator's ID in Intercom.
|
13
|
+
config.admin_id = '12345'
|
14
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'intercom'
|
3
|
+
require 'hertz'
|
4
|
+
|
5
|
+
require 'hertz/courier/intercom/engine'
|
6
|
+
require 'hertz/courier/intercom/version'
|
7
|
+
|
8
|
+
module Hertz
|
9
|
+
module Courier
|
10
|
+
module Intercom
|
11
|
+
mattr_accessor(
|
12
|
+
:intercom_api_key, :intercom_app_id, :email_template, :admin_id
|
13
|
+
)
|
14
|
+
|
15
|
+
class << self
|
16
|
+
def configure
|
17
|
+
yield(self)
|
18
|
+
end
|
19
|
+
|
20
|
+
def deliver_notification(notification)
|
21
|
+
Hertz::Courier::Intercom::NotificationDeliveryJob
|
22
|
+
.perform_later(notification)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
metadata
ADDED
@@ -0,0 +1,221 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: hertz-courier-intercom
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Alessandro Desantis
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-06-28 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rails
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 4.2.6
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 4.2.6
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: hertz
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 1.0.0
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 1.0.0
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: intercom
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 3.5.0
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 3.5.0
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rubocop
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rubocop-rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rspec-rails
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rspec-activejob
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: fuubar
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: faker
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: database_cleaner
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - ">="
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0'
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - ">="
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0'
|
153
|
+
- !ruby/object:Gem::Dependency
|
154
|
+
name: factory_girl_rails
|
155
|
+
requirement: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - ">="
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: '0'
|
160
|
+
type: :development
|
161
|
+
prerelease: false
|
162
|
+
version_requirements: !ruby/object:Gem::Requirement
|
163
|
+
requirements:
|
164
|
+
- - ">="
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: '0'
|
167
|
+
- !ruby/object:Gem::Dependency
|
168
|
+
name: pg
|
169
|
+
requirement: !ruby/object:Gem::Requirement
|
170
|
+
requirements:
|
171
|
+
- - ">="
|
172
|
+
- !ruby/object:Gem::Version
|
173
|
+
version: '0'
|
174
|
+
type: :development
|
175
|
+
prerelease: false
|
176
|
+
version_requirements: !ruby/object:Gem::Requirement
|
177
|
+
requirements:
|
178
|
+
- - ">="
|
179
|
+
- !ruby/object:Gem::Version
|
180
|
+
version: '0'
|
181
|
+
description:
|
182
|
+
email:
|
183
|
+
- desa.alessandro@gmail.com
|
184
|
+
executables: []
|
185
|
+
extensions: []
|
186
|
+
extra_rdoc_files: []
|
187
|
+
files:
|
188
|
+
- MIT-LICENSE
|
189
|
+
- README.md
|
190
|
+
- Rakefile
|
191
|
+
- app/jobs/hertz/courier/intercom/notification_delivery_job.rb
|
192
|
+
- lib/generators/hertz/courier/intercom/install_generator.rb
|
193
|
+
- lib/generators/hertz/courier/intercom/templates/initializer.rb
|
194
|
+
- lib/hertz/courier/intercom.rb
|
195
|
+
- lib/hertz/courier/intercom/engine.rb
|
196
|
+
- lib/hertz/courier/intercom/version.rb
|
197
|
+
homepage: https://github.com/alessandro1997/hertz-courier-intercom
|
198
|
+
licenses:
|
199
|
+
- MIT
|
200
|
+
metadata: {}
|
201
|
+
post_install_message:
|
202
|
+
rdoc_options: []
|
203
|
+
require_paths:
|
204
|
+
- lib
|
205
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
206
|
+
requirements:
|
207
|
+
- - ">="
|
208
|
+
- !ruby/object:Gem::Version
|
209
|
+
version: '0'
|
210
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
211
|
+
requirements:
|
212
|
+
- - ">="
|
213
|
+
- !ruby/object:Gem::Version
|
214
|
+
version: '0'
|
215
|
+
requirements: []
|
216
|
+
rubyforge_project:
|
217
|
+
rubygems_version: 2.5.1
|
218
|
+
signing_key:
|
219
|
+
specification_version: 4
|
220
|
+
summary: An Intercom courier for Hertz.
|
221
|
+
test_files: []
|