sendgrid4r 0.1.0 → 0.2.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.
@@ -11,52 +11,52 @@ module SendGrid4r
11
11
  # SendGrid Web API v3 Request
12
12
  #
13
13
  module Request
14
- def get(auth, endpoint, params = nil)
15
- resource = RestClient::Resource.new(
16
- endpoint, auth.username, auth.password)
17
- p = { params: params } unless params.nil?
18
- if p.nil?
19
- body = resource.get
20
- else
21
- body = resource.get(p)
22
- # TODO: handle ratelimit headers
23
- # do |response, request, result, &block|
24
- # # puts response.headers
25
- # break response.body
26
- # end
27
- end
28
- JSON.parse(body)
14
+ # TODO: handle ratelimit headers
15
+ def get(auth, endpoint, params = nil, payload = nil)
16
+ execute(:get, auth, endpoint, params, payload)
29
17
  end
30
18
 
31
- def post(auth, endpoint, params = nil)
32
- resource = RestClient::Resource.new(
33
- endpoint, auth.username, auth.password)
34
- if params.nil?
35
- body = resource.post(content_type: :json).body
36
- else
37
- body = resource.post(params.to_json, content_type: :json).body
38
- end
39
- JSON.parse(body)
19
+ def post(auth, endpoint, payload = nil)
20
+ execute(:post, auth, endpoint, nil, payload)
21
+ end
22
+
23
+ def patch(auth, endpoint, payload)
24
+ execute(:patch, auth, endpoint, nil, payload)
40
25
  end
41
26
 
42
- def patch(auth, endpoint, params)
43
- resource = RestClient::Resource.new(
44
- endpoint, auth.username, auth.password)
45
- body = resource.patch(params.to_json, content_type: :json).body
46
- JSON.parse(body)
27
+ def put(auth, endpoint, payload)
28
+ execute(:put, auth, endpoint, nil, payload)
47
29
  end
48
30
 
49
- def put(auth, endpoint, params)
50
- resource = RestClient::Resource.new(
51
- endpoint, auth.username, auth.password)
52
- body = resource.put(params.to_json, content_type: :json).body
53
- JSON.parse(body)
31
+ def delete(auth, endpoint, payload = nil)
32
+ execute(:delete, auth, endpoint, nil, payload)
54
33
  end
55
34
 
56
- def delete(auth, endpoint)
57
- resource = RestClient::Resource.new(
58
- endpoint, auth.username, auth.password)
59
- resource.delete
35
+ def execute(method, auth, endpoint, params, payload)
36
+ args = {}
37
+ args[:method] = method
38
+ args[:url] = process_url_params(endpoint, params)
39
+ args[:user] = auth.username
40
+ args[:password] = auth.password
41
+ args[:headers] = { content_type: :json }
42
+ args[:payload] = payload.to_json unless payload.nil?
43
+ body = RestClient::Request.execute(args)
44
+ if body.nil? || body.length < 2
45
+ body
46
+ else
47
+ JSON.parse(body)
48
+ end
49
+ end
50
+
51
+ def process_url_params(endpoint, params)
52
+ if params.nil? || params.empty?
53
+ endpoint
54
+ else
55
+ query_string = params.collect do |k, v|
56
+ "#{k}=#{CGI.escape(v.to_s)}"
57
+ end.join('&')
58
+ endpoint + "?#{query_string}"
59
+ end
60
60
  end
61
61
  end
62
62
  end
@@ -18,7 +18,6 @@ module SendGrid4r
18
18
  aggregated_by: aggregated_by,
19
19
  categories: categories
20
20
  }
21
- # TODO: categories does not support array yet
22
21
  resp_a = get(
23
22
  @auth, "#{SendGrid4r::Client::BASE_URL}/categories/stats", params)
24
23
  SendGrid4r::REST::Stats.create_top_stats(resp_a)
@@ -2,5 +2,5 @@
2
2
  # SendGrid API v3 wrapper implementation.
3
3
  #
4
4
  module SendGrid4r
5
- VERSION = '0.1.0'
5
+ VERSION = '0.2.0'
6
6
  end
@@ -38,9 +38,12 @@ describe 'SendGrid4r::REST::Asm::Groups::Suppressions' do
38
38
  # get the suppressions
39
39
  suppressions = @client.get_suppressions(@email1)
40
40
  expect(suppressions.length >= 1).to eq(true)
41
- expect(suppressions[0].name).to eq(@group_name)
42
- expect(suppressions[0].description).to eq(@group_desc)
43
- expect(suppressions[0].suppressed).to eq(true)
41
+ suppressions.each do |suppression|
42
+ next unless suppression.name == @group_name
43
+ expect(suppression.name).to eq(@group_name)
44
+ expect(suppression.description).to eq(@group_desc)
45
+ expect(suppression.suppressed).to eq(true)
46
+ end
44
47
  # get the recipient emails
45
48
  actual_emails = @client.get_suppressed_emails(new_group.id)
46
49
  expect(actual_emails.length).to eq(suppressed_emails.length)
data/spec/client_spec.rb CHANGED
@@ -87,12 +87,49 @@ describe 'SendGrid4r::Client' do
87
87
  expect(@client.respond_to?('get_esp_stats')).to eq(true)
88
88
  expect(@client.respond_to?('get_browsers_stats')).to eq(true)
89
89
  expect(@client.respond_to?('get_parse_stats')).to eq(true)
90
+ # Contacts
91
+ # CustomFields
92
+ expect(@client.respond_to?('post_custom_field')).to eq(true)
93
+ expect(@client.respond_to?('get_custom_fields')).to eq(true)
94
+ expect(@client.respond_to?('get_custom_field')).to eq(true)
95
+ expect(@client.respond_to?('delete_custom_field')).to eq(true)
96
+ # Lists
97
+ expect(@client.respond_to?('post_list')).to eq(true)
98
+ expect(@client.respond_to?('get_lists')).to eq(true)
99
+ expect(@client.respond_to?('get_list')).to eq(true)
100
+ expect(@client.respond_to?('patch_list')).to eq(true)
101
+ expect(@client.respond_to?('delete_list')).to eq(true)
102
+ expect(@client.respond_to?('post_recipients_to_list')).to eq(true)
103
+ expect(@client.respond_to?('get_recipients_from_list')).to eq(true)
104
+ expect(@client.respond_to?('post_recipients_to_list')).to eq(true)
105
+ expect(@client.respond_to?('delete_recipient_from_list')).to eq(true)
106
+ expect(@client.respond_to?('delete_lists')).to eq(true)
107
+ # Recipients
108
+ expect(@client.respond_to?('post_recipient')).to eq(true)
109
+ expect(@client.respond_to?('delete_recipients')).to eq(true)
110
+ expect(@client.respond_to?('get_recipients')).to eq(true)
111
+ expect(@client.respond_to?('get_recipients_by_id')).to eq(true)
112
+ expect(@client.respond_to?('get_recipients_count')).to eq(true)
113
+ expect(@client.respond_to?('search_recipients')).to eq(true)
114
+ expect(@client.respond_to?('get_recipient')).to eq(true)
115
+ expect(@client.respond_to?('delete_recipient')).to eq(true)
116
+ expect(@client.respond_to?('get_lists_recipient_belong')).to eq(true)
117
+ expect(@client.respond_to?('post_recipients')).to eq(true)
118
+ # ReservedFields
119
+ expect(@client.respond_to?('get_reserved_fields')).to eq(true)
120
+ # Segments
121
+ expect(@client.respond_to?('post_segment')).to eq(true)
122
+ expect(@client.respond_to?('get_segments')).to eq(true)
123
+ expect(@client.respond_to?('get_segment')).to eq(true)
124
+ expect(@client.respond_to?('put_segment')).to eq(true)
125
+ expect(@client.respond_to?('delete_segment')).to eq(true)
126
+ expect(@client.respond_to?('get_recipients_from_segment')).to eq(true)
90
127
  end
91
128
  end
92
129
 
93
130
  describe 'VERSION' do
94
131
  it 'returns VERSION value' do
95
- expect(SendGrid4r::VERSION).to eq('0.1.0')
132
+ expect(SendGrid4r::VERSION).to eq('0.2.0')
96
133
  end
97
134
  end
98
135
  end
@@ -0,0 +1,102 @@
1
+ # encoding: utf-8
2
+ require File.dirname(__FILE__) + '/../spec_helper'
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
15
+ begin
16
+ # celan up test env
17
+ fields = @client.get_custom_fields
18
+ expect(fields.custom_fields.length >= 0).to eq(true)
19
+ fields.custom_fields.each do |field|
20
+ next if field.name != @name
21
+ @client.delete_custom_field(field.id)
22
+ end
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)
51
+ rescue => e
52
+ puts e.inspect
53
+ raise e
54
+ end
55
+ end
56
+
57
+ it 'creates field instance' do
58
+ json =
59
+ '{'\
60
+ '"id": 1,'\
61
+ '"name": "pet",'\
62
+ '"type": "text"'\
63
+ '}'
64
+ hash = JSON.parse(json)
65
+ actual = SendGrid4r::REST::Contacts::CustomFields.create_field(hash)
66
+ expect(actual.id).to eq(1)
67
+ expect(actual.name).to eq('pet')
68
+ expect(actual.type).to eq('text')
69
+ end
70
+
71
+ it 'creates fields instance' do
72
+ json =
73
+ '{'\
74
+ '"custom_fields": ['\
75
+ '{'\
76
+ '"id": 1,'\
77
+ '"name": "birthday",'\
78
+ '"type": "date"'\
79
+ '},'\
80
+ '{'\
81
+ '"id": 2,'\
82
+ '"name": "middle_name",'\
83
+ '"type": "text"'\
84
+ '},'\
85
+ '{'\
86
+ '"id": 3,'\
87
+ '"name": "favorite_number",'\
88
+ '"type": "number"'\
89
+ '}'\
90
+ ']'\
91
+ '}'
92
+ hash = JSON.parse(json)
93
+ actual = SendGrid4r::REST::Contacts::CustomFields.create_fields(hash)
94
+ expect(actual.custom_fields.is_a?(Array)).to eq(true)
95
+ actual.custom_fields.each do |field|
96
+ expect(
97
+ field.is_a?(SendGrid4r::REST::Contacts::CustomFields::Field)
98
+ ).to eq(true)
99
+ end
100
+ end
101
+ end
102
+ end
@@ -0,0 +1,150 @@
1
+ # encoding: utf-8
2
+ require File.dirname(__FILE__) + '/../spec_helper'
3
+
4
+ describe 'SendGrid4r::REST::Contacts::Lists' do
5
+ context 'it test' do
6
+ before :all do
7
+ Dotenv.load
8
+ @client = SendGrid4r::Client.new(
9
+ ENV['SENDGRID_USERNAME'], ENV['SENDGRID_PASSWORD'])
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
+ @custom_field_name = 'pet'
20
+ @recipients = [@email1, @email2]
21
+ end
22
+
23
+ it 'is normal' do
24
+ begin
25
+ # celan up test env(lists)
26
+ lists = @client.get_lists
27
+ expect(lists.lists.length >= 0).to eq(true)
28
+ lists.lists.each do |list|
29
+ @client.delete_list(list.id) if list.name == @list_name1
30
+ @client.delete_list(list.id) if list.name == @edit_name1
31
+ @client.delete_list(list.id) if list.name == @list_name2
32
+ end
33
+ # celan up test env(recipients)
34
+ recipients = @client.get_recipients
35
+ expect(recipients.recipients.length >= 0).to eq(true)
36
+ recipients.recipients.each do |recipient|
37
+ @client.delete_recipient(recipient.id) if recipient.email == @email1
38
+ @client.delete_recipient(recipient.id) if recipient.email == @email2
39
+ end
40
+ # post a first list
41
+ new_list = @client.post_list(@list_name1)
42
+ expect(new_list.id.is_a?(Fixnum)).to eq(true)
43
+ expect(new_list.name).to eq(@list_name1)
44
+ expect(new_list.recipient_count).to eq(0)
45
+ # post same list
46
+ expect do
47
+ @client.post_list(@list_name1)
48
+ end.to raise_error(RestClient::BadRequest)
49
+ # get all list
50
+ lists = @client.get_lists
51
+ expect(lists.length >= 1).to eq(true)
52
+ lists.lists.each do |list|
53
+ next if list.name != @list_name1
54
+ expect(list.id).to eq(new_list.id)
55
+ expect(list.name).to eq(new_list.name)
56
+ expect(list.recipient_count).to eq(0)
57
+ end
58
+ # get a single list
59
+ actual_list = @client.get_list(new_list.id)
60
+ expect(actual_list.id).to eq(new_list.id)
61
+ expect(actual_list.name).to eq(new_list.name)
62
+ expect(actual_list.recipient_count).to eq(0)
63
+ # update the list
64
+ edit_list = @client.patch_list(new_list.id, @edit_name1)
65
+ expect(edit_list.id).to eq(new_list.id)
66
+ expect(edit_list.name).to eq(@edit_name1)
67
+ # add multiple recipients
68
+ recipient1 = {}
69
+ recipient1['email'] = @email1
70
+ recipient1['last_name'] = @last_name1
71
+ recipient1[@custom_field_name] = @pet1
72
+ @client.post_recipient(recipient1)
73
+ recipient2 = {}
74
+ recipient2['email'] = @email2
75
+ recipient2['last_name'] = @last_name2
76
+ recipient2[@custom_field_name] = @pet2
77
+ @client.post_recipient(recipient2)
78
+ # Add multiple recipients to a single list
79
+ @client.post_recipients_to_list(edit_list.id, @recipients)
80
+ # list recipients from a single list
81
+ recipients = @client.get_recipients_from_list(new_list.id)
82
+ recipients.recipients.each do |recipient|
83
+ expect(
84
+ recipient.is_a?(SendGrid4r::REST::Contacts::Recipients::Recipient)
85
+ ).to eq(true)
86
+ end
87
+ # list recipients from a single list with offset & limit
88
+ recipients = @client.get_recipients_from_list(new_list.id, 10, 0)
89
+ recipients.recipients.each do |recipient|
90
+ expect(
91
+ recipient.is_a?(SendGrid4r::REST::Contacts::Recipients::Recipient)
92
+ ).to eq(true)
93
+ end
94
+ # Add single recipient to a list
95
+ @client.post_recipient_to_list(edit_list.id, @email1)
96
+ # delete a single recipient from a single list
97
+ @client.delete_recipient_from_list(edit_list.id, @email1)
98
+ # delete the list
99
+ @client.delete_list(new_list.id)
100
+ expect do
101
+ @client.get_list(new_list.id)
102
+ end.to raise_error(RestClient::ResourceNotFound)
103
+ # post 2 lists
104
+ list1 = @client.post_list(@list_name1)
105
+ list2 = @client.post_list(@list_name2)
106
+ @client.delete_lists([list1.id, list2.id])
107
+ rescue => e
108
+ puts e.inspect
109
+ raise e
110
+ end
111
+ end
112
+ end
113
+
114
+ context 'unit test' do
115
+ it 'creates list instance' do
116
+ json =
117
+ '{'\
118
+ '"id": 1,'\
119
+ '"name": "listname",'\
120
+ '"recipient_count": 0'\
121
+ '}'
122
+ hash = JSON.parse(json)
123
+ actual = SendGrid4r::REST::Contacts::Lists.create_list(hash)
124
+ expect(actual.id).to eq(1)
125
+ expect(actual.name).to eq('listname')
126
+ expect(actual.recipient_count).to eq(0)
127
+ end
128
+
129
+ it 'creates lists instance' do
130
+ json =
131
+ '{'\
132
+ '"lists": ['\
133
+ '{'\
134
+ '"id": 1,'\
135
+ '"name": "the jones",'\
136
+ '"recipient_count": 1'\
137
+ '}'\
138
+ ']'\
139
+ '}'
140
+ hash = JSON.parse(json)
141
+ actual = SendGrid4r::REST::Contacts::Lists.create_lists(hash)
142
+ expect(actual.lists.is_a?(Array)).to eq(true)
143
+ actual.lists.each do |list|
144
+ expect(
145
+ list.is_a?(SendGrid4r::REST::Contacts::Lists::List)
146
+ ).to eq(true)
147
+ end
148
+ end
149
+ end
150
+ end
@@ -0,0 +1,200 @@
1
+ # encoding: utf-8
2
+ require File.dirname(__FILE__) + '/../spec_helper'
3
+
4
+ describe 'SendGrid4r::REST::Contacts::Recipients' do
5
+ before :all do
6
+ Dotenv.load
7
+ @client = SendGrid4r::Client.new(
8
+ ENV['SENDGRID_USERNAME'], ENV['SENDGRID_PASSWORD'])
9
+ @email1 = 'jones@example.com'
10
+ @email2 = 'miller@example.com'
11
+ @last_name1 = 'Jones'
12
+ @last_name2 = 'Miller'
13
+ @pet1 = 'Fluffy'
14
+ @pet2 = 'FrouFrou'
15
+ @custom_field_name = 'pet'
16
+ end
17
+
18
+ context 'always' do
19
+ it 'is normal' do
20
+ begin
21
+ # celan up test env
22
+ recipients = @client.get_recipients
23
+ expect(recipients.recipients.length >= 0).to eq(true)
24
+ recipients.recipients.each do |recipient|
25
+ next if recipient.email != @email1
26
+ @client.delete_recipient(recipient.id)
27
+ end
28
+ custom_fields = @client.get_custom_fields
29
+ custom_fields.custom_fields.each do |custom_field|
30
+ next if custom_field.name != @custom_field_name
31
+ @client.delete_custom_field(custom_field.id)
32
+ end
33
+ @client.post_custom_field(@custom_field_name, 'text')
34
+ # post a recipient
35
+ params = {}
36
+ params['email'] = @email1
37
+ params['last_name'] = @last_name1
38
+ params[@custom_field_name] = @pet1
39
+ new_recipient = @client.post_recipient(params)
40
+ expect(new_recipient.created_at.is_a?(Fixnum)).to eq(true)
41
+ new_recipient.custom_fields.each do |custom_field|
42
+ expect(
43
+ custom_field.is_a?(
44
+ SendGrid4r::REST::Contacts::CustomFields::Field
45
+ )
46
+ ).to eq(true)
47
+ end
48
+ expect(new_recipient.email).to eq(@email1)
49
+ expect(new_recipient.first_name).to eq(nil)
50
+ expect(new_recipient.id).to eq(@email1)
51
+ expect(new_recipient.last_clicked).to eq(nil)
52
+ expect(new_recipient.last_emailed).to eq(nil)
53
+ expect(new_recipient.last_name).to eq(@last_name1)
54
+ expect(new_recipient.last_opened).to eq(nil)
55
+ expect(new_recipient.updated_at.is_a?(Fixnum)).to eq(true)
56
+ # post same recipients
57
+ @client.post_recipient(params)
58
+ # get all recipients
59
+ recipients = @client.get_recipients(100, 0)
60
+ expect(recipients.recipients.length > 0).to eq(true)
61
+ recipients.recipients.each do |recipient|
62
+ expect(
63
+ recipient.is_a?(SendGrid4r::REST::Contacts::Recipients::Recipient)
64
+ ).to eq(true)
65
+ end
66
+ # get multiple recipients
67
+ recipient_ids = [@email1, @email2]
68
+ actual_recipients = @client.get_recipients_by_id(recipient_ids)
69
+ expect(actual_recipients.recipients.is_a?(Array)).to eq(true)
70
+ expect(actual_recipients.recipients.length).to eq(2)
71
+ actual_recipients.recipients.each do |recipient|
72
+ expect(
73
+ recipient.is_a?(SendGrid4r::REST::Contacts::Recipients::Recipient)
74
+ ).to eq(true)
75
+ end
76
+ # read a count of recipients
77
+ actual_count = @client.get_recipients_count
78
+ expect(actual_count > 0).to eq(true)
79
+ # Search recipients
80
+ params = {}
81
+ params['email'] = @email1
82
+ recipients = @client.search_recipients(params)
83
+ expect(recipients.recipients.length).to eq(1)
84
+ # get a single recipient
85
+ recipient = @client.get_recipient(new_recipient.id)
86
+ expect(
87
+ recipient.is_a?(SendGrid4r::REST::Contacts::Recipients::Recipient)
88
+ ).to eq(true)
89
+ # List the recipient lists to which the recipient belongs
90
+ lists = @client.get_lists_recipient_belong(new_recipient.id)
91
+ lists.lists.each do |list|
92
+ expect(
93
+ list.is_a?(SendGrid4r::REST::Contacts::Lists::List)
94
+ ).to eq(true)
95
+ end
96
+ # add multiple recipients
97
+ recipient1 = {}
98
+ recipient1['email'] = @email1
99
+ recipient1['last_name'] = @last_name1
100
+ recipient1[@custom_field_name] = @pet1
101
+ recipient2 = {}
102
+ recipient2['email'] = @email2
103
+ recipient2['last_name'] = @last_name2
104
+ recipient2[@custom_field_name] = @pet2
105
+ params = [recipient1, recipient2]
106
+ result = @client.post_recipients(params)
107
+ expect(result.error_count).to eq(0)
108
+ result.error_indices.each do |index|
109
+ expect(index.is_a?(Fixnum)).to eq(true)
110
+ end
111
+ expect(result.new_count).to eq(0)
112
+ expect(result.updated_count).to eq(2)
113
+ # delete a recipient
114
+ @client.delete_recipient(new_recipient.id)
115
+ expect do
116
+ @client.get_recipient(new_recipient.id)
117
+ end.to raise_error(RestClient::ResourceNotFound)
118
+ # delete multiple recipients
119
+ @client.delete_recipients([@email1, @email2])
120
+ rescue => e
121
+ puts e.inspect
122
+ raise e
123
+ end
124
+ end
125
+
126
+ it 'creates recipient instance' do
127
+ json =
128
+ '{'\
129
+ '"created_at": 1422313607,'\
130
+ '"email": "jones@example.com",'\
131
+ '"first_name": null,'\
132
+ '"id": "jones@example.com",'\
133
+ '"last_clicked": null,'\
134
+ '"last_emailed": null,'\
135
+ '"last_name": "Jones",'\
136
+ '"last_opened": null,'\
137
+ '"updated_at": 1422313790,'\
138
+ '"custom_fields": ['\
139
+ '{'\
140
+ '"id": 23,'\
141
+ '"name": "pet",'\
142
+ '"value": "Fluffy",'\
143
+ '"type": "text"'\
144
+ '}'\
145
+ ']'\
146
+ '}'
147
+ hash = JSON.parse(json)
148
+ actual = SendGrid4r::REST::Contacts::Recipients.create_recipient(hash)
149
+ expect(actual.created_at).to eq(1422313607)
150
+ expect(actual.email).to eq('jones@example.com')
151
+ expect(actual.first_name).to eq(nil)
152
+ expect(actual.id).to eq('jones@example.com')
153
+ expect(actual.last_clicked).to eq(nil)
154
+ expect(actual.last_emailed).to eq(nil)
155
+ expect(actual.last_name).to eq('Jones')
156
+ expect(actual.last_opened).to eq(nil)
157
+ expect(actual.updated_at).to eq(1422313790)
158
+ custom_field = actual.custom_fields[0]
159
+ expect(custom_field.id).to eq(23)
160
+ expect(custom_field.name).to eq('pet')
161
+ expect(custom_field.value).to eq('Fluffy')
162
+ expect(custom_field.type).to eq('text')
163
+ end
164
+
165
+ it 'creates recipients instance' do
166
+ json =
167
+ '{'\
168
+ '"recipients": ['\
169
+ '{'\
170
+ '"created_at": 1422313607,'\
171
+ '"email": "jones@example.com",'\
172
+ '"first_name": null,'\
173
+ '"id": "jones@example.com",'\
174
+ '"last_clicked": null,'\
175
+ '"last_emailed": null,'\
176
+ '"last_name": "Jones",'\
177
+ '"last_opened": null,'\
178
+ '"updated_at": 1422313790,'\
179
+ '"custom_fields": ['\
180
+ '{'\
181
+ '"id": 23,'\
182
+ '"name": "pet",'\
183
+ '"value": "Fluffy",'\
184
+ '"type": "text"'\
185
+ '}'\
186
+ ']'\
187
+ '}'\
188
+ ']'\
189
+ '}'
190
+ hash = JSON.parse(json)
191
+ actual = SendGrid4r::REST::Contacts::Recipients.create_recipients(hash)
192
+ expect(actual.recipients.is_a?(Array)).to eq(true)
193
+ actual.recipients.each do |recipient|
194
+ expect(
195
+ recipient.is_a?(SendGrid4r::REST::Contacts::Recipients::Recipient)
196
+ ).to eq(true)
197
+ end
198
+ end
199
+ end
200
+ end