sendgrid_contact_persist 0.0.1

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: 23adc8b55a50b06e4acce7efa67e774320306b18
4
+ data.tar.gz: 593171ff17776998d1297316f60d34c367bebcea
5
+ SHA512:
6
+ metadata.gz: fe29b9c898e23ce9a598ae706bb01a9cf0a703f6b0ed3b5096031e63f01f5db0645abaab0c1a9595bb5fd322cf36354f96239c56fafe868f7b689786f92a815f
7
+ data.tar.gz: 24bc785e52fe71ba99a93aebd521ee7ad9f51ea610ceb02d486032b8a43d79f50b56080fe17b7358b6a7d451d98cbf86ee4a17901a3df22f0fe7b63d4ad2b3aa
@@ -0,0 +1,12 @@
1
+ .DS_Store
2
+ coverage
3
+ rdoc
4
+ doc
5
+ pkg
6
+ .ruby-version
7
+ *.lock
8
+ .idea
9
+ .dev/
10
+ pkg/*
11
+ *.gem
12
+ .bundle
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source :rubygems
2
+
3
+ gem 'rest-client'
4
+
5
+ gemspec
6
+
@@ -0,0 +1,24 @@
1
+ # sendgrid_contact_persist
2
+
3
+ A microservice for persisting SendGrid contacts.
4
+
5
+ ## Usage
6
+ ```
7
+ gem install sendgrid_contact_persist
8
+ ```
9
+
10
+ You need to set SENDGRID_API_KEY on your environment for api authorization. Once you have your key set
11
+ you can call the service.
12
+
13
+ ### Service API
14
+ You can pass either a single email or a list of emails to persist:
15
+ ```
16
+ SendgridContactPersist "email@email.com"
17
+ SendgridContactPersist ["email1@email.com", "email2@email.com"]
18
+ ```
19
+
20
+ You can also pass custom fields to be applied to all of the emails you are persisting. You must define the custom fields
21
+ on Sendgrid's Admin Marketing interface before using them here.
22
+ ```
23
+ SendgridContactPersist "email@email.com", foo: :bar
24
+ ```
@@ -0,0 +1,3 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
3
+
@@ -0,0 +1,32 @@
1
+ require 'rest-client'
2
+
3
+ module SendgridContactPersist
4
+ class << self
5
+ attr_accessor :logger
6
+
7
+ def persist(emails, custom_attrs = {})
8
+ return nil unless api_key = ENV['SENDGRID_API_KEY']
9
+
10
+ headers = {'Authorization' => "Bearer #{api_key}"}
11
+ emails = [emails] unless emails.kind_of?(Array)
12
+ data = []
13
+ emails.each do |email|
14
+ data << {email: email}.merge(custom_attrs)
15
+ end
16
+
17
+ resp = RestClient.post 'https://api.sendgrid.com/v3/contactdb/recipients', data.to_json, headers
18
+ SendgridContactPersist.logger.info "Contact(s) added to Sendgrid: #{emails}"
19
+ resp
20
+ end
21
+ end
22
+
23
+ class Railties < ::Rails::Railtie
24
+ initializer 'Rails logger' do
25
+ SendgridContactPersist.logger = Rails.logger
26
+ end
27
+ end
28
+
29
+ if defined?(Rails)
30
+ require 'sendgrid_contact_persist/engine'
31
+ end
32
+ end
@@ -0,0 +1,6 @@
1
+ module SendgridContactPersist
2
+ class Engine < ::Rails::Engine
3
+ config.autoload_paths += Dir["#{config.root}/lib/**/"]
4
+ end
5
+ end
6
+
@@ -0,0 +1,3 @@
1
+ module SendgridContactPersist
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,22 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path("../lib/sendgrid_contact_persist/version", __FILE__)
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = 'sendgrid_contact_persist'
6
+ s.version = SendgridContactPersist::VERSION
7
+ s.date = '2017-01-11'
8
+ s.platform = Gem::Platform::RUBY
9
+ s.summary = "A microservice for persisting contacts to Sendgrid."
10
+ s.description = "A microservice for persisting contacts to Sendgrid."
11
+ s.authors = ["Jason Buehler"]
12
+ s.email = 'jason.c.buehler@gmail.com'
13
+ s.files = `git ls-files`.split("\n")
14
+
15
+ s.homepage = 'http://rubygems.org/gems/sendgrid_contact_persist'
16
+ s.license = 'MIT'
17
+
18
+ s.add_runtime_dependency "rest-client"
19
+ s.add_development_dependency "bundler", ">= 1.0.0"
20
+ s.require_path = 'lib'
21
+ end
22
+
metadata ADDED
@@ -0,0 +1,79 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sendgrid_contact_persist
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Jason Buehler
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-01-11 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rest-client
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 1.0.0
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 1.0.0
41
+ description: A microservice for persisting contacts to Sendgrid.
42
+ email: jason.c.buehler@gmail.com
43
+ executables: []
44
+ extensions: []
45
+ extra_rdoc_files: []
46
+ files:
47
+ - ".gitignore"
48
+ - Gemfile
49
+ - README.md
50
+ - Rakefile
51
+ - lib/sendgrid_contact_persist.rb
52
+ - lib/sendgrid_contact_persist/engine.rb
53
+ - lib/sendgrid_contact_persist/version.rb
54
+ - sendgrid_contact_persist.gemspec
55
+ homepage: http://rubygems.org/gems/sendgrid_contact_persist
56
+ licenses:
57
+ - MIT
58
+ metadata: {}
59
+ post_install_message:
60
+ rdoc_options: []
61
+ require_paths:
62
+ - lib
63
+ required_ruby_version: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ required_rubygems_version: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: '0'
73
+ requirements: []
74
+ rubyforge_project:
75
+ rubygems_version: 2.4.8
76
+ signing_key:
77
+ specification_version: 4
78
+ summary: A microservice for persisting contacts to Sendgrid.
79
+ test_files: []