sendgrid4r 1.12.0 → 1.13.0

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 +4 -4
  2. data/.rubocop.yml +1 -1
  3. data/README.md +2 -1
  4. data/lib/sendgrid4r/cli/alert.rb +51 -0
  5. data/lib/sendgrid4r/cli/campaign/campaign.rb +2 -2
  6. data/lib/sendgrid4r/cli/campaign/contact/custom_field.rb +1 -1
  7. data/lib/sendgrid4r/cli/campaign/contact/list.rb +1 -1
  8. data/lib/sendgrid4r/cli/campaign/contact/recipient.rb +2 -2
  9. data/lib/sendgrid4r/cli/campaign/contact/segment.rb +12 -3
  10. data/lib/sendgrid4r/cli/ipam/whitelist.rb +1 -1
  11. data/lib/sendgrid4r/cli/settings/enforced_tls.rb +2 -2
  12. data/lib/sendgrid4r/cli/settings/mail.rb +33 -9
  13. data/lib/sendgrid4r/cli/settings/partner.rb +4 -1
  14. data/lib/sendgrid4r/cli/settings/tracking.rb +13 -4
  15. data/lib/sendgrid4r/cli/sg.rb +16 -10
  16. data/lib/sendgrid4r/cli/sg_thor.rb +27 -11
  17. data/lib/sendgrid4r/cli/stats/advanced.rb +22 -20
  18. data/lib/sendgrid4r/cli/stats/category.rb +8 -8
  19. data/lib/sendgrid4r/cli/stats/global.rb +3 -3
  20. data/lib/sendgrid4r/cli/stats/parse.rb +3 -3
  21. data/lib/sendgrid4r/cli/stats/subuser.rb +10 -10
  22. data/lib/sendgrid4r/cli/suppressions/block.rb +2 -2
  23. data/lib/sendgrid4r/cli/suppressions/bounce.rb +2 -2
  24. data/lib/sendgrid4r/cli/suppressions/global_unsubscribe.rb +2 -2
  25. data/lib/sendgrid4r/cli/suppressions/group.rb +6 -1
  26. data/lib/sendgrid4r/cli/suppressions/group_unsubscribe.rb +9 -0
  27. data/lib/sendgrid4r/cli/suppressions/invalid_email.rb +2 -2
  28. data/lib/sendgrid4r/cli/suppressions/spam_report.rb +2 -2
  29. data/lib/sendgrid4r/cli/templates/version.rb +2 -2
  30. data/lib/sendgrid4r/cli/user.rb +5 -5
  31. data/lib/sendgrid4r/cli/webhooks/parse.rb +42 -2
  32. data/lib/sendgrid4r/cli/whitelabel/domain.rb +3 -3
  33. data/lib/sendgrid4r/cli/whitelabel/link.rb +2 -2
  34. data/lib/sendgrid4r/rest/alerts.rb +81 -0
  35. data/lib/sendgrid4r/rest/api.rb +1 -0
  36. data/lib/sendgrid4r/rest/blocks.rb +2 -4
  37. data/lib/sendgrid4r/rest/bounces.rb +2 -4
  38. data/lib/sendgrid4r/rest/invalid_emails.rb +2 -4
  39. data/lib/sendgrid4r/rest/request.rb +10 -6
  40. data/lib/sendgrid4r/rest/sm/groups.rb +3 -2
  41. data/lib/sendgrid4r/rest/sm/suppressions.rb +61 -14
  42. data/lib/sendgrid4r/rest/spam_reports.rb +2 -4
  43. data/lib/sendgrid4r/rest/webhooks/parse.rb +47 -6
  44. data/lib/sendgrid4r/version.rb +1 -1
  45. data/lib/sendgrid4r.rb +3 -0
  46. data/spec/cli/alert_spec.rb +71 -0
  47. data/spec/cli/sg_spec.rb +5 -0
  48. data/spec/cli/suppressions/group_spec.rb +11 -2
  49. data/spec/cli/suppressions/group_unsubscribe_spec.rb +12 -2
  50. data/spec/cli/webhooks/parse_spec.rb +53 -1
  51. data/spec/client_spec.rb +17 -1
  52. data/spec/rest/alerts_spec.rb +188 -0
  53. data/spec/rest/mail/mail_spec.rb +10 -10
  54. data/spec/rest/request_spec.rb +41 -0
  55. data/spec/rest/sm/groups_spec.rb +9 -0
  56. data/spec/rest/sm/suppressions_spec.rb +122 -35
  57. data/spec/rest/webhooks/parse_spec.rb +94 -7
  58. metadata +10 -2
@@ -0,0 +1,71 @@
1
+ # encoding: utf-8
2
+ require File.dirname(__FILE__) + '/../spec_helper'
3
+
4
+ module SendGrid4r::CLI
5
+ describe Alert do
6
+ describe 'integration test', :it do
7
+ before do
8
+ Dotenv.load
9
+ end
10
+
11
+ it '#list' do
12
+ args = [
13
+ 'list',
14
+ '--api-key', ENV['SILVER_API_KEY']
15
+ ]
16
+ Alert.start(args)
17
+ end
18
+
19
+ it '#create stats_notification alert' do
20
+ args = [
21
+ 'create',
22
+ '--api-key', ENV['SILVER_API_KEY'],
23
+ '--type', 'stats_notification',
24
+ '--email_to', ENV['MAIL'],
25
+ '--frequency', 'daily'
26
+ ]
27
+ Alert.start(args)
28
+ end
29
+
30
+ it '#create usage_limit alert' do
31
+ args = [
32
+ 'create',
33
+ '--api-key', ENV['SILVER_API_KEY'],
34
+ '--type', 'usage_limit',
35
+ '--email_to', ENV['MAIL'],
36
+ '--percentage', 50
37
+ ]
38
+ Alert.start(args)
39
+ end
40
+
41
+ it '#get' do
42
+ args = [
43
+ 'get',
44
+ '--api-key', ENV['SILVER_API_KEY'],
45
+ '--alert-id', 322729
46
+ ]
47
+ Alert.start(args)
48
+ end
49
+
50
+ it '#delete' do
51
+ args = [
52
+ 'delete',
53
+ '--api-key', ENV['SILVER_API_KEY'],
54
+ '--alert-id', 322729
55
+ ]
56
+ Alert.start(args)
57
+ end
58
+
59
+ it '#update' do
60
+ args = [
61
+ 'update',
62
+ '--api-key', ENV['SILVER_API_KEY'],
63
+ '--alert-id', 322729,
64
+ '--email_to', ENV['MAIL'],
65
+ '--percentage', 88
66
+ ]
67
+ Alert.start(args)
68
+ end
69
+ end
70
+ end
71
+ end
data/spec/cli/sg_spec.rb CHANGED
@@ -8,6 +8,11 @@ module SendGrid4r::CLI
8
8
  Dotenv.load
9
9
  end
10
10
 
11
+ it '#alert subcommend' do
12
+ args = ['alert']
13
+ SG.start(args)
14
+ end
15
+
11
16
  it '#api_key subcommand' do
12
17
  args = ['api_key']
13
18
  SG.start(args)
@@ -19,7 +19,7 @@ module SendGrid4r::CLI::Suppressions
19
19
  Group.start(args)
20
20
  end
21
21
 
22
- it '#list' do
22
+ it '#list without params' do
23
23
  args = [
24
24
  'list',
25
25
  '--api-key', ENV['SILVER_API_KEY']
@@ -27,11 +27,20 @@ module SendGrid4r::CLI::Suppressions
27
27
  Group.start(args)
28
28
  end
29
29
 
30
+ it '#list with email' do
31
+ args = [
32
+ 'list',
33
+ '--api-key', ENV['SILVER_API_KEY'],
34
+ '--email-address', 'test1@test.com'
35
+ ]
36
+ Group.start(args)
37
+ end
38
+
30
39
  it '#get' do
31
40
  args = [
32
41
  'get',
33
42
  '--api-key', ENV['SILVER_API_KEY'],
34
- '--group-id', 967
43
+ '--group-id', 889
35
44
  ]
36
45
  Group.start(args)
37
46
  end
@@ -12,7 +12,7 @@ module SendGrid4r::CLI::Suppressions
12
12
  args = [
13
13
  'add',
14
14
  '--api-key', ENV['SILVER_API_KEY'],
15
- '--group-id', 889,
15
+ '--group-id', 1099,
16
16
  '--recipient-emails', 'abc@abc.com', 'cde@cde.com'
17
17
  ]
18
18
  GroupUnsubscribe.start(args)
@@ -22,7 +22,17 @@ module SendGrid4r::CLI::Suppressions
22
22
  args = [
23
23
  'list',
24
24
  '--api-key', ENV['SILVER_API_KEY'],
25
- '--group-id', 889
25
+ '--group-id', 1099
26
+ ]
27
+ GroupUnsubscribe.start(args)
28
+ end
29
+
30
+ it '#search' do
31
+ args = [
32
+ 'search',
33
+ '--api-key', ENV['SILVER_API_KEY'],
34
+ '--group-id', 1099,
35
+ '--recipient-emails', 'abc@abc.com', 'cde@cde.com'
26
36
  ]
27
37
  GroupUnsubscribe.start(args)
28
38
  end
@@ -8,10 +8,62 @@ module SendGrid4r::CLI::Webhooks
8
8
  Dotenv.load
9
9
  end
10
10
 
11
+ it '#list without params' do
12
+ args = [
13
+ 'list',
14
+ '--api-key', ENV['SILVER_API_KEY']
15
+ ]
16
+ Parse.start(args)
17
+ end
18
+
19
+ it '#list with full params' do
20
+ args = [
21
+ 'list',
22
+ '--api-key', ENV['SILVER_API_KEY'],
23
+ '--limit', 0,
24
+ '--offset', 1
25
+ ]
26
+ Parse.start(args)
27
+ end
28
+
29
+ it '#create' do
30
+ args = [
31
+ 'create',
32
+ '--api-key', ENV['SILVER_API_KEY'],
33
+ '--hostname', 'host1.abc.abc',
34
+ '--url', 'http://host1.abc.abc',
35
+ '--spam_check', true,
36
+ '--send_raw', true
37
+ ]
38
+ Parse.start(args)
39
+ end
40
+
11
41
  it '#get' do
12
42
  args = [
13
43
  'get',
14
- '--api-key', ENV['SILVER_API_KEY']
44
+ '--api-key', ENV['SILVER_API_KEY'],
45
+ '--hostname', 'host1.abc.abc'
46
+ ]
47
+ Parse.start(args)
48
+ end
49
+
50
+ it '#update' do
51
+ args = [
52
+ 'update',
53
+ '--api-key', ENV['SILVER_API_KEY'],
54
+ '--hostname', 'host1.abc.abc',
55
+ '--url', 'http://host1.abc.abc',
56
+ '--spam_check', true,
57
+ '--send_raw', true
58
+ ]
59
+ Parse.start(args)
60
+ end
61
+
62
+ it '#delete' do
63
+ args = [
64
+ 'delete',
65
+ '--api-key', ENV['SILVER_API_KEY'],
66
+ '--hostname', 'host1.abc.abc'
15
67
  ]
16
68
  Parse.start(args)
17
69
  end
data/spec/client_spec.rb CHANGED
@@ -29,6 +29,13 @@ describe SendGrid4r::Client do
29
29
 
30
30
  describe 'methods' do
31
31
  it 'available' do
32
+ # Alerts
33
+ expect(@client.respond_to?('get_alerts')).to eq(true)
34
+ expect(@client.respond_to?('post_alert')).to eq(true)
35
+ expect(@client.respond_to?('get_alert')).to eq(true)
36
+ expect(@client.respond_to?('delete_alert')).to eq(true)
37
+ expect(@client.respond_to?('patch_alert')).to eq(true)
38
+
32
39
  # Subusers
33
40
  expect(@client.respond_to?('get_subusers')).to eq(true)
34
41
  expect(@client.respond_to?('post_subuser')).to eq(true)
@@ -55,8 +62,10 @@ describe SendGrid4r::Client do
55
62
  # suppressions
56
63
  expect(@client.respond_to?('post_suppressed_emails')).to eq(true)
57
64
  expect(@client.respond_to?('get_suppressions')).to eq(true)
65
+ expect(@client.respond_to?('get_groups_by_email')).to eq(true)
58
66
  expect(@client.respond_to?('get_suppressed_emails')).to eq(true)
59
67
  expect(@client.respond_to?('delete_suppressed_email')).to eq(true)
68
+ expect(@client.respond_to?('search_suppressed_emails')).to eq(true)
60
69
  # global unsubscribes
61
70
  expect(@client.respond_to?('get_global_unsubscribes')).to eq(true)
62
71
  expect(@client.respond_to?('post_global_unsubscribes')).to eq(true)
@@ -140,6 +149,13 @@ describe SendGrid4r::Client do
140
149
  expect(@client.respond_to?('get_settings_subscription')).to eq(true)
141
150
  expect(@client.respond_to?('patch_settings_subscription')).to eq(true)
142
151
 
152
+ # Parse Webhooks
153
+ expect(@client.respond_to?('get_parse_settings')).to eq(true)
154
+ expect(@client.respond_to?('post_parse_setting')).to eq(true)
155
+ expect(@client.respond_to?('get_parse_setting')).to eq(true)
156
+ expect(@client.respond_to?('patch_parse_setting')).to eq(true)
157
+ expect(@client.respond_to?('delete_parse_setting')).to eq(true)
158
+
143
159
  # Template Engine
144
160
  # templates
145
161
  expect(@client.respond_to?('get_templates')).to eq(true)
@@ -324,7 +340,7 @@ describe SendGrid4r::Client do
324
340
 
325
341
  describe 'VERSION' do
326
342
  it 'returns VERSION value' do
327
- expect(SendGrid4r::VERSION).to eq('1.12.0')
343
+ expect(SendGrid4r::VERSION).to eq('1.13.0')
328
344
  end
329
345
  end
330
346
  end
@@ -0,0 +1,188 @@
1
+ # encoding: utf-8
2
+ require File.dirname(__FILE__) + '/../spec_helper'
3
+
4
+ module SendGrid4r::REST
5
+ describe Alerts do
6
+ describe 'integration test', :it do
7
+ before do
8
+ Dotenv.load
9
+ @client = SendGrid4r::Client.new(api_key: ENV['SILVER_API_KEY'])
10
+
11
+ # clean up test env
12
+ alerts = @client.get_alerts
13
+ alerts.each do |alert|
14
+ @client.delete_alert(alert_id: alert.id)
15
+ end
16
+
17
+ # post a alert
18
+ @alert_usage = @client.post_alert(
19
+ type: :usage_limit, percentage: 66, email_to: ENV['MAIL']
20
+ )
21
+ @alert_stats = @client.post_alert(
22
+ type: :stats_notification, frequency: :daily, email_to: ENV['MAIL']
23
+ )
24
+ end
25
+
26
+ context 'without block call' do
27
+ it '#get_alerts' do
28
+ alerts = @client.get_alerts
29
+ expect(alerts).to be_a(Array)
30
+ alerts.each { |alert| expect(alert).to be_a(Alerts::Alert) }
31
+ end
32
+
33
+ it '#post_alert :usage_limit' do
34
+ alert = @client.post_alert(
35
+ type: :usage_limit,
36
+ email_to: ENV['MAIL'],
37
+ percentage: 66
38
+ )
39
+ expect(alert).to be_a(Alerts::Alert)
40
+ end
41
+
42
+ it '#post_alert :stats_notification' do
43
+ alert = @client.post_alert(
44
+ type: :stats_notification,
45
+ email_to: ENV['MAIL'],
46
+ frequency: :daily
47
+ )
48
+ expect(alert).to be_a(Alerts::Alert)
49
+ end
50
+
51
+ it '#get_alert' do
52
+ alert_usage = @client.get_alert(alert_id: @alert_usage.id)
53
+ expect(alert_usage).to be_a(Alerts::Alert)
54
+ end
55
+
56
+ it '#delete_alert' do
57
+ @client.delete_alert(
58
+ alert_id: @alert_stats.id
59
+ )
60
+ end
61
+
62
+ it '#patch_alert' do
63
+ alert = @client.patch_alert(
64
+ alert_id: @alert_stats.id,
65
+ frequency: :weekly,
66
+ email_to: ENV['MAIL']
67
+ )
68
+ expect(alert).to be_a(Alerts::Alert)
69
+ end
70
+ end
71
+ end
72
+
73
+ describe 'unit test', :ut do
74
+ let(:client) do
75
+ SendGrid4r::Client.new(api_key: '')
76
+ end
77
+
78
+ let(:alerts) do
79
+ '['\
80
+ '{'\
81
+ '"created_at": 1451498784,'\
82
+ '"email_to": "test@example.com",'\
83
+ '"id": 46,'\
84
+ '"percentage": 90,'\
85
+ '"type": "usage_limit",'\
86
+ '"updated_at": 1451498784'\
87
+ '},'\
88
+ '{'\
89
+ '"created_at": 1451498812,'\
90
+ '"email_to": "test@example.com",'\
91
+ '"frequency": "monthly",'\
92
+ '"id": 47,'\
93
+ '"type": "stats_notification",'\
94
+ '"updated_at": 1451498812'\
95
+ '},'\
96
+ '{'\
97
+ '"created_at": 1451520930,'\
98
+ '"email_to": "test@example.com",'\
99
+ '"frequency": "daily",'\
100
+ '"id": 48,'\
101
+ '"type": "stats_notification",'\
102
+ '"updated_at": 1451520930'\
103
+ '}'\
104
+ ']'
105
+ end
106
+
107
+ let(:alert) do
108
+ '{'\
109
+ '"created_at": 1451520930,'\
110
+ '"email_to": "test@example.com",'\
111
+ '"frequency": "daily",'\
112
+ '"id": 48,'\
113
+ '"type": "stats_notification",'\
114
+ '"updated_at": 1451520930'\
115
+ '}'
116
+ end
117
+
118
+ it '#get_alerts' do
119
+ allow(client).to receive(:execute).and_return(alerts)
120
+ actual = client.get_alerts
121
+ expect(actual).to be_a(Array)
122
+ actual.each { |alert| expect(alert).to be_a(Alerts::Alert) }
123
+ end
124
+
125
+ it '#post_alert' do
126
+ allow(client).to receive(:execute).and_return(alert)
127
+ actual = client.post_alert(
128
+ type: :usage_limit, email_to: '', percentage: 66
129
+ )
130
+ expect(actual).to be_a(Alerts::Alert)
131
+ end
132
+
133
+ it '#get_alert' do
134
+ allow(client).to receive(:execute).and_return(alert)
135
+ actual = client.get_alert(alert_id: 0)
136
+ expect(actual).to be_a(Alerts::Alert)
137
+ end
138
+
139
+ it '#delete_alert' do
140
+ allow(client).to receive(:execute).and_return('')
141
+ actual = client.delete_alert(alert_id: 0)
142
+ expect(actual).to eq('')
143
+ end
144
+
145
+ it '#patch_alert' do
146
+ allow(client).to receive(:execute).and_return(alert)
147
+ actual = client.patch_alert(
148
+ alert_id: 0, frequency: :weekly, email_to: ''
149
+ )
150
+ expect(actual).to be_a(Alerts::Alert)
151
+ end
152
+
153
+ it 'creates alerts instance' do
154
+ actual = Alerts.create_alerts(JSON.parse(alerts))
155
+ expect(actual).to be_a(Array)
156
+ expect(actual[0].created_at).to eq(Time.at(1451498784))
157
+ expect(actual[0].email_to).to eq('test@example.com')
158
+ expect(actual[0].id).to eq(46)
159
+ expect(actual[0].percentage).to eq(90)
160
+ expect(actual[0].type).to eq('usage_limit')
161
+ expect(actual[0].updated_at).to eq(Time.at(1451498784))
162
+ expect(actual[1].created_at).to eq(Time.at(1451498812))
163
+ expect(actual[1].email_to).to eq('test@example.com')
164
+ expect(actual[1].frequency).to eq('monthly')
165
+ expect(actual[1].id).to eq(47)
166
+ expect(actual[1].type).to eq('stats_notification')
167
+ expect(actual[1].updated_at).to eq(Time.at(1451498812))
168
+ expect(actual[2].created_at).to eq(Time.at(1451520930))
169
+ expect(actual[2].email_to).to eq('test@example.com')
170
+ expect(actual[2].frequency).to eq('daily')
171
+ expect(actual[2].id).to eq(48)
172
+ expect(actual[2].type).to eq('stats_notification')
173
+ expect(actual[2].updated_at).to eq(Time.at(1451520930))
174
+ end
175
+
176
+ it 'creates alert instance' do
177
+ actual = Alerts.create_alert(JSON.parse(alert))
178
+ expect(actual).to be_a(Alerts::Alert)
179
+ expect(actual.created_at).to eq(Time.at(1451520930))
180
+ expect(actual.email_to).to eq('test@example.com')
181
+ expect(actual.frequency).to eq('daily')
182
+ expect(actual.id).to eq(48)
183
+ expect(actual.type).to eq('stats_notification')
184
+ expect(actual.updated_at).to eq(Time.at(1451520930))
185
+ end
186
+ end
187
+ end
188
+ end
@@ -24,11 +24,11 @@ module SendGrid4r::REST
24
24
  )
25
25
  plain = SendGrid4r::Factory::MailFactory.create_content(
26
26
  type: 'text/plain',
27
- value: 'Hello! TEXT'
27
+ value: 'Hello! TEXT 天翔十字鳳'
28
28
  )
29
29
  params = SendGrid4r::Factory::MailFactory.create_params(
30
30
  personalizations: [per], from: from, content: [plain],
31
- subject: 'Hello v3 Mail'
31
+ subject: 'Hello v3 Mail 天翔十字鳳'
32
32
  )
33
33
  begin
34
34
  @client.send(params: params)
@@ -56,27 +56,27 @@ module SendGrid4r::REST
56
56
  per.cc = [cc]
57
57
  per.headers = { 'X-CUSTOM' => 'X-VALUE' }
58
58
  per.substitutions = {
59
- 'subkey' => 'subvalue', 'sectionkey' => 'sectionkey'
59
+ 'subkey' => 'subvalueサブ値', 'sectionkey' => 'sectionkey'
60
60
  }
61
61
  per.custom_args = { 'CUSTOM' => 'value' }
62
62
  per.send_at = Time.utc(2016)
63
63
  # Create Params
64
64
  from = SendGrid4r::Factory::MailFactory.create_address(
65
- email: ENV['FROM'], name: 'From Name'
65
+ email: ENV['FROM'], name: 'From 太郎'
66
66
  )
67
67
  plain = SendGrid4r::Factory::MailFactory.create_content(
68
68
  type: 'text/plain',
69
- value: 'Hello! TEXT subkey'\
70
- 'sectionkey\nhttps://www.google.com'
69
+ value: 'Hello! TEXT 天翔十字鳳 subkey'\
70
+ 'sectionkey\nhttps://abc.abc.abc'
71
71
  )
72
72
  html = SendGrid4r::Factory::MailFactory.create_content(
73
73
  type: 'text/html',
74
74
  value: '<h1>Hello! HTML subkey sectionkey</h1><br />'\
75
- '<a href="https://www.google.com">Google</a>'
75
+ '<a href="https://abc.abc.abc">abc</a>'
76
76
  )
77
77
  params = SendGrid4r::Factory::MailFactory.create_params(
78
78
  personalizations: [per], from: from, content: [plain, html],
79
- subject: 'Hello v3 Mail'
79
+ subject: 'Hello v3 Mail 天翔十字鳳 '
80
80
  )
81
81
  reply_to = SendGrid4r::Factory::MailFactory.create_address(
82
82
  email: ENV['MAIL']
@@ -91,7 +91,7 @@ module SendGrid4r::REST
91
91
  )
92
92
  params.attachments = [attachment0, attachment1]
93
93
  params.template_id = '8481d009-d1a6-4e1b-adae-22d2426da9fe'
94
- params.sections = { 'sectionkey' => 'sectionvalue' }
94
+ params.sections = { 'sectionkey' => 'sectionvalueセクション値' }
95
95
  params.headers = { 'X-GLOBAL' => 'GLOBAL_VALUE' }
96
96
  params.categories = %w(CAT1 CAT2)
97
97
  params.custom_args = { 'CUSTOM1' => 'CUSTOM_VALUE1' }
@@ -108,7 +108,7 @@ module SendGrid4r::REST
108
108
  mail_settings.disable_footer
109
109
  mail_settings.enable_sandbox_mode
110
110
  mail_settings.disable_sandbox_mode
111
- mail_settings.enable_spam_check(10, 'http://www.kke.co.jp')
111
+ mail_settings.enable_spam_check(10, 'http://abc.abc.abc')
112
112
  mail_settings.disable_spam_check
113
113
  params.mail_settings = mail_settings
114
114
  # Create TrackingSettings
@@ -0,0 +1,41 @@
1
+ # encoding: utf-8
2
+ require File.dirname(__FILE__) + '/../spec_helper'
3
+
4
+ module SendGrid4r::REST
5
+ describe Request do
6
+ describe 'unit test', :ut do
7
+ let(:client) do
8
+ SendGrid4r::Client.new(api_key: '')
9
+ end
10
+
11
+ it '#process_array_params with array' do
12
+ actual = client.process_array_params(%w(a b c))
13
+ expect(actual).to eq('a,b,c')
14
+ end
15
+
16
+ it '#process_array_params with string' do
17
+ actual = client.process_array_params('abc')
18
+ expect(actual).to eq('abc')
19
+ end
20
+
21
+ it '#process_url_params with nil' do
22
+ actual = client.process_url_params('http://aaa.bbb/', nil)
23
+ expect(actual).to eq('http://aaa.bbb/')
24
+ end
25
+
26
+ it '#process_url_params with hash' do
27
+ actual = client.process_url_params(
28
+ 'http://aaa.bbb/', ccc: :c1, ddd: :d1
29
+ )
30
+ expect(actual).to eq('http://aaa.bbb/?ccc=c1&ddd=d1')
31
+ end
32
+
33
+ it '#process_url_params with array of hash' do
34
+ actual = client.process_url_params(
35
+ 'http://aaa.bbb/', [{ ccc: :c1 }, { ccc: :c2, ddd: :d3 }]
36
+ )
37
+ expect(actual).to eq('http://aaa.bbb/?ccc=c1&ccc=c2&ddd=d3')
38
+ end
39
+ end
40
+ end
41
+ end
@@ -58,6 +58,15 @@ module SendGrid4r::REST::Sm
58
58
  end
59
59
  end
60
60
 
61
+ it '#get_groups with ids' do
62
+ groups = @client.get_groups(ids: [@group1.id])
63
+ expect(groups).to be_a(Array)
64
+ groups.each do |group|
65
+ expect(group).to be_a(Groups::Group)
66
+ expect(group.id).to eq(@group1.id)
67
+ end
68
+ end
69
+
61
70
  it '#get_group' do
62
71
  group = @client.get_group(group_id: @group1.id)
63
72
  expect(group.id).to be_a(Fixnum)