From 2ab224fec20005d36678f75a2ce40ca9e1030b8f Mon Sep 17 00:00:00 2001 From: Chris Cummer Date: Tue, 31 Jul 2018 21:01:12 -0700 Subject: [PATCH] Update Twitter client to use config.yml or ENV vars --- twitter/client.go | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/twitter/client.go b/twitter/client.go index eea00841..817878ab 100644 --- a/twitter/client.go +++ b/twitter/client.go @@ -5,6 +5,8 @@ import ( "fmt" "os" "strconv" + + "github.com/senorprogrammer/wtf/wtf" ) /* NOTE: Currently single application ONLY @@ -22,12 +24,13 @@ type Client struct { // NewClient creates and returns a new Twitter client func NewClient(url string) *Client { client := Client{ - apiBase: url, - screenName: "wtfutil", - count: 5, - bearerToken: os.Getenv("WTF_TWITTER_BEARER_TOKEN"), + apiBase: url, + screenName: "wtfutil", + count: 5, } + client.loadAPICredentials() + return &client } @@ -62,3 +65,10 @@ func (client *Client) tweets() (tweets []Tweet, err error) { return } + +func (client *Client) loadAPICredentials() { + client.bearerToken = wtf.Config.UString( + "wtf.mods.twitter.bearerToken", + os.Getenv("WTF_TWITTER_BEARER_TOKEN"), + ) +}