-
Notifications
You must be signed in to change notification settings - Fork 112
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: create linkedin post when TIL is created
Showing
7 changed files
with
87 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
defmodule Test.Notifications.Notifiers.Linkedin do | ||
use Tilex.Notifications.Notifier | ||
|
||
def handle_post_created(_post, _developer, _channel, _url) do | ||
:ok | ||
end | ||
|
||
def handle_post_liked(_post, _developer, _url) do | ||
:ok | ||
end | ||
|
||
def handle_page_views_report(_report) do | ||
:ok | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
defmodule Tilex.LinkedinApi do | ||
use Tesla, only: [:post] | ||
|
||
plug Tesla.Middleware.BaseUrl, "https://api.linkedin.com/v2" | ||
plug Tesla.Middleware.Headers, [{"Content-Type", "application/json"}] | ||
plug Tesla.Middleware.BearerAuth, token: Application.get_env(:tilex, :linkedin_access_token) | ||
plug Tesla.Middleware.JSON | ||
|
||
def create_post(post_body) do | ||
post("/posts", post_body) | ||
end | ||
|
||
def create_post_body(commentary, title, url) do | ||
%{ | ||
author: "urn:li:organization:" <> org_id(), | ||
commentary: commentary, | ||
visibility: "PUBLIC", | ||
distribution: %{ | ||
feedDistribution: "MAIN_FEED", | ||
targetEntities: [], | ||
thirdPartyDistributionChannels: [] | ||
}, | ||
content: %{ | ||
article: %{ | ||
source: url, | ||
title: title | ||
} | ||
}, | ||
lifecycleState: "PUBLISHED", | ||
isReshareDisabledByAuthor: false | ||
} | ||
end | ||
|
||
defp org_id, do: Application.get_env(:tilex, :linkedin_organization_id) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
defmodule Tilex.Notifications.Notifiers.Linkedin do | ||
alias Tilex.Blog.Developer | ||
|
||
import Tilex.LinkedinApi | ||
|
||
use Tilex.Notifications.Notifier | ||
|
||
@impl true | ||
def handle_post_created(post, developer, channel, url) do | ||
"#{post.title} #{url} via @#{Developer.twitter_handle(developer)} #til ##{channel.twitter_hashtag}" | ||
|> create_post_body(post.title, url) | ||
|> create_post() | ||
end | ||
|
||
@impl true | ||
def handle_post_liked(_post, _dev, _url) do | ||
:ok | ||
end | ||
|
||
@impl true | ||
def handle_page_views_report(_report) do | ||
:ok | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters