This repository has been archived by the owner on Nov 17, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from optikfluffel/rss
Add RSS feed of jobs at /feed
- Loading branch information
Showing
6 changed files
with
71 additions
and
18 deletions.
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
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,48 @@ | ||
defmodule ElixirJobs.FeedController do | ||
use ElixirJobs.Web, :controller | ||
use Timex | ||
|
||
alias Exrethinkdb.Query | ||
alias ElixirJobs.Repo | ||
|
||
@title "ElixirDose Jobs" | ||
@baseurl "http://jobs.elixirdose.com" | ||
@description "Elixir Jobs is the best place to find, list jobs and developer community space specifically for Elixir Programming Language." | ||
@lang "en-us" | ||
|
||
defp format_rfc(date) do | ||
date |> DateFormat.format!("%a, %d %b %Y %H:%M:%S %z", :strftime) | ||
end | ||
|
||
defp job_to_rss_item(job) do | ||
date = job["date_created"] |> Date.from(:secs, :epoch) | ||
|> format_rfc | ||
|
||
RSS.item( | ||
job["title"], | ||
job["description"], | ||
date, | ||
"#{@baseurl}/job/#{job["id"]}", | ||
job["id"] | ||
) | ||
end | ||
|
||
def index(conn, _params) do | ||
date = Date.now |> format_rfc | ||
|
||
channel = RSS.channel( | ||
@title, | ||
@baseurl, | ||
@description, | ||
date, | ||
"lang (#{@lang})" | ||
) | ||
|
||
items = Query.table("jobs") |> Repo.run | ||
|> Map.get(:data) | ||
|> Enum.map(&job_to_rss_item(&1)) | ||
|
||
conn |> put_resp_content_type("application/xml") | ||
|> text(RSS.feed(channel, items)) | ||
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