sendgrid4r 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fb22cf3a6851051dc9aff2ccd01bb58f44f05d6b
4
- data.tar.gz: 78395e30015b6182fdf8bdc61bf773d1a0b2c0f3
3
+ metadata.gz: 9e77f18ddd75a6b86d7d8fe6fb50b3cb64ec8955
4
+ data.tar.gz: d594830d614fe4ba1c7b648d3a3929f904bdbca5
5
5
  SHA512:
6
- metadata.gz: 4e38ab32b44f3bf59f2c5feb724af2ad0b3d1c128e99f8f490a41a4fecd2d2b44e42c2dd690c65654c2e68d706b465ed6e2fc57c028fbb893f8ecffb1ed1f45e
7
- data.tar.gz: d34d0ed4873dc08367e41c88101095b967b10c292807f39132fc994ab415e3a5551c843ba8ba5b4ee6aaeaebfb404865fee394bd3d22c5999da3bf3a06182fe1
6
+ metadata.gz: 1f5845e151068e2cfe8d78dd19914b8ba76dad7d4f747f1a36bf292d7cb1b4f977afc406f334581f41c92a9edffc719d265551512bf622f267ff8a993eeccad8
7
+ data.tar.gz: a998a7a72c8c0400066bc3576b51f4182155db45cea319fc7bda6ebf93f4decfcbaf2c70ebd24ce5e724550f7c568c16fcad64959750de8a60372294ebc969ab
data/.rubocop.yml CHANGED
@@ -19,3 +19,7 @@ AbcSize:
19
19
  # %r 内で利用できるスラッシュの数の制限変更
20
20
  RegexpLiteral:
21
21
  MaxSlashes: 0
22
+
23
+ # 数値の区切りをなくす
24
+ NumericLiterals:
25
+ MinDigits: 20
data/lib/client.rb CHANGED
@@ -4,6 +4,8 @@ $LOAD_PATH.unshift File.dirname(__FILE__)
4
4
  require 'auth'
5
5
  require 'sendgrid4r/rest/api'
6
6
  require 'sendgrid4r/factory/version_factory'
7
+ require 'sendgrid4r/factory/condition_factory'
8
+ require 'sendgrid4r/factory/segment_factory'
7
9
 
8
10
  module SendGrid4r
9
11
  #
@@ -0,0 +1,20 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $LOAD_PATH.unshift File.dirname(__FILE__)
3
+
4
+ module SendGrid4r
5
+ module Factory
6
+ #
7
+ # SendGrid Web API v3 Condition Factory Class implementation
8
+ #
9
+ class ConditionFactory
10
+ def create(field:, value:, operator:, and_or:)
11
+ SendGrid4r::REST::Contacts::Segments::Condition.new(
12
+ field,
13
+ value,
14
+ operator,
15
+ and_or
16
+ ).to_h
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $LOAD_PATH.unshift File.dirname(__FILE__)
3
+
4
+ module SendGrid4r
5
+ module Factory
6
+ #
7
+ # SendGrid Web API v3 Segment Factory Class implementation
8
+ #
9
+ class SegmentFactory
10
+ def create(name:, conditions:)
11
+ SendGrid4r::REST::Contacts::Segments::Segment.new(
12
+ nil,
13
+ name,
14
+ nil,
15
+ conditions,
16
+ nil
17
+ ).to_h
18
+ end
19
+ end
20
+ end
21
+ end
@@ -2,24 +2,26 @@
2
2
  $LOAD_PATH.unshift File.dirname(__FILE__)
3
3
 
4
4
  module SendGrid4r
5
- #
6
- # SendGrid Web API v3 Factory Class implementation
7
- #
8
- class VersionFactory
9
- def create(
10
- name:, subject: '<%subject%>',
11
- html_content: '<%body%>', plain_content: '<%body%>', active: 1)
12
- SendGrid4r::REST::Templates::Version.new(
13
- nil,
14
- nil,
15
- nil,
16
- active,
17
- name,
18
- html_content,
19
- plain_content,
20
- subject,
21
- nil
22
- )
5
+ module Factory
6
+ #
7
+ # SendGrid Web API v3 Factory Class implementation
8
+ #
9
+ class VersionFactory
10
+ def create(
11
+ name:, subject: '<%subject%>',
12
+ html_content: '<%body%>', plain_content: '<%body%>', active: 1)
13
+ SendGrid4r::REST::Templates::Version.new(
14
+ nil,
15
+ nil,
16
+ nil,
17
+ active,
18
+ name,
19
+ html_content,
20
+ plain_content,
21
+ subject,
22
+ nil
23
+ )
24
+ end
23
25
  end
24
26
  end
25
27
  end
@@ -17,6 +17,11 @@ require 'sendgrid4r/rest/stats/category'
17
17
  require 'sendgrid4r/rest/stats/subuser'
18
18
  require 'sendgrid4r/rest/stats/advanced'
19
19
  require 'sendgrid4r/rest/stats/parse'
20
+ require 'sendgrid4r/rest/contacts/custom_fields'
21
+ require 'sendgrid4r/rest/contacts/lists'
22
+ require 'sendgrid4r/rest/contacts/recipients'
23
+ require 'sendgrid4r/rest/contacts/reserved_fields'
24
+ require 'sendgrid4r/rest/contacts/segments'
20
25
 
21
26
  module SendGrid4r
22
27
  module REST
@@ -39,6 +44,11 @@ module SendGrid4r
39
44
  include SendGrid4r::REST::Stats::Subuser
40
45
  include SendGrid4r::REST::Stats::Advanced
41
46
  include SendGrid4r::REST::Stats::Parse
47
+ include SendGrid4r::REST::Contacts::CustomFields
48
+ include SendGrid4r::REST::Contacts::Lists
49
+ include SendGrid4r::REST::Contacts::Recipients
50
+ include SendGrid4r::REST::Contacts::ReservedFields
51
+ include SendGrid4r::REST::Contacts::Segments
42
52
  end
43
53
  end
44
54
  end
@@ -0,0 +1,79 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $LOAD_PATH.unshift File.dirname(__FILE__)
3
+
4
+ require 'sendgrid4r/rest/request'
5
+
6
+ module SendGrid4r
7
+ module REST
8
+ module Contacts
9
+ #
10
+ # SendGrid Web API v3 Contacts - Custom Fields
11
+ #
12
+ module CustomFields
13
+ include SendGrid4r::REST::Request
14
+
15
+ Field = Struct.new(:id, :name, :type, :value) do
16
+ def eql?(other)
17
+ id.eql?(other.id)
18
+ end
19
+
20
+ def hash
21
+ id.hash
22
+ end
23
+ end
24
+
25
+ Fields = Struct.new(:custom_fields)
26
+
27
+ def self.url(custom_field_id = nil)
28
+ url = "#{SendGrid4r::Client::BASE_URL}/contactdb/custom_fields"
29
+ url = "#{url}/#{custom_field_id}" unless custom_field_id.nil?
30
+ url
31
+ end
32
+
33
+ def self.create_field(resp)
34
+ Field.new(resp['id'], resp['name'], resp['type'], resp['value'])
35
+ end
36
+
37
+ def self.create_fields(resp)
38
+ custom_fields = []
39
+ resp['custom_fields'].each do |field|
40
+ custom_fields.push(
41
+ SendGrid4r::REST::Contacts::CustomFields.create_field(field)
42
+ )
43
+ end
44
+ Fields.new(custom_fields)
45
+ end
46
+
47
+ def post_custom_field(name, type)
48
+ params = {}
49
+ params['name'] = name
50
+ params['type'] = type
51
+ resp = post(
52
+ @auth, SendGrid4r::REST::Contacts::CustomFields.url, params
53
+ )
54
+ SendGrid4r::REST::Contacts::CustomFields.create_field(resp)
55
+ end
56
+
57
+ def get_custom_fields
58
+ resp = get(@auth, SendGrid4r::REST::Contacts::CustomFields.url)
59
+ SendGrid4r::REST::Contacts::CustomFields.create_fields(resp)
60
+ end
61
+
62
+ def get_custom_field(custom_field_id)
63
+ resp = get(
64
+ @auth,
65
+ SendGrid4r::REST::Contacts::CustomFields.url(custom_field_id)
66
+ )
67
+ SendGrid4r::REST::Contacts::CustomFields.create_field(resp)
68
+ end
69
+
70
+ def delete_custom_field(custom_field_id)
71
+ delete(
72
+ @auth,
73
+ SendGrid4r::REST::Contacts::CustomFields.url(custom_field_id)
74
+ )
75
+ end
76
+ end
77
+ end
78
+ end
79
+ end
@@ -0,0 +1,124 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $LOAD_PATH.unshift File.dirname(__FILE__)
3
+
4
+ require 'sendgrid4r/rest/request'
5
+
6
+ module SendGrid4r
7
+ module REST
8
+ module Contacts
9
+ #
10
+ # SendGrid Web API v3 Contacts - Lists
11
+ #
12
+ module Lists
13
+ include SendGrid4r::REST::Request
14
+
15
+ List = Struct.new(:id, :name, :recipient_count)
16
+ Lists = Struct.new(:lists)
17
+
18
+ def self.url(list_id = nil)
19
+ url = "#{SendGrid4r::Client::BASE_URL}/contactdb/lists"
20
+ url = "#{url}/#{list_id}" unless list_id.nil?
21
+ url
22
+ end
23
+
24
+ def self.recipients_url(list_id, recipient_id = nil)
25
+ url = "#{SendGrid4r::REST::Contacts::Lists.url(list_id)}/recipients"
26
+ url = "#{url}/#{recipient_id}" unless recipient_id.nil?
27
+ url
28
+ end
29
+
30
+ def self.create_list(resp)
31
+ List.new(resp['id'], resp['name'], resp['recipient_count'])
32
+ end
33
+
34
+ def self.create_lists(resp)
35
+ lists = []
36
+ resp['lists'].each do |list|
37
+ lists.push(SendGrid4r::REST::Contacts::Lists.create_list(list))
38
+ end
39
+ Lists.new(lists)
40
+ end
41
+
42
+ def post_list(name)
43
+ params = {}
44
+ params['name'] = name
45
+ resp = post(@auth, SendGrid4r::REST::Contacts::Lists.url, params)
46
+ SendGrid4r::REST::Contacts::Lists.create_list(resp)
47
+ end
48
+
49
+ def get_lists
50
+ resp = get(@auth, SendGrid4r::REST::Contacts::Lists.url)
51
+ SendGrid4r::REST::Contacts::Lists.create_lists(resp)
52
+ end
53
+
54
+ def get_list(list_id)
55
+ resp = get(@auth, SendGrid4r::REST::Contacts::Lists.url(list_id))
56
+ SendGrid4r::REST::Contacts::Lists.create_list(resp)
57
+ end
58
+
59
+ def patch_list(list_id, name)
60
+ params = {}
61
+ params['name'] = name
62
+ resp = patch(
63
+ @auth,
64
+ SendGrid4r::REST::Contacts::Lists.url(list_id),
65
+ params
66
+ )
67
+ SendGrid4r::REST::Contacts::Lists.create_list(resp)
68
+ end
69
+
70
+ def delete_list(list_id)
71
+ delete(@auth, SendGrid4r::REST::Contacts::Lists.url(list_id))
72
+ end
73
+
74
+ # no bodies returned
75
+ def post_recipients_to_list(list_id, recipients)
76
+ url = SendGrid4r::REST::Contacts::Lists.url(list_id)
77
+ post(
78
+ @auth,
79
+ "#{url}/recipients_batch",
80
+ recipients
81
+ )
82
+ end
83
+
84
+ def get_recipients_from_list(list_id, limit = nil, offset = nil)
85
+ params = {}
86
+ params['limit'] = limit unless limit.nil?
87
+ params['offset'] = offset unless offset.nil?
88
+ resp = get(
89
+ @auth,
90
+ SendGrid4r::REST::Contacts::Lists.recipients_url(list_id),
91
+ params
92
+ )
93
+ SendGrid4r::REST::Contacts::Recipients.create_recipients(resp)
94
+ end
95
+
96
+ def post_recipient_to_list(list_id, recipient_id)
97
+ post(
98
+ @auth,
99
+ SendGrid4r::REST::Contacts::Lists.recipients_url(
100
+ list_id, recipient_id
101
+ )
102
+ )
103
+ end
104
+
105
+ def delete_recipient_from_list(list_id, recipient_id)
106
+ delete(
107
+ @auth,
108
+ SendGrid4r::REST::Contacts::Lists.recipients_url(
109
+ list_id, recipient_id
110
+ )
111
+ )
112
+ end
113
+
114
+ def delete_lists(list_ids)
115
+ delete(
116
+ @auth,
117
+ "#{SendGrid4r::Client::BASE_URL}/contactdb/lists_batch",
118
+ list_ids
119
+ )
120
+ end
121
+ end
122
+ end
123
+ end
124
+ end
@@ -0,0 +1,176 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $LOAD_PATH.unshift File.dirname(__FILE__)
3
+
4
+ require 'sendgrid4r/rest/request'
5
+
6
+ module SendGrid4r
7
+ module REST
8
+ module Contacts
9
+ #
10
+ # SendGrid Web API v3 Contacts - Recipients
11
+ #
12
+ module Recipients
13
+ include SendGrid4r::REST::Request
14
+
15
+ Recipient = Struct.new(
16
+ :created_at,
17
+ :custom_fields,
18
+ :email,
19
+ :first_name,
20
+ :id,
21
+ :last_clicked,
22
+ :last_emailed,
23
+ :last_name,
24
+ :last_opened,
25
+ :updated_at
26
+ )
27
+
28
+ Recipients = Struct.new(:recipients)
29
+
30
+ def self.create_recipient(resp)
31
+ custom_fields = []
32
+ resp['custom_fields'].each do |field|
33
+ custom_fields.push(
34
+ SendGrid4r::REST::Contacts::CustomFields.create_field(field)
35
+ )
36
+ end
37
+ Recipient.new(
38
+ resp['created_at'],
39
+ custom_fields,
40
+ resp['email'],
41
+ resp['first_name'],
42
+ resp['id'],
43
+ resp['last_clicked'],
44
+ resp['last_emailed'],
45
+ resp['last_name'],
46
+ resp['last_opend'],
47
+ resp['updated_at']
48
+ )
49
+ end
50
+
51
+ def self.create_recipients(resp)
52
+ recipients = []
53
+ resp['recipients'].each do |recipient|
54
+ recipients.push(
55
+ SendGrid4r::REST::Contacts::Recipients.create_recipient(recipient)
56
+ )
57
+ end
58
+ Recipients.new(recipients)
59
+ end
60
+
61
+ def self.url(recipient_id = nil)
62
+ url = "#{SendGrid4r::Client::BASE_URL}/contactdb/recipients"
63
+ url = "#{url}/#{recipient_id}" unless recipient_id.nil?
64
+ url
65
+ end
66
+
67
+ def post_recipient(params)
68
+ resp = post(@auth, SendGrid4r::REST::Contacts::Recipients.url, params)
69
+ SendGrid4r::REST::Contacts::Recipients.create_recipient(resp)
70
+ end
71
+
72
+ def delete_recipients(emails)
73
+ delete(@auth, SendGrid4r::REST::Contacts::Recipients.url, emails)
74
+ end
75
+
76
+ def get_recipients(limit = nil, offset = nil)
77
+ params = {}
78
+ params['limit'] = limit unless limit.nil?
79
+ params['offset'] = offset unless offset.nil?
80
+ if params.length > 0
81
+ resp = get(
82
+ @auth, SendGrid4r::REST::Contacts::Recipients.url, params
83
+ )
84
+ else
85
+ resp = get(
86
+ @auth, SendGrid4r::REST::Contacts::Recipients.url
87
+ )
88
+ end
89
+ SendGrid4r::REST::Contacts::Recipients.create_recipients(resp)
90
+ end
91
+
92
+ def get_recipients_by_id(recipient_ids)
93
+ resp = get(
94
+ @auth,
95
+ "#{SendGrid4r::REST::Contacts::Recipients.url}/batch",
96
+ nil,
97
+ recipient_ids
98
+ )
99
+ SendGrid4r::REST::Contacts::Recipients.create_recipients(resp)
100
+ end
101
+
102
+ def get_recipients_count
103
+ resp = get(
104
+ @auth, "#{SendGrid4r::REST::Contacts::Recipients.url}/count")
105
+ resp['recipient_count']
106
+ end
107
+
108
+ def search_recipients(params)
109
+ resp = get(
110
+ @auth,
111
+ "#{SendGrid4r::REST::Contacts::Recipients.url}/search",
112
+ params
113
+ )
114
+ SendGrid4r::REST::Contacts::Recipients.create_recipients(resp)
115
+ end
116
+
117
+ def get_recipient(recipient_id)
118
+ resp = get(
119
+ @auth,
120
+ SendGrid4r::REST::Contacts::Recipients.url(recipient_id)
121
+ )
122
+ SendGrid4r::REST::Contacts::Recipients.create_recipient(resp)
123
+ end
124
+
125
+ def delete_recipient(recipient_id)
126
+ delete(
127
+ @auth, SendGrid4r::REST::Contacts::Recipients.url(recipient_id)
128
+ )
129
+ end
130
+
131
+ def get_lists_recipient_belong(recipient_id)
132
+ resp = get(
133
+ @auth,
134
+ "#{SendGrid4r::REST::Contacts::Recipients.url(recipient_id)}/lists"
135
+ )
136
+ SendGrid4r::REST::Contacts::Lists.create_lists(resp)
137
+ end
138
+
139
+ def post_recipients(recipients)
140
+ resp = post(
141
+ @auth,
142
+ "#{SendGrid4r::Client::BASE_URL}/contactdb/recipients_batch",
143
+ recipients
144
+ )
145
+ SendGrid4r::REST::Contacts::Recipients.create_result(resp)
146
+ end
147
+
148
+ ResultAddMultiple = Struct.new(
149
+ :error_count,
150
+ :error_indices,
151
+ :new_count,
152
+ :persisted_recipients,
153
+ :updated_count
154
+ )
155
+
156
+ def self.create_result(resp)
157
+ error_indices = []
158
+ resp['error_indices'].each do |index|
159
+ error_indices.push(index)
160
+ end
161
+ persisted_recipients = []
162
+ resp['persisted_recipients'].each do |value|
163
+ persisted_recipients.push(value)
164
+ end
165
+ ResultAddMultiple.new(
166
+ resp['error_count'],
167
+ error_indices,
168
+ resp['new_count'],
169
+ persisted_recipients,
170
+ resp['updated_count']
171
+ )
172
+ end
173
+ end
174
+ end
175
+ end
176
+ end
@@ -0,0 +1,50 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $LOAD_PATH.unshift File.dirname(__FILE__)
3
+
4
+ require 'sendgrid4r/rest/request'
5
+
6
+ module SendGrid4r
7
+ module REST
8
+ module Contacts
9
+ #
10
+ # SendGrid Web API v3 Contacts - Reserved Fields
11
+ #
12
+ module ReservedFields
13
+ include SendGrid4r::REST::Request
14
+
15
+ Field = Struct.new(:name, :type) do
16
+ def eql?(other)
17
+ name.eql?(other.name)
18
+ end
19
+
20
+ def hash
21
+ name.hash
22
+ end
23
+ end
24
+
25
+ Fields = Struct.new(:reserved_fields)
26
+
27
+ def self.create_fields(resp)
28
+ reserved_fields = []
29
+ resp['reserved_fields'].each do |field|
30
+ reserved_fields.push(
31
+ SendGrid4r::REST::Contacts::ReservedFields.create_field(field)
32
+ )
33
+ end
34
+ Fields.new(reserved_fields)
35
+ end
36
+
37
+ def self.create_field(resp)
38
+ Field.new(resp['name'], resp['type'])
39
+ end
40
+
41
+ def get_reserved_fields
42
+ resp = get(
43
+ @auth, "#{SendGrid4r::Client::BASE_URL}/contactdb/reserved_fields"
44
+ )
45
+ SendGrid4r::REST::Contacts::ReservedFields.create_fields(resp)
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,102 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $LOAD_PATH.unshift File.dirname(__FILE__)
3
+
4
+ require 'sendgrid4r/rest/request'
5
+
6
+ module SendGrid4r
7
+ module REST
8
+ module Contacts
9
+ #
10
+ # SendGrid Web API v3 Contacts - Segments
11
+ #
12
+ module Segments
13
+ include SendGrid4r::REST::Request
14
+
15
+ Condition = Struct.new(
16
+ :field, :value, :operator, :and_or
17
+ )
18
+ Segment = Struct.new(
19
+ :id, :name, :list_id, :conditions, :recipient_count
20
+ )
21
+ Segments = Struct.new(:segments)
22
+
23
+ def self.url(segment_id = nil)
24
+ url = "#{SendGrid4r::Client::BASE_URL}/contactdb/segments"
25
+ url = "#{url}/#{segment_id}" unless segment_id.nil?
26
+ url
27
+ end
28
+
29
+ def self.create_condition(resp)
30
+ Condition.new(
31
+ resp['field'], resp['value'], resp['operator'], resp['and_or']
32
+ )
33
+ end
34
+
35
+ def self.create_segment(resp)
36
+ conditions = []
37
+ resp['conditions'].each do |condition|
38
+ conditions.push(
39
+ SendGrid4r::REST::Contacts::Segments.create_condition(condition)
40
+ )
41
+ end
42
+ Segment.new(
43
+ resp['id'],
44
+ resp['name'],
45
+ resp['list_id'],
46
+ conditions,
47
+ resp['recipient_count']
48
+ )
49
+ end
50
+
51
+ def self.create_segments(resp)
52
+ segments = []
53
+ resp['segments'].each do |segment|
54
+ segments.push(
55
+ SendGrid4r::REST::Contacts::Segments.create_segment(segment)
56
+ )
57
+ end
58
+ Segments.new(segments)
59
+ end
60
+
61
+ def post_segment(params)
62
+ resp = post(
63
+ @auth, SendGrid4r::REST::Contacts::Segments.url, params.to_h
64
+ )
65
+ SendGrid4r::REST::Contacts::Segments.create_segment(resp)
66
+ end
67
+
68
+ def get_segments
69
+ resp = get(@auth, SendGrid4r::REST::Contacts::Segments.url)
70
+ SendGrid4r::REST::Contacts::Segments.create_segments(resp)
71
+ end
72
+
73
+ def get_segment(segment_id)
74
+ resp = get(
75
+ @auth, SendGrid4r::REST::Contacts::Segments.url(segment_id)
76
+ )
77
+ SendGrid4r::REST::Contacts::Segments.create_segment(resp)
78
+ end
79
+
80
+ def put_segment(segment_id, params)
81
+ resp = put(
82
+ @auth, SendGrid4r::REST::Contacts::Segments.url(segment_id), params
83
+ )
84
+ SendGrid4r::REST::Contacts::Segments.create_segment(resp)
85
+ end
86
+
87
+ def delete_segment(segment_id)
88
+ delete(@auth, SendGrid4r::REST::Contacts::Segments.url(segment_id))
89
+ end
90
+
91
+ def get_recipients_from_segment(segment_id, limit = nil, offset = nil)
92
+ params = {}
93
+ params['limit'] = limit unless limit.nil?
94
+ params['offset'] = offset unless offset.nil?
95
+ url = SendGrid4r::REST::Contacts::Segments.url(segment_id)
96
+ resp = get(@auth, "#{url}/recipients", params)
97
+ SendGrid4r::REST::Contacts::Recipients.create_recipients(resp)
98
+ end
99
+ end
100
+ end
101
+ end
102
+ end