Skip to content

Commit

Permalink
Add Sendgrid.api_key parameter to remove it from env.
Browse files Browse the repository at this point in the history
  • Loading branch information
Elodie Ailleaume authored and Elodie Ailleaume committed Mar 7, 2022
1 parent 709f84a commit 4b4c9fd
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 6 deletions.
20 changes: 20 additions & 0 deletions lib/sendgrid.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,22 @@
module Sendgrid
extend self

def parameter(*names)
names.each do |name|
attr_accessor name

define_method name do |*values|
value = values.first
value ? self.send("#{name}=", value) : instance_variable_get("@#{name}")
end
end
end

def config(&block)
instance_eval &block
end
end

Sendgrid.config do
parameter :api_key
end
2 changes: 1 addition & 1 deletion lib/sendgrid/list.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ class Sendgrid::List
attr_accessor :name

def initialize(data = {})
@api = ::SendGrid::API.new(api_key: ENV['SENDGRID_API_KEY'])
@api = ::SendGrid::API.new(api_key: Sendgrid.api_key)
@errors = nil
reset_properties
@name ||= data["name"]
Expand Down
2 changes: 1 addition & 1 deletion lib/sendgrid/recipient.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ class Sendgrid::Recipient
attr_accessor :email, :first_name, :last_name

def initialize
@api = ::SendGrid::API.new(api_key: ENV['SENDGRID_API_KEY'])
@api = ::SendGrid::API.new(api_key: Sendgrid.api_key)
@errors = nil
reset_properties
end
Expand Down
2 changes: 1 addition & 1 deletion lib/sendgrid/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Sendgrid
VERSION = "1.0.1"
VERSION = "1.1.0"
end
6 changes: 3 additions & 3 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
require "sendgrid-object"
require 'webmock/rspec'

ENV['SENDGRID_API_KEY']="ThisIsAFakeKey"
Sendgrid.api_key = "ThisIsAFakeKey"

RSpec.configure do |config|

Expand All @@ -12,14 +12,14 @@
headers = {
'Accept'=>'application/json',
'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
'Authorization'=>"Bearer #{ENV['SENDGRID_API_KEY']}",
'Authorization'=>"Bearer #{Sendgrid.api_key}",
'Content-Type'=>'application/json',
'User-Agent'=>'sendgrid/6.6.1;ruby'
}
headers_without_content_type = {
'Accept'=>'application/json',
'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
'Authorization'=>"Bearer #{ENV['SENDGRID_API_KEY']}",
'Authorization'=>"Bearer #{Sendgrid.api_key}",
'User-Agent'=>'sendgrid/6.6.1;ruby'
}

Expand Down

0 comments on commit 4b4c9fd

Please sign in to comment.