cm_email 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.
- checksums.yaml +7 -0
- data/Gemfile +6 -0
- data/README.md +12 -0
- data/cm_email.gemspec +23 -0
- data/lib/cm_email.rb +97 -0
- data/lib/cm_email/configuration.rb +10 -0
- data/lib/cm_email/version.rb +3 -0
- metadata +49 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 3290263df41ae164bd40b9bfc77b016028125804bdbc08cd74095c6e9f8c8037
|
4
|
+
data.tar.gz: a5ec5aecd10709d9bf0f914e6ceb62b4cc23b5a415c4c11a44bbf377e2e55bf2
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 1eb25a9d267b43e06a204a621de515d5db30101f35b708a7ff1475fe111407cc17881326d76cfaf3650c149adb82bdc06cc47d807e149f7609af1be207da8718
|
7
|
+
data.tar.gz: d5d9218a6510dd07b9f3b12e051ba2942b23a4c1ec6e2efea108b85fec12d3b88e1e8940aacf23c39c1f40e44f6046bddf8da0415b612b5af5170866cc47a140
|
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
# Cm_email Gem Setup Instructions
|
2
|
+
To install the gem in your application:
|
3
|
+
```
|
4
|
+
- Add to your Gemfile: gem 'cm_email'
|
5
|
+
- Run: bundle install
|
6
|
+
```
|
7
|
+
Create a configuration file like `config/initializers/cm_email.rb`, paste the following and replace the credentials.
|
8
|
+
```
|
9
|
+
Cm_email.configure do |config|
|
10
|
+
config.api_key = "xxxxxxxxxxxxxx"
|
11
|
+
end
|
12
|
+
```
|
data/cm_email.gemspec
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
require_relative 'lib/cm_email/version'
|
2
|
+
|
3
|
+
Gem::Specification.new do |spec|
|
4
|
+
spec.name = "cm_email"
|
5
|
+
spec.version = CmEmail::VERSION
|
6
|
+
spec.authors = ["PRATIK DHARAMDASANI"]
|
7
|
+
spec.email = ["pratik@commutatus.com"]
|
8
|
+
|
9
|
+
spec.summary = "cm_email gem facilitates sending emails using Cm-email's API."
|
10
|
+
spec.description = "This gem is a wrapper for Cm-email's API"
|
11
|
+
spec.homepage = 'https://github.com/commutatus/cm-email-gem'
|
12
|
+
spec.license = "MIT"
|
13
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
|
14
|
+
|
15
|
+
# Specify which files should be added to the gem when it is released.
|
16
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
17
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
18
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
19
|
+
end
|
20
|
+
spec.bindir = "exe"
|
21
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
|
+
spec.require_paths = ["lib"]
|
23
|
+
end
|
data/lib/cm_email.rb
ADDED
@@ -0,0 +1,97 @@
|
|
1
|
+
require "cm_email/version"
|
2
|
+
require 'cm_email/configuration'
|
3
|
+
|
4
|
+
module Cm_email
|
5
|
+
class << self
|
6
|
+
attr_accessor :configuration
|
7
|
+
require 'net/http'
|
8
|
+
require 'uri'
|
9
|
+
require 'json'
|
10
|
+
|
11
|
+
def configuration
|
12
|
+
@configuration ||= Configuration.new
|
13
|
+
end
|
14
|
+
|
15
|
+
def configure
|
16
|
+
yield(configuration)
|
17
|
+
end
|
18
|
+
|
19
|
+
# Either finds and updates, or creates a contact (with status subscribed).
|
20
|
+
def create_contact(first_name, email, last_name = '', date_of_birth = '', country = '')
|
21
|
+
request_body = {
|
22
|
+
first_name: first_name,
|
23
|
+
email: email,
|
24
|
+
last_name: last_name,
|
25
|
+
date_of_birth: date_of_birth,
|
26
|
+
country: country
|
27
|
+
}
|
28
|
+
create_response = request_cm_email('/api/contacts', request_body)
|
29
|
+
end
|
30
|
+
|
31
|
+
# Finds the contact and unsubscribes it from every segment.
|
32
|
+
def unsubscribe_contact(contact_email)
|
33
|
+
request_body = {
|
34
|
+
contact_email: contact_email
|
35
|
+
}
|
36
|
+
create_response = request_cm_email('/api/contacts/unsubscribe', request_body)
|
37
|
+
end
|
38
|
+
|
39
|
+
# Creates a segment (with atleast one existing contact).
|
40
|
+
# expected format for 'contact_emails' is Array[JSON].
|
41
|
+
def create_segment(name, contact_emails, note = '')
|
42
|
+
request_body = {
|
43
|
+
name: name,
|
44
|
+
note: note,
|
45
|
+
segment: {
|
46
|
+
segment_contacts: contact_emails
|
47
|
+
}
|
48
|
+
}
|
49
|
+
create_response = request_cm_email('/api/segments', request_body)
|
50
|
+
end
|
51
|
+
|
52
|
+
# Removes contact from the segment.
|
53
|
+
def remove_segment_contact(contact_email, segment_name)
|
54
|
+
request_body = {
|
55
|
+
contact_email: contact_email,
|
56
|
+
segment_name: segment_name
|
57
|
+
}
|
58
|
+
create_response = request_cm_email('/api/segments/segment_contacts/remove', request_body, 'delete')
|
59
|
+
end
|
60
|
+
|
61
|
+
# Adds a contact to a segment.
|
62
|
+
def add_segment_contact(contact_email, segment_name)
|
63
|
+
request_body = {
|
64
|
+
contact_email: contact_email,
|
65
|
+
segment: segment_name
|
66
|
+
}
|
67
|
+
create_response = request_cm_email('/api/segments/segment_contacts/add', request_body)
|
68
|
+
end
|
69
|
+
|
70
|
+
def request_cm_email(path, request_body, method = 'post')
|
71
|
+
domain_url = if api_mode.eql?('staging')
|
72
|
+
'https://staging.cm-email.commutatus.com/'
|
73
|
+
else
|
74
|
+
'https://cm-email.commutatus.com/'
|
75
|
+
end
|
76
|
+
uri = URI.parse(domain_url + path)
|
77
|
+
headers = {'Content-Type': 'application/json', 'api_key': api_key}
|
78
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
79
|
+
http.use_ssl = true
|
80
|
+
request = method == 'delete'? Net::HTTP::Delete.new(uri.request_uri, headers) : Net::HTTP::Post.new(uri.request_uri, headers)
|
81
|
+
puts request_body.to_json
|
82
|
+
request.body = request_body.to_json
|
83
|
+
# Send the request
|
84
|
+
response = http.request(request)
|
85
|
+
return JSON.parse(response.body)
|
86
|
+
end
|
87
|
+
|
88
|
+
def api_key
|
89
|
+
return configuration.api_key
|
90
|
+
end
|
91
|
+
|
92
|
+
def api_mode
|
93
|
+
return configuration.api_mode
|
94
|
+
end
|
95
|
+
|
96
|
+
end
|
97
|
+
end
|
metadata
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: cm_email
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- PRATIK DHARAMDASANI
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2021-06-07 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: This gem is a wrapper for Cm-email's API
|
14
|
+
email:
|
15
|
+
- pratik@commutatus.com
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- Gemfile
|
21
|
+
- README.md
|
22
|
+
- cm_email.gemspec
|
23
|
+
- lib/cm_email.rb
|
24
|
+
- lib/cm_email/configuration.rb
|
25
|
+
- lib/cm_email/version.rb
|
26
|
+
homepage: https://github.com/commutatus/cm-email-gem
|
27
|
+
licenses:
|
28
|
+
- MIT
|
29
|
+
metadata: {}
|
30
|
+
post_install_message:
|
31
|
+
rdoc_options: []
|
32
|
+
require_paths:
|
33
|
+
- lib
|
34
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
35
|
+
requirements:
|
36
|
+
- - ">="
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: 2.3.0
|
39
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
44
|
+
requirements: []
|
45
|
+
rubygems_version: 3.1.2
|
46
|
+
signing_key:
|
47
|
+
specification_version: 4
|
48
|
+
summary: cm_email gem facilitates sending emails using Cm-email's API.
|
49
|
+
test_files: []
|