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
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9e77f18ddd75a6b86d7d8fe6fb50b3cb64ec8955
4
- data.tar.gz: d594830d614fe4ba1c7b648d3a3929f904bdbca5
3
+ metadata.gz: 18804ec5896082dcfa570e2b27a7d58ab6092903
4
+ data.tar.gz: 09f1702cbe8b86550e66a8f8522b593562ce177d
5
5
  SHA512:
6
- metadata.gz: 1f5845e151068e2cfe8d78dd19914b8ba76dad7d4f747f1a36bf292d7cb1b4f977afc406f334581f41c92a9edffc719d265551512bf622f267ff8a993eeccad8
7
- data.tar.gz: a998a7a72c8c0400066bc3576b51f4182155db45cea319fc7bda6ebf93f4decfcbaf2c70ebd24ce5e724550f7c568c16fcad64959750de8a60372294ebc969ab
6
+ metadata.gz: cee31b5daa5bdc9b0fb90a7d16b0f7c7ce6efe375870c17200294b57f7c80b87110c3b3a580e985a91f3a1cbcb4ae4c4bf11aad91ecf9559096e917d7125e7ed
7
+ data.tar.gz: cdac0d4cbbd0308f9c0eb2945f0e566893543f2fb6e5d4f4dd427dfdb9a07e5aa83a64de52e8b44f94ea4f1e4169b13e756180b3a399a49b20f927e28710b763
data/.env.example CHANGED
@@ -1,2 +1,7 @@
1
1
  SENDGRID_USERNAME=sendgrid username
2
2
  SENDGRID_PASSWORD=sendgrid_password
3
+ API_KEY=apikey
4
+ USE_SILVER=true
5
+ SILVER_SENDGRID_USERNAME=silver_sendgrid_username
6
+ SILVER_SENDGRID_PASSWORD=silver_sendgird_password
7
+ SILVER_SUBUSER=subusername
data/.rubocop.yml CHANGED
@@ -1,25 +1,25 @@
1
- # メソッド名のprefixに「set_」「get_」を許可
1
+ # Let prefix of method name set_ and get_
2
2
  AccessorMethodName:
3
3
  Enabled: false
4
4
 
5
- # メソッドの行数上限を変更
5
+ # Change limitation of method length
6
6
  MethodLength:
7
7
  CountComments: true # count full line comments?
8
8
  Max: 20
9
9
 
10
- # 引数上限を変更
10
+ # Change limitation of the number of params
11
11
  ParameterLists:
12
- Max: 6
12
+ Max: 7
13
13
  CountKeywordArgs: true
14
14
 
15
- # AbcSizeの上限を変更
15
+ # Change limitation of AbcSize
16
16
  AbcSize:
17
- Max: 20
17
+ Max: 21
18
18
 
19
- # %r 内で利用できるスラッシュの数の制限変更
19
+ # Change limitation of the number of '/' within %r
20
20
  RegexpLiteral:
21
21
  MaxSlashes: 0
22
22
 
23
- # 数値の区切りをなくす
23
+ # Change numeric literals
24
24
  NumericLiterals:
25
25
  MinDigits: 20
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # Sendgrid4r
2
2
 
3
+ **This gem is BETA yet. The interfaces will be changed often.**
4
+
3
5
  This gem allows you to quickly and easily access to SendGrid Web API v3 for Ruby.
4
6
  See [api reference](https://sendgrid.com/docs/API_Reference/Web_API_v3/index.html) for more detail
5
7
 
data/lib/auth.rb CHANGED
@@ -6,11 +6,14 @@ module SendGrid4r
6
6
  # SendGrid Web API v3 data container for authentication
7
7
  #
8
8
  class Auth
9
- attr_reader :username, :password
9
+ attr_reader :username, :password, :api_key
10
10
 
11
- def initialize(username, password)
11
+ def initialize(
12
+ username: username, password: password, api_key: api_key = nil
13
+ )
12
14
  @username = username
13
15
  @password = password
16
+ @api_key = api_key
14
17
  end
15
18
  end
16
19
  end
data/lib/client.rb CHANGED
@@ -16,8 +16,10 @@ module SendGrid4r
16
16
 
17
17
  BASE_URL = 'https://api.sendgrid.com/v3'
18
18
 
19
- def initialize(username, password)
20
- @auth = Auth.new(username, password)
19
+ def initialize(
20
+ username: username, password: password, api_key: api_key = nil
21
+ )
22
+ @auth = Auth.new(username: username, password: password, api_key: api_key)
21
23
  end
22
24
  end
23
25
  end
@@ -10,7 +10,7 @@ module SendGrid4r
10
10
  def create(
11
11
  name:, subject: '<%subject%>',
12
12
  html_content: '<%body%>', plain_content: '<%body%>', active: 1)
13
- SendGrid4r::REST::Templates::Version.new(
13
+ SendGrid4r::REST::Templates::Versions::Version.new(
14
14
  nil,
15
15
  nil,
16
16
  nil,
@@ -3,6 +3,7 @@ $LOAD_PATH.unshift File.dirname(__FILE__)
3
3
 
4
4
  require 'sendgrid4r/rest/templates/templates'
5
5
  require 'sendgrid4r/rest/templates/versions'
6
+ require 'sendgrid4r/rest/asm/asm'
6
7
  require 'sendgrid4r/rest/asm/groups'
7
8
  require 'sendgrid4r/rest/asm/suppressions'
8
9
  require 'sendgrid4r/rest/asm/global_suppressions'
@@ -22,6 +23,7 @@ require 'sendgrid4r/rest/contacts/lists'
22
23
  require 'sendgrid4r/rest/contacts/recipients'
23
24
  require 'sendgrid4r/rest/contacts/reserved_fields'
24
25
  require 'sendgrid4r/rest/contacts/segments'
26
+ require 'sendgrid4r/rest/api_keys/api_keys'
25
27
 
26
28
  module SendGrid4r
27
29
  module REST
@@ -31,6 +33,7 @@ module SendGrid4r
31
33
  module API
32
34
  include SendGrid4r::REST::Templates
33
35
  include SendGrid4r::REST::Templates::Versions
36
+ include SendGrid4r::REST::Asm
34
37
  include SendGrid4r::REST::Asm::Groups
35
38
  include SendGrid4r::REST::Asm::Suppressions
36
39
  include SendGrid4r::REST::Asm::GlobalSuppressions
@@ -49,6 +52,7 @@ module SendGrid4r
49
52
  include SendGrid4r::REST::Contacts::Recipients
50
53
  include SendGrid4r::REST::Contacts::ReservedFields
51
54
  include SendGrid4r::REST::Contacts::Segments
55
+ include SendGrid4r::REST::ApiKeys
52
56
  end
53
57
  end
54
58
  end
@@ -0,0 +1,73 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $LOAD_PATH.unshift File.dirname(__FILE__)
3
+
4
+ require 'sendgrid4r/rest/request'
5
+
6
+ module SendGrid4r
7
+ module REST
8
+ #
9
+ # SendGrid Web API v3 ApiKeys
10
+ #
11
+ module ApiKeys
12
+ include SendGrid4r::REST::Request
13
+
14
+ ApiKeys = Struct.new(:result)
15
+ ApiKey = Struct.new(:name, :api_key_id, :api_key, :scope_set_id)
16
+
17
+ def self.url(api_key = nil)
18
+ url = "#{SendGrid4r::Client::BASE_URL}/api_keys"
19
+ url = "#{url}/#{api_key}" unless api_key.nil?
20
+ url
21
+ end
22
+
23
+ def self.create_api_keys(resp)
24
+ return resp if resp.nil?
25
+ api_keys = []
26
+ resp['result'].each do |api_key|
27
+ api_keys.push(SendGrid4r::REST::ApiKeys.create_api_key(api_key))
28
+ end
29
+ ApiKeys.new(api_keys)
30
+ end
31
+
32
+ def self.create_api_key(resp)
33
+ return resp if resp.nil?
34
+ ApiKey.new(
35
+ resp['name'],
36
+ resp['api_key_id'],
37
+ resp['api_key'],
38
+ resp['scope_set_id']
39
+ )
40
+ end
41
+
42
+ def get_api_keys(&block)
43
+ resp = get(@auth, SendGrid4r::REST::ApiKeys.url, &block)
44
+ SendGrid4r::REST::ApiKeys.create_api_keys(resp)
45
+ end
46
+
47
+ def post_api_key(name, &block)
48
+ params = {}
49
+ params['name'] = name
50
+ resp = post(
51
+ @auth, SendGrid4r::REST::ApiKeys.url, params, &block
52
+ )
53
+ SendGrid4r::REST::ApiKeys.create_api_key(resp)
54
+ end
55
+
56
+ def delete_api_key(api_key, &block)
57
+ delete(@auth, SendGrid4r::REST::ApiKeys.url(api_key), &block)
58
+ end
59
+
60
+ def patch_api_key(api_key, name, &block)
61
+ params = {}
62
+ params['name'] = name
63
+ resp = patch(
64
+ @auth,
65
+ SendGrid4r::REST::ApiKeys.url(api_key),
66
+ params,
67
+ &block
68
+ )
69
+ SendGrid4r::REST::ApiKeys.create_api_key(resp)
70
+ end
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,28 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $LOAD_PATH.unshift File.dirname(__FILE__)
3
+
4
+ require 'sendgrid4r/rest/request'
5
+
6
+ module SendGrid4r
7
+ module REST
8
+ #
9
+ # SendGrid Web API v3 Advanced Suppression Manager
10
+ #
11
+ module Asm
12
+ include SendGrid4r::REST::Request
13
+
14
+ RecipientEmails = Struct.new(:recipient_emails)
15
+ RecipientEmail = Struct.new(:recipient_email)
16
+
17
+ def self.create_recipient_emails(resp)
18
+ return resp if resp.nil?
19
+ RecipientEmails.new(resp['recipient_emails'])
20
+ end
21
+
22
+ def self.create_recipient_email(resp)
23
+ return resp if resp.nil?
24
+ RecipientEmail.new(resp['recipient_email'])
25
+ end
26
+ end
27
+ end
28
+ end
@@ -18,27 +18,31 @@ module SendGrid4r
18
18
  url
19
19
  end
20
20
 
21
- def post_global_suppressed_emails(recipient_emails)
21
+ def post_global_suppressed_emails(recipient_emails, &block)
22
22
  params = { recipient_emails: recipient_emails }
23
23
  resp = post(
24
24
  @auth,
25
25
  SendGrid4r::REST::Asm::GlobalSuppressions.url,
26
- params
26
+ params,
27
+ &block
27
28
  )
28
- resp['recipient_emails']
29
+ SendGrid4r::REST::Asm.create_recipient_emails(resp)
29
30
  end
30
31
 
31
- def get_global_suppressed_email(email_address)
32
+ def get_global_suppressed_email(email_address, &block)
32
33
  resp = get(
33
34
  @auth,
34
- SendGrid4r::REST::Asm::GlobalSuppressions.url(email_address)
35
+ SendGrid4r::REST::Asm::GlobalSuppressions.url(email_address),
36
+ &block
35
37
  )
36
- resp['recipient_email']
38
+ SendGrid4r::REST::Asm.create_recipient_email(resp)
37
39
  end
38
40
 
39
- def delete_global_suppressed_email(email_address)
41
+ def delete_global_suppressed_email(email_address, &block)
40
42
  delete(
41
- @auth, SendGrid4r::REST::Asm::GlobalSuppressions.url(email_address))
43
+ @auth,
44
+ SendGrid4r::REST::Asm::GlobalSuppressions.url(email_address),
45
+ &block)
42
46
  end
43
47
  end
44
48
  end
@@ -15,7 +15,23 @@ module SendGrid4r
15
15
  Group = Struct.new(
16
16
  :id, :name, :description, :last_email_sent_at, :unsubscribes)
17
17
 
18
+ def self.url(group_id = nil)
19
+ url = "#{SendGrid4r::Client::BASE_URL}/asm/groups"
20
+ url = "#{url}/#{group_id}" unless group_id.nil?
21
+ url
22
+ end
23
+
24
+ def self.create_groups(resp)
25
+ return resp if resp.nil?
26
+ groups = []
27
+ resp.each do |group|
28
+ groups.push(SendGrid4r::REST::Asm::Groups.create_group(group))
29
+ end
30
+ groups
31
+ end
32
+
18
33
  def self.create_group(resp)
34
+ return resp if resp.nil?
19
35
  Group.new(
20
36
  resp['id'],
21
37
  resp['name'],
@@ -25,43 +41,34 @@ module SendGrid4r
25
41
  )
26
42
  end
27
43
 
28
- def post_group(name, description)
44
+ def post_group(name, description, &block)
29
45
  params = { name: name, description: description }
30
- resp = post(
31
- @auth, "#{SendGrid4r::Client::BASE_URL}/asm/groups", params
32
- )
46
+ resp = post(@auth, SendGrid4r::REST::Asm::Groups.url, params, &block)
33
47
  SendGrid4r::REST::Asm::Groups.create_group(resp)
34
48
  end
35
49
 
36
- def get_groups
37
- resp_a = get(@auth, "#{SendGrid4r::Client::BASE_URL}/asm/groups")
38
- groups = []
39
- resp_a.each do |resp|
40
- groups.push(SendGrid4r::REST::Asm::Groups.create_group(resp))
41
- end
42
- groups
50
+ def get_groups(&block)
51
+ resp = get(@auth, SendGrid4r::REST::Asm::Groups.url, &block)
52
+ SendGrid4r::REST::Asm::Groups.create_groups(resp)
43
53
  end
44
54
 
45
- def get_group(group_id)
46
- resp = get(
47
- @auth, "#{SendGrid4r::Client::BASE_URL}/asm/groups/#{group_id}"
48
- )
55
+ def get_group(group_id, &block)
56
+ resp = get(@auth, SendGrid4r::REST::Asm::Groups.url(group_id), &block)
49
57
  SendGrid4r::REST::Asm::Groups.create_group(resp)
50
58
  end
51
59
 
52
- def patch_group(group_id, group)
60
+ def patch_group(group_id, group, &block)
53
61
  resp = patch(
54
62
  @auth,
55
- "#{SendGrid4r::Client::BASE_URL}/asm/groups/#{group_id}",
56
- group.to_h
63
+ SendGrid4r::REST::Asm::Groups.url(group_id),
64
+ group.to_h,
65
+ &block
57
66
  )
58
67
  SendGrid4r::REST::Asm::Groups.create_group(resp)
59
68
  end
60
69
 
61
- def delete_group(group_id)
62
- delete(
63
- @auth, "#{SendGrid4r::Client::BASE_URL}/asm/groups/#{group_id}"
64
- )
70
+ def delete_group(group_id, &block)
71
+ delete(@auth, SendGrid4r::REST::Asm::Groups.url(group_id), &block)
65
72
  end
66
73
  end
67
74
  end
@@ -13,6 +13,7 @@ module SendGrid4r
13
13
  include SendGrid4r::REST::Request
14
14
 
15
15
  Suppression = Struct.new(:id, :name, :description, :suppressed)
16
+ Suppressions = Struct.new(:suppressions)
16
17
 
17
18
  def self.url(group_id, email_address = nil)
18
19
  url =
@@ -22,9 +23,24 @@ module SendGrid4r
22
23
  url
23
24
  end
24
25
 
26
+ def self.create_suppressions(resp)
27
+ resp if resp.nil?
28
+ suppressions = []
29
+ resp['suppressions'].each do |suppression|
30
+ suppressions.push(
31
+ SendGrid4r::REST::Asm::Suppressions.create_suppression(
32
+ suppression
33
+ )
34
+ )
35
+ end
36
+ Suppressions.new(suppressions)
37
+ end
38
+
25
39
  def self.create_suppression(resp)
40
+ resp if resp.nil?
26
41
  Suppression.new(
27
- resp['id'], resp['name'], resp['description'], resp['suppressed'])
42
+ resp['id'], resp['name'], resp['description'], resp['suppressed']
43
+ )
28
44
  end
29
45
 
30
46
  def post_suppressed_emails(group_id, recipient_emails)
@@ -33,20 +49,7 @@ module SendGrid4r
33
49
  SendGrid4r::REST::Asm::Suppressions.url(group_id),
34
50
  recipient_emails: recipient_emails
35
51
  )
36
- resp['recipient_emails']
37
- end
38
-
39
- def get_suppressions(email_address)
40
- resp_a = get(
41
- @auth,
42
- "#{SendGrid4r::Client::BASE_URL}/asm/suppressions/#{email_address}")
43
- suppressions = []
44
- resp_a['suppressions'].each do |resp|
45
- suppressions.push(
46
- SendGrid4r::REST::Asm::Suppressions.create_suppression(resp)
47
- )
48
- end
49
- suppressions
52
+ SendGrid4r::REST::Asm.create_recipient_emails(resp)
50
53
  end
51
54
 
52
55
  def get_suppressed_emails(group_id)
@@ -56,6 +59,13 @@ module SendGrid4r
56
59
  )
57
60
  end
58
61
 
62
+ def get_suppressions(email_address)
63
+ resp = get(
64
+ @auth,
65
+ "#{SendGrid4r::Client::BASE_URL}/asm/suppressions/#{email_address}")
66
+ SendGrid4r::REST::Asm::Suppressions.create_suppressions(resp)
67
+ end
68
+
59
69
  def delete_suppressed_email(group_id, email_address)
60
70
  delete(
61
71
  @auth,
@@ -15,23 +15,33 @@ module SendGrid4r
15
15
  Category = Struct.new(:category)
16
16
 
17
17
  def self.create_category(resp)
18
+ return resp if resp.nil?
18
19
  Category.new(resp['category'])
19
20
  end
20
21
 
21
- def get_categories(category = nil, limit = nil, offset = nil)
22
- params = {}
23
- params['category'] = category unless category.nil?
24
- params['limit'] = limit unless limit.nil?
25
- params['offset'] = offset unless limit.nil?
26
- resp_a = get(
27
- @auth, "#{SendGrid4r::Client::BASE_URL}/categories", params)
22
+ def self.create_categories(resp)
23
+ return resp if resp.nil?
28
24
  categories = []
29
- resp_a.each do |resp|
25
+ resp.each do |category|
30
26
  categories.push(
31
- SendGrid4r::REST::Categories::Categories.create_category(resp))
27
+ SendGrid4r::REST::Categories::Categories.create_category(
28
+ category
29
+ )
30
+ )
32
31
  end
33
32
  categories
34
33
  end
34
+
35
+ def get_categories(category = nil, limit = nil, offset = nil, &block)
36
+ params = {}
37
+ params['category'] = category unless category.nil?
38
+ params['limit'] = limit unless limit.nil?
39
+ params['offset'] = offset unless limit.nil?
40
+ resp = get(
41
+ @auth, "#{SendGrid4r::Client::BASE_URL}/categories", params, &block
42
+ )
43
+ SendGrid4r::REST::Categories::Categories.create_categories(resp)
44
+ end
35
45
  end
36
46
  end
37
47
  end
@@ -31,10 +31,12 @@ module SendGrid4r
31
31
  end
32
32
 
33
33
  def self.create_field(resp)
34
+ return resp if resp.nil?
34
35
  Field.new(resp['id'], resp['name'], resp['type'], resp['value'])
35
36
  end
36
37
 
37
38
  def self.create_fields(resp)
39
+ return resp if resp.nil?
38
40
  custom_fields = []
39
41
  resp['custom_fields'].each do |field|
40
42
  custom_fields.push(
@@ -44,33 +46,37 @@ module SendGrid4r
44
46
  Fields.new(custom_fields)
45
47
  end
46
48
 
47
- def post_custom_field(name, type)
49
+ def post_custom_field(name, type, &block)
48
50
  params = {}
49
51
  params['name'] = name
50
52
  params['type'] = type
51
53
  resp = post(
52
- @auth, SendGrid4r::REST::Contacts::CustomFields.url, params
54
+ @auth, SendGrid4r::REST::Contacts::CustomFields.url, params, &block
53
55
  )
54
56
  SendGrid4r::REST::Contacts::CustomFields.create_field(resp)
55
57
  end
56
58
 
57
- def get_custom_fields
58
- resp = get(@auth, SendGrid4r::REST::Contacts::CustomFields.url)
59
+ def get_custom_fields(&block)
60
+ resp = get(
61
+ @auth, SendGrid4r::REST::Contacts::CustomFields.url, &block
62
+ )
59
63
  SendGrid4r::REST::Contacts::CustomFields.create_fields(resp)
60
64
  end
61
65
 
62
- def get_custom_field(custom_field_id)
66
+ def get_custom_field(custom_field_id, &block)
63
67
  resp = get(
64
68
  @auth,
65
- SendGrid4r::REST::Contacts::CustomFields.url(custom_field_id)
69
+ SendGrid4r::REST::Contacts::CustomFields.url(custom_field_id),
70
+ &block
66
71
  )
67
72
  SendGrid4r::REST::Contacts::CustomFields.create_field(resp)
68
73
  end
69
74
 
70
- def delete_custom_field(custom_field_id)
75
+ def delete_custom_field(custom_field_id, &block)
71
76
  delete(
72
77
  @auth,
73
- SendGrid4r::REST::Contacts::CustomFields.url(custom_field_id)
78
+ SendGrid4r::REST::Contacts::CustomFields.url(custom_field_id),
79
+ &block
74
80
  )
75
81
  end
76
82
  end
@@ -28,10 +28,12 @@ module SendGrid4r
28
28
  end
29
29
 
30
30
  def self.create_list(resp)
31
+ return resp if resp.nil?
31
32
  List.new(resp['id'], resp['name'], resp['recipient_count'])
32
33
  end
33
34
 
34
35
  def self.create_lists(resp)
36
+ return resp if resp.nil?
35
37
  lists = []
36
38
  resp['lists'].each do |list|
37
39
  lists.push(SendGrid4r::REST::Contacts::Lists.create_list(list))
@@ -39,83 +41,93 @@ module SendGrid4r
39
41
  Lists.new(lists)
40
42
  end
41
43
 
42
- def post_list(name)
44
+ def post_list(name, &block)
43
45
  params = {}
44
46
  params['name'] = name
45
- resp = post(@auth, SendGrid4r::REST::Contacts::Lists.url, params)
47
+ resp = post(
48
+ @auth, SendGrid4r::REST::Contacts::Lists.url, params, &block
49
+ )
46
50
  SendGrid4r::REST::Contacts::Lists.create_list(resp)
47
51
  end
48
52
 
49
- def get_lists
50
- resp = get(@auth, SendGrid4r::REST::Contacts::Lists.url)
53
+ def get_lists(&block)
54
+ resp = get(@auth, SendGrid4r::REST::Contacts::Lists.url, &block)
51
55
  SendGrid4r::REST::Contacts::Lists.create_lists(resp)
52
56
  end
53
57
 
54
- def get_list(list_id)
55
- resp = get(@auth, SendGrid4r::REST::Contacts::Lists.url(list_id))
58
+ def get_list(list_id, &block)
59
+ resp = get(
60
+ @auth, SendGrid4r::REST::Contacts::Lists.url(list_id), &block
61
+ )
56
62
  SendGrid4r::REST::Contacts::Lists.create_list(resp)
57
63
  end
58
64
 
59
- def patch_list(list_id, name)
65
+ def patch_list(list_id, name, &block)
60
66
  params = {}
61
67
  params['name'] = name
62
68
  resp = patch(
63
69
  @auth,
64
70
  SendGrid4r::REST::Contacts::Lists.url(list_id),
65
- params
71
+ params,
72
+ &block
66
73
  )
67
74
  SendGrid4r::REST::Contacts::Lists.create_list(resp)
68
75
  end
69
76
 
70
- def delete_list(list_id)
71
- delete(@auth, SendGrid4r::REST::Contacts::Lists.url(list_id))
77
+ def delete_list(list_id, &block)
78
+ delete(@auth, SendGrid4r::REST::Contacts::Lists.url(list_id), &block)
72
79
  end
73
80
 
74
81
  # no bodies returned
75
- def post_recipients_to_list(list_id, recipients)
82
+ def post_recipients_to_list(list_id, recipients, &block)
76
83
  url = SendGrid4r::REST::Contacts::Lists.url(list_id)
77
84
  post(
78
85
  @auth,
79
86
  "#{url}/recipients_batch",
80
- recipients
87
+ recipients,
88
+ &block
81
89
  )
82
90
  end
83
91
 
84
- def get_recipients_from_list(list_id, limit = nil, offset = nil)
92
+ def get_recipients_from_list(list_id, limit = nil, offset = nil, &block)
85
93
  params = {}
86
94
  params['limit'] = limit unless limit.nil?
87
95
  params['offset'] = offset unless offset.nil?
88
96
  resp = get(
89
97
  @auth,
90
98
  SendGrid4r::REST::Contacts::Lists.recipients_url(list_id),
91
- params
99
+ params,
100
+ &block
92
101
  )
93
102
  SendGrid4r::REST::Contacts::Recipients.create_recipients(resp)
94
103
  end
95
104
 
96
- def post_recipient_to_list(list_id, recipient_id)
105
+ def post_recipient_to_list(list_id, recipient_id, &block)
97
106
  post(
98
107
  @auth,
99
108
  SendGrid4r::REST::Contacts::Lists.recipients_url(
100
109
  list_id, recipient_id
101
- )
110
+ ),
111
+ &block
102
112
  )
103
113
  end
104
114
 
105
- def delete_recipient_from_list(list_id, recipient_id)
115
+ def delete_recipient_from_list(list_id, recipient_id, &block)
106
116
  delete(
107
117
  @auth,
108
118
  SendGrid4r::REST::Contacts::Lists.recipients_url(
109
119
  list_id, recipient_id
110
- )
120
+ ),
121
+ &block
111
122
  )
112
123
  end
113
124
 
114
- def delete_lists(list_ids)
125
+ def delete_lists(list_ids, &block)
115
126
  delete(
116
127
  @auth,
117
128
  "#{SendGrid4r::Client::BASE_URL}/contactdb/lists_batch",
118
- list_ids
129
+ list_ids,
130
+ &block
119
131
  )
120
132
  end
121
133
  end