clearbit-slack 0.1.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 5d9dfc7ac039cfaa0447d80da593ebd05aff9165
4
+ data.tar.gz: dfbcb4635d839a66769fddb3596eba20a0d9a1cc
5
+ SHA512:
6
+ metadata.gz: 47036dddbc356e39c732f34f33555a9507dae21eac3857215cd0c9f729d11462f45729a9fa626ecd30f56adf689f82258129007c8a80d66df851783dedc7398a
7
+ data.tar.gz: 7ee62b77dc88118e9547a52143bf9ef19da360a44d4962507a57f42298aaaca33936ca6ef5066f6c065312b76abbf88732a9fe4c740d6e12bc83c5d6d8af2c9b
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.5
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in clearbit-slack.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Clearbit
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,117 @@
1
+ # Clearbit Slack Notifier
2
+
3
+ Send Clearbit Person and Company data into a Slack channel.
4
+
5
+ ![alex_test](https://cloud.githubusercontent.com/assets/739782/8149387/3f89cd68-1276-11e5-863c-5529237bfe6c.png)
6
+
7
+ ## Installation
8
+
9
+ Add to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'clearbit'
13
+ gem 'clearbit-slack'
14
+ ```
15
+
16
+ ### Configuration
17
+
18
+ Add Clearbit and Slack config vars:
19
+
20
+ ```ruby
21
+ # config/initializers/clearbit.rb
22
+ Clearbit.key = ENV['CLEARBIT_KEY']
23
+
24
+ Clearbit::Slack.configure do |config|
25
+ config.slack_url = ENV['SLACK_URL']
26
+ config.slack_channel = '#signups'
27
+ end
28
+ ```
29
+
30
+ ### Clearbit Key
31
+
32
+ Sign up for a [Free Trial](https://clearbit.com/) if you don't already have a Clearbit key.
33
+
34
+ ## Notifications
35
+
36
+ ### Parameters
37
+
38
+ | Field | Description |
39
+ | ----------- | -------------------------------------------------- |
40
+ | company | Company data returned from Clearbit |
41
+ | person | Person data returned form Clearbit |
42
+ | message | Used for deep link into an internal Admin/CRM |
43
+ | email | Used to augment message data when Person not found |
44
+ | given_name | Used to augment message data when Person not found |
45
+ | family_name | Used to augment message data when Person not found |
46
+
47
+ ### Streaming API
48
+
49
+ Lookup email using the Clearbit streaming API and ping Slack channel:
50
+
51
+ ```ruby
52
+ # app/jobs/signup_notification.rb
53
+ module APIHub
54
+ module Jobs
55
+ class SignupNotification
56
+ include Sidekiq::Worker
57
+
58
+ def perform(customer_id)
59
+ customer = Customer.find!(customer_id)
60
+ response = Clearbit::Streaming::PersonCompany[email: customer.email]
61
+
62
+ if response.person || response.company
63
+ params = {
64
+ company: response.company,
65
+ email: customer.email,
66
+ family_name: customer.last_name,
67
+ given_name: customer.first_name,
68
+ message: "View details in <https://admin-panel.com/#{customer.token}|Admin Panel>",
69
+ person: response.person
70
+ }
71
+
72
+ Clearbit::Slack.ping(params)
73
+ end
74
+
75
+ # Persist Clearbit Data
76
+ end
77
+ end
78
+ end
79
+ end
80
+ ```
81
+
82
+ ### Webhooks
83
+
84
+ Receive a webhook with Clearbit data and ping Slack channel:
85
+
86
+ ```ruby
87
+ # app/controllers/webhooks_controller.rb
88
+ class WebhooksController < ApplicationController
89
+ def clearbit
90
+ webhook = Clearbit::Webhook.new(env)
91
+ customer = Customer.find!(webhook.webhook_id)
92
+
93
+ if webhook.body.person || webhook.body.company
94
+ params = {
95
+ company: webhook.body.company,
96
+ email: customer.email,
97
+ family_name: customer.last_name,
98
+ given_name: customer.first_name,
99
+ message: "View details in <https://admin-panel/#{webhook.webhook_id}|Admin Panel>",
100
+ person: webhook.body.person
101
+ }
102
+
103
+ Clearbit::Slack.ping(params)
104
+ end
105
+
106
+ # Persist Clearbit Data
107
+ end
108
+ end
109
+ ```
110
+
111
+ ## Contributing
112
+
113
+ 1. Fork it ( https://github.com/[my-github-username]/clearbit-slack/fork )
114
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
115
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
116
+ 4. Push to the branch (`git push origin my-new-feature`)
117
+ 5. Create a new Pull Request
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'clearbit/slack/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "clearbit-slack"
8
+ spec.version = Clearbit::Slack::VERSION
9
+ spec.authors = ["Harlow Ward"]
10
+ spec.email = ["harlow@clearbit.com"]
11
+
12
+ spec.summary = %q{Push Clearbit data into Slack channel}
13
+ spec.description = %q{Push Clearbit data into Slack channel}
14
+ spec.homepage = "https://github.com/clearbit/clearbit-slack"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.require_paths = ["lib"]
18
+
19
+ spec.add_dependency 'maccman-mash', '~> 0.0.2'
20
+ spec.add_dependency 'slack-notifier', '~> 1.2.1'
21
+ spec.add_development_dependency 'bundler', '~> 1.9'
22
+ spec.add_development_dependency 'pry', '~> 0.10.1'
23
+ spec.add_development_dependency 'rake', '~> 10.0'
24
+ end
@@ -0,0 +1,33 @@
1
+ require 'slack-notifier'
2
+ require 'mash'
3
+
4
+ require 'clearbit/slack/configuration'
5
+ require 'clearbit/slack/helpers'
6
+ require 'clearbit/slack/notifier'
7
+ require 'clearbit/slack/version'
8
+ require 'clearbit/slack/attachments/person'
9
+ require 'clearbit/slack/attachments/company'
10
+
11
+ module Clearbit
12
+ module Slack
13
+ def self.ping(attrs = {})
14
+ Notifier.new(attrs).ping
15
+ end
16
+
17
+ def self.slack_url
18
+ configuration.slack_url || raise('Config Error: No slack_url provided')
19
+ end
20
+
21
+ def self.slack_channel
22
+ configuration.slack_channel || raise('Config Error: No slack_channel provided')
23
+ end
24
+
25
+ def self.configure
26
+ yield configuration if block_given?
27
+ end
28
+
29
+ def self.configuration
30
+ @configuration ||= Configuration.new
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,69 @@
1
+ module Clearbit
2
+ module Slack
3
+ module Attachments
4
+ class Company
5
+ include Helpers
6
+ attr_reader :company
7
+
8
+ def initialize(company)
9
+ @company = company
10
+ end
11
+
12
+ def as_json(options = {})
13
+ {
14
+ author_name: company.name,
15
+ author_icon: company.logo,
16
+ text: company.description,
17
+ color: color,
18
+ fields: fields.compact
19
+ }
20
+ end
21
+
22
+ private
23
+
24
+ def color
25
+ 'good'
26
+ end
27
+
28
+ def fields
29
+ [
30
+ website,
31
+ raised,
32
+ location,
33
+ type,
34
+ employees,
35
+ angellist(company.angellist),
36
+ facebook(company.facebook),
37
+ linkedin(company.linkedin),
38
+ twitter(company.twitter),
39
+ ]
40
+ end
41
+
42
+ def type
43
+ return unless company.type
44
+ field 'Type', company.type
45
+ end
46
+
47
+ def employees
48
+ return unless company.employees
49
+ field 'Employees', format_number(company.employees)
50
+ end
51
+
52
+ def location
53
+ return unless company.location
54
+ field 'Location', company.location
55
+ end
56
+
57
+ def website
58
+ return unless company.url
59
+ field 'Website', company.url
60
+ end
61
+
62
+ def raised
63
+ return unless company.raised
64
+ field 'Raised', "$#{format_number(company.raised)}"
65
+ end
66
+ end
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,67 @@
1
+ module Clearbit
2
+ module Slack
3
+ module Attachments
4
+ class Person
5
+ include Helpers
6
+ attr_reader :person
7
+
8
+ def initialize(person)
9
+ @person = person
10
+ end
11
+
12
+ def as_json(options = {})
13
+ {
14
+ color: color,
15
+ fields: fields.compact
16
+ }
17
+ end
18
+
19
+ private
20
+
21
+ def fields
22
+ [
23
+ bio,
24
+ email,
25
+ employment,
26
+ position,
27
+ location,
28
+ aboutme(person.aboutme),
29
+ angellist(person.angellist),
30
+ facebook(person.facebook),
31
+ linkedin(person.linkedin),
32
+ twitter(person.twitter),
33
+ ]
34
+ end
35
+
36
+ def bio
37
+ return unless person.bio
38
+ field 'Bio', person.bio, false
39
+ end
40
+
41
+ def email
42
+ return unless person.email
43
+ field 'Email', person.email
44
+ end
45
+
46
+ def employment
47
+ return unless person.employment && person.employment.name
48
+ field 'Employment', person.employment.name
49
+ end
50
+
51
+ def position
52
+ return unless person.employment && person.employment.title
53
+ field 'Position', person.employment.title
54
+ end
55
+
56
+ def location
57
+ return unless person.location
58
+ field 'Location', person.location
59
+ end
60
+
61
+ def color
62
+ 'good'
63
+ end
64
+ end
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,7 @@
1
+ module Clearbit
2
+ module Slack
3
+ class Configuration
4
+ attr_accessor :slack_url, :slack_channel
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,83 @@
1
+ module Clearbit
2
+ module Slack
3
+ module Helpers
4
+ def format_number(value)
5
+ value.to_s.reverse.gsub(/(\d{3})(?=\d)/, '\\1,').reverse
6
+ end
7
+
8
+ def field(title, value, short = true)
9
+ {
10
+ title: title,
11
+ value: value,
12
+ short: short
13
+ }
14
+ end
15
+
16
+ def link(url, title, followers = nil)
17
+ if followers
18
+ followers = format_number(followers)
19
+ followers = " (#{followers} followers)"
20
+ end
21
+
22
+ "<#{url}|#{title}>#{followers}".strip
23
+ end
24
+
25
+ def aboutme(aboutme)
26
+ return unless aboutme && aboutme.handle
27
+ value = link(
28
+ "https://about.me/#{aboutme.handle}",
29
+ aboutme.handle
30
+ )
31
+ field 'AboutMe', value
32
+ end
33
+
34
+ def angellist(angellist)
35
+ return unless angellist && angellist.handle
36
+ value = link(
37
+ "https://angel.co/#{angellist.handle}",
38
+ angellist.handle,
39
+ angellist.followers
40
+ )
41
+ field 'AngelList', value
42
+ end
43
+
44
+ def github(github)
45
+ return unless github && github.handle
46
+ value = link(
47
+ "https://github.com/#{github.handle}",
48
+ github.handle,
49
+ github.followers
50
+ )
51
+ field 'GitHub', value
52
+ end
53
+
54
+ def facebook(facebook)
55
+ return unless facebook && facebook.handle
56
+ value = link(
57
+ "https://www.facebook.com/#{facebook.handle}",
58
+ facebook.handle
59
+ )
60
+ field 'Facebook', value
61
+ end
62
+
63
+ def twitter(twitter)
64
+ return unless twitter && twitter.handle
65
+ value = link(
66
+ "http://twitter.com/#{twitter.handle}",
67
+ twitter.handle,
68
+ twitter.followers
69
+ )
70
+ field 'Twitter', value
71
+ end
72
+
73
+ def linkedin(linkedin)
74
+ return unless linkedin && linkedin.handle
75
+ value = link(
76
+ "https://www.linkedin.com/#{linkedin.handle}",
77
+ linkedin.handle
78
+ )
79
+ field 'LinkedIn', value
80
+ end
81
+ end
82
+ end
83
+ end
@@ -0,0 +1,67 @@
1
+ module Clearbit
2
+ module Slack
3
+ class Notifier
4
+ attr_reader :company, :message, :person, :given_name, :family_name, :email
5
+
6
+ def initialize(attrs = {})
7
+ @company = attrs[:company]
8
+ @message = attrs[:message]
9
+ @person = attrs[:person]
10
+ @given_name = attrs[:given_name]
11
+ @family_name = attrs[:family_name]
12
+ @email = attrs[:email]
13
+ end
14
+
15
+ def ping
16
+ notifier = ::Slack::Notifier.new(
17
+ Slack.slack_url,
18
+ channel: Slack.slack_channel,
19
+ icon_url: icon_url,
20
+ username: username
21
+ )
22
+
23
+ attachments << Attachments::Person.new(person).as_json
24
+
25
+ if company
26
+ attachments << Attachments::Company.new(company).as_json
27
+ end
28
+
29
+ notifier.ping message.to_s, attachments: attachments
30
+ end
31
+
32
+ private
33
+
34
+ def icon_url
35
+ person && person.avatar || ''
36
+ end
37
+
38
+ def username
39
+ if person.name.full_name
40
+ person.name.full_name
41
+ elsif person.name.given_name && person.name.family_name
42
+ [person.name.given_name, person.name.family_name].join(' ')
43
+ else
44
+ 'Unknown'
45
+ end
46
+ end
47
+
48
+ def person
49
+ @person ||= unknown_person
50
+ end
51
+
52
+ def unknown_person
53
+ Mash.new(
54
+ email: email,
55
+ name: {
56
+ given: given_name,
57
+ family: family_name
58
+ }
59
+ )
60
+ end
61
+
62
+ def attachments
63
+ @attachments ||= []
64
+ end
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,5 @@
1
+ module Clearbit
2
+ module Slack
3
+ VERSION = '0.1.0'
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,128 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: clearbit-slack
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Harlow Ward
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-06-25 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: maccman-mash
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.0.2
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.0.2
27
+ - !ruby/object:Gem::Dependency
28
+ name: slack-notifier
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 1.2.1
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 1.2.1
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.9'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.9'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 0.10.1
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 0.10.1
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '10.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '10.0'
83
+ description: Push Clearbit data into Slack channel
84
+ email:
85
+ - harlow@clearbit.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - ".rspec"
92
+ - ".travis.yml"
93
+ - Gemfile
94
+ - LICENSE
95
+ - README.md
96
+ - Rakefile
97
+ - clearbit-slack.gemspec
98
+ - lib/clearbit/slack.rb
99
+ - lib/clearbit/slack/attachments/company.rb
100
+ - lib/clearbit/slack/attachments/person.rb
101
+ - lib/clearbit/slack/configuration.rb
102
+ - lib/clearbit/slack/helpers.rb
103
+ - lib/clearbit/slack/notifier.rb
104
+ - lib/clearbit/slack/version.rb
105
+ homepage: https://github.com/clearbit/clearbit-slack
106
+ licenses: []
107
+ metadata: {}
108
+ post_install_message:
109
+ rdoc_options: []
110
+ require_paths:
111
+ - lib
112
+ required_ruby_version: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
117
+ required_rubygems_version: !ruby/object:Gem::Requirement
118
+ requirements:
119
+ - - ">="
120
+ - !ruby/object:Gem::Version
121
+ version: '0'
122
+ requirements: []
123
+ rubyforge_project:
124
+ rubygems_version: 2.2.2
125
+ signing_key:
126
+ specification_version: 4
127
+ summary: Push Clearbit data into Slack channel
128
+ test_files: []