sendgrid-ruby 6.3.7 → 6.5.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 557de4c1544b5fabf263e6e2ba51ef3436df9d4e1ffcddd2a261364fae1a3741
4
- data.tar.gz: 9cff016cebe4cefaab71f93f78c90f69a95ab777361f811765dcd20f17942b82
3
+ metadata.gz: b941f6f9d42b1635efa45774843ac79466ae526b87ae1c4e11798f0f65f60d18
4
+ data.tar.gz: 50547fada575f32430c13b830faa1959867a8edc2285ede32c5e167f53990144
5
5
  SHA512:
6
- metadata.gz: 75f88a178eedb1c00bfb9afd77dfd74662679c49ef4005212bb23ffe7dc70ef89252a52781c3453f575aa92c5816e58a1750486c2e1d80878925e575bdf35312
7
- data.tar.gz: '08df2ab9cea1a8b25ba49812cebffde0073afc0f50227680045b3e1f8b2a87c4fb6bbe3dca4cc7b53a569d9df07097dcb6bc2f33185104854c5a9a6cefabd61d'
6
+ metadata.gz: 35436f3cf7a212e98dc9825eeca8fd64bc589f201956a890f158d740234f9b7399590d4e3c0b2836d9f072e2fbc88119b01ef8bac6b86fd10024ed5b36518b0b
7
+ data.tar.gz: 1917abc8a67a84c905a0b1ff071c3352ea8e73fc6cd06095dcd4888cc0e55b902c2103db71fa13919d625674fbb83a9ad3ee05de7d635380358906e3cf1f382f
@@ -0,0 +1,10 @@
1
+ contact_links:
2
+ - name: Twilio SendGrid Support
3
+ url: https://support.sendgrid.com
4
+ about: Get Support
5
+ - name: Stack Overflow
6
+ url: https://stackoverflow.com/questions/tagged/sendgrid-ruby+or+sendgrid+ruby
7
+ about: Ask questions on Stack Overflow
8
+ - name: Documentation
9
+ url: https://sendgrid.com/docs/for-developers/
10
+ about: View Reference Documentation
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/.travis.yml CHANGED
@@ -1,25 +1,25 @@
1
1
  language: ruby
2
2
  env:
3
- - version=ruby:2.7
4
- - version=ruby:2.6
5
- - version=ruby:2.5
6
- - version=ruby:2.4
7
- - version=jruby:9.2
8
-
3
+ - version=ruby:2.7
4
+ - version=ruby:2.6
5
+ - version=ruby:2.5
6
+ - version=ruby:2.4
7
+ - version=jruby:9.2
9
8
  gemfile:
10
- - gemfiles/Sinatra_1.gemfile
11
- - gemfiles/Sinatra_2.gemfile
12
-
13
- script: make test-docker
14
-
9
+ - gemfiles/Sinatra_1.gemfile
10
+ - gemfiles/Sinatra_2.gemfile
11
+ script:
12
+ - if [[ "$TRAVIS_BRANCH" == "main" || "$TRAVIS_BRANCH" == "travis" ]] && [ "$TRAVIS_PULL_REQUEST" == "false" ]; then
13
+ echo "${DOCKER_PASSWORD}" | docker login -u "${DOCKER_USERNAME}" --password-stdin;
14
+ fi
15
+ - make test-docker
15
16
  deploy:
16
17
  provider: rubygems
17
- api_key: $RUBYGEMS_API_KEY
18
+ api_key: "$RUBYGEMS_API_KEY"
18
19
  gem: sendgrid-ruby
19
20
  on:
20
21
  tags: true
21
22
  condition: $version = ruby:2.4 && $BUNDLE_GEMFILE = *"gemfiles/Sinatra_1.gemfile"
22
-
23
23
  notifications:
24
24
  slack:
25
25
  if: branch = main
@@ -27,4 +27,4 @@ notifications:
27
27
  on_success: never
28
28
  on_failure: change
29
29
  rooms:
30
- - secure: QwoVrGveeA1bo/26fO2A+OQHmUX69NLaC214qd18C1Z8ztYMHkd05/9+k9HFb+PSdPkGLSeYOPWAKJUqJWB7HfGINNGpRGIPFcmfB7vhvvLFnhud/SAdQPRZ+SCeZPdpZcjpVRLYENKv259ucGPBCPFXh1HfJF92R0IrKeW5CII=
30
+ secure: oSeohwM+ernyiRYSRLpNlICk0wgj0lku3y5LuouJLRHs45tCAzLZLbgxsor18wCSJkmhfn2vg4Rn969VnskFuj70OhJSLBKL4UXBnR1Ji0ClpfJlGojcbY/5Z8N/eGDrvf5ofA0Jc+L/ut+oSCMXnstEGbx4wBpPTajHuRtvb34=
data/CHANGELOG.md CHANGED
@@ -1,6 +1,31 @@
1
1
  # Change Log
2
2
  All notable changes to this project will be documented in this file.
3
3
 
4
+ [2021-08-11] Version 6.5.0
5
+ --------------------------
6
+ **Library - Feature**
7
+ - [PR #466](https://github.com/sendgrid/sendgrid-ruby/pull/466): Add From address to personalization. Thanks to [@grin](https://github.com/grin)!
8
+
9
+
10
+ [2021-02-10] Version 6.4.0
11
+ --------------------------
12
+ **Library - Feature**
13
+ - [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)!
14
+
15
+
16
+ [2021-01-27] Version 6.3.9
17
+ --------------------------
18
+ **Library - Fix**
19
+ - [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)!
20
+ - [PR #457](https://github.com/sendgrid/sendgrid-ruby/pull/457): email is required. Thanks to [@luk4s](https://github.com/luk4s)!
21
+
22
+
23
+ [2020-12-16] Version 6.3.8
24
+ --------------------------
25
+ **Library - Fix**
26
+ - [PR #448](https://github.com/sendgrid/sendgrid-ruby/pull/448): tests failing on rubocop rule. Thanks to [@thinkingserious](https://github.com/thinkingserious)!
27
+
28
+
4
29
  [2020-11-05] Version 6.3.7
5
30
  --------------------------
6
31
  **Library - Chore**
data/LICENSE CHANGED
@@ -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
data/README.md CHANGED
@@ -2,7 +2,6 @@
2
2
 
3
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
- [![Email Notifications Badge](https://dx.sendgrid.com/badge/ruby)](https://dx.sendgrid.com/newsletter/ruby)
6
5
  [![MIT licensed](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)
7
6
  [![Twitter Follow](https://img.shields.io/twitter/follow/sendgrid.svg?style=social&label=Follow)](https://twitter.com/sendgrid)
8
7
  [![GitHub contributors](https://img.shields.io/github/contributors/sendgrid/sendgrid-ruby.svg)](https://github.com/sendgrid/sendgrid-ruby/graphs/contributors)
@@ -18,6 +18,7 @@ def hello_world
18
18
  puts response.headers
19
19
  end
20
20
 
21
+ # rubocop:disable Metrics/AbcSize
21
22
  def kitchen_sink
22
23
  mail = SendGrid::Mail.new
23
24
  mail.from = Email.new(email: 'test@example.com')
@@ -29,6 +30,9 @@ def kitchen_sink
29
30
  personalization.add_cc(Email.new(email: 'test4@example.com', name: 'Example User'))
30
31
  personalization.add_bcc(Email.new(email: 'test5@example.com', name: 'Example User'))
31
32
  personalization.add_bcc(Email.new(email: 'test6@example.com', name: 'Example User'))
33
+ # Note, the domain of the from email property specified in any personalization must
34
+ # match the domain of the from email property specified at root level
35
+ personalization.from = Email.new(email: 'alias@example.com', name: "My alias")
32
36
  personalization.subject = 'Hello World from the Personalized Twilio SendGrid Ruby Library'
33
37
  personalization.add_header(Header.new(key: 'X-Test', value: 'True'))
34
38
  personalization.add_header(Header.new(key: 'X-Mock', value: 'False'))
@@ -124,6 +128,7 @@ def kitchen_sink
124
128
  puts response.body
125
129
  puts response.headers
126
130
  end
131
+ # rubocop:enable Metrics/AbcSize
127
132
 
128
133
  def dynamic_template_data_hello_world
129
134
  mail = Mail.new
@@ -4,7 +4,7 @@ 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
9
  # * *Args* :
10
10
  # - +auth+ -> authorization header value
@@ -14,8 +14,9 @@ class BaseInterface
14
14
  # currently only "v3" is supported
15
15
  # - +impersonate_subuser+ -> the subuser to impersonate, will be passed
16
16
  # in the "On-Behalf-Of" header
17
+ # - +http_options+ -> http options that you want to be globally applied to each request
17
18
  #
18
- 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: {})
19
20
  @auth = auth
20
21
  @host = host
21
22
  @version = version || 'v3'
@@ -31,7 +32,9 @@ class BaseInterface
31
32
  @request_headers['On-Behalf-Of'] = @impersonate_subuser if @impersonate_subuser
32
33
 
33
34
  @request_headers = @request_headers.merge(request_headers) if request_headers
35
+ @http_options = http_options
34
36
  @client = SendGrid::Client.new(host: "#{@host}/#{@version}",
35
- request_headers: @request_headers)
37
+ request_headers: @request_headers,
38
+ http_options: @http_options)
36
39
  end
37
40
  end
@@ -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 = []
@@ -5,10 +5,11 @@ module SendGrid
5
5
  attr_reader :tos, :ccs, :bccs, :headers, :substitutions, :custom_args,
6
6
  :dynamic_template_data
7
7
 
8
- attr_accessor :send_at, :subject
8
+ attr_accessor :send_at, :subject, :from
9
9
 
10
10
  def initialize
11
11
  @tos = []
12
+ @from = nil
12
13
  @ccs = []
13
14
  @bccs = []
14
15
  @subject = nil
@@ -59,6 +60,7 @@ module SendGrid
59
60
  def to_json(*)
60
61
  {
61
62
  'to' => tos,
63
+ 'from' => from,
62
64
  'cc' => ccs,
63
65
  'bcc' => bccs,
64
66
  'subject' => subject,
@@ -76,7 +78,7 @@ module SendGrid
76
78
  additional_email = addition.email.downcase
77
79
 
78
80
  [@tos, @ccs, @bccs].flatten.each do |elm|
79
- return true if elm&.dig('email') == additional_email
81
+ return true if elm&.dig('email')&.downcase == additional_email
80
82
  end
81
83
 
82
84
  false
@@ -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.7'.freeze
2
+ VERSION = '6.5.0'.freeze
3
3
  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
@@ -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.7', SendGrid::VERSION)
36
+ assert_equal('6.5.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}')
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.7
4
+ version: 6.5.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-11-05 00:00:00.000000000 Z
13
+ date: 2021-08-11 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: ruby_http_client
@@ -167,6 +167,7 @@ extra_rdoc_files: []
167
167
  files:
168
168
  - ".codeclimate.yml"
169
169
  - ".env_sample"
170
+ - ".github/ISSUE_TEMPLATE/config.yml"
170
171
  - ".gitignore"
171
172
  - ".rubocop.yml"
172
173
  - ".rubocop_todo.yml"