unione-ruby 0.0.1 → 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 +4 -4
- data/README.md +99 -8
- data/Rakefile +52 -0
- data/config/response_schema/domain.yml +74 -0
- data/config/response_schema/email.yml +23 -0
- data/config/response_schema/event_dump.yml +75 -0
- data/config/response_schema/project.yml +59 -0
- data/config/response_schema/suppression.yml +71 -0
- data/config/response_schema/system.yml +33 -0
- data/config/response_schema/tag.yml +26 -0
- data/config/response_schema/template.yml +134 -0
- data/config/response_schema/unsubscribed.yml +45 -0
- data/config/response_schema/webhook.yml +141 -0
- data/examples/api/custom_api.rb +14 -0
- data/examples/api/domain.rb +14 -7
- data/examples/api/email/attachments.rb +28 -0
- data/examples/api/email/multiple_recipients.rb +24 -0
- data/examples/api/email/send.rb +25 -0
- data/examples/api/email/settings.rb +41 -0
- data/examples/api/email/subscribe.rb +14 -0
- data/examples/api/email/template.rb +26 -0
- data/examples/api/event_dump.rb +44 -0
- data/examples/api/project.rb +35 -11
- data/examples/api/suppression.rb +34 -0
- data/examples/api/system.rb +10 -0
- data/examples/api/tag.rb +15 -0
- data/examples/api/template.rb +40 -22
- data/examples/api/unsubscribed.rb +20 -12
- data/examples/api/webhook.rb +34 -24
- data/examples/helpers.rb +29 -0
- data/examples/send_mail.rb +44 -0
- data/examples/setup.rb +34 -0
- data/lib/unione/client/domain.rb +19 -46
- data/lib/unione/client/email.rb +14 -21
- data/lib/unione/client/event_dump.rb +37 -0
- data/lib/unione/client/project.rb +19 -43
- data/lib/unione/client/suppression.rb +38 -0
- data/lib/unione/client/system.rb +19 -0
- data/lib/unione/client/tag.rb +24 -0
- data/lib/unione/client/template.rb +19 -65
- data/lib/unione/client/unsubscribed.rb +18 -31
- data/lib/unione/client/webhook.rb +19 -38
- data/lib/unione/client.rb +42 -17
- data/lib/unione/connection.rb +24 -16
- data/lib/unione/helpers.rb +22 -0
- data/lib/unione/response/raise_error.rb +4 -5
- data/lib/unione/validation.rb +32 -12
- data/lib/unione/version.rb +1 -1
- data/lib/unione-ruby.rb +0 -3
- data/test/CONFIGFILE.yml +71 -0
- data/unione-ruby.gemspec +2 -2
- metadata +36 -11
- data/examples/1_setup.rb +0 -25
- data/examples/2_mail_sending.rb +0 -23
- data/examples/api/email.rb +0 -36
- data/lib/unione/helpers/mail/mail.rb +0 -37
- data/lib/unione/helpers/template/template.rb +0 -31
- data/lib/unione/helpers/webhook/webhook.rb +0 -17
@@ -1,53 +1,34 @@
|
|
1
1
|
module UniOne
|
2
2
|
class Client
|
3
|
-
|
4
3
|
module Webhook
|
4
|
+
extend UniOne::Validation::ClassMethods
|
5
|
+
include UniOne::Validation::InstanceMethods
|
5
6
|
|
6
|
-
def set_webhook(
|
7
|
-
post
|
8
|
-
validate_response({'type' => 'object', 'required' => ['status', 'object'], 'properties' => {
|
9
|
-
'status' => {'type' => 'string'},
|
10
|
-
'object' => webhook_schema
|
11
|
-
}})
|
7
|
+
def set_webhook(params = {})
|
8
|
+
post('webhook/set.json', params)
|
12
9
|
end
|
13
10
|
|
14
|
-
def get_webhook(
|
15
|
-
params
|
16
|
-
post 'webhook/get.json', params
|
17
|
-
get_webhook_schema = remove_fields_from_schema(webhook_schema, ['delivery_info', 'single_event'])
|
18
|
-
validate_response({'type' => 'object', 'required' => ['status', 'object'], 'properties' => {
|
19
|
-
'status' => {'type' => 'string'},
|
20
|
-
'object' => get_webhook_schema
|
21
|
-
}})
|
11
|
+
def get_webhook(params = {})
|
12
|
+
post('webhook/get.json', params)
|
22
13
|
end
|
23
14
|
|
24
|
-
def
|
25
|
-
params
|
26
|
-
post 'webhook/delete.json', params
|
27
|
-
validate_response({'type' => 'object', 'required' => ['status'], 'properties' => {
|
28
|
-
'status' => {'type' => 'string'}
|
29
|
-
}})
|
15
|
+
def list_webhooks(params = {})
|
16
|
+
post('webhook/list.json', params)
|
30
17
|
end
|
31
18
|
|
32
|
-
|
33
|
-
|
34
|
-
def webhook_schema
|
35
|
-
{'type' => 'object', 'required' => ['url', 'events', 'event_format', 'delivery_info', 'single_event', 'max_parallel'], 'properties' => {
|
36
|
-
'url' => {'type' => 'string'},
|
37
|
-
'events' => webhook_events_schema,
|
38
|
-
'event_format' => {'type' => 'string'},
|
39
|
-
'delivery_info' => {'type' => 'integer'},
|
40
|
-
'single_event' => {'type' => 'integer'},
|
41
|
-
'max_parallel' => {'type' => 'integer'}
|
42
|
-
}}
|
19
|
+
def delete_webhook(params = {})
|
20
|
+
post('webhook/delete.json', params)
|
43
21
|
end
|
44
22
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
23
|
+
add_response_validations(
|
24
|
+
:webhook,
|
25
|
+
%w(
|
26
|
+
set_webhook
|
27
|
+
get_webhook
|
28
|
+
list_webhooks
|
29
|
+
delete_webhook
|
30
|
+
)
|
31
|
+
)
|
51
32
|
end
|
52
33
|
end
|
53
34
|
end
|
data/lib/unione/client.rb
CHANGED
@@ -1,44 +1,69 @@
|
|
1
1
|
require_relative 'connection'
|
2
2
|
require_relative 'validation'
|
3
|
+
require_relative 'helpers'
|
3
4
|
require_relative 'client/domain'
|
4
5
|
require_relative 'client/email'
|
6
|
+
require_relative 'client/event_dump'
|
7
|
+
require_relative 'client/project'
|
8
|
+
require_relative 'client/suppression'
|
9
|
+
require_relative 'client/system'
|
10
|
+
require_relative 'client/tag'
|
5
11
|
require_relative 'client/template'
|
6
|
-
require_relative 'client/webhook'
|
7
12
|
require_relative 'client/unsubscribed'
|
8
|
-
require_relative 'client/
|
13
|
+
require_relative 'client/webhook'
|
9
14
|
|
10
15
|
module UniOne
|
11
|
-
|
12
16
|
class Client
|
13
|
-
|
14
17
|
include UniOne::Connection
|
15
|
-
|
18
|
+
extend UniOne::Validation::ClassMethods
|
19
|
+
include UniOne::Validation::InstanceMethods
|
20
|
+
include UniOne::Client::Helpers
|
16
21
|
include UniOne::Client::Domain
|
17
22
|
include UniOne::Client::Email
|
23
|
+
include UniOne::Client::EventDump
|
24
|
+
include UniOne::Client::Project
|
25
|
+
include UniOne::Client::Suppression
|
26
|
+
include UniOne::Client::System
|
27
|
+
include UniOne::Client::Tag
|
18
28
|
include UniOne::Client::Template
|
19
|
-
include UniOne::Client::Webhook
|
20
29
|
include UniOne::Client::Unsubscribed
|
21
|
-
include UniOne::Client::
|
30
|
+
include UniOne::Client::Webhook
|
31
|
+
|
32
|
+
class BaseException < StandardError; end
|
33
|
+
class InvalidCallbackAuth < BaseException; end
|
22
34
|
|
23
35
|
API_ENDPOINT =
|
24
|
-
'https://%{
|
36
|
+
'https://%{hostname}/%{lang}/transactional/api/v1/'
|
25
37
|
|
26
38
|
# * *Args* :
|
27
|
-
# - +
|
28
|
-
# - +lang+
|
29
|
-
# - +api_key+
|
30
|
-
#
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
@
|
39
|
+
# - +hostname+ -> string, API hostname, for example 'eu1.unione.io'
|
40
|
+
# - +lang+ -> string, two-letter ISO 639-1 language abbreviation, e.g. 'en'
|
41
|
+
# - +api_key+ -> string, your UniOne API key
|
42
|
+
# - +timeout+ -> integer, timeout in seconds, 5 by default
|
43
|
+
# - +api_key_in_params+ -> boolean, pass API key in parameters, otherwise pass in headers (default)
|
44
|
+
# - +enable_logging+ -> boolean, enable logging
|
45
|
+
def initialize(params = {})
|
46
|
+
@hostname = params[:hostname]
|
47
|
+
@lang = params[:lang]
|
48
|
+
@api_key = params[:api_key]
|
49
|
+
@timeout = params[:timeout] || 5
|
50
|
+
@api_key_in_params = params[:api_key_in_params]
|
51
|
+
@enable_logging = params[:enable_logging] || ENV['ENABLE_LOGGING']
|
35
52
|
end
|
36
53
|
|
37
54
|
private
|
38
55
|
|
39
56
|
def api_endpoint
|
40
57
|
@api_endpoint ||=
|
41
|
-
API_ENDPOINT % {
|
58
|
+
API_ENDPOINT % { hostname: @hostname, lang: @lang }
|
59
|
+
end
|
60
|
+
|
61
|
+
def handle_time_param(param)
|
62
|
+
param.respond_to?(:strftime) ? param.strftime('%Y-%m-%d %H:%M:%S') : param
|
63
|
+
end
|
64
|
+
|
65
|
+
def handle_date_param(param)
|
66
|
+
param.respond_to?(:strftime) ? param.strftime('%Y-%m-%d') : param
|
42
67
|
end
|
43
68
|
end
|
44
69
|
end
|
data/lib/unione/connection.rb
CHANGED
@@ -6,45 +6,53 @@ require 'hashie'
|
|
6
6
|
module UniOne
|
7
7
|
module Connection
|
8
8
|
|
9
|
-
def get(url, params)
|
10
|
-
|
9
|
+
def get(url, params = {})
|
10
|
+
prepare_params!(params)
|
11
|
+
|
11
12
|
# Assume HTTP library receives params as Hash
|
12
|
-
request
|
13
|
+
request(:get, url, params)
|
13
14
|
end
|
14
15
|
|
15
|
-
def post(url, params)
|
16
|
-
|
16
|
+
def post(url, params = {})
|
17
|
+
prepare_params!(params)
|
18
|
+
|
17
19
|
# Assume HTTP library receives payload body as String
|
18
|
-
request
|
20
|
+
request(:post, url, JSON.dump(params))
|
19
21
|
end
|
20
22
|
|
21
23
|
private
|
22
24
|
|
23
25
|
def request(method, path, data)
|
24
26
|
path = add_version(path)
|
25
|
-
|
26
|
-
@last_response = conn.send(method, path, data)
|
27
|
-
rescue Faraday::Error => e
|
28
|
-
puts e.response[:body]
|
29
|
-
raise
|
30
|
-
end
|
27
|
+
@last_response = conn.send(method, path, data)
|
31
28
|
end
|
32
29
|
|
33
30
|
def conn
|
31
|
+
headers = {'Content-Type' => 'application/json'}
|
32
|
+
prepare_headers!(headers)
|
33
|
+
|
34
34
|
@conn ||= Faraday.new(
|
35
35
|
url: api_endpoint,
|
36
|
-
headers:
|
37
|
-
request: { timeout:
|
36
|
+
headers: headers,
|
37
|
+
request: { timeout: @timeout }
|
38
38
|
) do |conn|
|
39
39
|
conn.response :mashify, content_type: /\bjson$/
|
40
40
|
conn.response :json, content_type: /\bjson$/
|
41
41
|
conn.response :raise_error
|
42
42
|
conn.adapter :net_http_persistent
|
43
|
+
|
44
|
+
if @enable_logging
|
45
|
+
conn.response(:logger, nil, { headers: true, bodies: true, errors: true })
|
46
|
+
end
|
43
47
|
end
|
44
48
|
end
|
45
49
|
|
46
|
-
def
|
47
|
-
{
|
50
|
+
def prepare_params!(params)
|
51
|
+
params.merge!({api_key: @api_key}) if @api_key_in_params
|
52
|
+
end
|
53
|
+
|
54
|
+
def prepare_headers!(headers)
|
55
|
+
headers.merge!('X-API-KEY' => @api_key) unless @api_key_in_params
|
48
56
|
end
|
49
57
|
|
50
58
|
def add_version(path)
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'digest'
|
2
|
+
|
3
|
+
module UniOne
|
4
|
+
class Client
|
5
|
+
module Helpers
|
6
|
+
# Helper function for webhooks callback. It is checking auth field
|
7
|
+
# and if it is invalid, raises Unione::Client::InvalidCallbackAuth exception
|
8
|
+
def verify_callback_auth!(params)
|
9
|
+
params = params.transform_keys(&:to_sym)
|
10
|
+
auth = params[:auth]
|
11
|
+
unless auth == Digest::MD5.hexdigest(params.merge(auth: @api_key).to_json)
|
12
|
+
raise InvalidCallbackAuth
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def callback_helper(params)
|
17
|
+
verify_callback_auth!(params)
|
18
|
+
yield params.dig('events_by_user', 0, 'events')
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -1,14 +1,13 @@
|
|
1
|
+
# UniOne response middleware
|
2
|
+
|
1
3
|
require 'faraday'
|
2
4
|
require 'unione/error'
|
3
5
|
|
4
6
|
module UniOne
|
5
|
-
# UniOne response middleware
|
6
7
|
module Response
|
7
|
-
|
8
|
-
#
|
9
|
-
# HTTP status codes returned by the API
|
8
|
+
# This class raises an UniOne-flavored exception based on HTTP
|
9
|
+
# status codes returned by the API
|
10
10
|
class RaiseError < Faraday::Response::Middleware
|
11
|
-
|
12
11
|
private
|
13
12
|
|
14
13
|
def on_complete(response)
|
data/lib/unione/validation.rb
CHANGED
@@ -1,24 +1,44 @@
|
|
1
1
|
require 'json-schema'
|
2
|
+
require 'yaml'
|
2
3
|
|
3
4
|
module UniOne
|
4
5
|
module Validation
|
6
|
+
module ClassMethods
|
7
|
+
def add_response_validations(klass, methods)
|
8
|
+
methods.each do |method|
|
9
|
+
orig = "#{method}_without_hook"
|
10
|
+
alias_method orig, method
|
5
11
|
|
6
|
-
|
12
|
+
define_method method do |*args|
|
13
|
+
send(orig, *args)
|
14
|
+
schema = get_response_schema(klass, method)
|
15
|
+
validate_response(schema)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
7
20
|
|
8
|
-
|
9
|
-
|
21
|
+
module InstanceMethods
|
22
|
+
private
|
23
|
+
|
24
|
+
def validate_response(schema)
|
10
25
|
JSON::Validator.validate!(schema, @last_response.body)
|
11
|
-
|
12
|
-
|
13
|
-
|
26
|
+
@last_response
|
27
|
+
end
|
28
|
+
|
29
|
+
def get_response_schema(klass, method)
|
30
|
+
@response_schemas ||= {}
|
31
|
+
@response_schemas[klass] ||= begin
|
32
|
+
directory = File.join(File.dirname(__FILE__), '..', '..', 'config', 'response_schema')
|
33
|
+
filename = "#{klass}.yml"
|
34
|
+
YAML.load_file(File.join(directory, filename))
|
35
|
+
end
|
36
|
+
|
37
|
+
@response_schemas[klass][method]
|
14
38
|
end
|
15
|
-
@last_response
|
16
|
-
end
|
17
39
|
|
18
|
-
|
19
|
-
|
20
|
-
s['required'] = s['required'].reject { |f| fields.include?(f) }
|
21
|
-
s['properties'] = s['properties'].reject { |f| fields.include?(f) }
|
40
|
+
def undescore_class_name(class_name)
|
41
|
+
class_name.gsub(/([^\^])([A-Z])/,'\1_\2').downcase
|
22
42
|
end
|
23
43
|
end
|
24
44
|
end
|
data/lib/unione/version.rb
CHANGED
data/lib/unione-ruby.rb
CHANGED
data/test/CONFIGFILE.yml
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
- method: send_email
|
2
|
+
params:
|
3
|
+
message:
|
4
|
+
recipients:
|
5
|
+
- email: test@qadns.net
|
6
|
+
substitutions:
|
7
|
+
CustomerId: 12452
|
8
|
+
to_name: John Smith
|
9
|
+
metadata:
|
10
|
+
campaign_id: c77f4f4e-3561-49f7-9f07-c35be01b4f43
|
11
|
+
customer_hash: b253ac7
|
12
|
+
tags:
|
13
|
+
- string1
|
14
|
+
skip_unsubscribe: 0
|
15
|
+
global_language: en
|
16
|
+
template_engine: simple
|
17
|
+
global_substitutions:
|
18
|
+
property1: string
|
19
|
+
property2: string
|
20
|
+
global_metadata:
|
21
|
+
property1: string
|
22
|
+
property2: string
|
23
|
+
body:
|
24
|
+
html: "<b>Hello, {{to_name}}</b>"
|
25
|
+
plaintext: Hello, {{to_name}}
|
26
|
+
amp: <!doctype html><html amp4email><head> <meta charset="utf-8"><script async
|
27
|
+
src="https://cdn.ampproject.org/v0.js"></script> <style amp4email-boilerplate>body{visibility:hidden}</style></head><body>
|
28
|
+
Hello, AMP4EMAIL world.</body></html>
|
29
|
+
subject: string
|
30
|
+
from_email: test@qadns.net
|
31
|
+
from_name: John Smith
|
32
|
+
reply_to: test@qadns.net
|
33
|
+
track_links: 0
|
34
|
+
track_read: 0
|
35
|
+
bypass_global: 0
|
36
|
+
bypass_unavailable: 0
|
37
|
+
bypass_unsubscribed: 0
|
38
|
+
bypass_complained: 0
|
39
|
+
headers:
|
40
|
+
X-MyHeader: some data
|
41
|
+
List-Unsubscribe: "<mailto: unsubscribe@example.com?subject=unsubscribe>, <http://www.example.com/unsubscribe/{{CustomerId}}>"
|
42
|
+
attachments:
|
43
|
+
- type: text/plain
|
44
|
+
name: readme.txt
|
45
|
+
content: SGVsbG8sIHdvcmxkIQ==
|
46
|
+
inline_attachments:
|
47
|
+
- type: image/gif
|
48
|
+
name: IMAGECID1
|
49
|
+
content: R0lGODdhAwADAIABAP+rAP///ywAAAAAAwADAAACBIQRBwUAOw==
|
50
|
+
options:
|
51
|
+
unsubscribe_url: https://example.org/unsubscribe/{{CustomerId}}
|
52
|
+
- method: set_webhook
|
53
|
+
params:
|
54
|
+
url: http://example.com
|
55
|
+
status: active
|
56
|
+
event_format: json_post
|
57
|
+
delivery_info: 1
|
58
|
+
single_event: 0
|
59
|
+
max_parallel: 10
|
60
|
+
events:
|
61
|
+
email_status:
|
62
|
+
- sent
|
63
|
+
- delivered
|
64
|
+
- opened
|
65
|
+
- hard_bounced
|
66
|
+
- soft_bounced
|
67
|
+
- spam
|
68
|
+
- clicked
|
69
|
+
- unsubscribed
|
70
|
+
spam_block:
|
71
|
+
- '*'
|
data/unione-ruby.gemspec
CHANGED
@@ -7,7 +7,7 @@ Gem::Specification.new do |spec|
|
|
7
7
|
spec.add_dependency 'json', '~> 2.0'
|
8
8
|
spec.add_dependency 'faraday', '~> 1.0'
|
9
9
|
spec.add_dependency 'faraday_middleware', '~> 1.0'
|
10
|
-
spec.add_dependency 'net-http-persistent', '~>
|
10
|
+
spec.add_dependency 'net-http-persistent', '~> 4.0'
|
11
11
|
spec.add_dependency 'hashie', '~> 4.0'
|
12
12
|
spec.add_dependency 'json-schema', '~> 2.0'
|
13
13
|
spec.authors = ['UniOne developer']
|
@@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.licenses = ['MIT']
|
19
19
|
spec.name = 'unione-ruby'
|
20
20
|
spec.require_paths = ['lib']
|
21
|
-
spec.required_ruby_version = '>= 2.
|
21
|
+
spec.required_ruby_version = '>= 2.5'
|
22
22
|
spec.summary = 'Official UniOne Gem'
|
23
23
|
spec.version = UniOne::VERSION
|
24
24
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: unione-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- UniOne developer
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-06-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json
|
@@ -58,14 +58,14 @@ dependencies:
|
|
58
58
|
requirements:
|
59
59
|
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '
|
61
|
+
version: '4.0'
|
62
62
|
type: :runtime
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: '
|
68
|
+
version: '4.0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: hashie
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -102,29 +102,54 @@ extra_rdoc_files: []
|
|
102
102
|
files:
|
103
103
|
- LICENSE
|
104
104
|
- README.md
|
105
|
-
-
|
106
|
-
-
|
105
|
+
- Rakefile
|
106
|
+
- config/response_schema/domain.yml
|
107
|
+
- config/response_schema/email.yml
|
108
|
+
- config/response_schema/event_dump.yml
|
109
|
+
- config/response_schema/project.yml
|
110
|
+
- config/response_schema/suppression.yml
|
111
|
+
- config/response_schema/system.yml
|
112
|
+
- config/response_schema/tag.yml
|
113
|
+
- config/response_schema/template.yml
|
114
|
+
- config/response_schema/unsubscribed.yml
|
115
|
+
- config/response_schema/webhook.yml
|
116
|
+
- examples/api/custom_api.rb
|
107
117
|
- examples/api/domain.rb
|
108
|
-
- examples/api/email.rb
|
118
|
+
- examples/api/email/attachments.rb
|
119
|
+
- examples/api/email/multiple_recipients.rb
|
120
|
+
- examples/api/email/send.rb
|
121
|
+
- examples/api/email/settings.rb
|
122
|
+
- examples/api/email/subscribe.rb
|
123
|
+
- examples/api/email/template.rb
|
124
|
+
- examples/api/event_dump.rb
|
109
125
|
- examples/api/project.rb
|
126
|
+
- examples/api/suppression.rb
|
127
|
+
- examples/api/system.rb
|
128
|
+
- examples/api/tag.rb
|
110
129
|
- examples/api/template.rb
|
111
130
|
- examples/api/unsubscribed.rb
|
112
131
|
- examples/api/webhook.rb
|
132
|
+
- examples/helpers.rb
|
133
|
+
- examples/send_mail.rb
|
134
|
+
- examples/setup.rb
|
113
135
|
- lib/unione-ruby.rb
|
114
136
|
- lib/unione/client.rb
|
115
137
|
- lib/unione/client/domain.rb
|
116
138
|
- lib/unione/client/email.rb
|
139
|
+
- lib/unione/client/event_dump.rb
|
117
140
|
- lib/unione/client/project.rb
|
141
|
+
- lib/unione/client/suppression.rb
|
142
|
+
- lib/unione/client/system.rb
|
143
|
+
- lib/unione/client/tag.rb
|
118
144
|
- lib/unione/client/template.rb
|
119
145
|
- lib/unione/client/unsubscribed.rb
|
120
146
|
- lib/unione/client/webhook.rb
|
121
147
|
- lib/unione/connection.rb
|
122
|
-
- lib/unione/helpers
|
123
|
-
- lib/unione/helpers/template/template.rb
|
124
|
-
- lib/unione/helpers/webhook/webhook.rb
|
148
|
+
- lib/unione/helpers.rb
|
125
149
|
- lib/unione/response/raise_error.rb
|
126
150
|
- lib/unione/validation.rb
|
127
151
|
- lib/unione/version.rb
|
152
|
+
- test/CONFIGFILE.yml
|
128
153
|
- unione-ruby.gemspec
|
129
154
|
homepage: https://github.com/unione-repo/unione-ruby
|
130
155
|
licenses:
|
@@ -138,7 +163,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
138
163
|
requirements:
|
139
164
|
- - ">="
|
140
165
|
- !ruby/object:Gem::Version
|
141
|
-
version: '2.
|
166
|
+
version: '2.5'
|
142
167
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
143
168
|
requirements:
|
144
169
|
- - ">="
|
data/examples/1_setup.rb
DELETED
@@ -1,25 +0,0 @@
|
|
1
|
-
require 'unione-ruby'
|
2
|
-
require 'json'
|
3
|
-
|
4
|
-
unione = UniOne::Client.new(data_center: 'eu1', lang: 'en', api_key: ENV['UNIONE_API_KEY'])
|
5
|
-
|
6
|
-
# Validate domain verification record
|
7
|
-
unione.validate_verification_record("example.com")
|
8
|
-
|
9
|
-
# Create template
|
10
|
-
template = UniOne::Template.new
|
11
|
-
template.name = 'Template Name'
|
12
|
-
template.subject = 'Email Subject'
|
13
|
-
template.template_engine = 'simple'
|
14
|
-
template.global_substitutions = {"someVar" => "someVal"}
|
15
|
-
|
16
|
-
template.from = {from_email: 'test@example.com', from_name: 'userName'}
|
17
|
-
template.headers = {"X-ReplyTo" => "reply@example.com"}
|
18
|
-
template.body = {html: "<b>Hello {{substitutionName}}</b>"}
|
19
|
-
|
20
|
-
template.attachments << {"type" => "text/plain", "name" => "myfile.txt", "content" => "ZXhhbXBsZSBmaWxl"}
|
21
|
-
template.inline_attachments << {"type" => "image/png", "name" => "IMAGECID", "content" => "iVBORw0KGgo"}
|
22
|
-
template.options = {"unsubscribe_url" => "someurl"}
|
23
|
-
|
24
|
-
response = unione.set_template(template.to_json)
|
25
|
-
template_id = response.body.template.id
|
data/examples/2_mail_sending.rb
DELETED
@@ -1,23 +0,0 @@
|
|
1
|
-
require 'unione-ruby'
|
2
|
-
require 'json'
|
3
|
-
|
4
|
-
unione = UniOne::Client.new(data_center: 'eu1', lang: 'en', api_key: ENV['UNIONE_API_KEY'])
|
5
|
-
|
6
|
-
mail = UniOne::Mail.new
|
7
|
-
mail.template = {"template_engine" => "simple", "template_id" => template_id}
|
8
|
-
|
9
|
-
substitutions = {"substitutionName" => "substitutionVal", "to_name" => "Name Surname 1"}
|
10
|
-
recipient = {email: 'test1@example.com', substitutions: substitutions, metadata: {"key1" => "val1"}}
|
11
|
-
mail.recipients << recipient
|
12
|
-
|
13
|
-
substitutions = {"substitutionName" => "substitutionVal", "to_name" => "Name Surname 2"}
|
14
|
-
recipient = {email: 'test2@example.com', substitutions: substitutions, metadata: {"key1" => "val1"}}
|
15
|
-
mail.recipients << recipient
|
16
|
-
|
17
|
-
mail.metadata = {"key1" => "val1"}
|
18
|
-
mail.headers = {"X-ReplyTo" => "reply@example.com"}
|
19
|
-
mail.attachments << {"type" => "text/plain", "name" => "myfile.txt", "content" => "ZXhhbXBsZSBmaWxl"}
|
20
|
-
mail.inline_attachments << {"type" => "image/png", "name" => "IMAGECID", "content" => "iVBORw0KGgo"}
|
21
|
-
mail.options = {"unsubscribe_url" => "someurl"}
|
22
|
-
|
23
|
-
unione.send_email(mail.to_json)
|
data/examples/api/email.rb
DELETED
@@ -1,36 +0,0 @@
|
|
1
|
-
require 'unione-ruby'
|
2
|
-
require 'json'
|
3
|
-
|
4
|
-
# Send email
|
5
|
-
mail = UniOne::Mail.new
|
6
|
-
mail.body = {html: "<b>Hello {{substitutionName}}</b>"}
|
7
|
-
mail.from = {from_email: 'test@example.com', from_name: 'userName'}
|
8
|
-
mail.subject = 'Email Subject'
|
9
|
-
mail.template = {"template_engine" => "simple", "template_id" => "template_id"}
|
10
|
-
|
11
|
-
substitutions = {"substitutionName" => "substitutionVal", "to_name" => "Name Surname 1"}
|
12
|
-
recipient1 = {email: 'test1@example.com', substitutions: substitutions, metadata: {"key1" => "val1"}}
|
13
|
-
mail.recipients << recipient1
|
14
|
-
|
15
|
-
substitutions = {"substitutionName" => "substitutionVal", "to_name" => "Name Surname 2"}
|
16
|
-
recipient2 = {email: 'test2@example.com', substitutions: substitutions, metadata: {"key1" => "val1"}}
|
17
|
-
mail.recipients << recipient2
|
18
|
-
|
19
|
-
mail.metadata = {"key1" => "val1"}
|
20
|
-
mail.headers = {"X-ReplyTo" => "reply@example.com"}
|
21
|
-
mail.attachments << {"type" => "text/plain", "name" => "myfile.txt", "content" => "ZXhhbXBsZSBmaWxl"}
|
22
|
-
mail.inline_attachments << {"type" => "image/png", "name" => "IMAGECID", "content" => "iVBORw0KGgo"}
|
23
|
-
mail.options = {"unsubscribe_url" => "someurl"}
|
24
|
-
|
25
|
-
puts mail.to_json
|
26
|
-
|
27
|
-
unione = UniOne::Client.new(data_center: 'eu1', lang: 'en', api_key: ENV['UNIONE_API_KEY'])
|
28
|
-
response = unione.send_email(mail.to_json)
|
29
|
-
puts response.status
|
30
|
-
puts response.body
|
31
|
-
puts response.headers
|
32
|
-
|
33
|
-
# Subscribe email
|
34
|
-
unione = UniOne::Client.new(data_center: 'eu1', lang: 'en', api_key: ENV['UNIONE_API_KEY'])
|
35
|
-
response = unione.subscribe_email(email_address_from: "emailFrom",
|
36
|
-
email_address_to: "blackhole@example.com", name_from: "Example Sender")
|
@@ -1,37 +0,0 @@
|
|
1
|
-
module UniOne
|
2
|
-
class Mail
|
3
|
-
attr_accessor :template, :body, :track, :from, :subject, :metadata, :headers, :options,
|
4
|
-
:global_substitutions, :recipients, :attachments, :inline_attachments,
|
5
|
-
:reply_to
|
6
|
-
|
7
|
-
def initialize
|
8
|
-
@template = {}
|
9
|
-
@from = {}
|
10
|
-
@track = {}
|
11
|
-
@global_substitutions = {}
|
12
|
-
@recipients = []
|
13
|
-
@attachments = []
|
14
|
-
@inline_attachments = []
|
15
|
-
end
|
16
|
-
|
17
|
-
def to_json(*)
|
18
|
-
{
|
19
|
-
message: {
|
20
|
-
global_substitutions: self.global_substitutions,
|
21
|
-
body: self.body,
|
22
|
-
subject: self.subject,
|
23
|
-
reply_to: self.reply_to,
|
24
|
-
recipients: self.recipients,
|
25
|
-
metadata: self.metadata,
|
26
|
-
headers: self.headers,
|
27
|
-
attachments: self.attachments,
|
28
|
-
inline_attachments: self.inline_attachments,
|
29
|
-
options: self.options
|
30
|
-
}.merge(self.template)
|
31
|
-
.merge(self.from)
|
32
|
-
.merge(self.track)
|
33
|
-
.delete_if { |_, value| value.to_s.strip == '' || value == [] || value == {}}
|
34
|
-
}
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|