Skip to content

Commit

Permalink
refactor: move twitter creds to config
Browse files Browse the repository at this point in the history
  • Loading branch information
jackrosa183 authored and avogel3 committed Sep 20, 2024
1 parent 7d90da8 commit 66ec669
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 14 deletions.
6 changes: 6 additions & 0 deletions config/config.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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"
19 changes: 5 additions & 14 deletions lib/tilex/notifications/notifiers/twitter.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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

0 comments on commit 66ec669

Please sign in to comment.