diff --git a/config/config.exs b/config/config.exs index f38bcf98..56658113 100644 --- a/config/config.exs +++ b/config/config.exs @@ -108,6 +108,12 @@ config :tilex, Tilex.Auth.Guardian, "kty" => "oct" } +config :tilex, Tilex.Notifications.Notifiers.Twitter, + consumer_key: System.get_env("twitter_consumer_key"), + consumer_secret: System.get_env("twitter_consumer_secret"), + token: System.get_env("twitter_access_token"), + token_secret: System.get_env("twitter_access_token_secret") + # Import environment specific config. This must remain at the bottom # of this file so it overrides the configuration defined above. import_config "#{Mix.env()}.exs" diff --git a/lib/tilex/notifications/notifiers/twitter.ex b/lib/tilex/notifications/notifiers/twitter.ex index 1bdf3aa6..536592a2 100644 --- a/lib/tilex/notifications/notifiers/twitter.ex +++ b/lib/tilex/notifications/notifiers/twitter.ex @@ -4,6 +4,8 @@ defmodule Tilex.Notifications.Notifiers.Twitter do use Tilex.Notifications.Notifier + @tweets_url "https://api.x.com/2/tweets" + def handle_post_created(post, developer, channel, url) do "#{post.title} #{url} via @#{Developer.twitter_handle(developer)} #til ##{channel.twitter_hashtag}" |> send_tweet @@ -17,8 +19,6 @@ defmodule Tilex.Notifications.Notifiers.Twitter do :ok end - @tweets_url "https://api.x.com/2/tweets" - def send_tweet(message) do params = %{ "text" => message @@ -39,17 +39,8 @@ defmodule Tilex.Notifications.Notifiers.Twitter do end def oauth_creds do - consumer_key = System.get_env("twitter_consumer_key") - consumer_secret = System.get_env("twitter_consumer_secret") - access_token = System.get_env("twitter_access_token") - access_token_secret = System.get_env("twitter_access_token_secret") - - OAuther.credentials( - method: :hmac_sha1, - consumer_key: consumer_key, - consumer_secret: consumer_secret, - token: access_token, - token_secret: access_token_secret - ) + credentials = Application.get_env(:tilex, __MODULE__) + + OAuther.credentials(credentials ++ [method: :hmac_sha1]) end end