unione-ruby 0.0.1 → 0.0.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c8462ee8f317ff0d316298a45e0f6f948897776346bcbe7f70997190a681e02a
4
- data.tar.gz: 51f9b320c81f7bd65559b10eda50bdaf20a0bd1148c2d7017590a1d344319118
3
+ metadata.gz: e22befdd1f1c883aea070dc4fc563186de323067b32d3d5d9f992185b6f2daed
4
+ data.tar.gz: 95d1729d578640a7853b44498198a4253a587270344ba3b1893452e28489c4b8
5
5
  SHA512:
6
- metadata.gz: 46993c14f31096f8f22eefb96f050c26436088335ef44572d981fd599f25187b333d69b7c19790e0fe04f3efee05b164f226181d5633f0c06c30737a25e62bd4
7
- data.tar.gz: 33b4d179be489d1edb42b0a24f5866a672d640ae90e30dd8db1376a63ecb695624c5034b48f52b30584153c1298cf7fd780be610204ae7e02e43715d3e37e82f
6
+ metadata.gz: 2679550487b3d69e2bb922309a9581d3f6905f534a5d3a809e957ee7797fed443124c9454a1449e3983538daa88a94860c91153d630da1aef34ba7970586c647
7
+ data.tar.gz: 363db7dd049ddd4921de5ef64354b741b9353db1423cc2bace4a0ea99c460b6656531aeef371846cda6aaf17abe7c88b82115da2f54ab3d8483802858cb64f66
data/README.md CHANGED
@@ -3,12 +3,16 @@ UniOne (unione.io) integration gem for Ruby
3
3
 
4
4
  [Examples of usage](https://github.com/unione-repo/unione-ruby/tree/master/examples)
5
5
 
6
+ ## Install
7
+
8
+ gem install unione-ruby
9
+
6
10
  ## Working with API responses
7
11
  This library using [faraday](https://github.com/lostisland/faraday) gem for making HTTP queries along with [mashify middleware](https://github.com/hashie/hashie#mash) for post-processing response body. So, you can use extended syntax for accessing response fields.
8
12
 
9
13
  Example of work with responses:
10
14
 
11
- ```ruby
15
+ ~~~ruby
12
16
  require 'unione-ruby'
13
17
  unione = UniOne::Client.new(data_center: 'eu1', lang: 'en', api_key: ENV['UNIONE_API_KEY'])
14
18
  response = unione.get_dns_records("example.com")
@@ -18,6 +22,12 @@ puts response.headers
18
22
  # Access fields as hash or as methods
19
23
  puts response.body['status']
20
24
  puts response.body.status
25
+ ~~~
26
+
27
+ By default authentication produced through X-API-KEY header. For passing API key in params use:
28
+
29
+ ```
30
+ unione = UniOne::Client.new(data_center: 'eu1', lang: 'en', api_key: ENV['UNIONE_API_KEY'], api_key_in_params: true)
21
31
  ```
22
32
 
23
33
  ## Handling API errors
@@ -25,7 +35,7 @@ Library using [`raise-error' middleware](https://lostisland.github.io/faraday/mi
25
35
 
26
36
  Example of work with errors:
27
37
 
28
- ```ruby
38
+ ~~~ruby
29
39
  require 'unione-ruby'
30
40
  begin
31
41
  unione = UniOne::Client.new(data_center: 'eu1', lang: 'en', api_key: ENV['UNIONE_API_KEY'])
@@ -39,4 +49,4 @@ rescue Faraday::Error => e
39
49
  puts e.response[:body]
40
50
  puts e.response[:headers]
41
51
  end
42
- ```
52
+ ~~~
data/Rakefile ADDED
@@ -0,0 +1,3 @@
1
+ task :console do
2
+ exec "irb -r unione-ruby -I ./lib"
3
+ end
@@ -9,10 +9,10 @@ puts response.body.to_h
9
9
  puts response.headers
10
10
 
11
11
  # Validate domain verification record before use
12
- response = unione.validate_verification_record("example.com")
12
+ response = unione.validate_verification_record('example.com')
13
13
 
14
14
  # Validate DKIM signature before sending
15
- response = unione.validate_dkim("example.com")
15
+ response = unione.validate_dkim('example.com')
16
16
 
17
17
  # Get a list of your domains and their verification/DKIM statuses
18
18
  response = unione.list_domains
@@ -1,36 +1,51 @@
1
1
  require 'unione-ruby'
2
2
  require 'json'
3
3
 
4
- # Send email
4
+ unione = UniOne::Client.new(data_center: 'eu1', lang: 'en', api_key: ENV['UNIONE_API_KEY'])
5
+
6
+ # sending mail
5
7
  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
8
 
11
- substitutions = {"substitutionName" => "substitutionVal", "to_name" => "Name Surname 1"}
12
- recipient1 = {email: 'test1@example.com', substitutions: substitutions, metadata: {"key1" => "val1"}}
9
+ mail.subject = 'Email Subject'
10
+ mail.from = { from_email: 'test@qadns.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' } }
13
20
  mail.recipients << recipient1
14
21
 
15
- substitutions = {"substitutionName" => "substitutionVal", "to_name" => "Name Surname 2"}
16
- recipient2 = {email: 'test2@example.com', substitutions: substitutions, metadata: {"key1" => "val1"}}
22
+ substitutions = { 'substitutionName' => 'substitutionVal', to_name: 'Name Surname 2' }
23
+ recipient2 = { email: 'test2@example.com', substitutions: substitutions, metadata: { key1: 'val1' } }
17
24
  mail.recipients << recipient2
18
25
 
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"}
26
+ mail.global_metadata = { key1: 'val1' }
27
+ mail.headers = { 'X-ReplyTo' => 'reply@qadns.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' }
24
37
 
25
38
  puts mail.to_json
26
39
 
27
- unione = UniOne::Client.new(data_center: 'eu1', lang: 'en', api_key: ENV['UNIONE_API_KEY'])
28
40
  response = unione.send_email(mail.to_json)
41
+
29
42
  puts response.status
30
43
  puts response.body
31
44
  puts response.headers
32
45
 
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")
46
+ # subscribe email
47
+ response = unione.subscribe_email(
48
+ from_email: 'from@qadns.net',
49
+ from_name: 'Example Sender',
50
+ to_email: 'blackhole@example.com'
51
+ )
@@ -1,20 +1,37 @@
1
1
  require 'unione-ruby'
2
2
 
3
- # Create project
4
3
  unione = UniOne::Client.new(data_center: 'eu1', lang: 'en', api_key: ENV['UNIONE_API_KEY'])
5
- response = unione.create_project(
6
- {"name" => "Projectname 2", "send_enabled" => true, "custom_unsubscribe_url_enabled" => true})
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
+ })
11
+
7
12
  puts response.status
8
13
  puts response.body.to_h
9
14
  puts response.headers
10
15
 
11
- # Update project
12
- response = unione.update_project("5qugsquc85i1e87xfb4spgxh8bnmi1pjfrtx1w1c",
13
- {"name" => "Projectname 2", "send_enabled" => true, "custom_unsubscribe_url_enabled" => true})
16
+ project_id = response.body.project_id
14
17
 
15
- # Delete project
16
- response = unione.delete_project("5qegsquc85i1e87xfb4spgxh8bnmi1pjfrtx1w1c")
18
+ # update project
19
+ response = unione.update_project(
20
+ {
21
+ project_id: project_id
22
+ },
23
+ {
24
+ name: 'New Project Name',
25
+ send_enabled: true,
26
+ # custom_unsubscribe_url_enabled: true, # Should have rights to use
27
+ }
28
+ )
17
29
 
18
- # List projects
30
+ # list all projects
19
31
  response = unione.list_projects
20
- response = unione.list_projects("5qegsquc85i1e87xfb4spgxh8bnmi1pjfrtx1w1c")
32
+
33
+ # list project by id
34
+ response = unione.list_projects({ project_id: project_id })
35
+
36
+ # delete project
37
+ response = unione.delete_project({ project_id: project_id })
@@ -0,0 +1,10 @@
1
+ require 'unione-ruby'
2
+
3
+ unione = UniOne::Client.new(data_center: 'eu1', lang: 'en', api_key: ENV['UNIONE_API_KEY'])
4
+
5
+ # get user or project information
6
+ response = unione.info
7
+
8
+ puts response.status
9
+ puts response.body.to_h
10
+ puts response.headers
@@ -1,36 +1,42 @@
1
1
  require 'unione-ruby'
2
2
  require 'json'
3
3
 
4
- # Set template
4
+ unione = UniOne::Client.new(data_center: 'eu1', lang: 'en', api_key: ENV['UNIONE_API_KEY'])
5
+
6
+ # set template
5
7
  template = UniOne::Template.new
6
- template.name = 'Template Name'
7
- template.subject = 'Email Subject'
8
+
9
+ template.name = 'Template Name'
10
+ template.editor_type = 'html'
11
+ template.subject = 'Email Subject'
8
12
  template.template_engine = 'simple'
9
- template.global_substitutions = {"someVar" => "someVal"}
10
13
 
11
- template.from = {from_email: 'test@example.com', from_name: 'userName'}
12
- template.headers = {"X-ReplyTo" => "reply@example.com"}
13
- template.body = {html: "<b>Hello {{substitutionName}}</b>"}
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
+ template.options = { unsubscribe_url: 'someurl' }
14
20
 
15
- template.attachments << {"type" => "text/plain", "name" => "myfile.txt", "content" => "ZXhhbXBsZSBmaWxl"}
16
- template.inline_attachments << {"type" => "image/png", "name" => "IMAGECID", "content" => "iVBORw0KGgo"}
17
- template.options = {"unsubscribe_url" => "someurl"}
21
+ template.attachments << { type: 'text/plain', name: 'myfile.txt', content: 'ZXhhbXBsZSBmaWxl' }
22
+ template.inline_attachments << { type: 'image/png', name: 'IMAGECID', content: 'iVBORw0KGgo' }
18
23
 
19
24
  puts template.to_json
20
25
 
21
- unione = UniOne::Client.new(data_center: 'eu1', lang: 'en', api_key: ENV['UNIONE_API_KEY'])
22
26
  response = unione.set_template(template.to_json)
27
+
23
28
  puts response.status
24
29
  puts response.body.to_h
25
- puts response.body.template.id # Get Id of created template for later referencing
26
30
  puts response.headers
27
31
 
28
- # Get template
29
- unione = UniOne::Client.new(data_center: 'eu1', lang: 'en', api_key: ENV['UNIONE_API_KEY'])
30
- response = unione.get_template("cef89054-40a8-4b9b-a379-22030d525c49")
32
+ # get id of created template
33
+ template_id = response.body.template.id
34
+
35
+ # get template
36
+ response = unione.get_template(template_id)
31
37
 
32
- # List templates
38
+ # list all templates
33
39
  response = unione.list_templates(50, 0)
34
40
 
35
- # Delete template
36
- response = unione.delete_template("cef89054-40a8-4b9b-a379-22030d525c49")
41
+ # delete template
42
+ response = unione.delete_template(template_id)
@@ -1,14 +1,16 @@
1
1
  require 'unione-ruby'
2
2
 
3
- # Unsubscribe subscriber
4
3
  unione = UniOne::Client.new(data_center: 'eu1', lang: 'en', api_key: ENV['UNIONE_API_KEY'])
5
- response = unione.unsubscribe("email@example.com")
4
+
5
+ # unsubscribe email
6
+ response = unione.unsubscribe('email@example.com')
7
+
6
8
  puts response.status
7
9
  puts response.body.to_h
8
10
  puts response.headers
9
11
 
10
- # Check unsubscribed
11
- response = unione.check_unsubscribed("email@example.com")
12
+ # check email is unsubscribed
13
+ response = unione.check_unsubscribed('email@example.com')
12
14
 
13
- # List unsubscribed
14
- response = unione.list_unsubscribed("2019-01-01")
15
+ # list unsubscribed emails
16
+ response = unione.list_unsubscribed('2019-01-01')
@@ -1,32 +1,39 @@
1
1
  require 'unione-ruby'
2
2
  require 'json'
3
3
 
4
- # Set webhook
4
+ unione = UniOne::Client.new(data_center: 'eu1', lang: 'en', api_key: ENV['UNIONE_API_KEY'])
5
+
6
+ # set webhook
5
7
  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: ["*"]}
8
+
9
+ webhook.url = 'http://example.com'
10
+ webhook.status = :active
11
+
12
+ webhook.settings = {
13
+ event_format: :json_post,
14
+ delivery_info: 1,
15
+ single_event: 0,
16
+ max_parallel: 10
17
+ }
18
+
19
+ webhook.events = {
20
+ email_status: %w(sent delivered opened hard_bounced soft_bounced spam clicked unsubscribed),
21
+ spam_block: ["*"]
22
+ }
18
23
 
19
24
  puts webhook.to_json
20
25
 
21
- unione = UniOne::Client.new(data_center: 'eu1', lang: 'en', api_key: ENV['UNIONE_API_KEY'])
22
26
  response = unione.set_webhook(webhook.to_json)
27
+
23
28
  puts response.status
24
29
  puts response.body.to_h
25
30
  puts response.headers
26
31
 
27
- # 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")
32
+ # get webhook
33
+ response = unione.get_webhook('http://example.com')
34
+
35
+ # list all webhooks
36
+ response = unione.list_webhooks(50, 0)
30
37
 
31
- # Delete webhook
32
- response = unione.delete_webhook("http://example.com")
38
+ # delete webhook
39
+ response = unione.delete_webhook('http://example.com')
@@ -0,0 +1,32 @@
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
+
8
+ template_id = "bc0372d4-69f2-11eb-9d14-366b3a36c9e1"
9
+ mail.template = { template_engine: 'simple', template_id: template_id }
10
+
11
+ mail.from = { from_email: 'test@qadns.net', from_name: 'userName' }
12
+
13
+ substitutions = { 'substitutionName' => 'substitutionVal', to_name: 'Name Surname 1' }
14
+ recipient = { email: 'test1@example.com', substitutions: substitutions, metadata: { key1: 'val1' } }
15
+ mail.recipients << recipient
16
+
17
+ substitutions = { 'substitutionName' => 'substitutionVal', to_name: 'Name Surname 2' }
18
+ recipient = { email: 'test2@example.com', substitutions: substitutions, metadata: { key1: 'val1' } }
19
+ mail.recipients << recipient
20
+
21
+ mail.global_metadata = { key1: 'val1' }
22
+ mail.headers = { 'X-ReplyTo' => 'reply@example.com' }
23
+ mail.options = { unsubscribe_url: 'someurl' }
24
+
25
+ mail.attachments << { type: 'text/plain', name: 'myfile.txt', content: 'ZXhhbXBsZSBmaWxl' }
26
+ mail.inline_attachments << { type: 'image/png', name: 'IMAGECID', content: 'iVBORw0KGgo' }
27
+
28
+ response = unione.send_email(mail.to_json)
29
+
30
+ puts response.status
31
+ puts response.body.to_h
32
+ puts response.headers
data/examples/setup.rb ADDED
@@ -0,0 +1,27 @@
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
+
12
+ template.name = 'Template Name'
13
+ template.subject = 'Email Subject'
14
+ template.template_engine = 'simple'
15
+ template.headers = { 'X-ReplyTo' => 'reply@example.com' }
16
+ template.global_substitutions = { 'someVar' => 'someVal' }
17
+
18
+ template.from = { from_email: 'test@example.com', from_name: 'userName' }
19
+ template.body = { html: '<b>Hello {{substitutionName}}</b>' }
20
+
21
+ template.attachments << { type: 'text/plain', name: 'myfile.txt', content: 'ZXhhbXBsZSBmaWxl' }
22
+ template.inline_attachments << { type: 'image/png', name: 'IMAGECID', content: 'iVBORw0KGgo' }
23
+
24
+ template.options = { unsubscribe_url: 'someurl' }
25
+
26
+ response = unione.set_template(template.to_json)
27
+ template_id = response.body.template.id
data/lib/unione/client.rb CHANGED
@@ -2,10 +2,11 @@ require_relative 'connection'
2
2
  require_relative 'validation'
3
3
  require_relative 'client/domain'
4
4
  require_relative 'client/email'
5
+ require_relative 'client/project'
6
+ require_relative 'client/system'
5
7
  require_relative 'client/template'
6
- require_relative 'client/webhook'
7
8
  require_relative 'client/unsubscribed'
8
- require_relative 'client/project'
9
+ require_relative 'client/webhook'
9
10
 
10
11
  module UniOne
11
12
 
@@ -15,10 +16,11 @@ module UniOne
15
16
  include UniOne::Validation
16
17
  include UniOne::Client::Domain
17
18
  include UniOne::Client::Email
19
+ include UniOne::Client::Project
20
+ include UniOne::Client::System
18
21
  include UniOne::Client::Template
19
- include UniOne::Client::Webhook
20
22
  include UniOne::Client::Unsubscribed
21
- include UniOne::Client::Project
23
+ include UniOne::Client::Webhook
22
24
 
23
25
  API_ENDPOINT =
24
26
  'https://%{data_center}.unione.io/%{lang}/transactional/api/v1/'
@@ -27,11 +29,12 @@ module UniOne
27
29
  # - +data_center+ -> data center: ['eu1', 'us1']
28
30
  # - +lang+ -> Two-letter ISO 639-1 language abbreviation, e.g. 'en'
29
31
  # - +api_key+ -> your UniOne API key
30
- #
31
- def initialize(data_center:, lang:, api_key:)
32
- @data_center = data_center
33
- @lang = lang
34
- @api_key = api_key
32
+ # - +api_key_in_params+ -> boolean, pass API key inside form, otherwise pass in headers (default in headers)
33
+ def initialize(params = {})
34
+ @data_center = params[:data_center]
35
+ @lang = params[:lang]
36
+ @api_key = params[:api_key]
37
+ @api_key_in_params = !!params[:api_key_in_params]
35
38
  end
36
39
 
37
40
  private
@@ -1,8 +1,6 @@
1
1
  module UniOne
2
2
  class Client
3
-
4
3
  module Domain
5
-
6
4
  def get_dns_records(domain)
7
5
  params = { domain: domain }
8
6
  post 'domain/get-dns-records.json', params
@@ -55,7 +53,6 @@ module UniOne
55
53
  ]}}}
56
54
  })
57
55
  end
58
-
59
56
  end
60
57
  end
61
58
  end
@@ -1,8 +1,6 @@
1
1
  module UniOne
2
2
  class Client
3
-
4
3
  module Email
5
-
6
4
  def send_email(message)
7
5
  post 'email/send.json', message
8
6
  validate_response({
@@ -14,19 +12,13 @@ module UniOne
14
12
  })
15
13
  end
16
14
 
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
- }
15
+ def subscribe_email(params)
23
16
  post 'email/subscribe.json', params
24
17
  validate_response({
25
18
  'type' => 'object', 'required' => ['status'], 'properties' => {
26
19
  'status' => {'type' => 'string'}}
27
20
  })
28
21
  end
29
-
30
22
  end
31
23
  end
32
24
  end
@@ -1,55 +1,73 @@
1
1
  module UniOne
2
2
  class Client
3
-
4
3
  module Project
5
-
6
4
  def create_project(project)
7
5
  params = { project: project }
8
6
  post 'project/create.json', params
9
7
  validate_response({
10
- 'type' => 'object', 'required' => ['status', 'project_api_key'], 'properties' => {
8
+ 'type' => 'object', 'required' => ['status', 'project_id', 'project_api_key'], 'properties' => {
11
9
  'status' => {'type' => 'string'},
10
+ 'project_id' => {'type' => 'string'},
12
11
  'project_api_key' => {'type' => 'string'}}
13
12
  })
14
13
  end
15
14
 
16
- def update_project(project_api_key, project)
17
- params = { project_api_key: project_api_key, project: project }
15
+ def update_project(project_identity, project)
16
+ params = get_identity(project_identity).merge(project: project)
18
17
  post 'project/update.json', params
19
18
  validate_response({
20
- 'type' => 'object', 'required' => ['status', 'project_api_key'], 'properties' => {
19
+ 'type' => 'object', 'required' => ['status'], 'properties' => {
21
20
  'status' => {'type' => 'string'},
22
21
  'project_api_key' => {'type' => 'string'}}
23
22
  })
24
23
  end
25
24
 
26
- def delete_project(project_api_key)
27
- params = { project_api_key: project_api_key }
28
- post 'project/delete.json', params
25
+ def list_projects(project_identity = nil)
26
+ params = get_identity(project_identity)
27
+ post 'project/list.json', params
29
28
  validate_response({
30
- 'type' => 'object', 'required' => ['status'], 'properties' => {
31
- 'status' => {'type' => 'string'}}
29
+ 'type' => 'object',
30
+ 'required' => %w{ status },
31
+ 'properties' => {
32
+ 'status' => { 'type' => 'string' },
33
+ 'projects' => { 'items' => project_schema }
34
+ }
32
35
  })
33
36
  end
34
37
 
35
- def list_projects(project_api_key = nil)
36
- params = { project_api_key: project_api_key }
37
- post 'project/list.json', params
38
+ def delete_project(project_identity)
39
+ params = get_identity(project_identity)
40
+ post 'project/delete.json', params
38
41
  validate_response({
39
- 'type' => 'object', 'required' => ['status'], 'properties' => {
40
- 'status' => {'type' => 'string'},
41
- 'projects' => {'items' => project_schema}}
42
+ 'type' => 'object',
43
+ 'required' => %w{ status },
44
+ 'properties' => {
45
+ 'status' => { 'type' => 'string' }
46
+ }
42
47
  })
43
48
  end
44
49
 
45
50
  private
46
51
 
52
+ def get_identity(project_identity)
53
+ if project_identity.is_a?(Hash)
54
+ project_identity
55
+ elsif project_identity
56
+ { project_api_key: project_identity }
57
+ else
58
+ {}
59
+ end
60
+ end
61
+
47
62
  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'},
63
+ {'type' => 'object',
64
+ 'required' => %w{ id api_key name reg_time send_enabled custom_unsubscribe_url_enabled },
65
+ 'properties' => {
66
+ 'id' => {'type' => 'string'},
67
+ 'api_key' => {'type' => 'string'},
68
+ 'name' => {'type' => 'string'},
69
+ 'reg_time' => {'type' => 'string'},
70
+ 'send_enabled' => {'type' => 'boolean'},
53
71
  'custom_unsubscribe_url_enabled' => {'type' => 'boolean'}
54
72
  }}
55
73
  end
@@ -0,0 +1,24 @@
1
+ module UniOne
2
+ class Client
3
+ module System
4
+ def info
5
+ post 'system/info.json', {}
6
+ validate_response({
7
+ 'type' => 'object', 'required' => ['status', 'user_id', 'email'], 'properties' => {
8
+ 'status' => {'type' => 'string'},
9
+ 'user_id' => {'type' => 'integer'},
10
+ 'email' => {'type' => 'string'},
11
+ 'accounting' =>
12
+ {'type' => 'object', 'required' => ['period_start', 'period_end', 'emails_included', 'emails_sent'], 'properties' => [
13
+ 'period_start' => {'type' => 'string'},
14
+ 'period_end' => {'type' => 'string'},
15
+ 'emails_included' => {'type' => 'integer'},
16
+ 'emails_sent' => {'type' => 'integer'}
17
+ ]},
18
+ 'project_id' => {'type' => 'string'},
19
+ 'project_name' => {'type' => 'string'}}
20
+ })
21
+ end
22
+ end
23
+ end
24
+ end
@@ -45,10 +45,11 @@ module UniOne
45
45
  private
46
46
 
47
47
  def template_schema
48
- {'type' => 'object', 'required' => ['id', 'name', 'subject', 'from_name', 'body', 'headers', 'attachments',
49
- 'inline_attachments', 'options', 'created', 'user_id'], 'properties' => {
48
+ {'type' => 'object', 'required' => ['id', 'name', 'editor_type', 'subject', 'from_name', 'body', 'headers', 'attachments',
49
+ 'inline_attachments', 'created', 'user_id'], 'properties' => {
50
50
  'id' => {'type' => 'string'},
51
51
  'name' => {'type' => 'string'},
52
+ 'editor_type' => {'type' => 'string'},
52
53
  'subject' => {'type' => 'string'},
53
54
  'from_name' => {'type' => 'string'},
54
55
  'body' => template_body_schema,
@@ -21,6 +21,31 @@ module UniOne
21
21
  }})
22
22
  end
23
23
 
24
+ def list_webhooks(limit, offset)
25
+ params = { limit: limit, offset: offset }
26
+ post 'webhook/list.json', params
27
+ validate_response({
28
+ 'type' => 'object', 'required' => ['status', 'objects'], 'properties' => {
29
+ 'status' => {'type' => 'string'},
30
+ 'objects' =>
31
+ {'items' =>
32
+ {'type' => 'object', 'required' => ['id', 'url', 'status', 'updated_at', 'events', 'event_format', 'delivery_info', 'single_event', 'max_parallel'], 'properties' => [
33
+ 'id' => {'type' => 'integer'},
34
+ 'url' => {'type' => 'string'},
35
+ 'status' => {'type' => 'string'},
36
+ 'updated_at' => {'type' => 'string'},
37
+ 'events' =>
38
+ {'type' => 'object', 'required' => ['email_status', 'spam_block'], 'properties' => [
39
+ 'email_status' => {'items' => {'type' => 'string'}},
40
+ 'spam_block' => {'items' => {'type' => 'string'}}]},
41
+ 'event_format' => {'type' => 'string'},
42
+ 'delivery_info' => {'type' => 'integer'},
43
+ 'single_event' => {'type' => 'integer'},
44
+ 'max_parallel' => {'type' => 'integer'}
45
+ ]}}}
46
+ })
47
+ end
48
+
24
49
  def delete_webhook(url)
25
50
  params = { url: url }
26
51
  post 'webhook/delete.json', params
@@ -32,13 +57,15 @@ module UniOne
32
57
  private
33
58
 
34
59
  def webhook_schema
35
- {'type' => 'object', 'required' => ['url', 'events', 'event_format', 'delivery_info', 'single_event', 'max_parallel'], 'properties' => {
60
+ {'type' => 'object', 'required' => ['url', 'status', 'events', 'event_format', 'delivery_info', 'single_event', 'max_parallel'], 'properties' => {
61
+ 'id' => {'type' => 'integer'},
36
62
  'url' => {'type' => 'string'},
37
- 'events' => webhook_events_schema,
63
+ 'status' => {'type' => 'string'},
38
64
  'event_format' => {'type' => 'string'},
39
65
  'delivery_info' => {'type' => 'integer'},
40
66
  'single_event' => {'type' => 'integer'},
41
- 'max_parallel' => {'type' => 'integer'}
67
+ 'max_parallel' => {'type' => 'integer'},
68
+ 'events' => webhook_events_schema,
42
69
  }}
43
70
  end
44
71
 
@@ -7,33 +7,33 @@ module UniOne
7
7
  module Connection
8
8
 
9
9
  def get(url, params)
10
- params.merge!(default_params)
10
+ prepare_params!(params)
11
+
11
12
  # Assume HTTP library receives params as Hash
12
- request :get, url, params
13
+ request(:get, url, params)
13
14
  end
14
15
 
15
16
  def post(url, params)
16
- params.merge!(default_params)
17
+ prepare_params!(params)
18
+
17
19
  # Assume HTTP library receives payload body as String
18
- request :post, url, JSON.dump(params)
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
- begin
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: {'Content-Type' => 'application/json'},
36
+ headers: headers,
37
37
  request: { timeout: 30 }
38
38
  ) do |conn|
39
39
  conn.response :mashify, content_type: /\bjson$/
@@ -43,8 +43,12 @@ module UniOne
43
43
  end
44
44
  end
45
45
 
46
- def default_params
47
- { api_key: @api_key }
46
+ def prepare_params!(params)
47
+ params.merge!({api_key: @api_key}) if @api_key_in_params
48
+ end
49
+
50
+ def prepare_headers!(headers)
51
+ headers.merge!('X-API-KEY' => @api_key) unless @api_key_in_params
48
52
  end
49
53
 
50
54
  def add_version(path)
@@ -1,8 +1,8 @@
1
1
  module UniOne
2
2
  class Mail
3
- attr_accessor :template, :body, :track, :from, :subject, :metadata, :headers, :options,
3
+ attr_accessor :template, :body, :track, :from, :subject, :global_metadata, :headers, :options,
4
4
  :global_substitutions, :recipients, :attachments, :inline_attachments,
5
- :reply_to
5
+ :reply_to, :skip_unsubscribe, :force_send
6
6
 
7
7
  def initialize
8
8
  @template = {}
@@ -14,6 +14,9 @@ module UniOne
14
14
  @inline_attachments = []
15
15
  end
16
16
 
17
+ # backward compatibility
18
+ alias_method :"metadata=", :"global_metadata="
19
+
17
20
  def to_json(*)
18
21
  {
19
22
  message: {
@@ -22,11 +25,13 @@ module UniOne
22
25
  subject: self.subject,
23
26
  reply_to: self.reply_to,
24
27
  recipients: self.recipients,
25
- metadata: self.metadata,
28
+ global_metadata: self.global_metadata,
26
29
  headers: self.headers,
27
30
  attachments: self.attachments,
28
31
  inline_attachments: self.inline_attachments,
29
- options: self.options
32
+ options: self.options,
33
+ skip_unsubscribe: self.skip_unsubscribe,
34
+ force_send: self.force_send
30
35
  }.merge(self.template)
31
36
  .merge(self.from)
32
37
  .merge(self.track)
@@ -1,6 +1,6 @@
1
1
  module UniOne
2
2
  class Template
3
- attr_accessor :name, :subject, :template_engine, :global_substitutions, :from,
3
+ attr_accessor :name, :editor_type, :subject, :template_engine, :global_substitutions, :from,
4
4
  :headers, :body, :attachments, :inline_attachments, :options
5
5
 
6
6
  def initialize
@@ -15,6 +15,7 @@ module UniOne
15
15
  template: {
16
16
  id: '',
17
17
  name: self.name,
18
+ editor_type: self.editor_type,
18
19
  subject: self.subject,
19
20
  template_engine: self.template_engine,
20
21
  global_substitutions: self.global_substitutions,
@@ -1,6 +1,6 @@
1
1
  module UniOne
2
2
  class Webhook
3
- attr_accessor :url, :settings, :events
3
+ attr_accessor :url, :status, :settings, :events
4
4
 
5
5
  def initialize
6
6
  @settings = {}
@@ -9,6 +9,7 @@ module UniOne
9
9
  def to_json(*)
10
10
  {
11
11
  url: self.url,
12
+ status: self.status,
12
13
  events: self.events
13
14
  }.merge(self.settings)
14
15
  .delete_if { |_, value| value.to_s.strip == '' || value == [] || value == {}}
@@ -6,12 +6,7 @@ module UniOne
6
6
  private
7
7
 
8
8
  def validate_response(schema)
9
- begin
10
- JSON::Validator.validate!(schema, @last_response.body)
11
- rescue JSON::Schema::ValidationError => e
12
- puts @last_response.body
13
- raise
14
- end
9
+ JSON::Validator.validate!(schema, @last_response.body)
15
10
  @last_response
16
11
  end
17
12
 
@@ -1,3 +1,3 @@
1
1
  module UniOne
2
- VERSION = '0.0.1'
2
+ VERSION = '0.0.2'
3
3
  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.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - UniOne developer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-07-22 00:00:00.000000000 Z
11
+ date: 2021-03-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json
@@ -102,19 +102,22 @@ extra_rdoc_files: []
102
102
  files:
103
103
  - LICENSE
104
104
  - README.md
105
- - examples/1_setup.rb
106
- - examples/2_mail_sending.rb
105
+ - Rakefile
107
106
  - examples/api/domain.rb
108
107
  - examples/api/email.rb
109
108
  - examples/api/project.rb
109
+ - examples/api/system.rb
110
110
  - examples/api/template.rb
111
111
  - examples/api/unsubscribed.rb
112
112
  - examples/api/webhook.rb
113
+ - examples/sending_mail.rb
114
+ - examples/setup.rb
113
115
  - lib/unione-ruby.rb
114
116
  - lib/unione/client.rb
115
117
  - lib/unione/client/domain.rb
116
118
  - lib/unione/client/email.rb
117
119
  - lib/unione/client/project.rb
120
+ - lib/unione/client/system.rb
118
121
  - lib/unione/client/template.rb
119
122
  - lib/unione/client/unsubscribed.rb
120
123
  - lib/unione/client/webhook.rb
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
@@ -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)