sendgrid-ruby 6.3.5 → 6.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e029e78d950c6d118cf0444a43ea84aaaa93a7524fb35d22e0442e9a575ae18e
4
- data.tar.gz: 136c50aab4d0f6561acccad706b2238eee7bc3d76d723055ce43f38fd4ef747a
3
+ metadata.gz: 8a77256d8db572200bdedd90a2b719d0f36d1a1aecbf17070968b555ed404028
4
+ data.tar.gz: 10081de69452a519515b2fe5f086460935cac375e1d3ade7528412477aab38a9
5
5
  SHA512:
6
- metadata.gz: ff63561ef8b7ea73bf7125c3cd62803e0ffe50a73914fbd3736d7d3aed8a98c23f6f8b6a1ab7c07d9eefc5b1fabed78586d8d27bafd548c87d4f79f422eb430f
7
- data.tar.gz: 3d7eb06f425f60994db736113f45c9db3406b63f4bc1ff1a6e7eadd6761f8a67ba98eda05cf6830eef40fd9143046219ec3e7fa9d5b58da8bc270eddf0809a68
6
+ metadata.gz: fa4e2a6a2cd904d43f1c32a57ecbc1ea7db0729fed4cab05303566515975661fd12bb0e1d3f92480b3101276019db4a1858dc060ff35a1055ff587dc5582d071
7
+ data.tar.gz: 10493d88b4836f3f90a8813dbe3bb6d40e141a3d0f1ed99adc35c34a308c7a149104b7bde9829c8bf5b5b1efb7e855ad1236fc43c5f6c444c656a1e6f740599c
data/.rubocop.yml CHANGED
@@ -2,3 +2,7 @@ inherit_from: .rubocop_todo.yml
2
2
 
3
3
  Style/StringLiterals:
4
4
  Enabled: false
5
+
6
+ Metrics/BlockLength:
7
+ Exclude:
8
+ - 'spec/**/*'
data/.rubocop_todo.yml CHANGED
@@ -34,6 +34,8 @@ Metrics/BlockLength:
34
34
  # Configuration parameters: CountComments, CountAsOne.
35
35
  Metrics/ClassLength:
36
36
  Max: 2006
37
+ Exclude:
38
+ - 'test/sendgrid/test_sendgrid-ruby.rb'
37
39
 
38
40
  # Offense count: 41
39
41
  # Configuration parameters: CountComments, CountAsOne, ExcludedMethods.
data/CHANGELOG.md CHANGED
@@ -1,6 +1,37 @@
1
1
  # Change Log
2
2
  All notable changes to this project will be documented in this file.
3
3
 
4
+ [2021-02-10] Version 6.4.0
5
+ --------------------------
6
+ **Library - Feature**
7
+ - [PR #455](https://github.com/sendgrid/sendgrid-ruby/pull/455): Add http_options as a param in the SendGrid::API's constructor. Thanks to [@hoangtuanictvn](https://github.com/hoangtuanictvn)!
8
+
9
+
10
+ [2021-01-27] Version 6.3.9
11
+ --------------------------
12
+ **Library - Fix**
13
+ - [PR #446](https://github.com/sendgrid/sendgrid-ruby/pull/446): Accurate duplicate checking when adding email to Personalizations. Thanks to [@mito5525](https://github.com/mito5525)!
14
+ - [PR #457](https://github.com/sendgrid/sendgrid-ruby/pull/457): email is required. Thanks to [@luk4s](https://github.com/luk4s)!
15
+
16
+
17
+ [2020-12-16] Version 6.3.8
18
+ --------------------------
19
+ **Library - Fix**
20
+ - [PR #448](https://github.com/sendgrid/sendgrid-ruby/pull/448): tests failing on rubocop rule. Thanks to [@thinkingserious](https://github.com/thinkingserious)!
21
+
22
+
23
+ [2020-11-05] Version 6.3.7
24
+ --------------------------
25
+ **Library - Chore**
26
+ - [PR #447](https://github.com/sendgrid/sendgrid-ruby/pull/447): fix rubocop styling errors. Thanks to [@eshanholtz](https://github.com/eshanholtz)!
27
+
28
+
29
+ [2020-10-14] Version 6.3.6
30
+ --------------------------
31
+ **Library - Fix**
32
+ - [PR #440](https://github.com/sendgrid/sendgrid-ruby/pull/440): reading position of a request body. Thanks to [@snaka](https://github.com/snaka)!
33
+
34
+
4
35
  [2020-09-28] Version 6.3.5
5
36
  --------------------------
6
37
  **Library - Fix**
data/FIRST_TIMERS.md CHANGED
@@ -61,13 +61,13 @@ Before creating a pull request, make sure that you respect the repository's cons
61
61
  * [Node.js SDK](https://github.com/sendgrid/sendgrid-nodejs/issues?utf8=%E2%9C%93&q=is%3Aopen+label%3A%22difficulty%3A+easy%22+label%3A%22status%3A+help+wanted%22)
62
62
  * [Java SDK](https://github.com/sendgrid/sendgrid-java/issues?utf8=%E2%9C%93&q=is%3Aopen+label%3A%22difficulty%3A+easy%22+label%3A%22status%3A+help+wanted%22)
63
63
  * [Go SDK](https://github.com/sendgrid/sendgrid-go/issues?utf8=%E2%9C%93&q=is%3Aopen+label%3A%22difficulty%3A+easy%22+label%3A%22status%3A+help+wanted%22)
64
- * [Python STMPAPI Client](https://github.com/sendgrid/smtpapi-python/issues?utf8=%E2%9C%93&q=is%3Aopen+label%3A%22difficulty%3A+easy%22+label%3A%22status%3A+help+wanted%22)
65
- * [PHP STMPAPI Client](https://github.com/sendgrid/smtpapi-php/issues?utf8=%E2%9C%93&q=is%3Aopen+label%3A%22difficulty%3A+easy%22+label%3A%22status%3A+help+wanted%22)
66
- * [C# STMPAPI Client](https://github.com/sendgrid/smtpapi-csharp/issues?utf8=%E2%9C%93&q=is%3Aopen+label%3A%22difficulty%3A+easy%22+label%3A%22status%3A+help+wanted%22)
67
- * [Ruby STMPAPI Client](https://github.com/sendgrid/smtpapi-ruby/issues?utf8=%E2%9C%93&q=is%3Aopen+label%3A%22difficulty%3A+easy%22+label%3A%22status%3A+help+wanted%22)
68
- * [Node.js STMPAPI Client](https://github.com/sendgrid/smtpapi-nodejs/issues?utf8=%E2%9C%93&q=is%3Aopen+label%3A%22difficulty%3A+easy%22+label%3A%22status%3A+help+wanted%22)
69
- * [Java STMPAPI Client](https://github.com/sendgrid/smtpapi-java/issues?utf8=%E2%9C%93&q=is%3Aopen+label%3A%22difficulty%3A+easy%22+label%3A%22status%3A+help+wanted%22)
70
- * [Go STMPAPI Client](https://github.com/sendgrid/smtpapi-go/issues?utf8=%E2%9C%93&q=is%3Aopen+label%3A%22difficulty%3A+easy%22+label%3A%22status%3A+help+wanted%22)
64
+ * [Python SMTPAPI Client](https://github.com/sendgrid/smtpapi-python/issues?utf8=%E2%9C%93&q=is%3Aopen+label%3A%22difficulty%3A+easy%22+label%3A%22status%3A+help+wanted%22)
65
+ * [PHP SMTPAPI Client](https://github.com/sendgrid/smtpapi-php/issues?utf8=%E2%9C%93&q=is%3Aopen+label%3A%22difficulty%3A+easy%22+label%3A%22status%3A+help+wanted%22)
66
+ * [C# SMTPAPI Client](https://github.com/sendgrid/smtpapi-csharp/issues?utf8=%E2%9C%93&q=is%3Aopen+label%3A%22difficulty%3A+easy%22+label%3A%22status%3A+help+wanted%22)
67
+ * [Ruby SMTPAPI Client](https://github.com/sendgrid/smtpapi-ruby/issues?utf8=%E2%9C%93&q=is%3Aopen+label%3A%22difficulty%3A+easy%22+label%3A%22status%3A+help+wanted%22)
68
+ * [Node.js SMTPAPI Client](https://github.com/sendgrid/smtpapi-nodejs/issues?utf8=%E2%9C%93&q=is%3Aopen+label%3A%22difficulty%3A+easy%22+label%3A%22status%3A+help+wanted%22)
69
+ * [Java SMTPAPI Client](https://github.com/sendgrid/smtpapi-java/issues?utf8=%E2%9C%93&q=is%3Aopen+label%3A%22difficulty%3A+easy%22+label%3A%22status%3A+help+wanted%22)
70
+ * [Go SMTPAPI Client](https://github.com/sendgrid/smtpapi-go/issues?utf8=%E2%9C%93&q=is%3Aopen+label%3A%22difficulty%3A+easy%22+label%3A%22status%3A+help+wanted%22)
71
71
  * [Python HTTP Client](https://github.com/sendgrid/python-http-client/issues?utf8=%E2%9C%93&q=is%3Aopen+label%3A%22difficulty%3A+easy%22+label%3A%22status%3A+help+wanted%22)
72
72
  * [PHP HTTP Client](https://github.com/sendgrid/php-http-client/issues?utf8=%E2%9C%93&q=is%3Aopen+label%3A%22difficulty%3A+easy%22+label%3A%22status%3A+help+wanted%22)
73
73
  * [C# HTTP Client](https://github.com/sendgrid/csharp-http-client/issues?utf8=%E2%9C%93&q=is%3Aopen+label%3A%22difficulty%3A+easy%22+label%3A%22status%3A+help+wanted%22)
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (C) 2020, Twilio SendGrid, Inc. <help@twilio.com>
3
+ Copyright (C) 2021, Twilio SendGrid, Inc. <help@twilio.com>
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy of
6
6
  this software and associated documentation files (the "Software"), to deal in
@@ -19,13 +19,13 @@ Closes #2
19
19
  A short description of what this PR does.
20
20
 
21
21
  ### Checklist
22
- - [ ] I acknowledge that all my contributions will be made under the project's license
22
+ - [x] I acknowledge that all my contributions will be made under the project's license
23
23
  - [ ] I have made a material change to the repo (functionality, testing, spelling, grammar)
24
- - [ ] I have read the [Contribution Guidelines](CONTRIBUTING.md) and my PR follows them
24
+ - [ ] I have read the [Contribution Guidelines](https://github.com/sendgrid/sendgrid-ruby/blob/main/CONTRIBUTING.md) and my PR follows them
25
25
  - [ ] I have titled the PR appropriately
26
26
  - [ ] I have updated my branch with the main branch
27
27
  - [ ] I have added tests that prove my fix is effective or that my feature works
28
- - [ ] I have added necessary documentation about the functionality in the appropriate .md file
28
+ - [ ] I have added the necessary documentation about the functionality in the appropriate .md file
29
29
  - [ ] I have added inline documentation to the code I modified
30
30
 
31
- If you have questions, please file a [support ticket](https://twilio.com/help/contact), or create a GitHub Issue in this repository.
31
+ If you have questions, please file a [support ticket](https://support.sendgrid.com), or create a GitHub Issue in this repository.
data/README.md CHANGED
@@ -1,9 +1,9 @@
1
1
  ![Twilio SendGrid Logo](twilio_sendgrid_logo.png)
2
2
 
3
- [![Travis Badge](https://travis-ci.org/sendgrid/sendgrid-ruby.svg?branch=main)](https://travis-ci.org/sendgrid/sendgrid-ruby)
3
+ [![Travis Badge](https://travis-ci.com/sendgrid/sendgrid-ruby.svg?branch=main)](https://travis-ci.com/sendgrid/sendgrid-ruby)
4
4
  [![Gem Version](https://badge.fury.io/rb/sendgrid-ruby.svg)](https://badge.fury.io/rb/sendgrid-ruby)
5
5
  [![Email Notifications Badge](https://dx.sendgrid.com/badge/ruby)](https://dx.sendgrid.com/newsletter/ruby)
6
- [![MIT licensed](https://img.shields.io/badge/license-MIT-blue.svg)](./LICENSE.md)
6
+ [![MIT licensed](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)
7
7
  [![Twitter Follow](https://img.shields.io/twitter/follow/sendgrid.svg?style=social&label=Follow)](https://twitter.com/sendgrid)
8
8
  [![GitHub contributors](https://img.shields.io/github/contributors/sendgrid/sendgrid-ruby.svg)](https://github.com/sendgrid/sendgrid-ruby/graphs/contributors)
9
9
  [![Open Source Helpers](https://www.codetriage.com/sendgrid/sendgrid-ruby/badges/users.svg)](https://www.codetriage.com/sendgrid/sendgrid-ruby)
@@ -220,4 +220,4 @@ If you've instead found a bug in the library or would like new features added, g
220
220
 
221
221
  <a name="license"></a>
222
222
  # License
223
- [The MIT License (MIT)](LICENSE.md)
223
+ [The MIT License (MIT)](LICENSE)
data/USAGE.md CHANGED
@@ -3197,7 +3197,7 @@ puts response.status_code
3197
3197
  puts response.body
3198
3198
  puts response.headers
3199
3199
  ```
3200
- ## Remove an IP from a domain authenticaiton.
3200
+ ## Remove an IP from a domain authentication.
3201
3201
 
3202
3202
  **This endpoint allows you to remove a domain's IP address from that domain's authentication.**
3203
3203
 
@@ -1,4 +1,4 @@
1
- require_relative '../../lib/sendgrid-ruby.rb'
1
+ require_relative '../../lib/sendgrid-ruby'
2
2
  sg = SendGrid::API.new(api_key: ENV['SENDGRID_API_KEY'])
3
3
 
4
4
  ##################################################
@@ -39,6 +39,8 @@ module Rack
39
39
  request.env[SendGrid::EventWebhookHeader::TIMESTAMP]
40
40
  )
41
41
 
42
+ request.body.rewind
43
+
42
44
  if verified
43
45
  @app.call(env)
44
46
  else
@@ -4,7 +4,8 @@ require_relative 'version'
4
4
  # Initialize the HTTP client
5
5
  class BaseInterface
6
6
  attr_accessor :client
7
- attr_reader :request_headers, :host, :version, :impersonate_subuser
7
+ attr_reader :request_headers, :host, :version, :impersonate_subuser, :http_options
8
+
8
9
  # * *Args* :
9
10
  # - +auth+ -> authorization header value
10
11
  # - +host+ -> the base URL for the API
@@ -13,8 +14,9 @@ class BaseInterface
13
14
  # currently only "v3" is supported
14
15
  # - +impersonate_subuser+ -> the subuser to impersonate, will be passed
15
16
  # in the "On-Behalf-Of" header
17
+ # - +http_options+ -> http options that you want to be globally applied to each request
16
18
  #
17
- def initialize(auth:, host:, request_headers: nil, version: nil, impersonate_subuser: nil)
19
+ def initialize(auth:, host:, request_headers: nil, version: nil, impersonate_subuser: nil, http_options: {})
18
20
  @auth = auth
19
21
  @host = host
20
22
  @version = version || 'v3'
@@ -30,7 +32,9 @@ class BaseInterface
30
32
  @request_headers['On-Behalf-Of'] = @impersonate_subuser if @impersonate_subuser
31
33
 
32
34
  @request_headers = @request_headers.merge(request_headers) if request_headers
35
+ @http_options = http_options
33
36
  @client = SendGrid::Client.new(host: "#{@host}/#{@version}",
34
- request_headers: @request_headers)
37
+ request_headers: @request_headers,
38
+ http_options: @http_options)
35
39
  end
36
40
  end
@@ -18,7 +18,7 @@ require 'yaml'
18
18
  class Main < Sinatra::Base
19
19
  configure :production, :development do
20
20
  enable :logging
21
- set :config, YAML.load_file(File.dirname(__FILE__) + '/config.yml')
21
+ set :config, YAML.load_file("#{File.dirname(__FILE__)}/config.yml")
22
22
  end
23
23
 
24
24
  get '/' do
@@ -8,7 +8,7 @@ OPTS = {}.freeze
8
8
  opt = OptionParser.new
9
9
  opt.on('--host=HOST') { |v| OPTS[:host] = v }
10
10
  argv = opt.parse!(ARGV)
11
- config = YAML.load_file(File.dirname(__FILE__) + '/config.yml')
11
+ config = YAML.load_file("#{File.dirname(__FILE__)}/config.yml")
12
12
  host = OPTS[:host] || config['host']
13
13
  client = SendGrid::Client.new(host: host)
14
14
  File.open(argv[0]) do |file|
@@ -4,7 +4,9 @@ module SendGrid
4
4
  class Email
5
5
  attr_accessor :email, :name
6
6
 
7
- def initialize(email: nil, name: nil)
7
+ # @param [String] email required e-mail address
8
+ # @param [String] name optionally personification
9
+ def initialize(email:, name: nil)
8
10
  if name
9
11
  @email = email
10
12
  @name = name
@@ -15,6 +17,8 @@ module SendGrid
15
17
 
16
18
  def split_email(email)
17
19
  split = /(?:(?<address>.+)\s)?<?(?<email>.+@[^>]+)>?/.match(email)
20
+ raise ArgumentError, "email (#{email}) is invalid" unless split
21
+
18
22
  [split[:email], split[:address]]
19
23
  end
20
24
 
@@ -8,7 +8,9 @@ module SendGrid
8
8
  attr_reader :personalizations, :contents, :attachments, :categories, :sections, :headers, :custom_args
9
9
  attr_writer :from, :asm, :mail_settings, :tracking_settings, :reply_to
10
10
 
11
- def initialize(from_email = nil, subj = nil, to_email = nil, cont = nil)
11
+ # We allow for all nil values here to create uninitialized Mail objects
12
+ # (e.g. <project-root>/use-cases/transactional-templates.md)
13
+ def initialize(from_email = nil, subj = nil, to_email = nil, cont = nil) # rubocop:disable Metrics/ParameterLists
12
14
  @from = nil
13
15
  @subject = nil
14
16
  @personalizations = []
@@ -76,7 +76,7 @@ module SendGrid
76
76
  additional_email = addition.email.downcase
77
77
 
78
78
  [@tos, @ccs, @bccs].flatten.each do |elm|
79
- return true if elm&.dig('email') == additional_email
79
+ return true if elm&.dig('email')&.downcase == additional_email
80
80
  end
81
81
 
82
82
  false
@@ -3,6 +3,7 @@ require 'json'
3
3
  module SendGrid
4
4
  class TrackingSettings
5
5
  attr_writer :click_tracking, :open_tracking, :subscription_tracking, :ganalytics
6
+
6
7
  def initialize
7
8
  @click_tracking = nil
8
9
  @open_tracking = nil
@@ -3,7 +3,7 @@ require 'yaml'
3
3
 
4
4
  module SendGrid
5
5
  class Scope
6
- SCOPES = YAML.load_file(File.dirname(__FILE__) + '/scopes.yml').freeze
6
+ SCOPES = YAML.load_file("#{File.dirname(__FILE__)}/scopes.yml").freeze
7
7
 
8
8
  class << self
9
9
  def admin_permissions
@@ -9,12 +9,13 @@ module SendGrid
9
9
  # currently only "v3" is supported
10
10
  # - +impersonate_subuser+ -> the subuser to impersonate, will be passed
11
11
  # in the "On-Behalf-Of" header
12
+ # - +http_options+ -> http options that you want to be globally applied to each request
12
13
  #
13
- def initialize(api_key:, host: nil, request_headers: nil, version: nil, impersonate_subuser: nil)
14
+ def initialize(api_key:, host: nil, request_headers: nil, version: nil, impersonate_subuser: nil, http_options: {})
14
15
  auth = "Bearer #{api_key}"
15
16
  host ||= 'https://api.sendgrid.com'
16
17
 
17
- super(auth: auth, host: host, request_headers: request_headers, version: version, impersonate_subuser: impersonate_subuser)
18
+ super(auth: auth, host: host, request_headers: request_headers, version: version, impersonate_subuser: impersonate_subuser, http_options: http_options)
18
19
  end
19
20
  end
20
21
  end
@@ -1,3 +1,3 @@
1
1
  module SendGrid
2
- VERSION = '6.3.5'.freeze
2
+ VERSION = '6.4.0'.freeze
3
3
  end
@@ -7,7 +7,7 @@ module Fixtures
7
7
  SIGNATURE = 'MEUCIGHQVtGj+Y3LkG9fLcxf3qfI10QysgDWmMOVmxG0u6ZUAiEAyBiXDWzM+uOe5W0JuG+luQAbPIqHh89M15TluLtEZtM='.freeze
8
8
  FAILING_SIGNATURE = 'MEUCIQCtIHJeH93Y+qpYeWrySphQgpNGNr/U+UyUlBkU6n7RAwIgJTz2C+8a8xonZGi6BpSzoQsbVRamr2nlxFDWYNH3j/0='.freeze
9
9
  TIMESTAMP = '1600112502'.freeze
10
- PAYLOAD = [
10
+ PAYLOAD = "#{[
11
11
  {
12
12
  email: 'hello@world.com',
13
13
  event: 'dropped',
@@ -17,6 +17,6 @@ module Fixtures
17
17
  'smtp-id': '<LRzXl_NHStOGhQ4kofSm_A@ismtpd0039p1iad1.sendgrid.net>',
18
18
  timestamp: 1_600_112_492
19
19
  }
20
- ].to_json + "\r\n" # Be sure to include the trailing carriage return and newline!
20
+ ].to_json}\r\n".freeze # Be sure to include the trailing carriage return and newline!
21
21
  end
22
22
  end
@@ -112,5 +112,31 @@ unless RUBY_PLATFORM == 'java'
112
112
  expect(status).to eq(403)
113
113
  end
114
114
  end
115
+
116
+ describe 'request body which passed to an app' do
117
+ before do
118
+ @payload = nil
119
+ @spy_app = lambda do |env|
120
+ @payload = Rack::Request.new(env).body
121
+ [200, { 'Content-Type' => 'text/plain' }, ['Hello']]
122
+ end
123
+ end
124
+
125
+ let(:middleware) { Rack::SendGridWebhookVerification.new(@spy_app, public_key, %r{/email}) }
126
+
127
+ it 'keeps orignal reading position' do
128
+ options = {
129
+ :input => Fixtures::EventWebhook::PAYLOAD,
130
+ 'Content-Type' => "application/json"
131
+ }
132
+ options[SendGrid::EventWebhookHeader::SIGNATURE] = Fixtures::EventWebhook::SIGNATURE
133
+ options[SendGrid::EventWebhookHeader::TIMESTAMP] = Fixtures::EventWebhook::TIMESTAMP
134
+ request = Rack::MockRequest.env_for('/email', options)
135
+ status, headers, body = middleware.call(request)
136
+ expect(status).to eq(200)
137
+ expect(@payload).not_to be_nil
138
+ expect(@payload.pos).to be_zero
139
+ end
140
+ end
115
141
  end
116
142
  end
@@ -78,7 +78,7 @@ describe SendGrid::EventWebhook do
78
78
  Fixtures::EventWebhook::SIGNATURE,
79
79
  Fixtures::EventWebhook::TIMESTAMP
80
80
  )
81
- end .to raise_error(SendGrid::EventWebhook::NotSupportedError)
81
+ end.to raise_error(SendGrid::EventWebhook::NotSupportedError)
82
82
  end
83
83
  end
84
84
  end
@@ -29,4 +29,13 @@ class TestEmail < Minitest::Test
29
29
  }
30
30
  assert_equal @email.to_json, expected_json
31
31
  end
32
+
33
+ def test_mandatory_email_missing
34
+ assert_raises(ArgumentError) { Email.new(email: nil) }
35
+ assert_raises(ArgumentError) { Email.new(email: "") }
36
+ end
37
+
38
+ def test_invalid_email
39
+ assert_raises(ArgumentError) { Email.new(email: "some-invalid-string") }
40
+ end
32
41
  end
@@ -26,6 +26,7 @@ class TestPersonalization < Minitest::Test
26
26
  def test_duplicate_add_to
27
27
  @personalization = Personalization.new
28
28
  @personalization.add_to(Email.new(email: 'test1@example.com', name: 'Example User'))
29
+ @personalization.add_to(Email.new(email: 'TEST2@EXAMPLE.COM', name: 'Example User 2'))
29
30
 
30
31
  assert_raises(DuplicatePersonalizationError) do
31
32
  @personalization.add_to(Email.new(email: 'test1@example.com', name: 'Duplicate User'))
@@ -34,6 +35,14 @@ class TestPersonalization < Minitest::Test
34
35
  assert_raises(DuplicatePersonalizationError) do
35
36
  @personalization.add_to(Email.new(email: 'TEST1@EXAMPLE.COM', name: 'Duplicate User'))
36
37
  end
38
+
39
+ assert_raises(DuplicatePersonalizationError) do
40
+ @personalization.add_to(Email.new(email: 'test2@example.com', name: 'Duplicate User 2'))
41
+ end
42
+
43
+ assert_raises(DuplicatePersonalizationError) do
44
+ @personalization.add_to(Email.new(email: 'TEST2@EXAMPLE.COM', name: 'Duplicate User 2'))
45
+ end
37
46
  end
38
47
 
39
48
  def test_add_cc
@@ -58,6 +67,7 @@ class TestPersonalization < Minitest::Test
58
67
  def test_duplicate_add_cc
59
68
  @personalization = Personalization.new
60
69
  @personalization.add_cc(Email.new(email: 'test1@example.com', name: 'Example User'))
70
+ @personalization.add_cc(Email.new(email: 'TEST2@EXAMPLE.COM', name: 'Example User 2'))
61
71
 
62
72
  assert_raises(DuplicatePersonalizationError) do
63
73
  @personalization.add_cc(Email.new(email: 'test1@example.com', name: 'Duplicate User'))
@@ -66,6 +76,14 @@ class TestPersonalization < Minitest::Test
66
76
  assert_raises(DuplicatePersonalizationError) do
67
77
  @personalization.add_cc(Email.new(email: 'TEST1@EXAMPLE.COM', name: 'Duplicate User'))
68
78
  end
79
+
80
+ assert_raises(DuplicatePersonalizationError) do
81
+ @personalization.add_cc(Email.new(email: 'test2@example.com', name: 'Duplicate User 2'))
82
+ end
83
+
84
+ assert_raises(DuplicatePersonalizationError) do
85
+ @personalization.add_cc(Email.new(email: 'TEST2@EXAMPLE.COM', name: 'Duplicate User 2'))
86
+ end
69
87
  end
70
88
 
71
89
  def test_add_bcc
@@ -90,6 +108,7 @@ class TestPersonalization < Minitest::Test
90
108
  def test_duplicate_add_bcc
91
109
  @personalization = Personalization.new
92
110
  @personalization.add_bcc(Email.new(email: 'test1@example.com', name: 'Example User'))
111
+ @personalization.add_bcc(Email.new(email: 'TEST2@EXAMPLE.COM', name: 'Example User 2'))
93
112
 
94
113
  assert_raises(DuplicatePersonalizationError) do
95
114
  @personalization.add_bcc(Email.new(email: 'test1@example.com', name: 'Duplicate User'))
@@ -98,6 +117,14 @@ class TestPersonalization < Minitest::Test
98
117
  assert_raises(DuplicatePersonalizationError) do
99
118
  @personalization.add_bcc(Email.new(email: 'TEST1@EXAMPLE.COM', name: 'Duplicate User'))
100
119
  end
120
+
121
+ assert_raises(DuplicatePersonalizationError) do
122
+ @personalization.add_bcc(Email.new(email: 'test2@example.com', name: 'Duplicate User 2'))
123
+ end
124
+
125
+ assert_raises(DuplicatePersonalizationError) do
126
+ @personalization.add_bcc(Email.new(email: 'TEST2@EXAMPLE.COM', name: 'Duplicate User 2'))
127
+ end
101
128
  end
102
129
 
103
130
  def test_add_header
@@ -11,7 +11,7 @@ class TestCategory < Minitest::Test
11
11
  # 4. test read only and full access scopes by loading scopes.yaml
12
12
 
13
13
  def setup
14
- @scopes_from_yaml = YAML.load_file(File.dirname(__FILE__) + '/../../../lib/sendgrid/helpers/permissions/scopes.yml').freeze
14
+ @scopes_from_yaml = YAML.load_file("#{File.dirname(__FILE__)}/../../../lib/sendgrid/helpers/permissions/scopes.yml").freeze
15
15
  end
16
16
 
17
17
  def test_admin_scopes
@@ -1,6 +1,6 @@
1
1
  require 'simplecov'
2
2
  SimpleCov.start
3
- require_relative '../../lib/sendgrid-ruby.rb'
3
+ require_relative '../../lib/sendgrid-ruby'
4
4
  require 'ruby_http_client'
5
5
  require 'minitest/autorun'
6
6
  require 'minitest/unit'
@@ -33,8 +33,9 @@ class TestAPI < MiniTest::Test
33
33
  assert_equal(test_headers, sg.request_headers)
34
34
  assert_equal('v3', sg.version)
35
35
  assert_equal(subuser, sg.impersonate_subuser)
36
- assert_equal('6.3.5', SendGrid::VERSION)
36
+ assert_equal('6.4.0', SendGrid::VERSION)
37
37
  assert_instance_of(SendGrid::Client, sg.client)
38
+ assert_equal({}, sg.http_options)
38
39
  end
39
40
 
40
41
  def test_init_when_impersonate_subuser_is_not_given
@@ -42,6 +43,23 @@ class TestAPI < MiniTest::Test
42
43
  refute_includes(sg.request_headers, 'On-Behalf-Of')
43
44
  end
44
45
 
46
+ def test_init_when_http_options_is_given
47
+ params = JSON.parse('{"subuser": "test_string", "ip": "test_string", "limit": 1, "exclude_whitelabels": "true", "offset": 1}')
48
+ headers = JSON.parse('{"X-Mock": 200}')
49
+ http_options = {
50
+ open_timeout: 40,
51
+ read_timeout: 40
52
+ }
53
+
54
+ sg = SendGrid::API.new(api_key: 'SENDGRID_API_KEY', version: 'v3', http_options: http_options)
55
+ client = sg.client.ips
56
+ response = client.get(query_params: params, request_headers: headers)
57
+
58
+ assert_equal(40, client.http.open_timeout)
59
+ assert_equal(40, client.http.read_timeout)
60
+ assert_equal('200', response.status_code)
61
+ end
62
+
45
63
  def test_access_settings_activity_get
46
64
  params = JSON.parse('{"limit": 1}')
47
65
  headers = JSON.parse('{"X-Mock": 200}')
@@ -2653,7 +2671,7 @@ class TestAPI < MiniTest::Test
2653
2671
 
2654
2672
  def test_license_file_year
2655
2673
  # Read the third line from the license file
2656
- year = IO.readlines('./LICENSE.md')[2].gsub(/[^\d]/, '')
2674
+ year = IO.readlines('./LICENSE')[2].gsub(/[^\d]/, '')
2657
2675
  assert_equal(Time.now.year.to_s, year)
2658
2676
  end
2659
2677
 
@@ -2690,7 +2708,7 @@ class TestAPI < MiniTest::Test
2690
2708
  end
2691
2709
 
2692
2710
  def test_license_exists
2693
- assert(File.file?('./LICENSE.md'))
2711
+ assert(File.file?('./LICENSE'))
2694
2712
  end
2695
2713
 
2696
2714
  def test_pull_request_template_exists
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sendgrid-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 6.3.5
4
+ version: 6.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Elmer Thomas
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2020-09-28 00:00:00.000000000 Z
13
+ date: 2021-02-10 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: ruby_http_client
@@ -178,7 +178,7 @@ files:
178
178
  - FIRST_TIMERS.md
179
179
  - Gemfile
180
180
  - ISSUE_TEMPLATE.md
181
- - LICENSE.md
181
+ - LICENSE
182
182
  - Makefile
183
183
  - PULL_REQUEST_TEMPLATE.md
184
184
  - README.md