Skip to content

Instantly share code, notes, and snippets.

@bsag
Last active March 6, 2017 21:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bsag/5894847 to your computer and use it in GitHub Desktop.
Save bsag/5894847 to your computer and use it in GitHub Desktop.
Dashing (http://shopify.github.io/dashing/) widget that gets your recent posts on App.net. Uses the publicly available RSS feed.

Description

Dashing (http://shopify.github.io/dashing/) widget that gets your recent posts on App.net. Uses the publicly available RSS feed. You can find this feed on your profile page (RSS link).

Screenshot

appnet widget screenshot

Dependencies

feedzirra

Add feedzirra to Dashing's Gemfile:

gem 'feedzirra'

and then run bundle install

Usage

The easiest way to use this widget is to use dashing install 5894847 which will put all the files in their right place. If you would like to install manually, copy appnet.html, appnet.coffee, and appnet.scss into the /widgets/appnet directory. Put the appnet.rb file in your /jobs folder. Don't forget to change the URL in appnet.rb to your own App.net URL!

To include the widget in a dashboard, add the following snippet to the dashboard layout file:

<li data-row="1" data-col="1" data-sizex="1" data-sizey="1">
  <div data-id="adn" data-view="Appnet" data-title="App.net posts" data-interval="20"></div>
</li>

At the top of the news.rb job file, add any rss feed urls you want fetched to the hash, and the widget id to send data to. In the dashboard layout file, the optional data-interval binding can be used to specify how frequently to rotate the news items.

class Dashing.Appnet extends Dashing.Widget
ready: ->
@currentIndex = 0
@postElem = $(@node).find('.post-container')
@nextComment()
@startCarousel()
onData: (data) ->
@currentIndex = 0
startCarousel: ->
interval = $(@node).attr('data-interval')
interval = "30" if not interval
setInterval(@nextComment, parseInt( interval ) * 1000)
nextComment: =>
posts = @get('posts')
if posts
@postElem.fadeOut =>
@currentIndex = (@currentIndex + 1) % posts.length
@set 'current_post', posts[@currentIndex]
@postElem.fadeIn()
<div class="heading" data-bind="title"></div>
<div class="post-container">
<div class="summary" data-bind="current_post.summary | raw"></div>
</div>
<p class="more-info" data-bind="current_post.published | raw"></p>
require 'feedzirra'
# :first_in sets how long it takes before the job is first run. In this case, it is run immediately
SCHEDULER.every '30m', :first_in => 0 do |job|
# Add your own RSS feed URL here. You can find the link on your profile page
feed = Feedzirra::Feed.fetch_and_parse("https://alpha-api.app.net/feed/rss/users/3041/posts")
posts = []
feed.entries.each do |post|
summary = post.summary
published = post.published.strftime("Posted at %H:%S on %-d %b")
posts.push({summary: summary, published: published})
end
posts
send_event('adn', { :posts => posts })
end
$background-color: #ff9618;
$value-color: #fff;
$title-color: rgba(255, 255, 255, 0.7);
$moreinfo-color: rgba(255, 255, 255, 0.8);
.widget-appnet {
background-color: $background-color;
vertical-align: baseline !important;
.heading {
color: $title-color;
margin-bottom: 1.2em;
font-size: 1.2em;
}
.more-info {
color: $moreinfo-color;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment