sendgrid4r 1.2.0 → 1.2.1

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5d7f4961aa315c9383c28064b91f827b5649cca5
4
- data.tar.gz: 97bcf08a8000e314ac46d0641078112bb83eeb2e
3
+ metadata.gz: eb7caee98231bb2a059edc759bb2a60ed9e36998
4
+ data.tar.gz: 851393635739f5d439861e41a658e7fefbc28201
5
5
  SHA512:
6
- metadata.gz: 764e730d5f55c68eb2b1d9269b16b50419040f023ffc1e316842fa83607ea4f9f2333a72027318b136f8c0571a741b544a7d3840b6ced14c38172658b30b3c8d
7
- data.tar.gz: ccf33b5cb94663a33d54b49cf21b5fed12f4a180ce208b6f78c2938a227907518d57770c7c4da73fcc9a6e0a46ad33341127f41c14180f9de6beb1b65455446f
6
+ metadata.gz: 24f52934d7a0f7832b835fe47fc925d617dd1822673b8496d51a3f200b4b0329dcd5ff421b04605cd3db71e17ead302a926632684294ab6807594e5f45049510
7
+ data.tar.gz: 0e0e57d4ab406865b937ec4478e61476b935c18315bb17f8fc717a9be99d679776dfebead26c257712b75ae99e80c54959592c3cc655af3d48d8de2bab15cbc0
data/lib/auth.rb CHANGED
@@ -9,7 +9,7 @@ module SendGrid4r
9
9
  attr_reader :username, :password, :api_key
10
10
 
11
11
  def initialize(
12
- username: username, password: password, api_key: api_key = nil
12
+ username: nil, password: nil, api_key: nil
13
13
  )
14
14
  @username = username
15
15
  @password = password
data/lib/client.rb CHANGED
@@ -16,7 +16,7 @@ module SendGrid4r
16
16
  include SendGrid4r::REST::API
17
17
 
18
18
  def initialize(
19
- username: username, password: password, api_key: api_key = nil
19
+ username: nil, password: nil, api_key: nil
20
20
  )
21
21
  @auth = Auth.new(username: username, password: password, api_key: api_key)
22
22
  end
@@ -35,16 +35,13 @@ module SendGrid4r
35
35
 
36
36
  def execute(method, auth, endpoint, params, payload, &block)
37
37
  args = create_args(method, auth, endpoint, params, payload)
38
- if block_given?
39
- RestClient::Request.execute(args, &block)
40
- return nil
41
- end
42
- body = RestClient::Request.execute(args)
43
- if body.nil? || body.length < 2
44
- body
45
- else
46
- JSON.parse(body)
47
- end
38
+ body = RestClient::Request.execute(args, &block)
39
+ return nil if block_given?
40
+ return JSON.parse(body) unless body.nil? || body.length < 2
41
+ body
42
+ rescue RestClient::TooManyRequests => e
43
+ sleep e.response.headers[:x_ratelimit_reset].to_i - Time.now.to_i
44
+ retry
48
45
  end
49
46
 
50
47
  def create_args(method, auth, endpoint, params, payload)
@@ -42,7 +42,7 @@ module SendGrid4r
42
42
  SendGrid4r::REST::Users.create_profile(resp)
43
43
  end
44
44
 
45
- def patch_user_profile(params: params, &block)
45
+ def patch_user_profile(params: nil, &block)
46
46
  endpoint = SendGrid4r::REST::Users.url
47
47
  resp = patch(@auth, endpoint, params, &block)
48
48
  SendGrid4r::REST::Users.create_profile(resp)
@@ -2,5 +2,5 @@
2
2
  # SendGrid API v3 wrapper implementation.
3
3
  #
4
4
  module SendGrid4r
5
- VERSION = '1.2.0'
5
+ VERSION = '1.2.1'
6
6
  end
data/sendgrid4r.gemspec CHANGED
@@ -20,7 +20,7 @@ Gem::Specification.new do |spec|
20
20
 
21
21
  spec.add_dependency('rest-client', '>=1.8.0', '<1.9.0')
22
22
  spec.add_development_dependency('rubocop', '>=0.29.0', '<0.30.0')
23
- spec.add_development_dependency('bundler', '>=1.6.0', '<1.8.0')
23
+ spec.add_development_dependency('bundler', '>=1.6.0', '<1.11.0')
24
24
  spec.add_development_dependency('rspec', '3.1.0')
25
25
  spec.add_development_dependency('dotenv', '>=0.11.0', '<0.12.0')
26
26
  end
data/spec/client_spec.rb CHANGED
@@ -258,7 +258,7 @@ describe SendGrid4r::Client do
258
258
 
259
259
  describe 'VERSION' do
260
260
  it 'returns VERSION value' do
261
- expect(SendGrid4r::VERSION).to eq('1.2.0')
261
+ expect(SendGrid4r::VERSION).to eq('1.2.1')
262
262
  end
263
263
  end
264
264
  end
@@ -52,7 +52,6 @@ describe SendGrid4r::REST::ApiKeys do
52
52
  expect(api_key2.name).to eq(@name2)
53
53
  expect(api_key2.api_key_id).to be_a(String)
54
54
  expect(api_key2.api_key).to be_a(String)
55
- expect(api_key2.scope_set_id).to be_a(String)
56
55
  rescue RestClient::ExceptionWithResponse => e
57
56
  puts e.inspect
58
57
  raise e
@@ -22,6 +22,7 @@ describe SendGrid4r::REST::Settings::Partner do
22
22
  end
23
23
 
24
24
  it '#get_settings_new_relic' do
25
+ pending 'invalid json received'
25
26
  begin
26
27
  actual = @client.get_settings_new_relic
27
28
  expect(actual).to be_a(
@@ -34,6 +35,7 @@ describe SendGrid4r::REST::Settings::Partner do
34
35
  end
35
36
 
36
37
  it '#patch_settings_new_relic' do
38
+ pending 'invalid json received'
37
39
  begin
38
40
  # get original settings
39
41
  actual = @client.get_settings_new_relic
@@ -50,6 +52,7 @@ describe SendGrid4r::REST::Settings::Partner do
50
52
  end
51
53
 
52
54
  it '#get_settings_sendwithus' do
55
+ pending 'entry not found'
53
56
  begin
54
57
  actual = @client.get_settings_sendwithus
55
58
  expect(actual).to be_a(SendGrid4r::REST::Settings::Partner::Partner)
@@ -60,6 +63,7 @@ describe SendGrid4r::REST::Settings::Partner do
60
63
  end
61
64
 
62
65
  it '#patch_settings_sendwithus' do
66
+ pending 'entry not found'
63
67
  begin
64
68
  # get original settings
65
69
  actual = @client.get_settings_sendwithus
@@ -7,6 +7,17 @@ describe SendGrid4r::REST::Stats::Subuser do
7
7
  Dotenv.load
8
8
  @client = SendGrid4r::Client.new(api_key: ENV['SILVER_API_KEY'])
9
9
  @subuser = ENV['SUBUSER2']
10
+ @email1 = ENV['MAIL']
11
+ @password1 = ENV['PASS']
12
+ @ip = ENV['IP']
13
+ subusers = @client.get_subusers
14
+ count = subusers.count { |subuser| subuser.username == @subuser }
15
+ @client.post_subuser(
16
+ username: @subuser,
17
+ email: @email1,
18
+ password: @password1,
19
+ ips: [@ip]
20
+ ) if count == 0
10
21
  end
11
22
 
12
23
  context 'without block call' do
@@ -12,15 +12,16 @@ describe SendGrid4r::REST::Subusers do
12
12
  @username3 = ENV['SUBUSER3']
13
13
  @email1 = ENV['MAIL']
14
14
  @password1 = ENV['PASS']
15
-
16
15
  @ip = @client.get_ips[0].ip
17
16
  # celan up test env
18
- begin
19
- @client.delete_subuser(username: @username3)
20
- rescue => e
21
- puts e.inspect
22
- end
23
-
17
+ subusers = @client.get_subusers
18
+ count1 = subusers.count { |subuser| subuser.username == @username1 }
19
+ @client.delete_subuser(username: @username1) unless count1 == 0
20
+ count2 = subusers.count { |subuser| subuser.username == @username2 }
21
+ @client.delete_subuser(username: @username2) unless count2 == 0
22
+ count3 = subusers.count { |subuser| subuser.username == @username3 }
23
+ @client.delete_subuser(username: @username3) unless count3 == 0
24
+ # create a subuser
24
25
  @subuser3 = @client.post_subuser(
25
26
  username: @username3,
26
27
  email: @email1,
@@ -61,6 +62,7 @@ describe SendGrid4r::REST::Subusers do
61
62
  it '#patch_subuser' do
62
63
  begin
63
64
  @client.patch_subuser(username: @username3, disabled: true)
65
+ @client.patch_subuser(username: @username3, disabled: false)
64
66
  rescue RestClient::ExceptionWithResponse => e
65
67
  puts e.inspect
66
68
  raise e
@@ -130,8 +132,7 @@ describe SendGrid4r::REST::Subusers do
130
132
  it '#get_subuser_reputation' do
131
133
  begin
132
134
  params = []
133
- params.push(@username1)
134
- params.push(@username2)
135
+ params.push(@username3)
135
136
  subusers = @client.get_subuser_reputation(usernames: params)
136
137
  expect(subusers).to be_a(Array)
137
138
  subusers.each do |subuser|
@@ -146,7 +147,7 @@ describe SendGrid4r::REST::Subusers do
146
147
  it '#put_subuser_assigned_ips' do
147
148
  begin
148
149
  subuser = @client.put_subuser_assigned_ips(
149
- username: @username2, ips: [@ip]
150
+ username: @username3, ips: [@ip]
150
151
  )
151
152
  expect(subuser.ips).to be_a(Array)
152
153
  subuser.ips.each do |ip|
@@ -13,21 +13,51 @@ describe SendGrid4r::REST::Whitelabel::Domains do
13
13
  @ip = ENV['IP']
14
14
  @subuser1 = ENV['SUBUSER1']
15
15
  @subuser2 = ENV['SUBUSER2']
16
-
16
+ @email1 = ENV['MAIL']
17
+ @password1 = ENV['PASS']
18
+ @ip = ENV['IP']
17
19
  # celan up test env(lists)
20
+ @id1 = nil
21
+ @id2 = nil
22
+ @id3 = nil
18
23
  domains = @client.get_wl_domains
19
24
  domains.each do |domain|
20
25
  if domain.subdomain == "#{@subdomain_name}1" &&
21
26
  domain.domain == @domain_name
22
- @client.delete_wl_domain(id: domain.id)
27
+ @id1 = domain.id
23
28
  end
24
29
  if domain.subdomain == "#{@subdomain_name}2" &&
25
30
  domain.domain == @domain_name
26
- @client.delete_wl_domain(id: domain.id)
31
+ @id2 = domain.id
32
+ end
33
+ if domain.subdomain == "#{@subdomain_name}3" &&
34
+ domain.domain == @domain_name
35
+ @id3 = domain.id
27
36
  end
28
37
  end
29
-
30
38
  # post domain
39
+ @domain1 = @client.post_wl_domain(
40
+ domain: @domain_name, subdomain: @subdomain_name + '1',
41
+ username: @username, ips: nil,
42
+ automatic_security: true, custom_spf: false, default: false
43
+ ) if @id1.nil?
44
+ @domain2 = @client.post_wl_domain(
45
+ domain: @domain_name, subdomain: @subdomain_name + '2',
46
+ username: @username, ips: nil,
47
+ automatic_security: false, custom_spf: true, default: false
48
+ ) if @id2.nil?
49
+ @domain3 = @client.post_wl_domain(
50
+ domain: @domain_name, subdomain: @subdomain_name + '3',
51
+ username: @username, ips: nil,
52
+ automatic_security: true, custom_spf: false, default: false
53
+ ) if @id3.nil?
54
+ # make a default
55
+ @id1 = @domain1.id if @id1.nil?
56
+ @id2 = @domain2.id if @id2.nil?
57
+ @id3 = @domain3.id if @id3.nil?
58
+ @client.patch_wl_domain(id: @id3, default: true)
59
+ @client.delete_wl_domain(id: @id1)
60
+ @client.delete_wl_domain(id: @id2)
31
61
  @domain1 = @client.post_wl_domain(
32
62
  domain: @domain_name, subdomain: @subdomain_name + '1',
33
63
  username: @username, ips: nil,
@@ -38,6 +68,16 @@ describe SendGrid4r::REST::Whitelabel::Domains do
38
68
  username: @username, ips: nil,
39
69
  automatic_security: false, custom_spf: true, default: false
40
70
  )
71
+ # clean subusers
72
+ subusers = @client.get_subusers
73
+ count = subusers.count { |subuser| subuser.username == @subuser1 }
74
+ @client.delete_subuser(username: @subuser1) if count == 1
75
+ @client.post_subuser(
76
+ username: @subuser1,
77
+ email: @email1,
78
+ password: @password1,
79
+ ips: [@ip]
80
+ )
41
81
  rescue RestClient::ExceptionWithResponse => e
42
82
  puts e.inspect
43
83
  raise e
@@ -15,15 +15,12 @@ describe SendGrid4r::REST::Whitelabel::Ips do
15
15
  # celan up test env(lists)
16
16
  ips = @client.get_wl_ips
17
17
  ips.each do |ip|
18
- @client.delete_wl_ip(
19
- id: ip.id
20
- ) if ip.subdomain == @subdomain_name && ip.domain == @domain_name
18
+ @client.delete_wl_ip(id: ip.id)
21
19
  end
22
20
 
23
21
  @ipw = @client.post_wl_ip(
24
22
  ip: @ip, subdomain: @subdomain_name, domain: @domain_name
25
23
  )
26
-
27
24
  rescue RestClient::ExceptionWithResponse => e
28
25
  puts e.inspect
29
26
  raise e
@@ -11,19 +11,47 @@ describe SendGrid4r::REST::Whitelabel::Links do
11
11
  @domain_name = ENV['DOMAIN']
12
12
  @username = ENV['USERNAME']
13
13
  @subuser1 = ENV['SUBUSER1']
14
-
15
- # celan up test env(lists)
14
+ @email1 = ENV['MAIL']
15
+ @password1 = ENV['PASS']
16
+ @ip = @client.get_ips[0].ip
17
+ # celan up test env
18
+ @id1 = nil
19
+ @id2 = nil
16
20
  links = @client.get_wl_links
17
21
  links.each do |link|
18
22
  if link.subdomain == "#{@subdomain_name}1" &&
19
23
  link.domain == @domain_name
20
- @client.delete_wl_link(id: link.id)
24
+ @id1 = link.id
25
+ end
26
+ if link.subdomain == "#{@subdomain_name}2" &&
27
+ link.domain == @domain_name
28
+ @id2 = link.id
21
29
  end
22
30
  end
23
-
24
31
  # post link
25
32
  @link1 = @client.post_wl_link(
26
33
  subdomain: @subdomain_name + '1', domain: @domain_name, default: false
34
+ ) if @id1.nil?
35
+ @link2 = @client.post_wl_link(
36
+ subdomain: @subdomain_name + '2', domain: @domain_name, default: false
37
+ ) if @id2.nil?
38
+ # make a default
39
+ @id1 = @link1.id if @id1.nil?
40
+ @id2 = @link2.id if @id2.nil?
41
+ @client.patch_wl_link(id: @id1, default: true)
42
+ @client.delete_wl_link(id: @id2)
43
+ @link2 = @client.post_wl_link(
44
+ subdomain: @subdomain_name + '2', domain: @domain_name, default: false
45
+ )
46
+ # create a subuser
47
+ subusers = @client.get_subusers
48
+ count = subusers.count { |subuser| subuser.username == @subuser1 }
49
+ @client.delete_subuser(username: @subuser1) if count == 1
50
+ @client.post_subuser(
51
+ username: @subuser1,
52
+ email: @email1,
53
+ password: @password1,
54
+ ips: [@ip]
27
55
  )
28
56
  rescue RestClient::ExceptionWithResponse => e
29
57
  puts e.inspect
@@ -49,18 +77,18 @@ describe SendGrid4r::REST::Whitelabel::Links do
49
77
 
50
78
  it '#post_wl_link' do
51
79
  begin
52
- expect(@link1).to be_a(SendGrid4r::REST::Whitelabel::Links::Link)
53
- expect(@link1.domain).to eq(@domain_name)
54
- expect(@link1.subdomain).to eq(@subdomain_name + '1')
55
- expect(@link1.username).to eq(@username)
56
- expect(@link1.user_id).to be_a(Numeric)
57
- expect(@link1.default).to eq(false)
58
- expect(@link1.valid).to eq(false)
59
- expect(@link1.legacy).to eq(false)
60
- expect(@link1.dns.domain_cname).to be_a(
80
+ expect(@link2).to be_a(SendGrid4r::REST::Whitelabel::Links::Link)
81
+ expect(@link2.domain).to eq(@domain_name)
82
+ expect(@link2.subdomain).to eq(@subdomain_name + '2')
83
+ expect(@link2.username).to eq(@username)
84
+ expect(@link2.user_id).to be_a(Numeric)
85
+ expect(@link2.default).to eq(true)
86
+ expect(@link2.valid).to eq(false)
87
+ expect(@link2.legacy).to eq(false)
88
+ expect(@link2.dns.domain_cname).to be_a(
61
89
  SendGrid4r::REST::Whitelabel::Links::Record
62
90
  )
63
- expect(@link1.dns.owner_cname).to be_a(
91
+ expect(@link2.dns.owner_cname).to be_a(
64
92
  SendGrid4r::REST::Whitelabel::Links::Record
65
93
  )
66
94
  rescue RestClient::ExceptionWithResponse => e
@@ -71,19 +99,19 @@ describe SendGrid4r::REST::Whitelabel::Links do
71
99
 
72
100
  it '#get_wl_link' do
73
101
  begin
74
- link1 = @client.get_wl_link(id: @link1.id)
75
- expect(link1).to be_a(SendGrid4r::REST::Whitelabel::Links::Link)
76
- expect(link1.domain).to eq(@domain_name)
77
- expect(link1.subdomain).to eq(@subdomain_name + '1')
78
- expect(link1.username).to eq(@username)
79
- expect(link1.user_id).to be_a(Numeric)
80
- expect(link1.default).to eq(false)
81
- expect(link1.valid).to eq(false)
82
- expect(link1.legacy).to eq(false)
83
- expect(link1.dns.domain_cname).to be_a(
102
+ link2 = @client.get_wl_link(id: @link2.id)
103
+ expect(link2).to be_a(SendGrid4r::REST::Whitelabel::Links::Link)
104
+ expect(link2.domain).to eq(@domain_name)
105
+ expect(link2.subdomain).to eq(@subdomain_name + '2')
106
+ expect(link2.username).to eq(@username)
107
+ expect(link2.user_id).to be_a(Numeric)
108
+ expect(link2.default).to eq(true)
109
+ expect(link2.valid).to eq(false)
110
+ expect(link2.legacy).to eq(false)
111
+ expect(link2.dns.domain_cname).to be_a(
84
112
  SendGrid4r::REST::Whitelabel::Links::Record
85
113
  )
86
- expect(link1.dns.owner_cname).to be_a(
114
+ expect(link2.dns.owner_cname).to be_a(
87
115
  SendGrid4r::REST::Whitelabel::Links::Record
88
116
  )
89
117
  rescue RestClient::ExceptionWithResponse => e
@@ -94,19 +122,19 @@ describe SendGrid4r::REST::Whitelabel::Links do
94
122
 
95
123
  it '#patch_wl_link' do
96
124
  begin
97
- link1 = @client.patch_wl_link(id: @link1.id, default: false)
98
- expect(link1).to be_a(SendGrid4r::REST::Whitelabel::Links::Link)
99
- expect(link1.domain).to eq(@domain_name)
100
- expect(link1.subdomain).to eq(@subdomain_name + '1')
101
- expect(link1.username).to eq(@username)
102
- expect(link1.user_id).to be_a(Numeric)
103
- expect(link1.default).to eq(false)
104
- expect(link1.valid).to eq(false)
105
- expect(link1.legacy).to eq(false)
106
- expect(link1.dns.domain_cname).to be_a(
125
+ link2 = @client.patch_wl_link(id: @link2.id, default: true)
126
+ expect(link2).to be_a(SendGrid4r::REST::Whitelabel::Links::Link)
127
+ expect(link2.domain).to eq(@domain_name)
128
+ expect(link2.subdomain).to eq(@subdomain_name + '2')
129
+ expect(link2.username).to eq(@username)
130
+ expect(link2.user_id).to be_a(Numeric)
131
+ expect(link2.default).to eq(true)
132
+ expect(link2.valid).to eq(false)
133
+ expect(link2.legacy).to eq(false)
134
+ expect(link2.dns.domain_cname).to be_a(
107
135
  SendGrid4r::REST::Whitelabel::Links::Record
108
136
  )
109
- expect(link1.dns.owner_cname).to be_a(
137
+ expect(link2.dns.owner_cname).to be_a(
110
138
  SendGrid4r::REST::Whitelabel::Links::Record
111
139
  )
112
140
  rescue RestClient::ExceptionWithResponse => e
@@ -117,7 +145,7 @@ describe SendGrid4r::REST::Whitelabel::Links do
117
145
 
118
146
  it '#delete_wl_link' do
119
147
  begin
120
- @client.delete_wl_link(id: @link1.id)
148
+ @client.delete_wl_link(id: @id1)
121
149
  rescue RestClient::ExceptionWithResponse => e
122
150
  puts e.inspect
123
151
  raise e
@@ -136,7 +164,7 @@ describe SendGrid4r::REST::Whitelabel::Links do
136
164
 
137
165
  it '#validate_wl_link' do
138
166
  begin
139
- result1 = @client.validate_wl_link(id: @link1.id)
167
+ result1 = @client.validate_wl_link(id: @id1)
140
168
  expect(result1).to be_a(
141
169
  SendGrid4r::REST::Whitelabel::Links::Result
142
170
  )
@@ -168,7 +196,7 @@ describe SendGrid4r::REST::Whitelabel::Links do
168
196
  it '#associate_wl_link' do
169
197
  begin
170
198
  @client.associate_wl_link(
171
- id: @link1.id, username: @subuser1
199
+ id: @id1, username: @subuser1
172
200
  )
173
201
  rescue RestClient::ExceptionWithResponse => e
174
202
  puts e.inspect
@@ -179,7 +207,7 @@ describe SendGrid4r::REST::Whitelabel::Links do
179
207
  it '#disassociate_wl_link' do
180
208
  begin
181
209
  @client.associate_wl_link(
182
- id: @link1.id, username: @subuser1
210
+ id: @id1, username: @subuser1
183
211
  )
184
212
  @client.disassociate_wl_link(username: @subuser1)
185
213
  rescue RestClient::ExceptionWithResponse => e
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sendgrid4r
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - awwa500@gmail.com
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-09-04 00:00:00.000000000 Z
11
+ date: 2015-09-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client
@@ -59,7 +59,7 @@ dependencies:
59
59
  version: 1.6.0
60
60
  - - "<"
61
61
  - !ruby/object:Gem::Version
62
- version: 1.8.0
62
+ version: 1.11.0
63
63
  type: :development
64
64
  prerelease: false
65
65
  version_requirements: !ruby/object:Gem::Requirement
@@ -69,7 +69,7 @@ dependencies:
69
69
  version: 1.6.0
70
70
  - - "<"
71
71
  - !ruby/object:Gem::Version
72
- version: 1.8.0
72
+ version: 1.11.0
73
73
  - !ruby/object:Gem::Dependency
74
74
  name: rspec
75
75
  requirement: !ruby/object:Gem::Requirement