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
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c8462ee8f317ff0d316298a45e0f6f948897776346bcbe7f70997190a681e02a
4
- data.tar.gz: 51f9b320c81f7bd65559b10eda50bdaf20a0bd1148c2d7017590a1d344319118
3
+ metadata.gz: d8807a2fc79452659177a7447867e38ca650482c9bd691a6c701a20d7c115f20
4
+ data.tar.gz: 9ecb1e6785c72f73d465c5469d754bbd93f41de4a64ecd8e6c042690886638fc
5
5
  SHA512:
6
- metadata.gz: 46993c14f31096f8f22eefb96f050c26436088335ef44572d981fd599f25187b333d69b7c19790e0fe04f3efee05b164f226181d5633f0c06c30737a25e62bd4
7
- data.tar.gz: 33b4d179be489d1edb42b0a24f5866a672d640ae90e30dd8db1376a63ecb695624c5034b48f52b30584153c1298cf7fd780be610204ae7e02e43715d3e37e82f
6
+ metadata.gz: 95b0951bef570f71a7481ec8e6f9460e57ff827c3fe3b9083645ed28ab71904bfbdde6f83f853008f0a7ce1707fe62b6dfb47fb941ac36f008eb98c63e72e92c
7
+ data.tar.gz: 3cc19ac8f9641a6849a59f4fab4b7c72e5585f10928831ff0f41da3d24ddc38aa24d764183008e5fc6184d619a52d8bbeb544a9abae16afc97cdb56301ace9a7
data/README.md CHANGED
@@ -1,42 +1,133 @@
1
1
  # unione-ruby
2
+
2
3
  UniOne (unione.io) integration gem for Ruby
3
4
 
4
5
  [Examples of usage](https://github.com/unione-repo/unione-ruby/tree/master/examples)
5
6
 
7
+ ## Installation
8
+
9
+ gem install unione-ruby
10
+
6
11
  ## Working with API responses
12
+
7
13
  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
14
 
9
15
  Example of work with responses:
10
16
 
11
- ```ruby
17
+ ~~~ruby
12
18
  require 'unione-ruby'
13
- unione = UniOne::Client.new(data_center: 'eu1', lang: 'en', api_key: ENV['UNIONE_API_KEY'])
19
+
20
+ unione = UniOne::Client.new(
21
+ hostname: 'eu1.unione.io',
22
+ lang: 'en',
23
+ api_key: ENV['UNIONE_API_KEY']
24
+ )
25
+
14
26
  response = unione.get_dns_records("example.com")
27
+
15
28
  puts response.status
16
29
  puts response.body.to_h
17
30
  puts response.headers
18
- # Access fields as hash or as methods
31
+
32
+ # Access fields as hash keys or as object attributes:
19
33
  puts response.body['status']
20
34
  puts response.body.status
21
- ```
35
+ ~~~
36
+
37
+ ## Passing API key in parameters
38
+
39
+ By default authentication sent through X-API-KEY header.
40
+
41
+ For passing API key in parameters, use:
42
+
43
+ ~~~ruby
44
+ unione = UniOne::Client.new(
45
+ hostname: 'eu1.unione.io',
46
+ lang: 'en',
47
+ api_key: ENV['UNIONE_API_KEY'],
48
+ api_key_in_params: true
49
+ )
50
+ ~~~
51
+
52
+ ## Verify webhook callback message
53
+
54
+ Will raise Unione::Client::InvalidCallbackAuth error unless `auth' field is correct.
55
+
56
+ ~~~ruby
57
+ unione.verify_callback_auth!(params)
58
+ ~~~
59
+
60
+ ## Webhook callback helper
61
+
62
+ Use it to substitute webhook handler verification and parsing to
63
+ directly get list of events.
64
+
65
+ Will raise Unione::Client::InvalidCallbackAuth error unless `auth' field is correct.
66
+
67
+ ~~~ruby
68
+ unione.callback_helper(params) do |events|
69
+ # [
70
+ # {
71
+ # 'event_name' => 'transactional_email_status',
72
+ # 'event_data' =>
73
+ # {
74
+ # 'email' => 'recipient.email@example.com',
75
+ # 'status' => 'sent',
76
+ # 'event_time' => '2015-11-30 15:09:42',
77
+ # ...
78
+ # }
79
+ # },
80
+ # ...
81
+ # ]
82
+ end
83
+ ~~~
22
84
 
23
85
  ## Handling API errors
86
+
24
87
  Library using [`raise-error' middleware](https://lostisland.github.io/faraday/middleware/raise-error) for handling error responses.
25
88
 
26
89
  Example of work with errors:
27
90
 
28
- ```ruby
91
+ ~~~ruby
29
92
  require 'unione-ruby'
93
+
30
94
  begin
31
- unione = UniOne::Client.new(data_center: 'eu1', lang: 'en', api_key: ENV['UNIONE_API_KEY'])
95
+
96
+ unione = UniOne::Client.new(
97
+ hostname: 'eu1.unione.io',
98
+ lang: 'en',
99
+ api_key: ENV['UNIONE_API_KEY']
100
+ )
101
+
32
102
  response = unione.get_dns_records("example.com")
103
+
33
104
  puts response.status
34
105
  puts response.body.to_h
35
106
  puts response.headers
107
+
36
108
  rescue Faraday::Error => e
37
- # Note that exception response has internal format which is a little bit different and body field is not post-processed
109
+
110
+ # Note that exception response has internal format which is a little
111
+ # bit different and body field is not post-processed
112
+
38
113
  puts e.response[:status]
39
114
  puts e.response[:body]
40
115
  puts e.response[:headers]
116
+
41
117
  end
42
- ```
118
+ ~~~
119
+
120
+ ## HTTP timeout configuration
121
+
122
+ Pass `timeout: <seconds>` parameter on creating client, default is 5.
123
+
124
+ ## HTTP logging
125
+
126
+ Pass `enable_logging: true` parameter on creating client to enable logging, default false.
127
+
128
+ ## Testing
129
+
130
+ You can run tests through included test task and passing methods for
131
+ test and data inside YAML config file:
132
+
133
+ rake test DOMAIN APIKEY WEBHOOK_URL FROM_EMAIL ./test/CONFIGFILE.yml
data/Rakefile ADDED
@@ -0,0 +1,52 @@
1
+ $LOAD_PATH.unshift(File.expand_path('../lib', __FILE__))
2
+ require 'unione-ruby'
3
+ require 'yaml'
4
+
5
+ task :console do
6
+ exec "irb -r unione-ruby -I ./lib"
7
+ end
8
+
9
+ task :test do
10
+ unione = UniOne::Client.new(
11
+ hostname: ARGV[1],
12
+ lang: 'en',
13
+ api_key: ARGV[2],
14
+ enable_logging: true,
15
+ )
16
+
17
+ webhook_url = ARGV[3].to_s.empty? ? nil : ARGV[3]
18
+ from_email = ARGV[4].to_s.empty? ? nil : ARGV[4]
19
+ config_file_path = ARGV[5].to_s.empty? ? './test/CONFIGFILE.yml' : ARGV[5]
20
+
21
+ data = YAML.load_file(config_file_path)
22
+
23
+ success = true
24
+
25
+ data.each do |call|
26
+ begin
27
+ puts "## RUN: #{call['method']}"
28
+
29
+ if call['method'] == 'callback_helper'
30
+ unione.send(call['method'], call['params']) do |events|
31
+ pp events
32
+ end
33
+ else
34
+ if call['method'] == 'send_email'
35
+ call['params']['message']['from_email'] = from_email if from_email
36
+ elsif call['method'] == 'set_webhook'
37
+ call['params']['url'] = webhook_url if webhook_url
38
+ end
39
+
40
+ unione.send(call['method'], call['params'])
41
+ end
42
+
43
+ puts "## => SUCCESS"
44
+ puts ""
45
+ rescue => e
46
+ success = false
47
+ puts "## => FAILED: #{e.message}"
48
+ end
49
+ end
50
+
51
+ success ? exit : abort
52
+ end
@@ -0,0 +1,74 @@
1
+ get_dns_records:
2
+ type: object
3
+ required:
4
+ - status
5
+ - domain
6
+ - verification-record
7
+ - dkim
8
+ properties:
9
+ status:
10
+ type: string
11
+ domain:
12
+ type: string
13
+ verification-record:
14
+ type: string
15
+ dkim:
16
+ type: string
17
+ validate_verification_record:
18
+ type: object
19
+ required:
20
+ - status
21
+ - message
22
+ properties:
23
+ status:
24
+ type: string
25
+ message:
26
+ type: string
27
+ validate_dkim:
28
+ type: object
29
+ required:
30
+ - status
31
+ - message
32
+ properties:
33
+ status:
34
+ type: string
35
+ message:
36
+ type: string
37
+ list_domains:
38
+ type: object
39
+ required:
40
+ - status
41
+ - domains
42
+ properties:
43
+ status:
44
+ type: string
45
+ domains:
46
+ items:
47
+ type: object
48
+ required:
49
+ - domain
50
+ - verification-record
51
+ - dkim
52
+ properties:
53
+ - domain:
54
+ type: string
55
+ verification-record:
56
+ type: object
57
+ required:
58
+ - value
59
+ - status
60
+ properties:
61
+ - value:
62
+ type: string
63
+ status:
64
+ type: string
65
+ dkim:
66
+ type: object
67
+ required:
68
+ - key
69
+ - status
70
+ properties:
71
+ - key:
72
+ type: string
73
+ status:
74
+ type: string
@@ -0,0 +1,23 @@
1
+ send_email:
2
+ type: object
3
+ required:
4
+ - status
5
+ - job_id
6
+ - emails
7
+ properties:
8
+ status:
9
+ type: string
10
+ job_id:
11
+ type: string
12
+ emails:
13
+ items:
14
+ type: string
15
+ failed_emails:
16
+ type: object
17
+ subscribe_email:
18
+ type: object
19
+ required:
20
+ - status
21
+ properties:
22
+ status:
23
+ type: string
@@ -0,0 +1,75 @@
1
+ create_event_dump:
2
+ type: object
3
+ required:
4
+ - status
5
+ - dump_id
6
+ properties:
7
+ status:
8
+ type: string
9
+ dump_id:
10
+ type: string
11
+ get_event_dump:
12
+ type: object
13
+ required:
14
+ - status
15
+ - event_dump
16
+ properties:
17
+ status:
18
+ type: string
19
+ event_dump:
20
+ type: object
21
+ required:
22
+ - dump_id
23
+ - dump_status
24
+ properties:
25
+ dump_id:
26
+ type: string
27
+ dump_status:
28
+ type: string
29
+ files:
30
+ items:
31
+ type: object
32
+ required:
33
+ - url
34
+ - size
35
+ properties:
36
+ url:
37
+ type: string
38
+ size:
39
+ type: integer
40
+ list_event_dumps:
41
+ type: object
42
+ required:
43
+ - status
44
+ - event_dumps
45
+ properties:
46
+ status:
47
+ type: string
48
+ event_dumps:
49
+ items:
50
+ type: object
51
+ required:
52
+ - dump_id
53
+ - dump_status
54
+ properties:
55
+ dump_id:
56
+ type: string
57
+ dump_status:
58
+ type: string
59
+ files:
60
+ items:
61
+ required:
62
+ - url
63
+ - size
64
+ properties:
65
+ url:
66
+ type: string
67
+ size:
68
+ type: integer
69
+ delete_event_dump:
70
+ type: object
71
+ required:
72
+ - status
73
+ properties:
74
+ status:
75
+ type: string
@@ -0,0 +1,59 @@
1
+ create_project:
2
+ type: object
3
+ required:
4
+ - status
5
+ - project_id
6
+ - project_api_key
7
+ properties:
8
+ status:
9
+ type: string
10
+ project_id:
11
+ type: string
12
+ project_api_key:
13
+ type: string
14
+ update_project:
15
+ type: object
16
+ required:
17
+ - status
18
+ properties:
19
+ status:
20
+ type: string
21
+ project_api_key:
22
+ type: string
23
+ list_projects:
24
+ type: object
25
+ required:
26
+ - status
27
+ properties:
28
+ status:
29
+ type: string
30
+ projects:
31
+ items:
32
+ type: object
33
+ required:
34
+ - id
35
+ - api_key
36
+ - name
37
+ - reg_time
38
+ - send_enabled
39
+ - custom_unsubscribe_url_enabled
40
+ properties:
41
+ id:
42
+ type: string
43
+ api_key:
44
+ type: string
45
+ name:
46
+ type: string
47
+ reg_time:
48
+ type: string
49
+ send_enabled:
50
+ type: boolean
51
+ custom_unsubscribe_url_enabled:
52
+ type: boolean
53
+ delete_project:
54
+ type: object
55
+ required:
56
+ - status
57
+ properties:
58
+ status:
59
+ type: string
@@ -0,0 +1,71 @@
1
+ set_suppression:
2
+ type: object
3
+ required:
4
+ - status
5
+ properties:
6
+ status:
7
+ type: string
8
+ get_suppression:
9
+ type: object
10
+ required:
11
+ - status
12
+ - email
13
+ - suppressions
14
+ properties:
15
+ status:
16
+ type: string
17
+ email:
18
+ type: string
19
+ suppressions:
20
+ items:
21
+ type: object
22
+ required:
23
+ - cause
24
+ - source
25
+ - is_deletable
26
+ - created
27
+ properties:
28
+ project_id:
29
+ type: string
30
+ cause:
31
+ type: string
32
+ source:
33
+ type: string
34
+ is_deletable:
35
+ type: boolean
36
+ created:
37
+ type: string
38
+ list_suppressions:
39
+ type: object
40
+ required:
41
+ - status
42
+ - suppressions
43
+ - cursor
44
+ properties:
45
+ status:
46
+ type: string
47
+ suppressions:
48
+ items:
49
+ type: object
50
+ required:
51
+ - cause
52
+ - source
53
+ - is_deletable
54
+ - created
55
+ properties:
56
+ project_id:
57
+ type: string
58
+ cause:
59
+ type: string
60
+ source:
61
+ type: string
62
+ is_deletable:
63
+ type: boolean
64
+ created:
65
+ type: string
66
+ cursor:
67
+ type: string
68
+ delete_suppression:
69
+ type: object
70
+ required:
71
+ - status
@@ -0,0 +1,33 @@
1
+ info:
2
+ type: object
3
+ required:
4
+ - status
5
+ - user_id
6
+ - email
7
+ properties:
8
+ status:
9
+ type: string
10
+ user_id:
11
+ type: integer
12
+ email:
13
+ type: string
14
+ accounting:
15
+ type: object
16
+ required:
17
+ - period_start
18
+ - period_end
19
+ - emails_included
20
+ - emails_sent
21
+ properties:
22
+ - period_start:
23
+ type: string
24
+ period_end:
25
+ type: string
26
+ emails_included:
27
+ type: integer
28
+ emails_sent:
29
+ type: integer
30
+ project_id:
31
+ type: string
32
+ project_name:
33
+ type: string
@@ -0,0 +1,26 @@
1
+ list_tags:
2
+ type: object
3
+ required:
4
+ - status
5
+ - tags
6
+ properties:
7
+ status:
8
+ type: string
9
+ tags:
10
+ items:
11
+ type: object
12
+ required:
13
+ - tag_id
14
+ - tag
15
+ properties:
16
+ tag_id:
17
+ type: integer
18
+ tag:
19
+ type: string
20
+ delete_tag:
21
+ type: object
22
+ required:
23
+ - status
24
+ properties:
25
+ status:
26
+ type: string
@@ -0,0 +1,134 @@
1
+ set_template: &template
2
+ type: object
3
+ required:
4
+ - status
5
+ - template
6
+ properties:
7
+ status:
8
+ type: string
9
+ template:
10
+ type: object
11
+ required:
12
+ - id
13
+ - name
14
+ - editor_type
15
+ - subject
16
+ - from_name
17
+ - body
18
+ - headers
19
+ - attachments
20
+ - inline_attachments
21
+ - created
22
+ - user_id
23
+ properties:
24
+ id:
25
+ type: string
26
+ name:
27
+ type: string
28
+ editor_type:
29
+ type: string
30
+ subject:
31
+ type: string
32
+ from_name:
33
+ type: string
34
+ body:
35
+ type: object
36
+ required:
37
+ - html
38
+ - plaintext
39
+ - amp
40
+ properties:
41
+ html:
42
+ type: string, null
43
+ plaintext:
44
+ type: string, null
45
+ amp:
46
+ type: string, null
47
+ headers:
48
+ type: object
49
+ attachments:
50
+ items:
51
+ type: object
52
+ inline_attachments:
53
+ items:
54
+ type: object
55
+ options:
56
+ type: object
57
+ required:
58
+ - unsubscribe_url
59
+ properties:
60
+ unsubscribe_url:
61
+ type: string
62
+ created:
63
+ type: string
64
+ user_id:
65
+ type: integer
66
+ get_template:
67
+ <<: *template
68
+ list_templates:
69
+ type: object
70
+ required:
71
+ - status
72
+ - templates
73
+ properties:
74
+ status:
75
+ type: string
76
+ templates:
77
+ items:
78
+ type: object
79
+ required:
80
+ - id
81
+ - name
82
+ - editor_type
83
+ - subject
84
+ - body
85
+ - attachments
86
+ - inline_attachments
87
+ - created
88
+ - user_id
89
+ properties:
90
+ id:
91
+ type: string
92
+ name:
93
+ type: string
94
+ editor_type:
95
+ type: string
96
+ subject:
97
+ type: string
98
+ body:
99
+ type: object
100
+ required:
101
+ - html
102
+ - plaintext
103
+ - amp
104
+ properties:
105
+ html:
106
+ type: string, null
107
+ plaintext:
108
+ type: string, null
109
+ amp:
110
+ type: string, null
111
+ attachments:
112
+ items:
113
+ type: object
114
+ inline_attachments:
115
+ items:
116
+ type: object
117
+ options:
118
+ type: object
119
+ required:
120
+ - unsubscribe_url
121
+ properties:
122
+ unsubscribe_url:
123
+ type: string
124
+ created:
125
+ type: string
126
+ user_id:
127
+ type: integer
128
+ delete_template:
129
+ type: object
130
+ required:
131
+ - status
132
+ properties:
133
+ status:
134
+ type: string