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.
Files changed (58) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +99 -8
  3. data/Rakefile +52 -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 +14 -0
  15. data/examples/api/domain.rb +14 -7
  16. data/examples/api/email/attachments.rb +28 -0
  17. data/examples/api/email/multiple_recipients.rb +24 -0
  18. data/examples/api/email/send.rb +25 -0
  19. data/examples/api/email/settings.rb +41 -0
  20. data/examples/api/email/subscribe.rb +14 -0
  21. data/examples/api/email/template.rb +26 -0
  22. data/examples/api/event_dump.rb +44 -0
  23. data/examples/api/project.rb +35 -11
  24. data/examples/api/suppression.rb +34 -0
  25. data/examples/api/system.rb +10 -0
  26. data/examples/api/tag.rb +15 -0
  27. data/examples/api/template.rb +40 -22
  28. data/examples/api/unsubscribed.rb +20 -12
  29. data/examples/api/webhook.rb +34 -24
  30. data/examples/helpers.rb +29 -0
  31. data/examples/send_mail.rb +44 -0
  32. data/examples/setup.rb +34 -0
  33. data/lib/unione/client/domain.rb +19 -46
  34. data/lib/unione/client/email.rb +14 -21
  35. data/lib/unione/client/event_dump.rb +37 -0
  36. data/lib/unione/client/project.rb +19 -43
  37. data/lib/unione/client/suppression.rb +38 -0
  38. data/lib/unione/client/system.rb +19 -0
  39. data/lib/unione/client/tag.rb +24 -0
  40. data/lib/unione/client/template.rb +19 -65
  41. data/lib/unione/client/unsubscribed.rb +18 -31
  42. data/lib/unione/client/webhook.rb +19 -38
  43. data/lib/unione/client.rb +42 -17
  44. data/lib/unione/connection.rb +24 -16
  45. data/lib/unione/helpers.rb +22 -0
  46. data/lib/unione/response/raise_error.rb +4 -5
  47. data/lib/unione/validation.rb +32 -12
  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 +36 -11
  53. data/examples/1_setup.rb +0 -25
  54. data/examples/2_mail_sending.rb +0 -23
  55. data/examples/api/email.rb +0 -36
  56. data/lib/unione/helpers/mail/mail.rb +0 -37
  57. data/lib/unione/helpers/template/template.rb +0 -31
  58. data/lib/unione/helpers/webhook/webhook.rb +0 -17
@@ -1,32 +1,42 @@
1
1
  require 'unione-ruby'
2
2
  require 'json'
3
3
 
4
+ unione = UniOne::Client.new(
5
+ hostname: 'eu1.unione.io',
6
+ lang: 'en',
7
+ api_key: ENV['UNIONE_API_KEY']
8
+ )
9
+
4
10
  # Set webhook
5
- webhook = UniOne::Webhook.new
6
- webhook.url = "http://example.com"
7
- webhook.settings = {event_format: "json_post", delivery_info: 1, single_event: 0, max_parallel: 10}
8
- webhook.events = {email_status: [
9
- "sent",
10
- "delivered",
11
- "opened",
12
- "hard_bounced",
13
- "soft_bounced",
14
- "spam",
15
- "clicked",
16
- "unsubscribed"
17
- ], spam_block: ["*"]}
18
-
19
- puts webhook.to_json
20
-
21
- unione = UniOne::Client.new(data_center: 'eu1', lang: 'en', api_key: ENV['UNIONE_API_KEY'])
22
- response = unione.set_webhook(webhook.to_json)
23
- puts response.status
24
- puts response.body.to_h
25
- puts response.headers
11
+ params = {}
12
+
13
+ params[:url] = 'http://example.com'
14
+ params[:status] = :active
15
+
16
+ params[:event_format] = :json_post
17
+ params[:delivery_info] = 1
18
+ params[:single_event] = 0
19
+ params[:max_parallel] = 10
20
+
21
+ params[:events] = {
22
+ email_status: %w(sent delivered opened hard_bounced soft_bounced spam clicked unsubscribed),
23
+ spam_block: ["*"]
24
+ }
25
+
26
+ response = unione.set_webhook(params)
26
27
 
27
28
  # Get webhook
28
- unione = UniOne::Client.new(data_center: 'eu1', lang: 'en', api_key: ENV['UNIONE_API_KEY'])
29
- response = unione.get_webhook("http://example.com")
29
+ response = unione.get_webhook(
30
+ url: 'http://example.com'
31
+ )
32
+
33
+ # List all webhooks
34
+ response = unione.list_webhooks(
35
+ limit: 50,
36
+ offset: 0
37
+ )
30
38
 
31
39
  # Delete webhook
32
- response = unione.delete_webhook("http://example.com")
40
+ response = unione.delete_webhook(
41
+ url: 'http://example.com'
42
+ )
@@ -0,0 +1,29 @@
1
+ require 'unione-ruby'
2
+
3
+ unione = UniOne::Client.new(
4
+ hostname: 'eu1.unione.io',
5
+ lang: 'en',
6
+ api_key: ENV['UNIONE_API_KEY']
7
+ )
8
+
9
+ # Verify webhook callback message
10
+ # Will raise Unione::Client::InvalidCallbackAuth error unless `auth' field is correct.
11
+ unione.verify_callback_auth!(params)
12
+
13
+ # Callback helper usage
14
+ # Will raise Unione::Client::InvalidCallbackAuth error unless `auth' field is correct.
15
+ unione.callback_helper(params) do |events|
16
+ # [
17
+ # {
18
+ # 'event_name' => 'transactional_email_status',
19
+ # 'event_data' =>
20
+ # {
21
+ # 'email' => 'recipient.email@example.com',
22
+ # 'status' => 'sent',
23
+ # 'event_time' => '2015-11-30 15:09:42',
24
+ # ...
25
+ # }
26
+ # },
27
+ # ...
28
+ # ]
29
+ end
@@ -0,0 +1,44 @@
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
+ enable_logging: true
9
+ )
10
+
11
+ message = {}
12
+
13
+ message[:template_engine] = 'simple'
14
+ message[:template_id] = 'template_id'
15
+
16
+ # In case template_id is not specified, subject and body are mandatory
17
+ message[:subject] = 'test letter'
18
+ message[:body] = {"html": "tests", "plaintext": "plaintext"}
19
+
20
+ message[:from_email] = 'test@qadns.net'
21
+ message[:from_name] = 'userName'
22
+
23
+ message[:recipients] = []
24
+ message[:recipients] << {
25
+ email: 'test1@example.com',
26
+ substitutions: { 'substitutionName' => 'substitutionVal', to_name: 'Name Surname' },
27
+ metadata: { key1: 'val' },
28
+ }
29
+
30
+ message[:global_metadata] = { key1: 'val' }
31
+ message[:headers] = { 'X-ReplyTo' => 'reply@example.com' }
32
+ message[:options] = { unsubscribe_url: 'someurl' }
33
+
34
+ message[:attachments] = []
35
+ message[:attachments] << { type: 'text/plain', name: 'myfile.txt', content: 'ZXhhbXBsZSBmaWxl' }
36
+
37
+ message[:inline_attachments] = []
38
+ message[:inline_attachments] << { type: 'image/png', name: 'IMAGECID', content: 'iVBORw0KGgo' }
39
+
40
+ response = unione.send_email(message: message)
41
+
42
+ puts response.status
43
+ puts response.body.to_h
44
+ puts response.headers
data/examples/setup.rb ADDED
@@ -0,0 +1,34 @@
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
+ # Validate domain verification record
11
+ unione.validate_verification_record(domain: 'qadns.net')
12
+
13
+ # Create template
14
+ template = {}
15
+
16
+ template[:name] = 'Template Name'
17
+ template[:subject] = 'Email Subject'
18
+ template[:template_engine] = 'simple'
19
+ template[:headers] = {'X-ReplyTo' => 'reply@example.com'}
20
+
21
+ template[:global_substitutions] = { 'someVar' => 'someVal' }
22
+ template[:from_email] = 'test@example.com'
23
+ template[:from_name] = 'userName'
24
+ template[:body] = { html: '<b>Hello {{substitutionName}}</b>' }
25
+ template[:options] = { unsubscribe_url: 'someurl' }
26
+
27
+ template[:attachments] = []
28
+ template[:attachments] << { type: 'text/plain', name: 'myfile.txt', content: 'ZXhhbXBsZSBmaWxl' }
29
+
30
+ template[:inline_attachments] = []
31
+ template[:inline_attachments] << { type: 'image/png', name: 'IMAGECID', content: 'iVBORw0KGgo' }
32
+
33
+ response = unione.set_template(template: template)
34
+ template_id = response.body.template.id
@@ -1,61 +1,34 @@
1
1
  module UniOne
2
2
  class Client
3
-
4
3
  module Domain
4
+ extend UniOne::Validation::ClassMethods
5
+ include UniOne::Validation::InstanceMethods
5
6
 
6
- def get_dns_records(domain)
7
- params = { domain: domain }
8
- post 'domain/get-dns-records.json', params
9
- validate_response({
10
- 'type' => 'object', 'required' => ['status', 'domain', 'verification-record', 'dkim'], 'properties' => {
11
- 'status' => {'type' => 'string'},
12
- 'domain' => {'type' => 'string'},
13
- 'verification-record' => {'type' => 'string'},
14
- 'dkim' => {'type' => 'string'}}
15
- })
7
+ def get_dns_records(params = {})
8
+ post('domain/get-dns-records.json', params)
16
9
  end
17
10
 
18
- def validate_verification_record(domain)
19
- params = { domain: domain }
20
- post 'domain/validate-verification-record.json', params
21
- validate_response({
22
- 'type' => 'object', 'required' => ['status', 'message'], 'properties' => {
23
- 'status' => {'type' => 'string'},
24
- 'message' => {'type' => 'string'}}
25
- })
11
+ def validate_verification_record(params = {})
12
+ post('domain/validate-verification-record.json', params)
26
13
  end
27
14
 
28
- def validate_dkim(domain)
29
- params = { domain: domain }
30
- post 'domain/validate-dkim.json', params
31
- validate_response({
32
- 'type' => 'object', 'required' => ['status', 'message'], 'properties' => {
33
- 'status' => {'type' => 'string'},
34
- 'message' => {'type' => 'string'}}
35
- })
15
+ def validate_dkim(params = {})
16
+ post('domain/validate-dkim.json', params)
36
17
  end
37
18
 
38
- def list_domains
39
- post 'domain/list.json', {}
40
- validate_response({
41
- 'type' => 'object', 'required' => ['status', 'domains'], 'properties' => {
42
- 'status' => {'type' => 'string'},
43
- 'domains' =>
44
- {'items' =>
45
- {'type' => 'object', 'required' => ['domain', 'verification-record', 'dkim'], 'properties' => [
46
- 'domain' => {'type' => 'string'},
47
- 'verification-record' =>
48
- {'type' => 'object', 'required' => ['value', 'status'], 'properties' => [
49
- 'value' => {'type' => 'string'},
50
- 'status' => {'type' => 'string'}]},
51
- 'dkim' =>
52
- {'type' => 'object', 'required' => ['key', 'status'], 'properties' => [
53
- 'key' => {'type' => 'string'},
54
- 'status' => {'type' => 'string'}]}
55
- ]}}}
56
- })
19
+ def list_domains(params = {})
20
+ post('domain/list.json', params)
57
21
  end
58
22
 
23
+ add_response_validations(
24
+ :domain,
25
+ %w(
26
+ get_dns_records
27
+ validate_verification_record
28
+ validate_dkim
29
+ list_domains
30
+ )
31
+ )
59
32
  end
60
33
  end
61
34
  end
@@ -1,32 +1,25 @@
1
1
  module UniOne
2
2
  class Client
3
-
4
3
  module Email
4
+ extend UniOne::Validation::ClassMethods
5
+ include UniOne::Validation::InstanceMethods
5
6
 
6
- def send_email(message)
7
- post 'email/send.json', message
8
- validate_response({
9
- 'type' => 'object', 'required' => ['status', 'job_id', 'emails'], 'properties' => {
10
- 'status' => {'type' => 'string'},
11
- 'job_id' => {'type' => 'string'},
12
- 'emails' => {'items' => {'type' => 'string'}},
13
- 'failed_emails' => {'type' => 'object'}}
14
- })
7
+ def send_email(params = {})
8
+ params[:message][:options][:send_at] = handle_time_param(params.dig(:message, :options, :send_at)) if params.dig(:message, :options, :send_at)
9
+ post('email/send.json', params)
15
10
  end
16
11
 
17
- def subscribe_email(email_address_from:, email_address_to:, name_from:)
18
- params = {
19
- email_address_from: email_address_from,
20
- email_address_to: email_address_to,
21
- name_from: name_from
22
- }
23
- post 'email/subscribe.json', params
24
- validate_response({
25
- 'type' => 'object', 'required' => ['status'], 'properties' => {
26
- 'status' => {'type' => 'string'}}
27
- })
12
+ def subscribe_email(params = {})
13
+ post('email/subscribe.json', params)
28
14
  end
29
15
 
16
+ add_response_validations(
17
+ :email,
18
+ %w(
19
+ send_email
20
+ subscribe_email
21
+ )
22
+ )
30
23
  end
31
24
  end
32
25
  end
@@ -0,0 +1,37 @@
1
+ module UniOne
2
+ class Client
3
+ module EventDump
4
+ extend UniOne::Validation::ClassMethods
5
+ include UniOne::Validation::InstanceMethods
6
+
7
+ def create_event_dump(params = {})
8
+ params[:start_time] = handle_time_param(params[:start_time]) if params[:start_time]
9
+ params[:end_time] = handle_time_param(params[:end_time]) if params[:end_time]
10
+
11
+ post('event-dump/create.json', params)
12
+ end
13
+
14
+ def get_event_dump(params = {})
15
+ post('event-dump/get.json', params)
16
+ end
17
+
18
+ def list_event_dumps(params = {})
19
+ post('event-dump/list.json', params)
20
+ end
21
+
22
+ def delete_event_dump(params = {})
23
+ post('event-dump/delete.json', params)
24
+ end
25
+
26
+ add_response_validations(
27
+ :event_dump,
28
+ %w(
29
+ create_event_dump
30
+ get_event_dump
31
+ list_event_dumps
32
+ delete_event_dump
33
+ )
34
+ )
35
+ end
36
+ end
37
+ end
@@ -1,58 +1,34 @@
1
1
  module UniOne
2
2
  class Client
3
-
4
3
  module Project
4
+ extend UniOne::Validation::ClassMethods
5
+ include UniOne::Validation::InstanceMethods
5
6
 
6
- def create_project(project)
7
- params = { project: project }
8
- post 'project/create.json', params
9
- validate_response({
10
- 'type' => 'object', 'required' => ['status', 'project_api_key'], 'properties' => {
11
- 'status' => {'type' => 'string'},
12
- 'project_api_key' => {'type' => 'string'}}
13
- })
7
+ def create_project(params = {})
8
+ post('project/create.json', params)
14
9
  end
15
10
 
16
- def update_project(project_api_key, project)
17
- params = { project_api_key: project_api_key, project: project }
18
- post 'project/update.json', params
19
- validate_response({
20
- 'type' => 'object', 'required' => ['status', 'project_api_key'], 'properties' => {
21
- 'status' => {'type' => 'string'},
22
- 'project_api_key' => {'type' => 'string'}}
23
- })
11
+ def update_project(params = {})
12
+ post('project/update.json', params)
24
13
  end
25
14
 
26
- def delete_project(project_api_key)
27
- params = { project_api_key: project_api_key }
28
- post 'project/delete.json', params
29
- validate_response({
30
- 'type' => 'object', 'required' => ['status'], 'properties' => {
31
- 'status' => {'type' => 'string'}}
32
- })
15
+ def list_projects(params = {})
16
+ post('project/list.json', params)
33
17
  end
34
18
 
35
- def list_projects(project_api_key = nil)
36
- params = { project_api_key: project_api_key }
37
- post 'project/list.json', params
38
- validate_response({
39
- 'type' => 'object', 'required' => ['status'], 'properties' => {
40
- 'status' => {'type' => 'string'},
41
- 'projects' => {'items' => project_schema}}
42
- })
19
+ def delete_project(params = {})
20
+ post('project/delete.json', params)
43
21
  end
44
22
 
45
- private
46
-
47
- def project_schema
48
- {'type' => 'object', 'required' => ['api_key', 'name', 'reg_time', 'send_enabled', 'custom_unsubscribe_url_enabled'], 'properties' => {
49
- 'api_key' => {'type' => 'string'},
50
- 'name' => {'type' => 'string'},
51
- 'reg_time' => {'type' => 'string'},
52
- 'send_enabled' => {'type' => 'boolean'},
53
- 'custom_unsubscribe_url_enabled' => {'type' => 'boolean'}
54
- }}
55
- end
23
+ add_response_validations(
24
+ :project,
25
+ %w(
26
+ create_project
27
+ update_project
28
+ list_projects
29
+ delete_project
30
+ )
31
+ )
56
32
  end
57
33
  end
58
34
  end
@@ -0,0 +1,38 @@
1
+ module UniOne
2
+ class Client
3
+ module Suppression
4
+ extend UniOne::Validation::ClassMethods
5
+ include UniOne::Validation::InstanceMethods
6
+
7
+ def set_suppression(params = {})
8
+ params[:created] = handle_time_param(params[:created]) if params[:created]
9
+
10
+ post('suppression/set.json', params)
11
+ end
12
+
13
+ def get_suppression(params = {})
14
+ post('suppression/get.json', params)
15
+ end
16
+
17
+ def list_suppressions(params = {})
18
+ params[:start_time] = handle_time_param(params[:start_time]) if params[:start_time]
19
+
20
+ post('suppression/list.json', params)
21
+ end
22
+
23
+ def delete_suppression(params = {})
24
+ post('suppression/delete.json', params)
25
+ end
26
+
27
+ add_response_validations(
28
+ :suppression,
29
+ %w(
30
+ set_suppression
31
+ get_suppression
32
+ list_suppressions
33
+ delete_suppression
34
+ )
35
+ )
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,19 @@
1
+ module UniOne
2
+ class Client
3
+ module System
4
+ extend UniOne::Validation::ClassMethods
5
+ include UniOne::Validation::InstanceMethods
6
+
7
+ def info(params = {})
8
+ post('system/info.json', params)
9
+ end
10
+
11
+ add_response_validations(
12
+ :system,
13
+ %w(
14
+ info
15
+ )
16
+ )
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,24 @@
1
+ module UniOne
2
+ class Client
3
+ module Tag
4
+ extend UniOne::Validation::ClassMethods
5
+ include UniOne::Validation::InstanceMethods
6
+
7
+ def list_tags(params = {})
8
+ post('tag/list.json', params)
9
+ end
10
+
11
+ def delete_tag(params = {})
12
+ post('tag/delete.json', params)
13
+ end
14
+
15
+ add_response_validations(
16
+ :tag,
17
+ %w(
18
+ list_tags
19
+ delete_tag
20
+ )
21
+ )
22
+ end
23
+ end
24
+ end
@@ -1,80 +1,34 @@
1
1
  module UniOne
2
2
  class Client
3
-
4
3
  module Template
4
+ extend UniOne::Validation::ClassMethods
5
+ include UniOne::Validation::InstanceMethods
5
6
 
6
- def set_template(template)
7
- post 'template/set.json', template
8
- validate_response({
9
- 'type' => 'object', 'required' => ['status', 'template'], 'properties' => {
10
- 'status' => {'type' => 'string'},
11
- 'template' => template_schema}
12
- })
13
- end
14
-
15
- def get_template(id)
16
- params = { id: id }
17
- post 'template/get.json', params
18
- validate_response({
19
- 'type' => 'object', 'required' => ['status', 'template'], 'properties' => {
20
- 'status' => {'type' => 'string'},
21
- 'template' => template_schema}
22
- })
23
- end
24
-
25
- def list_templates(limit, offset)
26
- params = { limit: limit, offset: offset }
27
- post 'template/list.json', params
28
- list_template_schema = remove_fields_from_schema(template_schema, ['from_name', 'headers'])
29
- validate_response({
30
- 'type' => 'object', 'required' => ['status', 'templates'], 'properties' => {
31
- 'status' => {'type' => 'string'},
32
- 'templates' => {'items' => list_template_schema}}
33
- })
34
- end
35
-
36
- def delete_template(id)
37
- params = { id: id }
38
- post 'template/delete.json', params
39
- validate_response({
40
- 'type' => 'object', 'required' => ['status'], 'properties' => {
41
- 'status' => {'type' => 'string'}}
42
- })
7
+ def set_template(params = {})
8
+ post('template/set.json', params)
43
9
  end
44
10
 
45
- private
46
-
47
- def template_schema
48
- {'type' => 'object', 'required' => ['id', 'name', 'subject', 'from_name', 'body', 'headers', 'attachments',
49
- 'inline_attachments', 'options', 'created', 'user_id'], 'properties' => {
50
- 'id' => {'type' => 'string'},
51
- 'name' => {'type' => 'string'},
52
- 'subject' => {'type' => 'string'},
53
- 'from_name' => {'type' => 'string'},
54
- 'body' => template_body_schema,
55
- 'headers' => {'type' => 'object'},
56
- 'attachments' => {'items' => {'type' => 'object'}},
57
- 'inline_attachments' => {'items' => {'type' => 'object'}},
58
- 'options' => template_options_schema,
59
- 'created' => {'type' => 'string'},
60
- 'user_id' => {'type' => 'integer'},
61
- }}
11
+ def get_template(params = {})
12
+ post('template/get.json', params)
62
13
  end
63
14
 
64
- def template_body_schema
65
- {'type' => 'object', 'required' => ['html', 'plaintext', 'amp'], 'properties' => {
66
- 'html' => {'type' => 'string, null'},
67
- 'plaintext' => {'type' => 'string, null'},
68
- 'amp' => {'type' => 'string, null'}
69
- }}
15
+ def list_templates(params = {})
16
+ post('template/list.json', params)
70
17
  end
71
18
 
72
- def template_options_schema
73
- {'type' => 'object', 'required' => ['unsubscribe_url'], 'properties' => {
74
- 'unsubscribe_url' => {'type' => 'string'}
75
- }}
19
+ def delete_template(params = {})
20
+ post('template/delete.json', params)
76
21
  end
77
22
 
23
+ add_response_validations(
24
+ :template,
25
+ %w(
26
+ set_template
27
+ get_template
28
+ list_templates
29
+ delete_template
30
+ )
31
+ )
78
32
  end
79
33
  end
80
34
  end
@@ -1,44 +1,31 @@
1
1
  module UniOne
2
2
  class Client
3
-
4
3
  module Unsubscribed
4
+ extend UniOne::Validation::ClassMethods
5
+ include UniOne::Validation::InstanceMethods
5
6
 
6
- def unsubscribe(address)
7
- params = { address: address }
8
- post 'unsubscribed/set.json', params
9
- validate_response({
10
- 'type' => 'object', 'required' => ['status', 'address', 'message'], 'properties' => {
11
- 'status' => {'type' => 'string'},
12
- 'address' => {'type' => 'string'},
13
- 'message' => {'type' => 'string'}}
14
- })
7
+ def unsubscribe(params = {})
8
+ post('unsubscribed/set.json', params)
15
9
  end
16
10
 
17
- def check_unsubscribed(address)
18
- params = { address: address }
19
- post 'unsubscribed/check.json', params
20
- validate_response({
21
- 'type' => 'object', 'required' => ['status', 'address', 'is_unsubscribed'], 'properties' => {
22
- 'status' => {'type' => 'string'},
23
- 'address' => {'type' => 'string'},
24
- 'is_unsubscribed' => {'type' => 'boolean'}}
25
- })
11
+ def check_unsubscribed(params = {})
12
+ post('unsubscribed/check.json', params)
26
13
  end
27
14
 
28
- def list_unsubscribed(date_from)
29
- params = { date_from: date_from }
30
- post 'unsubscribed/list.json', params
31
- validate_response({
32
- 'type' => 'object', 'required' => ['status', 'unsubscribed'], 'properties' => {
33
- 'status' => {'type' => 'string'},
34
- 'unsubscribed' => {
35
- 'items' => {'type' => 'object'}, 'required' => ['address', 'unsubscribed_on'], 'properties' => {
36
- 'address' => {'type' => 'string'},
37
- 'unsubscribed_on' => {'type' => 'string'}
38
- }}}
39
- })
15
+ def list_unsubscribed(params = {})
16
+ params[:date_from] = handle_date_param(params[:date_from]) if params[:date_from]
17
+
18
+ post('unsubscribed/list.json', params)
40
19
  end
41
20
 
21
+ add_response_validations(
22
+ :unsubscribed,
23
+ %w(
24
+ unsubscribe
25
+ check_unsubscribed
26
+ list_unsubscribed
27
+ )
28
+ )
42
29
  end
43
30
  end
44
31
  end