unigo-ruby 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
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
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 47c239c42d5ea1419bc0ede3993dba48d063fcd4f840a065d5a133001f794d4d
4
+ data.tar.gz: c360ffdd2daada06c9346b78a3a7c3642da739536345270a15fe50132e319a38
5
+ SHA512:
6
+ metadata.gz: b5a877cfd9037b2df1b8943f293500f5cf79cc6d60b25c3c1838b834263565b005eb4ccafe0ac1d63aec7c00599fbf6b786821b4eb1867309fc6722fd64b3764
7
+ data.tar.gz: 263ceb2695d515e8410a8d925d474954df64218fc1211f219f69dd142c42eb2d98ef4fe2f50c364b8b1166356d483599785550d2ef67fb848b9d89eec2f48d69
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2020 UniGo
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,133 @@
1
+ # unigo-ruby
2
+
3
+ Unisender Go (https://go.unisender.ru) integration gem for Ruby
4
+
5
+ [Examples of usage](https://gitflic.ru/project/unisender/unigo-ruby/tree/master/examples)
6
+
7
+ ## Installation
8
+
9
+ gem install unigo-ruby
10
+
11
+ ## Working with API responses
12
+
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.
14
+
15
+ Example of work with responses:
16
+
17
+ ~~~ruby
18
+ require 'unigo-ruby'
19
+
20
+ unigo = UniGo::Client.new(
21
+ hostname: 'go1.unisender.ru',
22
+ lang: 'ru',
23
+ api_key: ENV['UNIGO_API_KEY']
24
+ )
25
+
26
+ response = unigo.get_dns_records("example.com")
27
+
28
+ puts response.status
29
+ puts response.body.to_h
30
+ puts response.headers
31
+
32
+ # Access fields as hash keys or as object attributes:
33
+ puts response.body['status']
34
+ puts response.body.status
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
+ unigo = UniGo::Client.new(
45
+ hostname: 'go1.unisender.ru',
46
+ lang: 'ru',
47
+ api_key: ENV['UNIGO_API_KEY'],
48
+ api_key_in_params: true
49
+ )
50
+ ~~~
51
+
52
+ ## Verify webhook callback message
53
+
54
+ Will raise UniGo::Client::InvalidCallbackAuth error unless `auth' field is correct.
55
+
56
+ ~~~ruby
57
+ unigo.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 UniGo::Client::InvalidCallbackAuth error unless `auth' field is correct.
66
+
67
+ ~~~ruby
68
+ unigo.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
+ ~~~
84
+
85
+ ## Handling API errors
86
+
87
+ Library using [`raise-error' middleware](https://lostisland.github.io/faraday/middleware/raise-error) for handling error responses.
88
+
89
+ Example of work with errors:
90
+
91
+ ~~~ruby
92
+ require 'unigo-ruby'
93
+
94
+ begin
95
+
96
+ unigo = UniGo::Client.new(
97
+ hostname: 'go1.unisender.ru',
98
+ lang: 'ru',
99
+ api_key: ENV['UNIGO_API_KEY']
100
+ )
101
+
102
+ response = unigo.get_dns_records("example.com")
103
+
104
+ puts response.status
105
+ puts response.body.to_h
106
+ puts response.headers
107
+
108
+ rescue Faraday::Error => e
109
+
110
+ # Note that exception response has internal format which is a little
111
+ # bit different and body field is not post-processed
112
+
113
+ puts e.response[:status]
114
+ puts e.response[:body]
115
+ puts e.response[:headers]
116
+
117
+ end
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 'unigo-ruby'
3
+ require 'yaml'
4
+
5
+ task :console do
6
+ exec "irb -r unigo-ruby -I ./lib"
7
+ end
8
+
9
+ task :test do
10
+ unigo = UniGo::Client.new(
11
+ hostname: ARGV[1],
12
+ lang: 'ru',
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
+ unigo.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
+ unigo.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