sendgrid4r 0.2.0 → 0.3.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 (61) hide show
  1. checksums.yaml +4 -4
  2. data/.env.example +5 -0
  3. data/.rubocop.yml +8 -8
  4. data/README.md +2 -0
  5. data/lib/auth.rb +5 -2
  6. data/lib/client.rb +4 -2
  7. data/lib/sendgrid4r/factory/version_factory.rb +1 -1
  8. data/lib/sendgrid4r/rest/api.rb +4 -0
  9. data/lib/sendgrid4r/rest/api_keys/api_keys.rb +73 -0
  10. data/lib/sendgrid4r/rest/asm/asm.rb +28 -0
  11. data/lib/sendgrid4r/rest/asm/global_suppressions.rb +12 -8
  12. data/lib/sendgrid4r/rest/asm/groups.rb +29 -22
  13. data/lib/sendgrid4r/rest/asm/suppressions.rb +25 -15
  14. data/lib/sendgrid4r/rest/categories/categories.rb +19 -9
  15. data/lib/sendgrid4r/rest/contacts/custom_fields.rb +14 -8
  16. data/lib/sendgrid4r/rest/contacts/lists.rb +32 -20
  17. data/lib/sendgrid4r/rest/contacts/recipients.rb +42 -31
  18. data/lib/sendgrid4r/rest/contacts/reserved_fields.rb +6 -2
  19. data/lib/sendgrid4r/rest/contacts/segments.rb +22 -12
  20. data/lib/sendgrid4r/rest/ips/addresses.rb +36 -22
  21. data/lib/sendgrid4r/rest/ips/pools.rb +31 -16
  22. data/lib/sendgrid4r/rest/ips/warmup.rb +34 -15
  23. data/lib/sendgrid4r/rest/request.rb +33 -19
  24. data/lib/sendgrid4r/rest/settings/enforced_tls.rb +12 -5
  25. data/lib/sendgrid4r/rest/stats/advanced.rb +73 -25
  26. data/lib/sendgrid4r/rest/stats/category.rb +11 -6
  27. data/lib/sendgrid4r/rest/stats/global.rb +6 -4
  28. data/lib/sendgrid4r/rest/stats/parse.rb +10 -4
  29. data/lib/sendgrid4r/rest/stats/stats.rb +13 -18
  30. data/lib/sendgrid4r/rest/stats/subuser.rb +10 -6
  31. data/lib/sendgrid4r/rest/templates/templates.rb +23 -16
  32. data/lib/sendgrid4r/rest/templates/versions.rb +39 -36
  33. data/lib/sendgrid4r/version.rb +1 -1
  34. data/spec/api_keys/api_keys_spec.rb +152 -0
  35. data/spec/asm/asm_spec.rb +33 -0
  36. data/spec/asm/global_suppressions_spec.rb +111 -45
  37. data/spec/asm/groups_spec.rb +172 -48
  38. data/spec/asm/suppressions_spec.rb +180 -54
  39. data/spec/categories/categories_spec.rb +81 -25
  40. data/spec/client_spec.rb +11 -4
  41. data/spec/contacts/custom_fields_spec.rb +135 -44
  42. data/spec/contacts/lists_spec.rb +314 -84
  43. data/spec/contacts/recipients_spec.rb +337 -92
  44. data/spec/contacts/reserved_fields_spec.rb +80 -60
  45. data/spec/contacts/segments_spec.rb +219 -88
  46. data/spec/factory/condition_factory_spec.rb +12 -12
  47. data/spec/factory/segment_factory_spec.rb +19 -19
  48. data/spec/factory/version_factory_spec.rb +6 -6
  49. data/spec/ips/addresses_spec.rb +177 -84
  50. data/spec/ips/pools_spec.rb +190 -34
  51. data/spec/ips/warmup_spec.rb +106 -38
  52. data/spec/settings/enforced_tls_spec.rb +76 -18
  53. data/spec/stats/advanced_spec.rb +373 -196
  54. data/spec/stats/category_spec.rb +133 -71
  55. data/spec/stats/global_spec.rb +74 -47
  56. data/spec/stats/parse_spec.rb +46 -29
  57. data/spec/stats/stats_spec.rb +246 -0
  58. data/spec/stats/subuser_spec.rb +99 -54
  59. data/spec/templates/templates_spec.rb +219 -54
  60. data/spec/templates/versions_spec.rb +171 -67
  61. metadata +10 -2
@@ -1,38 +1,94 @@
1
1
  # encoding: utf-8
2
2
  require File.dirname(__FILE__) + '/../spec_helper'
3
3
 
4
- describe 'SendGrid4r::REST::Categories' do
5
- before :all do
6
- Dotenv.load
7
- @client = SendGrid4r::Client.new(
8
- ENV['SENDGRID_USERNAME'], ENV['SENDGRID_PASSWORD'])
9
- end
4
+ describe SendGrid4r::REST::Categories do
5
+ describe 'integration test' do
6
+ before do
7
+ Dotenv.load
8
+ @client = SendGrid4r::Client.new(
9
+ username: ENV['SENDGRID_USERNAME'],
10
+ password: ENV['SENDGRID_PASSWORD'])
11
+ end
12
+
13
+ context 'without block call' do
14
+ it '#get_categories if no params' do
15
+ begin
16
+ categories = @client.get_categories
17
+ expect(categories.length).to be >= 0
18
+ categories.each do |category|
19
+ expect(category.category).to be_a(String)
20
+ end
21
+ rescue => e
22
+ puts e.inspect
23
+ raise e
24
+ end
25
+ end
10
26
 
11
- context 'always' do
12
- it 'is normal when nothing specified' do
13
- categories = @client.get_categories
14
- expect(true).to eq(categories.is_a?(Array))
15
- expect(categories.length >= 0).to eq(true)
16
- categories.each do |category|
17
- expect(category.category.length > 0).to eq(true)
27
+ it '#get_categories if name was specified' do
28
+ begin
29
+ categories = @client.get_categories('Newsletter')
30
+ expect(categories.length).to eq(1)
31
+ categories.each do |category|
32
+ expect(category.category).to eq('Newsletter')
33
+ end
34
+ rescue => e
35
+ puts e.inspect
36
+ raise e
37
+ end
38
+ end
39
+
40
+ it '#get_categories if offset & limit were specified' do
41
+ begin
42
+ categories = @client.get_categories(nil, 5, 2)
43
+ expect(categories.length).to be > 0
44
+ categories.each do |category|
45
+ expect(category.category).to be_a(String)
46
+ end
47
+ rescue => e
48
+ puts e.inspect
49
+ raise e
50
+ end
18
51
  end
19
52
  end
20
53
 
21
- it 'is normal when specify category' do
22
- categories = @client.get_categories('Newsletter', nil, nil)
23
- expect(true).to eq(categories.is_a?(Array))
24
- expect(categories.length).to eq(1)
25
- categories.each do |category|
26
- expect(category.category).to eq('Newsletter')
54
+ context 'with block call' do
55
+ it '#get_categories' do
56
+ @client.get_categories do |resp, req, res|
57
+ resp =
58
+ SendGrid4r::REST::Categories::Categories.create_categories(
59
+ JSON.parse(resp)
60
+ )
61
+ expect(resp).to be_a(Array)
62
+ resp.each do |category|
63
+ expect(category).to be_a(
64
+ SendGrid4r::REST::Categories::Categories::Category
65
+ )
66
+ end
67
+ expect(req).to be_a(RestClient::Request)
68
+ expect(res).to be_a(Net::HTTPOK)
69
+ end
27
70
  end
28
71
  end
72
+ end
29
73
 
30
- it 'returns is normal' do
31
- categories = @client.get_categories(nil, 5, 2)
32
- expect(true).to eq(categories.is_a?(Array))
33
- expect(categories.length).to eq(5)
34
- categories.each do |category|
35
- expect(category.category.length > 0).to eq(true)
74
+ describe 'unit test' do
75
+ it 'creates categories instance' do
76
+ json =
77
+ '['\
78
+ '{"category": "cat1"},'\
79
+ '{"category": "cat2"},'\
80
+ '{"category": "cat3"},'\
81
+ '{"category": "cat4"},'\
82
+ '{"category": "cat5"}'\
83
+ ']'
84
+ hash = JSON.parse(json)
85
+ actual = SendGrid4r::REST::Categories::Categories.create_categories(hash)
86
+ expect(actual).to be_a(Array)
87
+ actual.each do |category|
88
+ expect(category).to be_a(
89
+ SendGrid4r::REST::Categories::Categories::Category
90
+ )
91
+ expect(category.category).to be_a(String)
36
92
  end
37
93
  end
38
94
  end
data/spec/client_spec.rb CHANGED
@@ -1,14 +1,16 @@
1
1
  # encoding: utf-8
2
2
  require File.dirname(__FILE__) + '/spec_helper'
3
3
 
4
- describe 'SendGrid4r::Client' do
4
+ describe SendGrid4r::Client do
5
5
  before :all do
6
6
  Dotenv.load
7
7
  end
8
8
 
9
9
  context 'always' do
10
10
  before :all do
11
- @client = SendGrid4r::Client.new('username', 'password')
11
+ @client = SendGrid4r::Client.new(
12
+ username: 'username',
13
+ password: 'password')
12
14
  end
13
15
 
14
16
  describe '#initialize' do
@@ -19,6 +21,11 @@ describe 'SendGrid4r::Client' do
19
21
 
20
22
  describe 'methods' do
21
23
  it 'available' do
24
+ # Api Keys
25
+ expect(@client.respond_to?('get_api_keys')).to eq(true)
26
+ expect(@client.respond_to?('post_api_key')).to eq(true)
27
+ expect(@client.respond_to?('delete_api_key')).to eq(true)
28
+ expect(@client.respond_to?('patch_api_key')).to eq(true)
22
29
  # Advanced Suppression Manager
23
30
  # groups
24
31
  expect(@client.respond_to?('get_groups')).to eq(true)
@@ -84,7 +91,7 @@ describe 'SendGrid4r::Client' do
84
91
  expect(@client.respond_to?('get_devices_stats')).to eq(true)
85
92
  expect(@client.respond_to?('get_clients_stats')).to eq(true)
86
93
  expect(@client.respond_to?('get_clients_type_stats')).to eq(true)
87
- expect(@client.respond_to?('get_esp_stats')).to eq(true)
94
+ expect(@client.respond_to?('get_mailbox_providers_stats')).to eq(true)
88
95
  expect(@client.respond_to?('get_browsers_stats')).to eq(true)
89
96
  expect(@client.respond_to?('get_parse_stats')).to eq(true)
90
97
  # Contacts
@@ -129,7 +136,7 @@ describe 'SendGrid4r::Client' do
129
136
 
130
137
  describe 'VERSION' do
131
138
  it 'returns VERSION value' do
132
- expect(SendGrid4r::VERSION).to eq('0.2.0')
139
+ expect(SendGrid4r::VERSION).to eq('0.3.0')
133
140
  end
134
141
  end
135
142
  end
@@ -1,59 +1,150 @@
1
1
  # encoding: utf-8
2
2
  require File.dirname(__FILE__) + '/../spec_helper'
3
3
 
4
- describe 'SendGrid4r::REST::Contacts::CustomFields' do
5
- before :all do
6
- Dotenv.load
7
- @client = SendGrid4r::Client.new(
8
- ENV['SENDGRID_USERNAME'], ENV['SENDGRID_PASSWORD'])
9
- @name = 'birthday'
10
- @type = 'text'
11
- end
12
-
13
- context 'always' do
14
- it 'is normal' do
4
+ describe SendGrid4r::REST::Contacts::CustomFields do
5
+ describe 'integration test' do
6
+ before do
15
7
  begin
8
+ Dotenv.load
9
+ @client = SendGrid4r::Client.new(
10
+ username: ENV['SENDGRID_USERNAME'],
11
+ password: ENV['SENDGRID_PASSWORD'])
12
+ @name1 = 'birthday'
13
+ @type1 = 'text'
14
+ @name2 = 'born_at'
15
+ @type2 = 'date'
16
+
16
17
  # celan up test env
17
18
  fields = @client.get_custom_fields
18
- expect(fields.custom_fields.length >= 0).to eq(true)
19
19
  fields.custom_fields.each do |field|
20
- next if field.name != @name
20
+ next if field.name != @name1 && field.name != @name2
21
21
  @client.delete_custom_field(field.id)
22
22
  end
23
23
  # post a custom field
24
- new_field = @client.post_custom_field(@name, @type)
25
- expect(new_field.id.is_a?(Fixnum)).to eq(true)
26
- expect(new_field.name).to eq(@name)
27
- expect(new_field.type).to eq(@type)
28
- # post same custom fieled
29
- expect do
30
- @client.post_custom_field(@name, @type)
31
- end.to raise_error(RestClient::BadRequest)
32
- # get the custom fields
33
- fields = @client.get_custom_fields
34
- expect(fields.length >= 1).to eq(true)
35
- fields.custom_fields.each do |field|
36
- next if field.name != @name
37
- expect(field.id).to eq(new_field.id)
38
- expect(field.name).to eq(new_field.name)
39
- expect(field.type).to eq(new_field.type)
40
- end
41
- # get a single custom field
42
- actual_field = @client.get_custom_field(new_field.id)
43
- expect(actual_field.id).to eq(new_field.id)
44
- expect(actual_field.name).to eq(new_field.name)
45
- expect(actual_field.type).to eq(new_field.type)
46
- # delete the custom field
47
- @client.delete_custom_field(new_field.id)
48
- expect do
49
- @client.get_custom_field(new_field.id)
50
- end.to raise_error(RestClient::ResourceNotFound)
24
+ @new_field = @client.post_custom_field(@name1, @type1)
51
25
  rescue => e
52
26
  puts e.inspect
53
27
  raise e
54
28
  end
55
29
  end
56
30
 
31
+ context 'without block call' do
32
+ it '#post_custom_field' do
33
+ begin
34
+ new_field = @client.post_custom_field(@name2, @type2)
35
+ expect(new_field.id).to be_a(Fixnum)
36
+ expect(new_field.name).to eq(@name2)
37
+ expect(new_field.type).to eq(@type2)
38
+ rescue => e
39
+ puts e.inspect
40
+ raise e
41
+ end
42
+ end
43
+
44
+ it '#post_custom_field for same key' do
45
+ begin
46
+ expect do
47
+ @client.post_custom_field(@name1, @type1)
48
+ end.to raise_error(RestClient::BadRequest)
49
+ rescue => e
50
+ puts e.inspect
51
+ raise e
52
+ end
53
+ end
54
+
55
+ it '#get_custom_fields' do
56
+ begin
57
+ fields = @client.get_custom_fields
58
+ expect(fields.length).to be >= 1
59
+ fields.custom_fields.each do |field|
60
+ next if field.name != @name1
61
+ expect(field.id).to eq(@new_field.id)
62
+ expect(field.name).to eq(@new_field.name)
63
+ expect(field.type).to eq(@new_field.type)
64
+ end
65
+ rescue => e
66
+ puts e.inspect
67
+ raise e
68
+ end
69
+ end
70
+
71
+ it '#get_custom_field' do
72
+ begin
73
+ actual_field = @client.get_custom_field(@new_field.id)
74
+ expect(actual_field.id).to eq(@new_field.id)
75
+ expect(actual_field.name).to eq(@new_field.name)
76
+ expect(actual_field.type).to eq(@new_field.type)
77
+ rescue => e
78
+ puts e.inspect
79
+ raise e
80
+ end
81
+ end
82
+
83
+ it '#delete_custom_field' do
84
+ begin
85
+ @client.delete_custom_field(@new_field.id)
86
+ rescue => e
87
+ puts e.inspect
88
+ raise e
89
+ end
90
+ end
91
+ end
92
+
93
+ context 'with block call' do
94
+ it '#post_custom_field' do
95
+ @client.post_custom_field(@name2, @type2) do |resp, req, res|
96
+ resp =
97
+ SendGrid4r::REST::Contacts::CustomFields.create_field(
98
+ JSON.parse(resp)
99
+ )
100
+ expect(resp).to be_a(SendGrid4r::REST::Contacts::CustomFields::Field)
101
+ expect(req).to be_a(RestClient::Request)
102
+ expect(res).to be_a(Net::HTTPCreated)
103
+ end
104
+ end
105
+
106
+ it '#post_custom_field for same key' do
107
+ @client.post_custom_field(@name1, @type1) do |_resp, req, res|
108
+ # TODO: _resp
109
+ expect(req).to be_a(RestClient::Request)
110
+ expect(res).to be_a(Net::HTTPBadRequest)
111
+ end
112
+ end
113
+
114
+ it '#get_custom_fields' do
115
+ @client.get_custom_fields do |resp, req, res|
116
+ resp =
117
+ SendGrid4r::REST::Contacts::CustomFields.create_fields(
118
+ JSON.parse(resp)
119
+ )
120
+ expect(resp).to be_a(SendGrid4r::REST::Contacts::CustomFields::Fields)
121
+ expect(req).to be_a(RestClient::Request)
122
+ expect(res).to be_a(Net::HTTPOK)
123
+ end
124
+ end
125
+
126
+ it '#get_custom_field' do
127
+ @client.get_custom_field(@new_field.id) do |resp, req, res|
128
+ resp = SendGrid4r::REST::Contacts::CustomFields.create_field(
129
+ JSON.parse(resp)
130
+ )
131
+ expect(resp).to be_a(SendGrid4r::REST::Contacts::CustomFields::Field)
132
+ expect(req).to be_a(RestClient::Request)
133
+ expect(res).to be_a(Net::HTTPOK)
134
+ end
135
+ end
136
+
137
+ it '#delete_custom_field' do
138
+ @client.delete_custom_field(@new_field.id) do |resp, req, res|
139
+ expect(resp).to eq('')
140
+ expect(req).to be_a(RestClient::Request)
141
+ expect(res).to be_a(Net::HTTPNoContent)
142
+ end
143
+ end
144
+ end
145
+ end
146
+
147
+ describe 'unit test' do
57
148
  it 'creates field instance' do
58
149
  json =
59
150
  '{'\
@@ -63,6 +154,7 @@ describe 'SendGrid4r::REST::Contacts::CustomFields' do
63
154
  '}'
64
155
  hash = JSON.parse(json)
65
156
  actual = SendGrid4r::REST::Contacts::CustomFields.create_field(hash)
157
+ expect(actual).to be_a(SendGrid4r::REST::Contacts::CustomFields::Field)
66
158
  expect(actual.id).to eq(1)
67
159
  expect(actual.name).to eq('pet')
68
160
  expect(actual.type).to eq('text')
@@ -91,11 +183,10 @@ describe 'SendGrid4r::REST::Contacts::CustomFields' do
91
183
  '}'
92
184
  hash = JSON.parse(json)
93
185
  actual = SendGrid4r::REST::Contacts::CustomFields.create_fields(hash)
94
- expect(actual.custom_fields.is_a?(Array)).to eq(true)
186
+ expect(actual).to be_a(SendGrid4r::REST::Contacts::CustomFields::Fields)
187
+ expect(actual.custom_fields).to be_a(Array)
95
188
  actual.custom_fields.each do |field|
96
- expect(
97
- field.is_a?(SendGrid4r::REST::Contacts::CustomFields::Field)
98
- ).to eq(true)
189
+ expect(field).to be_a(SendGrid4r::REST::Contacts::CustomFields::Field)
99
190
  end
100
191
  end
101
192
  end