I'm trying to display SendGrid email statistics inside my Rails application.
So far, I've been able to display them in API's return format (e.g. [{"delivered"=>9, "unsubscribes"=>0, "repeat_bounces"=>2,....
), but that's only if I put the plaintext username and password into my controller's private method because I cannot seem to use 'SENDGRID_USERNAME'
and the 'SENDGRID_PASSWORD'
environment variables. What's a guy to do?
In summation:
NewslettersController:
before_action :set_client, only: :index
private
def set_client
@client = SendGridWebApi::Client.new('the plaintext username', 'the plaintext password')
end
Newsletters Index View
<p><%= @client.stats.get %></p>
Is there another place where I can set @client
where my view can get to it and my plaintext password can be hidden from the outside world? preferably a place I can put in secrets.yml
?
@client = SendGridWebApi::Client.new('SENDGRID_USERNAME', 'SENDGRID_PASSWORD')
Returns an incorrect username and password, even though I got the plaintext username and password I'm using for testing from those variables, so I know that they're set to the correct ones.
Or, is there a way to use environment variables in either my controller or my view?
I'm able to set the variables in the Rails Console and then use them, but since they don't get saved I can't access them afterwords in my actual application.