unigo-ruby 1.0.1

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.
Files changed (58) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +21 -0
  3. data/README.md +133 -0
  4. data/Rakefile +52 -0
  5. data/config/response_schema/domain.yml +74 -0
  6. data/config/response_schema/email.yml +23 -0
  7. data/config/response_schema/event_dump.yml +75 -0
  8. data/config/response_schema/project.yml +59 -0
  9. data/config/response_schema/suppression.yml +71 -0
  10. data/config/response_schema/system.yml +33 -0
  11. data/config/response_schema/tag.yml +26 -0
  12. data/config/response_schema/template.yml +134 -0
  13. data/config/response_schema/unsubscribed.yml +45 -0
  14. data/config/response_schema/webhook.yml +141 -0
  15. data/examples/api/custom_api.rb +14 -0
  16. data/examples/api/domain.rb +25 -0
  17. data/examples/api/email/attachments.rb +28 -0
  18. data/examples/api/email/multiple_recipients.rb +24 -0
  19. data/examples/api/email/send.rb +25 -0
  20. data/examples/api/email/settings.rb +41 -0
  21. data/examples/api/email/subscribe.rb +14 -0
  22. data/examples/api/email/template.rb +26 -0
  23. data/examples/api/email.rb +51 -0
  24. data/examples/api/event_dump.rb +44 -0
  25. data/examples/api/project.rb +44 -0
  26. data/examples/api/suppression.rb +34 -0
  27. data/examples/api/system.rb +10 -0
  28. data/examples/api/tag.rb +15 -0
  29. data/examples/api/template.rb +54 -0
  30. data/examples/api/unsubscribed.rb +22 -0
  31. data/examples/api/webhook.rb +42 -0
  32. data/examples/helpers.rb +29 -0
  33. data/examples/send_mail.rb +44 -0
  34. data/examples/sending_mail.rb +32 -0
  35. data/examples/setup.rb +34 -0
  36. data/lib/unigo/client/domain.rb +34 -0
  37. data/lib/unigo/client/email.rb +25 -0
  38. data/lib/unigo/client/event_dump.rb +37 -0
  39. data/lib/unigo/client/project.rb +34 -0
  40. data/lib/unigo/client/suppression.rb +38 -0
  41. data/lib/unigo/client/system.rb +19 -0
  42. data/lib/unigo/client/tag.rb +24 -0
  43. data/lib/unigo/client/template.rb +34 -0
  44. data/lib/unigo/client/unsubscribed.rb +31 -0
  45. data/lib/unigo/client/webhook.rb +34 -0
  46. data/lib/unigo/client.rb +69 -0
  47. data/lib/unigo/connection.rb +62 -0
  48. data/lib/unigo/helpers/mail/mail.rb +42 -0
  49. data/lib/unigo/helpers/template/template.rb +32 -0
  50. data/lib/unigo/helpers/webhook/webhook.rb +18 -0
  51. data/lib/unigo/helpers.rb +22 -0
  52. data/lib/unigo/response/raise_error.rb +20 -0
  53. data/lib/unigo/validation.rb +45 -0
  54. data/lib/unigo/version.rb +3 -0
  55. data/lib/unigo-ruby.rb +2 -0
  56. data/test/CONFIGFILE.yml +71 -0
  57. data/unigo-ruby.gemspec +24 -0
  58. metadata +182 -0
@@ -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,14 @@
1
+ require 'unigo-ruby'
2
+
3
+ unigo = UniGo::Client.new(
4
+ hostname: 'go1.unisender.ru',
5
+ lang: 'ru',
6
+ api_key: ENV['UNIGO_API_KEY']
7
+ )
8
+
9
+ # Custom Api call
10
+ response =
11
+ unigo.post(
12
+ 'domain/get-dns-records.json',
13
+ domain: 'example.com'
14
+ )
@@ -0,0 +1,25 @@
1
+ require 'unigo-ruby'
2
+
3
+ unigo = UniGo::Client.new(
4
+ hostname: 'go1.unisender.ru',
5
+ lang: 'ru',
6
+ api_key: ENV['UNIGO_API_KEY']
7
+ )
8
+
9
+ # Generate/get DNS records for domain verification and DKIM signing
10
+ response = unigo.get_dns_records(
11
+ domain: 'example.com'
12
+ )
13
+
14
+ # Validate domain verification record before use
15
+ response = unigo.validate_verification_record(
16
+ domain: 'example.com'
17
+ )
18
+
19
+ # Validate DKIM signature before sending
20
+ response = unigo.validate_dkim(
21
+ domain: 'example.com'
22
+ )
23
+
24
+ # Get a list of your domains and their verification/DKIM statuses
25
+ response = unigo.list_domains
@@ -0,0 +1,28 @@
1
+ require 'unigo-ruby'
2
+ require 'json'
3
+
4
+ unigo = UniGo::Client.new(
5
+ hostname: 'go1.unisender.ru',
6
+ lang: 'ru',
7
+ api_key: ENV['UNIGO_API_KEY']
8
+ )
9
+
10
+ # Send email with attachments
11
+ message = {}
12
+
13
+ message[:subject] = 'Subject'
14
+
15
+ message[:from_email] = 'test@example.net'
16
+ message[:from_name] = 'userName'
17
+
18
+ message[:body] = { html: '<b>Hello {{substitutionName}}</b>' }
19
+
20
+ message[:recipients] = []
21
+ message[:recipients] << { email: 'recipient@example.com' }
22
+
23
+ message[:attachments] = []
24
+ message[:attachments] << { type: 'text/plain', name: 'myfile.txt', content: 'ZXhhbXBsZSBmaWxl' }
25
+ message[:inline_attachments] = []
26
+ message[:inline_attachments] << { type: 'image/png', name: 'IMAGECID', content: 'iVBORw0KGgo' }
27
+
28
+ response = unigo.send_email(message: message)
@@ -0,0 +1,24 @@
1
+ require 'unigo-ruby'
2
+ require 'json'
3
+
4
+ unigo = UniGo::Client.new(
5
+ hostname: 'go1.unisender.ru',
6
+ lang: 'ru',
7
+ api_key: ENV['UNIGO_API_KEY']
8
+ )
9
+
10
+ # Send email with multiple recipients
11
+ message = {}
12
+
13
+ message[:subject] = 'Subject'
14
+
15
+ message[:from_email] = 'test@example.net'
16
+ message[:from_name] = 'userName'
17
+
18
+ message[:body] = { html: '<b>Hello {{substitutionName}}</b>' }
19
+
20
+ message[:recipients] = []
21
+ message[:recipients] << { email: 'recipient1@example.com' }
22
+ message[:recipients] << { email: 'recipient2@example.com' }
23
+
24
+ response = unigo.send_email(message: message)
@@ -0,0 +1,25 @@
1
+ require 'unigo-ruby'
2
+ require 'json'
3
+
4
+ unigo = UniGo::Client.new(
5
+ hostname: 'go1.unisender.ru',
6
+ lang: 'ru',
7
+ api_key: ENV['UNIGO_API_KEY']
8
+ )
9
+
10
+ message = {}
11
+
12
+ message[:subject] = 'Subject'
13
+
14
+ message[:from_email] = 'test@example.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 = unigo.send_email(message: message)
@@ -0,0 +1,41 @@
1
+ require 'unigo-ruby'
2
+ require 'json'
3
+
4
+ unigo = UniGo::Client.new(
5
+ hostname: 'go1.unisender.ru',
6
+ lang: 'ru',
7
+ api_key: ENV['UNIGO_API_KEY']
8
+ )
9
+
10
+ message = {}
11
+
12
+ message[:subject] = 'Subject'
13
+
14
+ message[:from_email] = 'test@example.net'
15
+ message[:from_name] = 'userName'
16
+
17
+ message[:body] = { plaintext: 'Hello' }
18
+
19
+ message[:recipients] = []
20
+ message[:recipients] << { email: 'recipient@example.com' }
21
+
22
+ message[:global_metadata] = { key: 'val' }
23
+ message[:headers] = { 'X-ReplyTo' => 'reply@example.net' }
24
+
25
+ message[:track_links] = 1
26
+ message[:track_read] = 1
27
+
28
+ # Should have permissions to use this option
29
+ message[:skip_unsubscribe] = 1
30
+
31
+ # Language of the unsubscribe footer and unsubscribe page
32
+ message[:global_language] = 'ru'
33
+
34
+ message[:options] = {
35
+ unsubscribe_url: 'https://domain.com/unsubscribe',
36
+ send_at: Time.now, # Or String: '2021-11-19 10:00:00'
37
+ custom_backend_id: 1, # Need permission
38
+ smtp_pool_id: 1 # Need permission
39
+ }
40
+
41
+ response = unigo.send_email(message: message)
@@ -0,0 +1,14 @@
1
+ require 'unigo-ruby'
2
+ require 'json'
3
+
4
+ unigo = UniGo::Client.new(
5
+ hostname: 'go1.unisender.ru',
6
+ lang: 'ru',
7
+ api_key: ENV['UNIGO_API_KEY']
8
+ )
9
+
10
+ response = unigo.subscribe_email(
11
+ from_email: 'from@example.net',
12
+ from_name: 'Example Sender',
13
+ to_email: 'blackhole@example.com'
14
+ )
@@ -0,0 +1,26 @@
1
+ require 'unigo-ruby'
2
+ require 'json'
3
+
4
+ unigo = UniGo::Client.new(
5
+ hostname: 'go1.unisender.ru',
6
+ lang: 'ru',
7
+ api_key: ENV['UNIGO_API_KEY']
8
+ )
9
+
10
+ # Send email using template
11
+ message = {}
12
+
13
+ message[:subject] = 'Subject'
14
+
15
+ message[:from_email] = 'test@example.net'
16
+ message[:from_name] = 'userName'
17
+
18
+ message[:recipients] = []
19
+ message[:recipients] << { email: 'recipient@example.com' }
20
+
21
+ message[:template_engine] = 'simple'
22
+ message[:template_id] = 'template_id'
23
+
24
+ message[:tags] = ['string1']
25
+
26
+ response = unigo.send_email(message: message)
@@ -0,0 +1,51 @@
1
+ require 'unigo-ruby'
2
+ require 'json'
3
+
4
+ unigo = UniGo::Client.new(data_center: 'eu1', lang: 'ru', api_key: ENV['UNIGO_API_KEY'])
5
+
6
+ # sending mail
7
+ mail = UniGo::Mail.new
8
+
9
+ mail.subject = 'Email Subject'
10
+ mail.from = { from_email: 'test@example.net', from_name: 'userName' }
11
+
12
+ # Using body
13
+ mail.body = { html: '<b>Hello {{substitutionName}}</b>' }
14
+
15
+ # Using template
16
+ # mail.template = { template_engine: 'simple', template_id: 'template_id' }
17
+
18
+ substitutions = { 'substitutionName' => 'substitutionVal', to_name: 'Name Surname 1' }
19
+ recipient1 = { email: 'test1@example.com', substitutions: substitutions, metadata: { key1: 'val1' } }
20
+ mail.recipients << recipient1
21
+
22
+ substitutions = { 'substitutionName' => 'substitutionVal', to_name: 'Name Surname 2' }
23
+ recipient2 = { email: 'test2@example.com', substitutions: substitutions, metadata: { key1: 'val1' } }
24
+ mail.recipients << recipient2
25
+
26
+ mail.global_metadata = { key1: 'val1' }
27
+ mail.headers = { 'X-ReplyTo' => 'reply@example.net' }
28
+ mail.track = { track_links: 1, track_read: 1 }
29
+ mail.options = { unsubscribe_url: 'someurl' }
30
+
31
+ # Should have rights to use this option
32
+ # mail.skip_unsubscribe = 1
33
+ mail.force_send = 0
34
+
35
+ mail.attachments << { type: 'text/plain', name: 'myfile.txt', content: 'ZXhhbXBsZSBmaWxl' }
36
+ mail.inline_attachments << { type: 'image/png', name: 'IMAGECID', content: 'iVBORw0KGgo' }
37
+
38
+ puts mail.to_json
39
+
40
+ response = unigo.send_email(mail.to_json)
41
+
42
+ puts response.status
43
+ puts response.body
44
+ puts response.headers
45
+
46
+ # subscribe email
47
+ response = unigo.subscribe_email(
48
+ from_email: 'from@example.net',
49
+ from_name: 'Example Sender',
50
+ to_email: 'blackhole@example.com'
51
+ )
@@ -0,0 +1,44 @@
1
+ require 'unigo-ruby'
2
+
3
+ unigo = UniGo::Client.new(
4
+ hostname: 'go1.unisender.ru',
5
+ lang: 'ru',
6
+ api_key: ENV['UNIGO_API_KEY']
7
+ )
8
+
9
+ # Create event dump
10
+ filter = {
11
+ job_id: '1ZymBc-00041N-9X',
12
+ status: 'sent',
13
+ delivery_status: 'err_user_unknown',
14
+ email: 'david@example.org',
15
+ email_from: 'sender@example.com',
16
+ domain: 'example.org',
17
+ campaign_id: 'c77f4f4e-3561-49f7-9f07-c35be01b4f43'
18
+ }
19
+
20
+ response = unigo.create_event_dump(
21
+ start_time: Time.now, # Or String: '2022-07-20 00:00:00'
22
+ end_time: Time.now, # Or String: '2022-07-21 00:00:00'
23
+ limit: 50,
24
+ all_projects: false,
25
+ filter: filter,
26
+ delimiter: ';',
27
+ format: 'csv'
28
+ )
29
+
30
+ # Get id of created event dump
31
+ dump_id = response.body.dump_id
32
+
33
+ # Get event dump
34
+ response = unigo.get_event_dump(
35
+ dump_id: dump_id
36
+ )
37
+
38
+ # List event dumps
39
+ response = unigo.list_event_dumps
40
+
41
+ # Delete event dump
42
+ response = unigo.delete_event_dump(
43
+ dump_id: dump_id
44
+ )
@@ -0,0 +1,44 @@
1
+ require 'unigo-ruby'
2
+
3
+ unigo = UniGo::Client.new(
4
+ hostname: 'go1.unisender.ru',
5
+ lang: 'ru',
6
+ api_key: ENV['UNIGO_API_KEY']
7
+ )
8
+
9
+ # Create project
10
+ response = unigo.create_project(
11
+ project: {
12
+ name: 'Project Name',
13
+ country: 'ES',
14
+ send_enabled: true,
15
+ custom_unsubscribe_url_enabled: true # Need permission
16
+ }
17
+ )
18
+
19
+ # Get id of created project
20
+ project_id = response.body.project_id
21
+
22
+ # Update project
23
+ response = unigo.update_project(
24
+ project_id: project_id,
25
+ project: {
26
+ name: 'Project Name',
27
+ country: 'ES',
28
+ send_enabled: true,
29
+ custom_unsubscribe_url_enabled: true # Need permission
30
+ }
31
+ )
32
+
33
+ # List projects
34
+ response = unigo.list_projects
35
+
36
+ # List project by id
37
+ response = unigo.list_projects(
38
+ project_id: project_id
39
+ )
40
+
41
+ # Delete project
42
+ response = unigo.delete_project(
43
+ project_id: project_id
44
+ )
@@ -0,0 +1,34 @@
1
+ require 'unigo-ruby'
2
+
3
+ unigo = UniGo::Client.new(
4
+ hostname: 'go1.unisender.ru',
5
+ lang: 'ru',
6
+ api_key: ENV['UNIGO_API_KEY']
7
+ )
8
+
9
+ # Create suppression
10
+ response = unigo.set_suppression(
11
+ email: 'user@example.com',
12
+ cause: 'unsubscribed',
13
+ created: Time.now, # Or String: '2021-12-19 10:15:49'
14
+ )
15
+
16
+ # Get suppression
17
+ response = unigo.get_suppression(
18
+ email: 'user@example.com',
19
+ all_projects: false
20
+ )
21
+
22
+ # List suppressions
23
+ response = unigo.list_suppressions(
24
+ cause: 'unsubscribed',
25
+ source: 'user',
26
+ start_time: Time.now, # Or String: '2021-12-19 10:15:49'
27
+ cursor: 'Ajfb6Hvdkn3hdhhvG57xbdufhG5',
28
+ limit: 50
29
+ )
30
+
31
+ # Delete suppression
32
+ response = unigo.delete_suppression(
33
+ email: 'user@example.com'
34
+ )
@@ -0,0 +1,10 @@
1
+ require 'unigo-ruby'
2
+
3
+ unigo = UniGo::Client.new(
4
+ hostname: 'go1.unisender.ru',
5
+ lang: 'ru',
6
+ api_key: ENV['UNIGO_API_KEY']
7
+ )
8
+
9
+ # Get user or project info
10
+ response = unigo.info
@@ -0,0 +1,15 @@
1
+ require 'unigo-ruby'
2
+
3
+ unigo = UniGo::Client.new(
4
+ hostname: 'go1.unisender.ru',
5
+ lang: 'ru',
6
+ api_key: ENV['UNIGO_API_KEY']
7
+ )
8
+
9
+ # List tags
10
+ response = unigo.list_tags
11
+
12
+ # Delete tag
13
+ response = unigo.delete_tag(
14
+ tag_id: tag_id
15
+ )
@@ -0,0 +1,54 @@
1
+ require 'unigo-ruby'
2
+ require 'json'
3
+
4
+ unigo = UniGo::Client.new(
5
+ hostname: 'go1.unisender.ru',
6
+ lang: 'ru',
7
+ api_key: ENV['UNIGO_API_KEY']
8
+ )
9
+
10
+ # Set template
11
+ template = {}
12
+
13
+ template[:name] = 'Template Name 1'
14
+ template[:editor_type] = 'html'
15
+ template[:subject] = 'Email Subject'
16
+ template[:template_engine] = 'simple'
17
+
18
+ template[:global_substitutions] = {
19
+ 'someVar' => 'someVal'
20
+ }
21
+
22
+ template[:from_email] = 'test@example.com'
23
+ template[:from_name] = 'userName'
24
+
25
+ template[:headers] = { 'X-ReplyTo' => 'reply@example.com' }
26
+ template[:body] = { html: '<b>Hello {{substitutionName}}</b>' }
27
+ template[:options] = { unsubscribe_url: 'someurl' }
28
+
29
+ template[:attachments] = []
30
+ template[:attachments] << { type: 'text/plain', name: 'myfile.txt', content: 'ZXhhbXBsZSBmaWxl' }
31
+
32
+ template[:inline_attachments] = []
33
+ template[:inline_attachments] << { type: 'image/png', name: 'IMAGECID', content: 'iVBORw0KGgo' }
34
+
35
+ response = unigo.set_template(template: template)
36
+
37
+ # Get id of created template
38
+ template_id = response.body.template.id
39
+
40
+ # Get template
41
+ response = unigo.get_template(
42
+ id: template_id
43
+ )
44
+
45
+ # List templates
46
+ response = unigo.list_templates(
47
+ limit: 50,
48
+ offset: 0
49
+ )
50
+
51
+ # Delete template
52
+ response = unigo.delete_template(
53
+ id: template_id
54
+ )
@@ -0,0 +1,22 @@
1
+ require 'unigo-ruby'
2
+
3
+ unigo = UniGo::Client.new(
4
+ hostname: 'go1.unisender.ru',
5
+ lang: 'ru',
6
+ api_key: ENV['UNIGO_API_KEY']
7
+ )
8
+
9
+ # Unsubscribe email
10
+ response = unigo.unsubscribe(
11
+ address: 'email@example.com'
12
+ )
13
+
14
+ # Check email is unsubscribed
15
+ response = unigo.check_unsubscribed(
16
+ address: 'email@example.com'
17
+ )
18
+
19
+ # List unsubscribed emails
20
+ response = unigo.list_unsubscribed(
21
+ date_from: Date.today # Or String: '2019-01-01'
22
+ )