unione-ruby 0.0.2 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (54) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +90 -10
  3. data/Rakefile +49 -0
  4. data/config/response_schema/domain.yml +74 -0
  5. data/config/response_schema/email.yml +23 -0
  6. data/config/response_schema/event_dump.yml +75 -0
  7. data/config/response_schema/project.yml +59 -0
  8. data/config/response_schema/suppression.yml +71 -0
  9. data/config/response_schema/system.yml +33 -0
  10. data/config/response_schema/tag.yml +26 -0
  11. data/config/response_schema/template.yml +134 -0
  12. data/config/response_schema/unsubscribed.yml +45 -0
  13. data/config/response_schema/webhook.yml +141 -0
  14. data/examples/api/custom_api.rb +13 -0
  15. data/examples/api/domain.rb +13 -7
  16. data/examples/api/email/attachments.rb +27 -0
  17. data/examples/api/email/multiple_recipients.rb +23 -0
  18. data/examples/api/email/send.rb +25 -0
  19. data/examples/api/email/settings.rb +40 -0
  20. data/examples/api/email/subscribe.rb +13 -0
  21. data/examples/api/email/template.rb +25 -0
  22. data/examples/api/event_dump.rb +43 -0
  23. data/examples/api/project.rb +29 -23
  24. data/examples/api/suppression.rb +33 -0
  25. data/examples/api/system.rb +5 -6
  26. data/examples/api/tag.rb +14 -0
  27. data/examples/api/template.rb +39 -28
  28. data/examples/api/unsubscribed.rb +16 -11
  29. data/examples/api/webhook.rb +27 -25
  30. data/examples/helpers.rb +28 -0
  31. data/examples/send_mail.rb +44 -0
  32. data/examples/setup.rb +20 -14
  33. data/lib/unione/client/domain.rb +21 -45
  34. data/lib/unione/client/email.rb +16 -15
  35. data/lib/unione/client/event_dump.rb +37 -0
  36. data/lib/unione/client/project.rb +19 -61
  37. data/lib/unione/client/suppression.rb +38 -0
  38. data/lib/unione/client/system.rb +12 -17
  39. data/lib/unione/client/tag.rb +24 -0
  40. data/lib/unione/client/template.rb +19 -66
  41. data/lib/unione/client/unsubscribed.rb +18 -31
  42. data/lib/unione/client/webhook.rb +19 -65
  43. data/lib/unione/client.rb +34 -12
  44. data/lib/unione/connection.rb +7 -3
  45. data/lib/unione/helpers.rb +22 -0
  46. data/lib/unione/response/raise_error.rb +4 -5
  47. data/lib/unione/validation.rb +34 -9
  48. data/lib/unione/version.rb +1 -1
  49. data/lib/unione-ruby.rb +0 -3
  50. data/test/CONFIGFILE.yml +71 -0
  51. data/unione-ruby.gemspec +2 -2
  52. metadata +33 -9
  53. data/examples/api/email.rb +0 -51
  54. data/examples/sending_mail.rb +0 -32
@@ -0,0 +1,45 @@
1
+ unsubscribe:
2
+ type: object
3
+ required:
4
+ - status
5
+ - address
6
+ - message
7
+ properties:
8
+ status:
9
+ type: string
10
+ address:
11
+ type: string
12
+ message:
13
+ type: string
14
+ check_unsubscribed:
15
+ type: object
16
+ required:
17
+ - status
18
+ - address
19
+ - is_unsubscribed
20
+ properties:
21
+ status:
22
+ type: string
23
+ address:
24
+ type: string
25
+ is_unsubscribed:
26
+ type: boolean
27
+ list_unsubscribed:
28
+ type: object
29
+ required:
30
+ - status
31
+ - unsubscribed
32
+ properties:
33
+ status:
34
+ type: string
35
+ unsubscribed:
36
+ items:
37
+ type: object
38
+ required:
39
+ - address
40
+ - unsubscribed_on
41
+ properties:
42
+ address:
43
+ type: string
44
+ unsubscribed_on:
45
+ type: string
@@ -0,0 +1,141 @@
1
+ set_webhook:
2
+ type: object
3
+ required:
4
+ - status
5
+ - object
6
+ properties:
7
+ status:
8
+ type: string
9
+ object:
10
+ type: object
11
+ required:
12
+ - url
13
+ - status
14
+ - events
15
+ - event_format
16
+ - delivery_info
17
+ - single_event
18
+ - max_parallel
19
+ properties:
20
+ id:
21
+ type: integer
22
+ url:
23
+ type: string
24
+ status:
25
+ type: string
26
+ event_format:
27
+ type: string
28
+ delivery_info:
29
+ type: integer
30
+ single_event:
31
+ type: integer
32
+ max_parallel:
33
+ type: integer
34
+ events:
35
+ type: object
36
+ required:
37
+ - email_status
38
+ - spam_block
39
+ properties:
40
+ email_status:
41
+ items:
42
+ type: string
43
+ spam_block:
44
+ items:
45
+ type: string
46
+ get_webhook:
47
+ type: object
48
+ required:
49
+ - status
50
+ - object
51
+ properties:
52
+ status:
53
+ type: string
54
+ object:
55
+ type: object
56
+ required:
57
+ - url
58
+ - status
59
+ - events
60
+ - event_format
61
+ - max_parallel
62
+ properties:
63
+ id:
64
+ type: integer
65
+ url:
66
+ type: string
67
+ status:
68
+ type: string
69
+ event_format:
70
+ type: string
71
+ max_parallel:
72
+ type: integer
73
+ events:
74
+ type: object
75
+ required:
76
+ - email_status
77
+ - spam_block
78
+ properties:
79
+ email_status:
80
+ items:
81
+ type: string
82
+ spam_block:
83
+ items:
84
+ type: string
85
+ list_webhooks:
86
+ type: object
87
+ required:
88
+ - status
89
+ - objects
90
+ properties:
91
+ status:
92
+ type: string
93
+ objects:
94
+ items:
95
+ type: object
96
+ required:
97
+ - id
98
+ - url
99
+ - status
100
+ - updated_at
101
+ - events
102
+ - event_format
103
+ - delivery_info
104
+ - single_event
105
+ - max_parallel
106
+ properties:
107
+ id:
108
+ type: integer
109
+ url:
110
+ type: string
111
+ status:
112
+ type: string
113
+ event_format:
114
+ type: string
115
+ delivery_info:
116
+ type: integer
117
+ single_event:
118
+ type: integer
119
+ max_parallel:
120
+ type: integer
121
+ updated_at:
122
+ type: string
123
+ events:
124
+ type: object
125
+ required:
126
+ - email_status
127
+ - spam_block
128
+ properties:
129
+ spam_block:
130
+ items:
131
+ type: string
132
+ email_status:
133
+ items:
134
+ type: string
135
+ delete_webhook:
136
+ type: object
137
+ required:
138
+ - status
139
+ properties:
140
+ status:
141
+ type: string
@@ -0,0 +1,13 @@
1
+ require 'unione-ruby'
2
+
3
+ unione = UniOne::Client.new(
4
+ hostname: 'eu1.unione.io',
5
+ api_key: ENV['UNIONE_API_KEY']
6
+ )
7
+
8
+ # Custom Api call
9
+ response =
10
+ unione.post(
11
+ 'domain/get-dns-records.json',
12
+ domain: 'example.com'
13
+ )
@@ -1,18 +1,24 @@
1
1
  require 'unione-ruby'
2
2
 
3
- unione = UniOne::Client.new(data_center: 'eu1', lang: 'en', api_key: ENV['UNIONE_API_KEY'])
3
+ unione = UniOne::Client.new(
4
+ hostname: 'eu1.unione.io',
5
+ api_key: ENV['UNIONE_API_KEY']
6
+ )
4
7
 
5
8
  # Generate/get DNS records for domain verification and DKIM signing
6
- response = unione.get_dns_records("example.com")
7
- puts response.status
8
- puts response.body.to_h
9
- puts response.headers
9
+ response = unione.get_dns_records(
10
+ domain: 'example.com'
11
+ )
10
12
 
11
13
  # Validate domain verification record before use
12
- response = unione.validate_verification_record('example.com')
14
+ response = unione.validate_verification_record(
15
+ domain: 'example.com'
16
+ )
13
17
 
14
18
  # Validate DKIM signature before sending
15
- response = unione.validate_dkim('example.com')
19
+ response = unione.validate_dkim(
20
+ domain: 'example.com'
21
+ )
16
22
 
17
23
  # Get a list of your domains and their verification/DKIM statuses
18
24
  response = unione.list_domains
@@ -0,0 +1,27 @@
1
+ require 'unione-ruby'
2
+ require 'json'
3
+
4
+ unione = UniOne::Client.new(
5
+ hostname: 'eu1.unione.io',
6
+ api_key: ENV['UNIONE_API_KEY']
7
+ )
8
+
9
+ # Send email with attachments
10
+ message = {}
11
+
12
+ message[:subject] = 'Subject'
13
+
14
+ message[:from_email] = 'test@qadns.net'
15
+ message[:from_name] = 'userName'
16
+
17
+ message[:body] = { html: '<b>Hello {{substitutionName}}</b>' }
18
+
19
+ message[:recipients] = []
20
+ message[:recipients] << { email: 'recipient@example.com' }
21
+
22
+ message[:attachments] = []
23
+ message[:attachments] << { type: 'text/plain', name: 'myfile.txt', content: 'ZXhhbXBsZSBmaWxl' }
24
+ message[:inline_attachments] = []
25
+ message[:inline_attachments] << { type: 'image/png', name: 'IMAGECID', content: 'iVBORw0KGgo' }
26
+
27
+ response = unione.send_email(message: message)
@@ -0,0 +1,23 @@
1
+ require 'unione-ruby'
2
+ require 'json'
3
+
4
+ unione = UniOne::Client.new(
5
+ hostname: 'eu1.unione.io',
6
+ api_key: ENV['UNIONE_API_KEY']
7
+ )
8
+
9
+ # Send email with multiple recipients
10
+ message = {}
11
+
12
+ message[:subject] = 'Subject'
13
+
14
+ message[:from_email] = 'test@qadns.net'
15
+ message[:from_name] = 'userName'
16
+
17
+ message[:body] = { html: '<b>Hello {{substitutionName}}</b>' }
18
+
19
+ message[:recipients] = []
20
+ message[:recipients] << { email: 'recipient1@example.com' }
21
+ message[:recipients] << { email: 'recipient2@example.com' }
22
+
23
+ response = unione.send_email(message: message)
@@ -0,0 +1,25 @@
1
+ require 'unione-ruby'
2
+ require 'json'
3
+
4
+ unione = UniOne::Client.new(
5
+ hostname: 'eu1.unione.io',
6
+ lang: 'en',
7
+ api_key: ENV['UNIONE_API_KEY']
8
+ )
9
+
10
+ message = {}
11
+
12
+ message[:subject] = 'Subject'
13
+
14
+ message[:from_email] = 'test@qadns.net'
15
+ message[:from_name] = 'userName'
16
+
17
+ message[:body] = { plaintext: 'Hello' }
18
+
19
+ # HTML body
20
+ message[:body] = { html: '<b>Hello {{substitutionName}}</b>' }
21
+
22
+ message[:recipients] = []
23
+ message[:recipients] << { email: 'recipient@example.com' }
24
+
25
+ response = unione.send_email(message: message)
@@ -0,0 +1,40 @@
1
+ require 'unione-ruby'
2
+ require 'json'
3
+
4
+ unione = UniOne::Client.new(
5
+ hostname: 'eu1.unione.io',
6
+ api_key: ENV['UNIONE_API_KEY']
7
+ )
8
+
9
+ message = {}
10
+
11
+ message[:subject] = 'Subject'
12
+
13
+ message[:from_email] = 'test@qadns.net'
14
+ message[:from_name] = 'userName'
15
+
16
+ message[:body] = { plaintext: 'Hello' }
17
+
18
+ message[:recipients] = []
19
+ message[:recipients] << { email: 'recipient@example.com' }
20
+
21
+ message[:global_metadata] = { key: 'val' }
22
+ message[:headers] = { 'X-ReplyTo' => 'reply@qadns.net' }
23
+
24
+ message[:track_links] = 1
25
+ message[:track_read] = 1
26
+
27
+ # Should have permissions to use this option
28
+ message[:skip_unsubscribe] = 1
29
+
30
+ # Language of the unsubscribe footer and unsubscribe page
31
+ message[:global_language] = 'en'
32
+
33
+ message[:options] = {
34
+ unsubscribe_url: 'https://domain.com/unsubscribe',
35
+ send_at: Time.now, # Or String: '2021-11-19 10:00:00'
36
+ custom_backend_id: 1, # Need permission
37
+ smtp_pool_id: 1 # Need permission
38
+ }
39
+
40
+ response = unione.send_email(message: message)
@@ -0,0 +1,13 @@
1
+ require 'unione-ruby'
2
+ require 'json'
3
+
4
+ unione = UniOne::Client.new(
5
+ hostname: 'eu1.unione.io',
6
+ api_key: ENV['UNIONE_API_KEY']
7
+ )
8
+
9
+ response = unione.subscribe_email(
10
+ from_email: 'from@qadns.net',
11
+ from_name: 'Example Sender',
12
+ to_email: 'blackhole@example.com'
13
+ )
@@ -0,0 +1,25 @@
1
+ require 'unione-ruby'
2
+ require 'json'
3
+
4
+ unione = UniOne::Client.new(
5
+ hostname: 'eu1.unione.io',
6
+ api_key: ENV['UNIONE_API_KEY']
7
+ )
8
+
9
+ # Send email using template
10
+ message = {}
11
+
12
+ message[:subject] = 'Subject'
13
+
14
+ message[:from_email] = 'test@qadns.net'
15
+ message[:from_name] = 'userName'
16
+
17
+ message[:recipients] = []
18
+ message[:recipients] << { email: 'recipient@example.com' }
19
+
20
+ message[:template_engine] = 'simple'
21
+ message[:template_id] = 'template_id'
22
+
23
+ message[:tags] = ['string1']
24
+
25
+ response = unione.send_email(message: message)
@@ -0,0 +1,43 @@
1
+ require 'unione-ruby'
2
+
3
+ unione = UniOne::Client.new(
4
+ hostname: 'eu1.unione.io',
5
+ api_key: ENV['UNIONE_API_KEY']
6
+ )
7
+
8
+ # Create event dump
9
+ filter = {
10
+ job_id: '1ZymBc-00041N-9X',
11
+ status: 'sent',
12
+ delivery_status: 'err_user_unknown',
13
+ email: 'david@example.org',
14
+ email_from: 'sender@example.com',
15
+ domain: 'example.org',
16
+ campaign_id: 'c77f4f4e-3561-49f7-9f07-c35be01b4f43'
17
+ }
18
+
19
+ response = unione.create_event_dump(
20
+ start_time: Time.now, # Or String: '2022-07-20 00:00:00'
21
+ end_time: Time.now, # Or String: '2022-07-21 00:00:00'
22
+ limit: 50,
23
+ all_projects: false,
24
+ filter: filter,
25
+ delimiter: ';',
26
+ format: 'csv'
27
+ )
28
+
29
+ # Get id of created event dump
30
+ dump_id = response.body.dump_id
31
+
32
+ # Get event dump
33
+ response = unione.get_event_dump(
34
+ dump_id: dump_id
35
+ )
36
+
37
+ # List event dumps
38
+ response = unione.list_event_dumps
39
+
40
+ # Delete event dump
41
+ response = unione.delete_event_dump(
42
+ dump_id: dump_id
43
+ )
@@ -1,37 +1,43 @@
1
1
  require 'unione-ruby'
2
2
 
3
- unione = UniOne::Client.new(data_center: 'eu1', lang: 'en', api_key: ENV['UNIONE_API_KEY'])
4
-
5
- # create project
6
- response = unione.create_project({
7
- name: 'Project Name',
8
- send_enabled: true,
9
- # custom_unsubscribe_url_enabled: true, # Should have rights to use
10
- })
3
+ unione = UniOne::Client.new(
4
+ hostname: 'eu1.unione.io',
5
+ api_key: ENV['UNIONE_API_KEY']
6
+ )
11
7
 
12
- puts response.status
13
- puts response.body.to_h
14
- puts response.headers
8
+ # Create project
9
+ response = unione.create_project(
10
+ project: {
11
+ name: 'Project Name',
12
+ country: 'ES',
13
+ send_enabled: true,
14
+ custom_unsubscribe_url_enabled: true # Need permission
15
+ }
16
+ )
15
17
 
18
+ # Get id of created project
16
19
  project_id = response.body.project_id
17
20
 
18
- # update project
21
+ # Update project
19
22
  response = unione.update_project(
20
- {
21
- project_id: project_id
22
- },
23
- {
24
- name: 'New Project Name',
23
+ project_id: project_id,
24
+ project: {
25
+ name: 'Project Name',
26
+ country: 'ES',
25
27
  send_enabled: true,
26
- # custom_unsubscribe_url_enabled: true, # Should have rights to use
28
+ custom_unsubscribe_url_enabled: true # Need permission
27
29
  }
28
30
  )
29
31
 
30
- # list all projects
32
+ # List projects
31
33
  response = unione.list_projects
32
34
 
33
- # list project by id
34
- response = unione.list_projects({ project_id: project_id })
35
+ # List project by id
36
+ response = unione.list_projects(
37
+ project_id: project_id
38
+ )
35
39
 
36
- # delete project
37
- response = unione.delete_project({ project_id: project_id })
40
+ # Delete project
41
+ response = unione.delete_project(
42
+ project_id: project_id
43
+ )
@@ -0,0 +1,33 @@
1
+ require 'unione-ruby'
2
+
3
+ unione = UniOne::Client.new(
4
+ hostname: 'eu1.unione.io',
5
+ api_key: ENV['UNIONE_API_KEY']
6
+ )
7
+
8
+ # Create suppression
9
+ response = unione.set_suppression(
10
+ email: 'user@example.com',
11
+ cause: 'unsubscribed',
12
+ created: Time.now, # Or String: '2021-12-19 10:15:49'
13
+ )
14
+
15
+ # Get suppression
16
+ response = unione.get_suppression(
17
+ email: 'user@example.com',
18
+ all_projects: false
19
+ )
20
+
21
+ # List suppressions
22
+ response = unione.list_suppressions(
23
+ cause: 'unsubscribed',
24
+ source: 'user',
25
+ start_time: Time.now, # Or String: '2021-12-19 10:15:49'
26
+ cursor: 'Ajfb6Hvdkn3hdhhvG57xbdufhG5',
27
+ limit: 50
28
+ )
29
+
30
+ # Delete suppression
31
+ response = unione.delete_suppression(
32
+ email: 'user@example.com'
33
+ )
@@ -1,10 +1,9 @@
1
1
  require 'unione-ruby'
2
2
 
3
- unione = UniOne::Client.new(data_center: 'eu1', lang: 'en', api_key: ENV['UNIONE_API_KEY'])
3
+ unione = UniOne::Client.new(
4
+ hostname: 'eu1.unione.io',
5
+ api_key: ENV['UNIONE_API_KEY']
6
+ )
4
7
 
5
- # get user or project information
8
+ # Get user or project info
6
9
  response = unione.info
7
-
8
- puts response.status
9
- puts response.body.to_h
10
- puts response.headers
@@ -0,0 +1,14 @@
1
+ require 'unione-ruby'
2
+
3
+ unione = UniOne::Client.new(
4
+ hostname: 'eu1.unione.io',
5
+ api_key: ENV['UNIONE_API_KEY']
6
+ )
7
+
8
+ # List tags
9
+ response = unione.list_tags
10
+
11
+ # Delete tag
12
+ response = unione.delete_tag(
13
+ tag_id: tag_id
14
+ )
@@ -1,42 +1,53 @@
1
1
  require 'unione-ruby'
2
2
  require 'json'
3
3
 
4
- unione = UniOne::Client.new(data_center: 'eu1', lang: 'en', api_key: ENV['UNIONE_API_KEY'])
4
+ unione = UniOne::Client.new(
5
+ hostname: 'eu1.unione.io',
6
+ api_key: ENV['UNIONE_API_KEY']
7
+ )
5
8
 
6
- # set template
7
- template = UniOne::Template.new
9
+ # Set template
10
+ template = {}
8
11
 
9
- template.name = 'Template Name'
10
- template.editor_type = 'html'
11
- template.subject = 'Email Subject'
12
- template.template_engine = 'simple'
12
+ template[:name] = 'Template Name 1'
13
+ template[:editor_type] = 'html'
14
+ template[:subject] = 'Email Subject'
15
+ template[:template_engine] = 'simple'
13
16
 
14
- template.global_substitutions = { 'someVar' => 'someVal' }
17
+ template[:global_substitutions] = {
18
+ 'someVar' => 'someVal'
19
+ }
15
20
 
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
- template.options = { unsubscribe_url: 'someurl' }
21
+ template[:from_email] = 'test@example.com'
22
+ template[:from_name] = 'userName'
20
23
 
21
- template.attachments << { type: 'text/plain', name: 'myfile.txt', content: 'ZXhhbXBsZSBmaWxl' }
22
- template.inline_attachments << { type: 'image/png', name: 'IMAGECID', content: 'iVBORw0KGgo' }
24
+ template[:headers] = { 'X-ReplyTo' => 'reply@example.com' }
25
+ template[:body] = { html: '<b>Hello {{substitutionName}}</b>' }
26
+ template[:options] = { unsubscribe_url: 'someurl' }
23
27
 
24
- puts template.to_json
28
+ template[:attachments] = []
29
+ template[:attachments] << { type: 'text/plain', name: 'myfile.txt', content: 'ZXhhbXBsZSBmaWxl' }
25
30
 
26
- response = unione.set_template(template.to_json)
31
+ template[:inline_attachments] = []
32
+ template[:inline_attachments] << { type: 'image/png', name: 'IMAGECID', content: 'iVBORw0KGgo' }
27
33
 
28
- puts response.status
29
- puts response.body.to_h
30
- puts response.headers
34
+ response = unione.set_template(template: template)
31
35
 
32
- # get id of created template
36
+ # Get id of created template
33
37
  template_id = response.body.template.id
34
38
 
35
- # get template
36
- response = unione.get_template(template_id)
37
-
38
- # list all templates
39
- response = unione.list_templates(50, 0)
40
-
41
- # delete template
42
- response = unione.delete_template(template_id)
39
+ # Get template
40
+ response = unione.get_template(
41
+ id: template_id
42
+ )
43
+
44
+ # List templates
45
+ response = unione.list_templates(
46
+ limit: 50,
47
+ offset: 0
48
+ )
49
+
50
+ # Delete template
51
+ response = unione.delete_template(
52
+ id: template_id
53
+ )
@@ -1,16 +1,21 @@
1
1
  require 'unione-ruby'
2
2
 
3
- unione = UniOne::Client.new(data_center: 'eu1', lang: 'en', api_key: ENV['UNIONE_API_KEY'])
3
+ unione = UniOne::Client.new(
4
+ hostname: 'eu1.unione.io',
5
+ api_key: ENV['UNIONE_API_KEY']
6
+ )
4
7
 
5
- # unsubscribe email
6
- response = unione.unsubscribe('email@example.com')
8
+ # Unsubscribe email
9
+ response = unione.unsubscribe(
10
+ address: 'email@example.com'
11
+ )
7
12
 
8
- puts response.status
9
- puts response.body.to_h
10
- puts response.headers
13
+ # Check email is unsubscribed
14
+ response = unione.check_unsubscribed(
15
+ address: 'email@example.com'
16
+ )
11
17
 
12
- # check email is unsubscribed
13
- response = unione.check_unsubscribed('email@example.com')
14
-
15
- # list unsubscribed emails
16
- response = unione.list_unsubscribed('2019-01-01')
18
+ # List unsubscribed emails
19
+ response = unione.list_unsubscribed(
20
+ date_from: Date.today # Or String: '2019-01-01'
21
+ )