sendgrid4r 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,128 @@
1
+ # encoding: utf-8
2
+ require File.dirname(__FILE__) + '/../spec_helper'
3
+
4
+ describe 'SendGrid4r::REST::Contacts::ReservedFields' do
5
+ before :all do
6
+ Dotenv.load
7
+ @client = SendGrid4r::Client.new(
8
+ ENV['SENDGRID_USERNAME'], ENV['SENDGRID_PASSWORD'])
9
+ @first_name =
10
+ SendGrid4r::REST::Contacts::ReservedFields::Field.new(
11
+ 'first_name', 'text'
12
+ )
13
+ @last_name =
14
+ SendGrid4r::REST::Contacts::ReservedFields::Field.new(
15
+ 'last_name', 'text'
16
+ )
17
+ @email =
18
+ SendGrid4r::REST::Contacts::ReservedFields::Field.new(
19
+ 'email', 'text'
20
+ )
21
+ @created_at =
22
+ SendGrid4r::REST::Contacts::ReservedFields::Field.new(
23
+ 'created_at', 'date'
24
+ )
25
+ @updated_at =
26
+ SendGrid4r::REST::Contacts::ReservedFields::Field.new(
27
+ 'updated_at', 'date'
28
+ )
29
+ @last_emailed =
30
+ SendGrid4r::REST::Contacts::ReservedFields::Field.new(
31
+ 'last_emailed', 'date'
32
+ )
33
+ @last_clicked =
34
+ SendGrid4r::REST::Contacts::ReservedFields::Field.new(
35
+ 'last_clicked', 'date'
36
+ )
37
+ @last_opened =
38
+ SendGrid4r::REST::Contacts::ReservedFields::Field.new(
39
+ 'last_opened', 'date'
40
+ )
41
+ end
42
+
43
+ context 'always' do
44
+ it 'is normal' do
45
+ begin
46
+ # get the reserved fields
47
+ fields = @client.get_reserved_fields
48
+ expect(fields.reserved_fields.length).to eq(8)
49
+ set = Set.new(fields.reserved_fields)
50
+ expect(set.include?(@first_name)).to eq(true)
51
+ expect(set.include?(@last_name)).to eq(true)
52
+ expect(set.include?(@email)).to eq(true)
53
+ expect(set.include?(@created_at)).to eq(true)
54
+ expect(set.include?(@updated_at)).to eq(true)
55
+ expect(set.include?(@last_emailed)).to eq(true)
56
+ expect(set.include?(@last_clicked)).to eq(true)
57
+ expect(set.include?(@last_opened)).to eq(true)
58
+ rescue => e
59
+ puts e.inspect
60
+ raise e
61
+ end
62
+ end
63
+
64
+ it 'creates field instance' do
65
+ json =
66
+ '{'\
67
+ '"name": "first_name",'\
68
+ '"type": "text"'\
69
+ '}'
70
+ hash = JSON.parse(json)
71
+ actual = SendGrid4r::REST::Contacts::CustomFields.create_field(hash)
72
+ expect(actual.name).to eq('first_name')
73
+ expect(actual.type).to eq('text')
74
+ end
75
+
76
+ it 'creates fields instance' do
77
+ json =
78
+ '{'\
79
+ '"reserved_fields": ['\
80
+ '{'\
81
+ '"name": "first_name",'\
82
+ '"type": "text"'\
83
+ '},'\
84
+ '{'\
85
+ '"name": "last_name",'\
86
+ '"type": "text"'\
87
+ '},'\
88
+ '{'\
89
+ '"name": "email",'\
90
+ '"type": "text"'\
91
+ '},'\
92
+ '{'\
93
+ '"name": "created_at",'\
94
+ '"type": "date"'\
95
+ '},'\
96
+ '{'\
97
+ '"name": "updated_at",'\
98
+ '"type": "date"'\
99
+ '},'\
100
+ '{'\
101
+ '"name": "last_emailed",'\
102
+ '"type": "date"'\
103
+ '},'\
104
+ '{'\
105
+ '"name": "last_clicked",'\
106
+ '"type": "date"'\
107
+ '},'\
108
+ '{'\
109
+ '"name": "last_opened",'\
110
+ '"type": "date"'\
111
+ '},'\
112
+ '{'\
113
+ '"name": "my_custom_field",'\
114
+ '"type": "text"'\
115
+ '}'\
116
+ ']'\
117
+ '}'
118
+ hash = JSON.parse(json)
119
+ actual = SendGrid4r::REST::Contacts::ReservedFields.create_fields(hash)
120
+ expect(actual.reserved_fields.is_a?(Array)).to eq(true)
121
+ actual.reserved_fields.each do |field|
122
+ expect(
123
+ field.is_a?(SendGrid4r::REST::Contacts::ReservedFields::Field)
124
+ ).to eq(true)
125
+ end
126
+ end
127
+ end
128
+ end
@@ -0,0 +1,170 @@
1
+ # encoding: utf-8
2
+ require File.dirname(__FILE__) + '/../spec_helper'
3
+
4
+ describe 'SendGrid4r::REST::Contacts::Segments' do
5
+ before :all do
6
+ Dotenv.load
7
+ @client = SendGrid4r::Client.new(
8
+ ENV['SENDGRID_USERNAME'], ENV['SENDGRID_PASSWORD'])
9
+ @name = 'test_segment'
10
+ @edit_name = 'test_segment_edit'
11
+ @field = 'last_name'
12
+ @value = 'Miller'
13
+ @operator = 'eq'
14
+ @and_or = ''
15
+ @condition_factory = SendGrid4r::Factory::ConditionFactory.new
16
+ @segment_factory = SendGrid4r::Factory::SegmentFactory.new
17
+ end
18
+
19
+ context 'always' do
20
+ it 'is normal' do
21
+ begin
22
+ # celan up test env
23
+ segments = @client.get_segments
24
+ expect(segments.segments.length >= 0).to eq(true)
25
+ segments.segments.each do |segment|
26
+ next if segment.name != @name && segment.name != @edit_name
27
+ @client.delete_segment(segment.id)
28
+ end
29
+ # post a segment
30
+ condition = @condition_factory.create(
31
+ field: @field,
32
+ value: @value,
33
+ operator: @operator,
34
+ and_or: @and_or
35
+ )
36
+ params = @segment_factory.create(
37
+ name: @name, conditions: [condition]
38
+ )
39
+ new_segment = @client.post_segment(params)
40
+ expect(new_segment.id.is_a?(Fixnum)).to eq(true)
41
+ expect(new_segment.name).to eq(@name)
42
+ expect(new_segment.list_id).to eq(nil)
43
+ expect(new_segment.conditions.length).to eq(1)
44
+ expect(new_segment.recipient_count).to eq(0)
45
+ new_condition = new_segment.conditions[0]
46
+ expect(new_condition.field).to eq(@field)
47
+ expect(new_condition.value).to eq(@value)
48
+ expect(new_condition.operator).to eq(@operator)
49
+ expect(new_condition.and_or).to eq(nil)
50
+ expect(new_segment.recipient_count).to eq(0)
51
+ # get a single segment
52
+ actual_segment = @client.get_segment(new_segment.id)
53
+ expect(actual_segment.id).to eq(new_segment.id)
54
+ expect(actual_segment.name).to eq(new_segment.name)
55
+ expect(actual_segment.list_id).to eq(nil)
56
+ actual_condition = actual_segment.conditions[0]
57
+ expect(actual_condition.field).to eq(@field)
58
+ expect(actual_condition.value).to eq(@value)
59
+ expect(actual_condition.operator).to eq(@operator)
60
+ expect(actual_condition.and_or).to eq(nil)
61
+ expect(actual_segment.recipient_count).to eq(1)
62
+ # update the segment
63
+ edit_condition = @condition_factory.create(
64
+ field: @field,
65
+ value: @value,
66
+ operator: @operator,
67
+ and_or: @and_or
68
+ )
69
+ edit_params = @segment_factory.create(
70
+ name: @edit_name, conditions: [edit_condition]
71
+ )
72
+ edit_segment = @client.put_segment(new_segment.id, edit_params)
73
+ expect(edit_segment.name).to eq(@edit_name)
74
+ # list recipients from a single segment
75
+ recipients = @client.get_recipients_from_segment(new_segment.id)
76
+ recipients.recipients.each do |recipient|
77
+ expect(
78
+ recipient.is_a?(SendGrid4r::REST::Contacts::Recipients::Recipient)
79
+ ).to eq(true)
80
+ end
81
+ # delete the segment
82
+ @client.delete_segment(new_segment.id)
83
+ expect do
84
+ @client.get_segment(new_segment.id)
85
+ end.to raise_error(RestClient::ResourceNotFound)
86
+ rescue => e
87
+ puts e.inspect
88
+ raise e
89
+ end
90
+ end
91
+
92
+ it 'creates condition instance' do
93
+ json =
94
+ '{'\
95
+ '"field": "last_name",'\
96
+ '"value": "Miller",'\
97
+ '"operator": "eq",'\
98
+ '"and_or": ""'\
99
+ '}'
100
+ hash = JSON.parse(json)
101
+ actual = SendGrid4r::REST::Contacts::Segments.create_condition(hash)
102
+ expect(actual.field).to eq('last_name')
103
+ expect(actual.value).to eq('Miller')
104
+ expect(actual.operator).to eq('eq')
105
+ expect(actual.and_or).to eq('')
106
+ end
107
+
108
+ it 'creates segment instance' do
109
+ json =
110
+ '{'\
111
+ '"id": 1,'\
112
+ '"name": "Last Name Miller",'\
113
+ '"list_id": null,'\
114
+ '"conditions": ['\
115
+ '{'\
116
+ '"field": "last_name",'\
117
+ '"value": "Miller",'\
118
+ '"operator": "eq",'\
119
+ '"and_or": ""'\
120
+ '}'\
121
+ '],'\
122
+ '"recipient_count": 1'\
123
+ '}'
124
+ hash = JSON.parse(json)
125
+ actual = SendGrid4r::REST::Contacts::Segments.create_segment(hash)
126
+ expect(actual.id).to eq(1)
127
+ expect(actual.name).to eq('Last Name Miller')
128
+ expect(actual.list_id).to eq(nil)
129
+ expect(actual.conditions.is_a?(Array)).to eq(true)
130
+ actual.conditions.each do |condition|
131
+ expect(
132
+ condition.is_a?(
133
+ SendGrid4r::REST::Contacts::Segments::Condition
134
+ )
135
+ ).to eq(true)
136
+ end
137
+ expect(actual.recipient_count).to eq(1)
138
+ end
139
+
140
+ it 'creates segments instance' do
141
+ json =
142
+ '{'\
143
+ '"segments": ['\
144
+ '{'\
145
+ '"id": 1,'\
146
+ '"name": "Last Name Miller",'\
147
+ '"list_id": null,'\
148
+ '"conditions": ['\
149
+ '{'\
150
+ '"field": "last_name",'\
151
+ '"value": "Miller",'\
152
+ '"operator": "eq",'\
153
+ '"and_or": ""'\
154
+ '}'\
155
+ '],'\
156
+ '"recipient_count": 1'\
157
+ '}'\
158
+ ']'\
159
+ '}'
160
+ hash = JSON.parse(json)
161
+ actual = SendGrid4r::REST::Contacts::Segments.create_segments(hash)
162
+ expect(actual.segments.is_a?(Array)).to eq(true)
163
+ actual.segments.each do |segment|
164
+ expect(
165
+ segment.is_a?(SendGrid4r::REST::Contacts::Segments::Segment)
166
+ ).to eq(true)
167
+ end
168
+ end
169
+ end
170
+ end
@@ -0,0 +1,25 @@
1
+ # encoding: utf-8
2
+ require File.dirname(__FILE__) + '/../spec_helper'
3
+
4
+ describe 'SendGrid4r::Factory::ConditionFactory' do
5
+ before :all do
6
+ Dotenv.load
7
+ @factory = SendGrid4r::Factory::ConditionFactory.new
8
+ @expect = {}
9
+ @expect[:field] = 'last_name'
10
+ @expect[:value] = 'Miller'
11
+ @expect[:operator] = 'eq'
12
+ @expect[:and_or] = ''
13
+ end
14
+
15
+ context 'always' do
16
+ it 'is full case' do
17
+ condition = @factory.create(
18
+ field: 'last_name',
19
+ value: 'Miller',
20
+ operator: 'eq',
21
+ and_or: '')
22
+ expect(condition).to eq(@expect)
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,30 @@
1
+ # encoding: utf-8
2
+ require File.dirname(__FILE__) + '/../spec_helper'
3
+
4
+ describe 'SendGrid4r::Factory::SegmentFactory' do
5
+ before :all do
6
+ Dotenv.load
7
+ @segment_factory = SendGrid4r::Factory::SegmentFactory.new
8
+ @condition_factory = SendGrid4r::Factory::ConditionFactory.new
9
+ @condition = @condition_factory.create(
10
+ field: 'last_name',
11
+ value: 'Miller',
12
+ operator: 'eq',
13
+ and_or: '')
14
+ @expect = {}
15
+ @expect[:id] = nil
16
+ @expect[:name] = 'Last Name Miller'
17
+ @expect[:list_id] = nil
18
+ @expect[:conditions] = [@condition]
19
+ @expect[:recipient_count] = nil
20
+ end
21
+
22
+ context 'always' do
23
+ it 'is full params case' do
24
+ segment = @segment_factory.create(
25
+ name: 'Last Name Miller', conditions: [@condition]
26
+ )
27
+ expect(segment).to eq(@expect)
28
+ end
29
+ end
30
+ end
@@ -1,10 +1,10 @@
1
1
  # encoding: utf-8
2
- require File.dirname(__FILE__) + '/spec_helper'
2
+ require File.dirname(__FILE__) + '/../spec_helper'
3
3
 
4
- describe 'SendGrid4r::VersionFactory' do
4
+ describe 'SendGrid4r::Factory::VersionFactory' do
5
5
  before :all do
6
6
  Dotenv.load
7
- @factory = SendGrid4r::VersionFactory.new
7
+ @factory = SendGrid4r::Factory::VersionFactory.new
8
8
  end
9
9
 
10
10
  context 'always' do
@@ -68,7 +68,7 @@ describe 'SendGrid4r::REST::Stats::Cateogry' do
68
68
  actual = @client.get_categories_stats_sums(start_date: '2015-01-01')
69
69
  expect(actual.class).to be(SendGrid4r::REST::Stats::TopStat)
70
70
  stats = actual.stats
71
- expect(stats.length).to eq(3)
71
+ expect(stats.length > 0).to eq(true)
72
72
  stats.each do |stat|
73
73
  expect(stat.class).to be(SendGrid4r::REST::Stats::Stat)
74
74
  expect(stat.metrics.class).to be(SendGrid4r::REST::Stats::Metric)
@@ -76,7 +76,7 @@ describe 'SendGrid4r::REST::Stats::Subuser' do
76
76
  actual = @client.get_subusers_stats_sums(start_date: '2015-01-01')
77
77
  expect(actual.class).to be(SendGrid4r::REST::Stats::TopStat)
78
78
  stats = actual.stats
79
- expect(stats.length).to eq(2)
79
+ expect(stats.length > 1).to eq(true)
80
80
  stats.each do |stat|
81
81
  expect(stat.class).to be(SendGrid4r::REST::Stats::Stat)
82
82
  expect(stat.metrics.class).to be(SendGrid4r::REST::Stats::Metric)
@@ -28,7 +28,7 @@ describe 'SendGrid4r::REST::Templates::Versions' do
28
28
  new_template = @client.post_template(@template_edit)
29
29
  expect(@template_edit).to eq(new_template.name)
30
30
  # post a version
31
- factory = SendGrid4r::VersionFactory.new
31
+ factory = SendGrid4r::Factory::VersionFactory.new
32
32
  ver1 = factory.create(name: @version1_name)
33
33
  ver1 = @client.post_version(new_template.id, ver1)
34
34
  # get the version
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sendgrid4r
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - awwa500@gmail.com
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-02-25 00:00:00.000000000 Z
11
+ date: 2015-04-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client
@@ -116,12 +116,19 @@ files:
116
116
  - lib/auth.rb
117
117
  - lib/client.rb
118
118
  - lib/sendgrid4r.rb
119
+ - lib/sendgrid4r/factory/condition_factory.rb
120
+ - lib/sendgrid4r/factory/segment_factory.rb
119
121
  - lib/sendgrid4r/factory/version_factory.rb
120
122
  - lib/sendgrid4r/rest/api.rb
121
123
  - lib/sendgrid4r/rest/asm/global_suppressions.rb
122
124
  - lib/sendgrid4r/rest/asm/groups.rb
123
125
  - lib/sendgrid4r/rest/asm/suppressions.rb
124
126
  - lib/sendgrid4r/rest/categories/categories.rb
127
+ - lib/sendgrid4r/rest/contacts/custom_fields.rb
128
+ - lib/sendgrid4r/rest/contacts/lists.rb
129
+ - lib/sendgrid4r/rest/contacts/recipients.rb
130
+ - lib/sendgrid4r/rest/contacts/reserved_fields.rb
131
+ - lib/sendgrid4r/rest/contacts/segments.rb
125
132
  - lib/sendgrid4r/rest/ips/addresses.rb
126
133
  - lib/sendgrid4r/rest/ips/pools.rb
127
134
  - lib/sendgrid4r/rest/ips/warmup.rb
@@ -142,6 +149,14 @@ files:
142
149
  - spec/asm/suppressions_spec.rb
143
150
  - spec/categories/categories_spec.rb
144
151
  - spec/client_spec.rb
152
+ - spec/contacts/custom_fields_spec.rb
153
+ - spec/contacts/lists_spec.rb
154
+ - spec/contacts/recipients_spec.rb
155
+ - spec/contacts/reserved_fields_spec.rb
156
+ - spec/contacts/segments_spec.rb
157
+ - spec/factory/condition_factory_spec.rb
158
+ - spec/factory/segment_factory_spec.rb
159
+ - spec/factory/version_factory_spec.rb
145
160
  - spec/ips/addresses_spec.rb
146
161
  - spec/ips/pools_spec.rb
147
162
  - spec/ips/warmup_spec.rb
@@ -154,7 +169,6 @@ files:
154
169
  - spec/stats/subuser_spec.rb
155
170
  - spec/templates/templates_spec.rb
156
171
  - spec/templates/versions_spec.rb
157
- - spec/version_factory_spec.rb
158
172
  homepage: ''
159
173
  licenses:
160
174
  - MIT
@@ -185,6 +199,14 @@ test_files:
185
199
  - spec/asm/suppressions_spec.rb
186
200
  - spec/categories/categories_spec.rb
187
201
  - spec/client_spec.rb
202
+ - spec/contacts/custom_fields_spec.rb
203
+ - spec/contacts/lists_spec.rb
204
+ - spec/contacts/recipients_spec.rb
205
+ - spec/contacts/reserved_fields_spec.rb
206
+ - spec/contacts/segments_spec.rb
207
+ - spec/factory/condition_factory_spec.rb
208
+ - spec/factory/segment_factory_spec.rb
209
+ - spec/factory/version_factory_spec.rb
188
210
  - spec/ips/addresses_spec.rb
189
211
  - spec/ips/pools_spec.rb
190
212
  - spec/ips/warmup_spec.rb
@@ -197,5 +219,4 @@ test_files:
197
219
  - spec/stats/subuser_spec.rb
198
220
  - spec/templates/templates_spec.rb
199
221
  - spec/templates/versions_spec.rb
200
- - spec/version_factory_spec.rb
201
222
  has_rdoc: