zoho_cpaas-ruby 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/lib/zoho_cpaas/client.rb +27 -0
- data/lib/zoho_cpaas/mail/sendmail.rb +110 -0
- data/lib/zoho_cpaas/mail/sendtemplatemail.rb +90 -0
- data/lib/zoho_cpaas/ruby.rb +9 -0
- data/lib/zoho_cpaas-ruby.rb +3 -0
- data/lib/zoho_cpaas.rb +3 -0
- data/lib/zohocpaas_ruby.rb +3 -0
- metadata +110 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: bfb0a432c3bcd8ea7726b4a15f9ec225b154957b5ec1c035be17d56f7f88b918
|
|
4
|
+
data.tar.gz: 800040eacab0e7ca29af4c11b5719b5b01df2026563a7d107a0b4f0cbcbd16a3
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: f5c99155f0e79c13a28bef5fea5fa744cc0c2792fd1c12b561acda11fa05ce9834e5fb790712b8c010e451aeff5cc10bb861650c910b817cb99f7fdfabd72551
|
|
7
|
+
data.tar.gz: 6c811757184a494bb5abab61d47ed9563c077078d7cc25ad0cf1ee3c5eebc6a04398fc7249c93ea3da810d7f7497de39c814ff028a41f4901c50f9e71fcc12ae
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'http'
|
|
4
|
+
|
|
5
|
+
ZohoCpaas_API_BASE_HOST = 'cpaas.zoho.com'
|
|
6
|
+
|
|
7
|
+
# ZohoCpaas-ruby is a gem that integrates all endpoints from ZohoCpaas API
|
|
8
|
+
module ZohoCpaas
|
|
9
|
+
class Client
|
|
10
|
+
attr_reader :api_token
|
|
11
|
+
attr_reader :host_region
|
|
12
|
+
|
|
13
|
+
# Inits the client.
|
|
14
|
+
def initialize(api_token = ENV.fetch('ZOHO_ZEPTOMAIL_API_KEY_TOKEN', nil), api_host = ENV.fetch('ZOHO_ZEPTOMAIL_HOSTED_REGION', ZohoCpaas_API_BASE_HOST))
|
|
15
|
+
raise ArgumentError, 'API key token is not provided' if api_token.nil?
|
|
16
|
+
@api_token = api_token
|
|
17
|
+
@host_region = api_host
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def http
|
|
21
|
+
HTTP
|
|
22
|
+
.headers('User-Agent' => "Ruby on Rails ZohoCpaas",
|
|
23
|
+
'Accept' => 'application/json',
|
|
24
|
+
'Authorization' => "Zoho-enczapikey #{@api_token}")
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
require 'base64'
|
|
5
|
+
|
|
6
|
+
module ZohoCpaas
|
|
7
|
+
# Send an mail through ZohoCpaas API
|
|
8
|
+
class SendMail
|
|
9
|
+
attr_accessor :client,
|
|
10
|
+
:from,
|
|
11
|
+
:recipients,
|
|
12
|
+
:subject,
|
|
13
|
+
:body,
|
|
14
|
+
:cc,
|
|
15
|
+
:bcc,
|
|
16
|
+
:reply_to,
|
|
17
|
+
:attachments
|
|
18
|
+
|
|
19
|
+
def initialize(client = ZohoCpaas::Client.new)
|
|
20
|
+
@client = client
|
|
21
|
+
@from = {}
|
|
22
|
+
@recipients = []
|
|
23
|
+
@body = nil
|
|
24
|
+
@bcc = []
|
|
25
|
+
@cc = []
|
|
26
|
+
@reply_to = []
|
|
27
|
+
@subject = nil
|
|
28
|
+
@attachments = []
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def add_recipients(recipients)
|
|
32
|
+
@recipients << {'email_address' => recipients}
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def add_from(from)
|
|
36
|
+
@from = from
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def add_cc(cc)
|
|
40
|
+
@cc << {'email_address' => cc}
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def add_bcc(bcc)
|
|
44
|
+
@bcc << {'email_address' => bcc}
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def add_reply_to(reply_to)
|
|
48
|
+
@reply_to << reply_to
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def add_subject(subject)
|
|
52
|
+
@subject = subject
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def add_body(body)
|
|
56
|
+
@body = body
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def add_attachment(content:, filename:, mime_type:)
|
|
60
|
+
content_string = content.to_s
|
|
61
|
+
if File.readable?(content_string)
|
|
62
|
+
data = File.read(content_string)
|
|
63
|
+
content_string = data
|
|
64
|
+
end
|
|
65
|
+
add_attachments(content: content_string, filename: filename, mime_type: mime_type)
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def add_attachments(content:, filename:, mime_type:)
|
|
69
|
+
data_content = Base64.strict_encode64(content.to_s)
|
|
70
|
+
@attachments << { 'content' => data_content, 'name' => filename, 'mime_type' => mime_type }
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def handle_to_response(response)
|
|
74
|
+
response_data = {}
|
|
75
|
+
data = JSON.parse(response.body)
|
|
76
|
+
|
|
77
|
+
if response.code.to_i / 100 == 2
|
|
78
|
+
response_data['status'] = 'success'
|
|
79
|
+
response_data['message'] = data['data'][0]['message'] || 'successfully sent the email'
|
|
80
|
+
else
|
|
81
|
+
response_data['status'] = 'failure'
|
|
82
|
+
response_data['message'] = data['error']['details'][0]['message']
|
|
83
|
+
|
|
84
|
+
begin
|
|
85
|
+
response_data['target'] = data['error']['details'][0]['target']
|
|
86
|
+
rescue
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
response_data
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
def send
|
|
94
|
+
message = {
|
|
95
|
+
'from' => @from,
|
|
96
|
+
'to' => @recipients,
|
|
97
|
+
'subject' => @subject,
|
|
98
|
+
'htmlbody' => @body,
|
|
99
|
+
'reply_to' => @reply_to,
|
|
100
|
+
'cc' => @cc,
|
|
101
|
+
'bcc' => @bcc,
|
|
102
|
+
'attachments' => @attachments,
|
|
103
|
+
}
|
|
104
|
+
response = client.http.post("https://#{client.host_region}/v1.1/email", json: message)
|
|
105
|
+
handled = handle_to_response(response)
|
|
106
|
+
puts "Response: #{handled}"
|
|
107
|
+
handled
|
|
108
|
+
end
|
|
109
|
+
end
|
|
110
|
+
end
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
require 'json'
|
|
5
|
+
|
|
6
|
+
module ZohoCpaas
|
|
7
|
+
# Send an Template Mail through ZohoCpaas API
|
|
8
|
+
class SendTemplateMail
|
|
9
|
+
attr_accessor :client,
|
|
10
|
+
:from,
|
|
11
|
+
:recipients,
|
|
12
|
+
:cc,
|
|
13
|
+
:bcc,
|
|
14
|
+
:reply_to,
|
|
15
|
+
:template_key,
|
|
16
|
+
:template_value
|
|
17
|
+
|
|
18
|
+
def initialize(client = ZohoCpaas::Client.new)
|
|
19
|
+
@client = client
|
|
20
|
+
@from = {}
|
|
21
|
+
@recipients = []
|
|
22
|
+
@bcc = []
|
|
23
|
+
@cc = []
|
|
24
|
+
@reply_to = []
|
|
25
|
+
@template_key = nil
|
|
26
|
+
@template_value = nil
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def add_recipients(recipients)
|
|
30
|
+
@recipients << {'email_address' => recipients}
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def add_from(from)
|
|
34
|
+
@from = from
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def add_cc(cc)
|
|
38
|
+
@cc << {'email_address' => cc}
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def add_bcc(bcc)
|
|
42
|
+
@bcc << {'email_address' => bcc}
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def add_reply_to(reply_to)
|
|
46
|
+
@reply_to << reply_to
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def add_template(key:, value:)
|
|
50
|
+
@template_key = key.to_s
|
|
51
|
+
@template_value = value.is_a?(String) ? JSON.parse(value) : value
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def handle_to_response(response)
|
|
55
|
+
response_data = {}
|
|
56
|
+
data = JSON.parse(response.body)
|
|
57
|
+
|
|
58
|
+
if response.code.to_i / 100 == 2
|
|
59
|
+
response_data['status'] = 'success'
|
|
60
|
+
response_data['message'] = data['data'][0]['message'] || 'successfully sent the email'
|
|
61
|
+
else
|
|
62
|
+
response_data['status'] = 'failure'
|
|
63
|
+
response_data['message'] = data['error']['details'][0]['message']
|
|
64
|
+
|
|
65
|
+
begin
|
|
66
|
+
response_data['target'] = data['error']['details'][0]['target']
|
|
67
|
+
rescue
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
response_data
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
def send
|
|
75
|
+
message = {
|
|
76
|
+
'from' => @from,
|
|
77
|
+
'to' => @recipients,
|
|
78
|
+
'reply_to' => @reply_to,
|
|
79
|
+
'cc' => @cc,
|
|
80
|
+
'bcc' => @bcc,
|
|
81
|
+
'template_key' => @template_key,
|
|
82
|
+
'merge_info' => @template_value
|
|
83
|
+
}
|
|
84
|
+
response = client.http.post("https://#{client.host_region}/v1.1/email/template", json: message)
|
|
85
|
+
handled = handle_to_response(response)
|
|
86
|
+
puts "Response: #{handled}"
|
|
87
|
+
handled
|
|
88
|
+
end
|
|
89
|
+
end
|
|
90
|
+
end
|
data/lib/zoho_cpaas.rb
ADDED
metadata
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: zoho_cpaas-ruby
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 1.0.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- ACO
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: exe
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2026-11-13 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: '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: rspec
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - ">="
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '0'
|
|
34
|
+
type: :development
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - ">="
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: '0'
|
|
41
|
+
- !ruby/object:Gem::Dependency
|
|
42
|
+
name: vcr
|
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - ">="
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: '0'
|
|
48
|
+
type: :development
|
|
49
|
+
prerelease: false
|
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - ">="
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: '0'
|
|
55
|
+
- !ruby/object:Gem::Dependency
|
|
56
|
+
name: webmock
|
|
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
|
+
description: Zoho CPaas Ruby SDK.
|
|
70
|
+
email:
|
|
71
|
+
- contact@aurarians.com
|
|
72
|
+
executables: []
|
|
73
|
+
extensions: []
|
|
74
|
+
extra_rdoc_files: []
|
|
75
|
+
files:
|
|
76
|
+
- lib/zoho_cpaas-ruby.rb
|
|
77
|
+
- lib/zoho_cpaas.rb
|
|
78
|
+
- lib/zoho_cpaas/client.rb
|
|
79
|
+
- lib/zoho_cpaas/mail/sendmail.rb
|
|
80
|
+
- lib/zoho_cpaas/mail/sendtemplatemail.rb
|
|
81
|
+
- lib/zoho_cpaas/ruby.rb
|
|
82
|
+
- lib/zohocpaas_ruby.rb
|
|
83
|
+
homepage: https://alexason.com
|
|
84
|
+
licenses:
|
|
85
|
+
- MIT
|
|
86
|
+
metadata:
|
|
87
|
+
allowed_push_host: https://rubygems.org
|
|
88
|
+
homepage_uri: https://alexason.com
|
|
89
|
+
source_code_uri: https://alexason.com
|
|
90
|
+
changelog_uri: https://alexason.com
|
|
91
|
+
post_install_message:
|
|
92
|
+
rdoc_options: []
|
|
93
|
+
require_paths:
|
|
94
|
+
- lib
|
|
95
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
96
|
+
requirements:
|
|
97
|
+
- - ">="
|
|
98
|
+
- !ruby/object:Gem::Version
|
|
99
|
+
version: 3.1.0
|
|
100
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
101
|
+
requirements:
|
|
102
|
+
- - ">="
|
|
103
|
+
- !ruby/object:Gem::Version
|
|
104
|
+
version: '0'
|
|
105
|
+
requirements: []
|
|
106
|
+
rubygems_version: 3.5.22
|
|
107
|
+
signing_key:
|
|
108
|
+
specification_version: 4
|
|
109
|
+
summary: Zoho Cpaas Ruby SDK
|
|
110
|
+
test_files: []
|