maxemail_api 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/maxemail_api.rb +74 -0
- metadata +57 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 8ed69942ce651c7d29ecb6894019b80068fc1217
|
4
|
+
data.tar.gz: b50dc7d3634599e0b408169b1fc374286648c0ff
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 99e47221a6f383900530cdd1b2e4cb6564f941f46ea9fc637467145c05dbce9b124542d03733d1f76c4107f3755895a8ee915655a90fd0adad4473c53f97a6c2
|
7
|
+
data.tar.gz: bdd5f3920c1fcc05ae6990e7c5f9bc0d6c311f7b4f089bb54dae42c62cb39d9bc761cda5664156a3dbe4f84d237cb1a75baf57be6181b2b06365f67000ca531b
|
data/lib/maxemail_api.rb
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
module MaxemailApi
|
2
|
+
class << self
|
3
|
+
require 'base64'
|
4
|
+
require 'http'
|
5
|
+
require 'json'
|
6
|
+
|
7
|
+
def send(params)
|
8
|
+
params[:email_id] = email_id(folder_name: params[:folder_name], email_name: params[:email_name]) if params[:email_id].nil?
|
9
|
+
send_triggered(email_address: params[:email_address], email_id: params[:email_id], profile_data: params[:profile_data])
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
def fetch_root(tree: 'email', children: '[]')
|
15
|
+
HTTP.headers(authentication_header)
|
16
|
+
.get("#{ENV['MAXEMAIL_API_URL']}tree",
|
17
|
+
params: {
|
18
|
+
method: 'fetchRoot',
|
19
|
+
tree: tree,
|
20
|
+
children: children
|
21
|
+
})
|
22
|
+
end
|
23
|
+
|
24
|
+
def fetch_tree(tree: 'email', node_id: nil, node_class: 'folder')
|
25
|
+
HTTP.headers(authentication_header)
|
26
|
+
.get("#{ENV['MAXEMAIL_API_URL']}tree",
|
27
|
+
params: {
|
28
|
+
method: 'fetchTree',
|
29
|
+
tree: tree,
|
30
|
+
nodeId: node_id,
|
31
|
+
nodeClass: node_class
|
32
|
+
})
|
33
|
+
end
|
34
|
+
|
35
|
+
def fetch_trigged(folder_id: nil)
|
36
|
+
HTTP.headers(authentication_header)
|
37
|
+
.get("#{ENV['MAXEMAIL_API_URL']}email_triggered",
|
38
|
+
params: {
|
39
|
+
method: 'fetchAll',
|
40
|
+
folderId: folder_id
|
41
|
+
})
|
42
|
+
end
|
43
|
+
|
44
|
+
def send_triggered(email_address: nil, email_id: nil, profile_data: nil)
|
45
|
+
HTTP.headers(authentication_header)
|
46
|
+
.get("#{ENV['MAXEMAIL_API_URL']}email_send",
|
47
|
+
params: {
|
48
|
+
method: 'trigger',
|
49
|
+
emailAddress: email_address,
|
50
|
+
emailId: email_id,
|
51
|
+
profileData: profile_data
|
52
|
+
})
|
53
|
+
end
|
54
|
+
|
55
|
+
def folder_id(folder_name: nil)
|
56
|
+
response = JSON.parse(fetch_root)
|
57
|
+
response[0]['children'].map do |node|
|
58
|
+
node['nodeId'].to_i if node['text'] == folder_name
|
59
|
+
end.compact.first
|
60
|
+
end
|
61
|
+
|
62
|
+
def email_id(folder_name: nil, email_name: nil)
|
63
|
+
folder_id = folder_id(folder_name: folder_name)
|
64
|
+
response = JSON.parse(fetch_tree(tree: 'email', node_id: folder_id, node_class: 'folder'))
|
65
|
+
response.map do |node|
|
66
|
+
node['nodeId'].to_i if node['text'] == email_name
|
67
|
+
end.compact.first
|
68
|
+
end
|
69
|
+
|
70
|
+
def authentication_header
|
71
|
+
{ Authorization: 'Basic ' + Base64.encode64(ENV['MAXEMAIL_USERNAME'] + ':' + ENV['MAXEMAIL_PASSWORD']).remove("\n") }
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
metadata
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: maxemail_api
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Murray Catto
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-07-11 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: http
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 3.3.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 3.3.0
|
27
|
+
description:
|
28
|
+
email:
|
29
|
+
executables: []
|
30
|
+
extensions: []
|
31
|
+
extra_rdoc_files: []
|
32
|
+
files:
|
33
|
+
- lib/maxemail_api.rb
|
34
|
+
homepage:
|
35
|
+
licenses: []
|
36
|
+
metadata: {}
|
37
|
+
post_install_message:
|
38
|
+
rdoc_options: []
|
39
|
+
require_paths:
|
40
|
+
- lib
|
41
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
42
|
+
requirements:
|
43
|
+
- - ">="
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
47
|
+
requirements:
|
48
|
+
- - ">="
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: '0'
|
51
|
+
requirements: []
|
52
|
+
rubyforge_project:
|
53
|
+
rubygems_version: 2.5.2.3
|
54
|
+
signing_key:
|
55
|
+
specification_version: 4
|
56
|
+
summary: Maxemails API wrapped in a gem
|
57
|
+
test_files: []
|