sendgrid4r 1.8.1 → 1.10.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 (145) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +6 -2
  3. data/README.md +1 -0
  4. data/lib/sendgrid4r/factory/campaign_factory.rb +18 -5
  5. data/lib/sendgrid4r/factory/condition_factory.rb +1 -1
  6. data/lib/sendgrid4r/factory/mail_factory.rb +57 -0
  7. data/lib/sendgrid4r/factory/segment_factory.rb +2 -5
  8. data/lib/sendgrid4r/factory/version_factory.rb +1 -1
  9. data/lib/sendgrid4r/rest/api.rb +48 -49
  10. data/lib/sendgrid4r/rest/api_keys_management/api_keys.rb +75 -0
  11. data/lib/sendgrid4r/rest/api_keys_management/permissions.rb +31 -0
  12. data/lib/sendgrid4r/rest/blocks.rb +49 -68
  13. data/lib/sendgrid4r/rest/bounces.rb +45 -64
  14. data/lib/sendgrid4r/rest/cancel_scheduled_sends.rb +53 -72
  15. data/lib/sendgrid4r/rest/categories.rb +31 -0
  16. data/lib/sendgrid4r/rest/email_activity.rb +72 -0
  17. data/lib/sendgrid4r/rest/invalid_emails.rb +50 -68
  18. data/lib/sendgrid4r/rest/ip_access_management.rb +86 -111
  19. data/lib/sendgrid4r/rest/ips/addresses.rb +50 -59
  20. data/lib/sendgrid4r/rest/ips/pools.rb +42 -53
  21. data/lib/sendgrid4r/rest/ips/warmup.rb +46 -55
  22. data/lib/sendgrid4r/rest/mail/address.rb +14 -0
  23. data/lib/sendgrid4r/rest/mail/attachment.rb +22 -0
  24. data/lib/sendgrid4r/rest/mail/content.rb +10 -0
  25. data/lib/sendgrid4r/rest/mail/mail.rb +28 -0
  26. data/lib/sendgrid4r/rest/mail/mail_settings.rb +62 -0
  27. data/lib/sendgrid4r/rest/mail/params.rb +64 -0
  28. data/lib/sendgrid4r/rest/mail/personalization.rb +33 -0
  29. data/lib/sendgrid4r/rest/mail/tracking_settings.rb +74 -0
  30. data/lib/sendgrid4r/rest/{contacts → marketing_campaigns/contacts}/custom_fields.rb +12 -27
  31. data/lib/sendgrid4r/rest/{contacts → marketing_campaigns/contacts}/lists.rb +20 -34
  32. data/lib/sendgrid4r/rest/marketing_campaigns/contacts/recipients.rb +134 -0
  33. data/lib/sendgrid4r/rest/{contacts → marketing_campaigns/contacts}/reserved_fields.rb +6 -9
  34. data/lib/sendgrid4r/rest/marketing_campaigns/contacts/segments.rb +86 -0
  35. data/lib/sendgrid4r/rest/marketing_campaigns/marketing_campaigns.rb +119 -0
  36. data/lib/sendgrid4r/rest/marketing_campaigns/senders.rb +101 -0
  37. data/lib/sendgrid4r/rest/request.rb +61 -63
  38. data/lib/sendgrid4r/rest/settings/enforced_tls.rb +23 -26
  39. data/lib/sendgrid4r/rest/settings/mail.rb +167 -183
  40. data/lib/sendgrid4r/rest/settings/partner.rb +33 -36
  41. data/lib/sendgrid4r/rest/settings/settings.rb +17 -22
  42. data/lib/sendgrid4r/rest/settings/tracking.rb +97 -107
  43. data/lib/sendgrid4r/rest/sm/global_unsubscribes.rb +52 -60
  44. data/lib/sendgrid4r/rest/sm/groups.rb +52 -58
  45. data/lib/sendgrid4r/rest/sm/sm.rb +15 -17
  46. data/lib/sendgrid4r/rest/sm/suppressions.rb +50 -67
  47. data/lib/sendgrid4r/rest/spam_reports.rb +49 -69
  48. data/lib/sendgrid4r/rest/stats/advanced.rb +100 -102
  49. data/lib/sendgrid4r/rest/stats/category.rb +31 -33
  50. data/lib/sendgrid4r/rest/stats/global.rb +17 -19
  51. data/lib/sendgrid4r/rest/stats/parse.rb +18 -20
  52. data/lib/sendgrid4r/rest/stats/stats.rb +59 -69
  53. data/lib/sendgrid4r/rest/stats/subuser.rb +70 -32
  54. data/lib/sendgrid4r/rest/subusers.rb +106 -134
  55. data/lib/sendgrid4r/rest/transactional_templates/templates.rb +63 -0
  56. data/lib/sendgrid4r/rest/transactional_templates/versions.rb +90 -0
  57. data/lib/sendgrid4r/rest/users.rb +125 -57
  58. data/lib/sendgrid4r/rest/webhooks/event.rb +36 -42
  59. data/lib/sendgrid4r/rest/webhooks/parse.rb +28 -37
  60. data/lib/sendgrid4r/rest/whitelabel/domains.rb +176 -222
  61. data/lib/sendgrid4r/rest/whitelabel/ips.rb +107 -128
  62. data/lib/sendgrid4r/rest/whitelabel/links.rb +131 -167
  63. data/lib/sendgrid4r/version.rb +1 -1
  64. data/lib/sendgrid4r.rb +23 -13
  65. data/sendgrid4r.gemspec +1 -1
  66. data/spec/client_spec.rb +12 -1
  67. data/spec/factory/campaign_factory_spec.rb +75 -35
  68. data/spec/factory/condition_factory_spec.rb +19 -18
  69. data/spec/factory/segment_factory_spec.rb +28 -21
  70. data/spec/factory/version_factory_spec.rb +28 -27
  71. data/spec/photo.jpg +0 -0
  72. data/spec/rest/api_keys_management/api_keys_spec.rb +174 -0
  73. data/spec/rest/api_keys_management/permissions_spec.rb +54 -0
  74. data/spec/rest/blocks_spec.rb +78 -106
  75. data/spec/rest/bounces_spec.rb +91 -118
  76. data/spec/rest/cancel_scheduled_sends_spec.rb +94 -149
  77. data/spec/rest/categories_spec.rb +77 -0
  78. data/spec/rest/email_activity_spec.rb +151 -0
  79. data/spec/rest/invalid_emails_spec.rb +85 -119
  80. data/spec/rest/ip_access_management_spec.rb +157 -195
  81. data/spec/rest/ips/addresses_spec.rb +94 -122
  82. data/spec/rest/ips/pools_spec.rb +84 -112
  83. data/spec/rest/ips/warmup_spec.rb +63 -71
  84. data/spec/rest/mail/address_spec.rb +28 -0
  85. data/spec/rest/mail/attachment_spec.rb +48 -0
  86. data/spec/rest/mail/content_spec.rb +32 -0
  87. data/spec/rest/mail/mail_settings_spec.rb +51 -0
  88. data/spec/rest/mail/mail_spec.rb +136 -0
  89. data/spec/rest/mail/params_spec.rb +152 -0
  90. data/spec/rest/mail/personalization_spec.rb +66 -0
  91. data/spec/rest/mail/tracking_settings_spec.rb +63 -0
  92. data/spec/rest/marketing_campaigns/contacts/custom_fields_spec.rb +146 -0
  93. data/spec/rest/marketing_campaigns/contacts/lists_spec.rb +307 -0
  94. data/spec/rest/marketing_campaigns/contacts/recipients_spec.rb +331 -0
  95. data/spec/rest/marketing_campaigns/contacts/reserved_fields_spec.rb +119 -0
  96. data/spec/rest/marketing_campaigns/contacts/segments_spec.rb +268 -0
  97. data/spec/rest/marketing_campaigns/marketing_campaigns_spec.rb +427 -0
  98. data/spec/rest/marketing_campaigns/senders_spec.rb +230 -0
  99. data/spec/rest/settings/enforced_tls_spec.rb +38 -54
  100. data/spec/rest/settings/mail_spec.rb +227 -330
  101. data/spec/rest/settings/partner_spec.rb +40 -59
  102. data/spec/rest/settings/settings_spec.rb +44 -42
  103. data/spec/rest/settings/tracking_spec.rb +130 -189
  104. data/spec/rest/sm/global_unsubscribes_spec.rb +47 -72
  105. data/spec/rest/sm/groups_spec.rb +88 -123
  106. data/spec/rest/sm/sm_spec.rb +32 -30
  107. data/spec/rest/sm/suppressions_spec.rb +105 -140
  108. data/spec/rest/spam_reports_spec.rb +81 -109
  109. data/spec/rest/stats/advanced_spec.rb +67 -125
  110. data/spec/rest/stats/category_spec.rb +27 -45
  111. data/spec/rest/stats/global_spec.rb +34 -42
  112. data/spec/rest/stats/parse_spec.rb +32 -30
  113. data/spec/rest/stats/stats_spec.rb +174 -172
  114. data/spec/rest/stats/subuser_spec.rb +97 -57
  115. data/spec/rest/subusers_spec.rb +156 -209
  116. data/spec/rest/transactional_templates/templates_spec.rb +199 -0
  117. data/spec/rest/transactional_templates/versions_spec.rb +228 -0
  118. data/spec/rest/users_spec.rb +176 -91
  119. data/spec/rest/webhooks/event_spec.rb +59 -85
  120. data/spec/rest/webhooks/parse_spec.rb +51 -71
  121. data/spec/rest/whitelabel/domains_spec.rb +333 -513
  122. data/spec/rest/whitelabel/ips_spec.rb +109 -147
  123. data/spec/rest/whitelabel/links_spec.rb +181 -265
  124. metadata +70 -40
  125. data/lib/sendgrid4r/rest/api_keys/api_keys.rb +0 -80
  126. data/lib/sendgrid4r/rest/api_keys/permissions.rb +0 -33
  127. data/lib/sendgrid4r/rest/campaigns/campaigns.rb +0 -126
  128. data/lib/sendgrid4r/rest/categories/categories.rb +0 -43
  129. data/lib/sendgrid4r/rest/contacts/recipients.rb +0 -150
  130. data/lib/sendgrid4r/rest/contacts/segments.rb +0 -97
  131. data/lib/sendgrid4r/rest/email_activity/email_activity.rb +0 -81
  132. data/lib/sendgrid4r/rest/templates/templates.rb +0 -69
  133. data/lib/sendgrid4r/rest/templates/versions.rb +0 -95
  134. data/spec/rest/api_keys/api_keys_spec.rb +0 -210
  135. data/spec/rest/api_keys/permissions_spec.rb +0 -65
  136. data/spec/rest/campaigns/campaigns_spec.rb +0 -492
  137. data/spec/rest/categories/categories_spec.rb +0 -96
  138. data/spec/rest/contacts/custom_fields_spec.rb +0 -174
  139. data/spec/rest/contacts/lists_spec.rb +0 -372
  140. data/spec/rest/contacts/recipients_spec.rb +0 -343
  141. data/spec/rest/contacts/reserved_fields_spec.rb +0 -146
  142. data/spec/rest/contacts/segments_spec.rb +0 -307
  143. data/spec/rest/email_activity/email_activity_spec.rb +0 -179
  144. data/spec/rest/templates/templates_spec.rb +0 -222
  145. data/spec/rest/templates/versions_spec.rb +0 -252
@@ -0,0 +1,63 @@
1
+ # encoding: utf-8
2
+ require File.dirname(__FILE__) + '/../../spec_helper'
3
+
4
+ module SendGrid4r::REST
5
+ describe Mail do
6
+ describe 'unit test', :ut do
7
+ before do
8
+ Dotenv.load
9
+ end
10
+
11
+ it '#to_h with mandatory parameters' do
12
+ settings =
13
+ SendGrid4r::Factory::MailFactory.create_tracking_settings
14
+ expect(settings.to_h).to eq({})
15
+ end
16
+
17
+ it '#to_h with full parameters enable' do
18
+ settings =
19
+ SendGrid4r::Factory::MailFactory.create_tracking_settings
20
+ settings.enable_click_tracking(true)
21
+ settings.enable_open_tracking('<tag>')
22
+ settings.enable_subscription_tracking('text', 'html', '<tag>')
23
+ settings.enable_ganalytics(
24
+ 'source', 'medium', 'term', 'content', 'campaign'
25
+ )
26
+ expect(settings.to_h).to eq(
27
+ click_tracking: { enable: true, enable_text: true },
28
+ open_tracking: {
29
+ enable: true,
30
+ substitution_tag: '<tag>'
31
+ },
32
+ subscription_tracking: {
33
+ enable: true, text: 'text', html: 'html',
34
+ substitution_tag: '<tag>'
35
+ },
36
+ ganalytics: {
37
+ enable: true,
38
+ utm_source: 'source',
39
+ utm_medium: 'medium',
40
+ utm_term: 'term',
41
+ utm_content: 'content',
42
+ utm_campaign: 'campaign'
43
+ }
44
+ )
45
+ end
46
+
47
+ it '#to_h with full parameters disable' do
48
+ settings =
49
+ SendGrid4r::Factory::MailFactory.create_tracking_settings
50
+ settings.disable_click_tracking
51
+ settings.disable_open_tracking
52
+ settings.disable_subscription_tracking
53
+ settings.disable_ganalytics
54
+ expect(settings.to_h).to eq(
55
+ click_tracking: { enable: false },
56
+ open_tracking: { enable: false },
57
+ subscription_tracking: { enable: false },
58
+ ganalytics: { enable: false }
59
+ )
60
+ end
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,146 @@
1
+ # encoding: utf-8
2
+ require File.dirname(__FILE__) + '/../../../spec_helper'
3
+
4
+ module SendGrid4r::REST::MarketingCampaigns::Contacts
5
+ describe CustomFields 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
+ @name1 = 'birthday'
11
+ @type1 = 'text'
12
+ @name2 = 'born_at'
13
+ @type2 = 'date'
14
+
15
+ # celan up test env
16
+ fields = @client.get_custom_fields
17
+ fields.custom_fields.each do |field|
18
+ next if field.name != @name1 && field.name != @name2
19
+ @client.delete_custom_field(custom_field_id: field.id)
20
+ end
21
+ # post a custom field
22
+ @new_field = @client.post_custom_field(name: @name1, type: @type1)
23
+ end
24
+
25
+ context 'without block call' do
26
+ it '#post_custom_field' do
27
+ new_field = @client.post_custom_field(name: @name2, type: @type2)
28
+ expect(new_field.id).to be_a(Fixnum)
29
+ expect(new_field.name).to eq(@name2)
30
+ expect(new_field.type).to eq(@type2)
31
+ end
32
+
33
+ it '#post_custom_field for same key' do
34
+ expect do
35
+ @client.post_custom_field(name: @name1, type: @type1)
36
+ end.to raise_error(RestClient::BadRequest)
37
+ end
38
+
39
+ it '#get_custom_fields' do
40
+ fields = @client.get_custom_fields
41
+ expect(fields.length).to be >= 1
42
+ fields.custom_fields.each do |field|
43
+ next if field.name != @name1
44
+ expect(field.id).to eq(@new_field.id)
45
+ expect(field.name).to eq(@new_field.name)
46
+ expect(field.type).to eq(@new_field.type)
47
+ end
48
+ end
49
+
50
+ it '#get_custom_field' do
51
+ actual_field = @client.get_custom_field(
52
+ custom_field_id: @new_field.id
53
+ )
54
+ expect(actual_field.id).to eq(@new_field.id)
55
+ expect(actual_field.name).to eq(@new_field.name)
56
+ expect(actual_field.type).to eq(@new_field.type)
57
+ end
58
+
59
+ it '#delete_custom_field' do
60
+ @client.delete_custom_field(custom_field_id: @new_field.id)
61
+ end
62
+ end
63
+ end
64
+
65
+ describe 'unit test', :ut do
66
+ let(:client) do
67
+ SendGrid4r::Client.new(api_key: '')
68
+ end
69
+
70
+ let(:field) do
71
+ JSON.parse(
72
+ '{'\
73
+ '"id": 1,'\
74
+ '"name": "pet",'\
75
+ '"type": "text"'\
76
+ '}'
77
+ )
78
+ end
79
+
80
+ let(:fields) do
81
+ JSON.parse(
82
+ '{'\
83
+ '"custom_fields": ['\
84
+ '{'\
85
+ '"id": 1,'\
86
+ '"name": "birthday",'\
87
+ '"type": "date"'\
88
+ '},'\
89
+ '{'\
90
+ '"id": 2,'\
91
+ '"name": "middle_name",'\
92
+ '"type": "text"'\
93
+ '},'\
94
+ '{'\
95
+ '"id": 3,'\
96
+ '"name": "favorite_number",'\
97
+ '"type": "number"'\
98
+ '}'\
99
+ ']'\
100
+ '}'
101
+ )
102
+ end
103
+
104
+ it '#post_custom_field' do
105
+ allow(client).to receive(:execute).and_return(field)
106
+ actual = client.post_custom_field(name: '', type: '')
107
+ expect(actual).to be_a(CustomFields::Field)
108
+ end
109
+
110
+ it '#get_custom_fields' do
111
+ allow(client).to receive(:execute).and_return(fields)
112
+ actual = client.get_custom_fields
113
+ expect(actual).to be_a(CustomFields::Fields)
114
+ end
115
+
116
+ it '#get_custom_field' do
117
+ allow(client).to receive(:execute).and_return(field)
118
+ actual = client.get_custom_field(custom_field_id: 0)
119
+ expect(actual).to be_a(CustomFields::Field)
120
+ end
121
+
122
+ it '#delete_custom_field' do
123
+ allow(client).to receive(:execute).and_return('')
124
+ actual = client.delete_custom_field(custom_field_id: 0)
125
+ expect(actual).to eq('')
126
+ end
127
+
128
+ it 'creates field instance' do
129
+ actual = CustomFields.create_field(field)
130
+ expect(actual).to be_a(CustomFields::Field)
131
+ expect(actual.id).to eq(1)
132
+ expect(actual.name).to eq('pet')
133
+ expect(actual.type).to eq('text')
134
+ end
135
+
136
+ it 'creates fields instance' do
137
+ actual = CustomFields.create_fields(fields)
138
+ expect(actual).to be_a(CustomFields::Fields)
139
+ expect(actual.custom_fields).to be_a(Array)
140
+ actual.custom_fields.each do |field|
141
+ expect(field).to be_a(CustomFields::Field)
142
+ end
143
+ end
144
+ end
145
+ end
146
+ end
@@ -0,0 +1,307 @@
1
+ # encoding: utf-8
2
+ require File.dirname(__FILE__) + '/../../../spec_helper'
3
+
4
+ module SendGrid4r::REST::MarketingCampaigns::Contacts
5
+ describe Lists 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
+ @list_name1 = 'test_list1'
11
+ @edit_name1 = 'test_list1_edit'
12
+ @list_name2 = 'test_list2'
13
+ @email1 = 'jones@example.com'
14
+ @email2 = 'miller@example.com'
15
+ @last_name1 = 'Jones'
16
+ @last_name2 = 'Miller'
17
+ @pet1 = 'Fluffy'
18
+ @pet2 = 'FrouFrou'
19
+
20
+ # celan up test env(lists)
21
+ lists = @client.get_lists
22
+ lists.lists.each do |list|
23
+ @client.delete_list(list_id: list.id) if list.name == @list_name1
24
+ @client.delete_list(list_id: list.id) if list.name == @edit_name1
25
+ @client.delete_list(list_id: list.id) if list.name == @list_name2
26
+ end
27
+ # celan up test env(recipients)
28
+ recipients = @client.get_recipients
29
+ recipients.recipients.each do |recipient|
30
+ @client.delete_recipient(
31
+ recipient_id: recipient.id
32
+ ) if recipient.email == @email1
33
+ @client.delete_recipient(
34
+ recipient_id: recipient.id
35
+ ) if recipient.email == @email2
36
+ end
37
+ # post a first list
38
+ @list1 = @client.post_list(name: @list_name1)
39
+ # add multiple recipients
40
+ recipient1 = {}
41
+ recipient1['email'] = @email1
42
+ recipient1['last_name'] = @last_name1
43
+ recipient2 = {}
44
+ recipient2['email'] = @email2
45
+ recipient2['last_name'] = @last_name2
46
+ result = @client.post_recipients(params: [recipient1, recipient2])
47
+ @recipients = result.persisted_recipients
48
+ @client.post_recipient_to_list(
49
+ list_id: @list1.id, recipient_id: result.persisted_recipients[0]
50
+ )
51
+ @client.post_recipient_to_list(
52
+ list_id: @list1.id, recipient_id: result.persisted_recipients[1]
53
+ )
54
+ end
55
+
56
+ context 'without block call' do
57
+ it '#post_list' do
58
+ list2 = @client.post_list(name: @list_name2)
59
+ expect(list2.id).to be_a(Fixnum)
60
+ expect(list2.name).to eq(@list_name2)
61
+ expect(list2.recipient_count).to eq(0)
62
+ @client.delete_list(list_id: list2.id)
63
+ end
64
+
65
+ it '#post_list for same key' do
66
+ expect do
67
+ @client.post_list(name: @list_name1)
68
+ end.to raise_error(RestClient::BadRequest)
69
+ end
70
+
71
+ it '#get_lists' do
72
+ lists = @client.get_lists
73
+ expect(lists.length).to be >= 1
74
+ lists.lists.each do |list|
75
+ next if list.name != @list_name1
76
+ expect(list.id).to eq(@list1.id)
77
+ expect(list.name).to eq(@list1.name)
78
+ expect(list.recipient_count).to be_a(Fixnum)
79
+ end
80
+ end
81
+
82
+ it '#get_list' do
83
+ actual_list = @client.get_list(list_id: @list1.id)
84
+ expect(actual_list.id).to eq(@list1.id)
85
+ expect(actual_list.name).to eq(@list1.name)
86
+ expect(actual_list.recipient_count).to be_a(Fixnum)
87
+ end
88
+
89
+ it '#patch_list' do
90
+ edit_list = @client.patch_list(list_id: @list1.id, name: @edit_name1)
91
+ expect(edit_list.id).to eq(@list1.id)
92
+ expect(edit_list.name).to eq(@edit_name1)
93
+ end
94
+
95
+ it '#get_recipients_from_list' do
96
+ recipients = @client.get_recipients_from_list(list_id: @list1.id)
97
+ recipients.recipients.each do |recipient|
98
+ expect(recipient).to be_a(Recipients::Recipient)
99
+ end
100
+ end
101
+
102
+ it '#get_recipients_from_list with offset & limit' do
103
+ recipients = @client.get_recipients_from_list(
104
+ list_id: @list1.id, page: 1, page_size: 10
105
+ )
106
+ recipients.recipients.each do |recipient|
107
+ expect(recipient).to be_a(Recipients::Recipient)
108
+ end
109
+ end
110
+
111
+ it '#delete_recipient_from_list' do
112
+ @client.delete_recipient_from_list(
113
+ list_id: @list1.id, recipient_id: @recipients[0]
114
+ )
115
+ end
116
+
117
+ it '#delete_list' do
118
+ @client.delete_list(list_id: @list1.id)
119
+ expect do
120
+ @client.get_list(list_id: @list1.id)
121
+ end.to raise_error(RestClient::ResourceNotFound)
122
+ end
123
+
124
+ it '#delete_lists' do
125
+ list2 = @client.post_list(name: @list_name2)
126
+ @client.delete_lists(list_ids: [@list1.id, list2.id])
127
+ end
128
+
129
+ it '#post_recipients_to_list' do
130
+ @client.post_recipients_to_list(
131
+ list_id: @list1.id, recipients: @recipients
132
+ )
133
+ end
134
+
135
+ it '#post_recipient_to_list' do
136
+ recipient1 = {}
137
+ recipient1['email'] = @email1
138
+ recipient1['last_name'] = @last_name1
139
+ result = @client.post_recipients(params: [recipient1])
140
+ @client.post_recipient_to_list(
141
+ list_id: @list1.id, recipient_id: result.persisted_recipients[0]
142
+ )
143
+ end
144
+ end
145
+ end
146
+
147
+ describe 'unit test', :ut do
148
+ let(:client) do
149
+ SendGrid4r::Client.new(api_key: '')
150
+ end
151
+
152
+ let(:list) do
153
+ JSON.parse(
154
+ '{'\
155
+ '"id": 1,'\
156
+ '"name": "listname",'\
157
+ '"recipient_count": 0'\
158
+ '}'
159
+ )
160
+ end
161
+
162
+ let(:lists) do
163
+ JSON.parse(
164
+ '{'\
165
+ '"lists": ['\
166
+ '{'\
167
+ '"id": 1,'\
168
+ '"name": "the jones",'\
169
+ '"recipient_count": 1'\
170
+ '}'\
171
+ ']'\
172
+ '}'
173
+ )
174
+ end
175
+
176
+ let(:recipient) do
177
+ JSON.parse(
178
+ '{'\
179
+ '"created_at": 1422313607,'\
180
+ '"email": "jones@example.com",'\
181
+ '"first_name": null,'\
182
+ '"id": "jones@example.com",'\
183
+ '"last_clicked": null,'\
184
+ '"last_emailed": null,'\
185
+ '"last_name": "Jones",'\
186
+ '"last_opened": null,'\
187
+ '"updated_at": 1422313790,'\
188
+ '"custom_fields": ['\
189
+ '{'\
190
+ '"id": 23,'\
191
+ '"name": "pet",'\
192
+ '"value": "Fluffy",'\
193
+ '"type": "text"'\
194
+ '}'\
195
+ ']'\
196
+ '}'
197
+ )
198
+ end
199
+
200
+ let(:recipients) do
201
+ JSON.parse(
202
+ '{'\
203
+ '"recipients": ['\
204
+ '{'\
205
+ '"created_at": 1422313607,'\
206
+ '"email": "jones@example.com",'\
207
+ '"first_name": null,'\
208
+ '"id": "jones@example.com",'\
209
+ '"last_clicked": null,'\
210
+ '"last_emailed": null,'\
211
+ '"last_name": "Jones",'\
212
+ '"last_opened": null,'\
213
+ '"updated_at": 1422313790,'\
214
+ '"custom_fields": ['\
215
+ '{'\
216
+ '"id": 23,'\
217
+ '"name": "pet",'\
218
+ '"value": "Fluffy",'\
219
+ '"type": "text"'\
220
+ '}'\
221
+ ']'\
222
+ '}'\
223
+ ']'\
224
+ '}'
225
+ )
226
+ end
227
+
228
+ it '#post_list' do
229
+ allow(client).to receive(:execute).and_return(list)
230
+ actual = client.post_list(name: '')
231
+ expect(actual).to be_a(Lists::List)
232
+ end
233
+
234
+ it '#get_lists' do
235
+ allow(client).to receive(:execute).and_return(lists)
236
+ actual = client.get_lists
237
+ expect(actual).to be_a(Lists::Lists)
238
+ end
239
+
240
+ it '#get_list' do
241
+ allow(client).to receive(:execute).and_return(list)
242
+ actual = client.get_list(list_id: 0)
243
+ expect(actual).to be_a(Lists::List)
244
+ end
245
+
246
+ it '#patch_list' do
247
+ allow(client).to receive(:execute).and_return(list)
248
+ actual = client.patch_list(list_id: 0, name: '')
249
+ expect(actual).to be_a(Lists::List)
250
+ end
251
+
252
+ it '#get_recipients_from_list' do
253
+ allow(client).to receive(:execute).and_return(recipients)
254
+ actual = client.get_recipients_from_list(list_id: 0)
255
+ expect(actual).to be_a(Recipients::Recipients)
256
+ end
257
+
258
+ it '#delete_recipient_from_list' do
259
+ allow(client).to receive(:execute).and_return('')
260
+ actual = client.delete_recipient_from_list(list_id: 0, recipient_id: '')
261
+ expect(actual).to eq('')
262
+ end
263
+
264
+ it '#delete_list' do
265
+ allow(client).to receive(:execute).and_return('')
266
+ actual = client.delete_list(list_id: 0)
267
+ expect(actual).to eq('')
268
+ end
269
+
270
+ it '#delete_lists' do
271
+ allow(client).to receive(:execute).and_return('')
272
+ actual = client.delete_lists(list_ids: [0, 1])
273
+ expect(actual).to eq('')
274
+ end
275
+
276
+ it '#post_recipients_to_list' do
277
+ allow(client).to receive(:execute).and_return('')
278
+ actual = client.post_recipients_to_list(
279
+ list_id: 0, recipients: ['', '']
280
+ )
281
+ expect(actual).to eq('')
282
+ end
283
+
284
+ it '#post_recipient_to_list' do
285
+ allow(client).to receive(:execute).and_return('')
286
+ actual = client.post_recipient_to_list(list_id: 0, recipient_id: 0)
287
+ expect(actual).to eq('')
288
+ end
289
+
290
+ it 'creates list instance' do
291
+ actual = Lists.create_list(list)
292
+ expect(actual).to be_a(Lists::List)
293
+ expect(actual.id).to eq(1)
294
+ expect(actual.name).to eq('listname')
295
+ expect(actual.recipient_count).to eq(0)
296
+ end
297
+
298
+ it 'creates lists instance' do
299
+ actual = Lists.create_lists(lists)
300
+ expect(actual.lists).to be_a(Array)
301
+ actual.lists.each do |list|
302
+ expect(list).to be_a(Lists::List)
303
+ end
304
+ end
305
+ end
306
+ end
307
+ end