Unverified Commit fe68d57d authored by Aral Balkan's avatar Aral Balkan
Browse files

Migrate example with client side updates from App.net to Mastodon

parent 30878dd5
......@@ -2,7 +2,7 @@
#
# Set client side updates example.
#
# Displays the global timeline from App.net with client side updates
# Displays the global timeline from mastodon.social with client side updates
# using the same template.
#
# Copyright © Aral Balkan.
......@@ -15,36 +15,26 @@ superagent = require 'superagent'
exports.route = (request, response) ->
superagent.get('https://alpha-api.app.net/stream/0/posts/stream/global')
superagent.get('https://mastodon.social/api/v1/timelines/public')
.end (error, globalTimelineResponse) ->
globalTimeline = globalTimelineResponse.body
# Attach a custom function to the data to count the number of posts
globalTimelineResponse.body.numberOfPosts = ->
if this.data
return this.data.length
else
return 0
# Ask for the data to be injected into the rendered template
# (we’re going to append to it via Ajax calls on the client‐side to render an
# expanding timeline of App.net posts.)
globalTimeline.__set =
injectData: yes
# Handle network and App.net errors gracefully.
if error
# There was a network error
globalTimeline.errorType = 'Network'
globalTimeline.error = error
# There was a network error
globalTimeline.errorType = 'Network'
globalTimeline.error = error
else if not globalTimeline.data
else if not globalTimeline
# There was an App.net error
globalTimeline.errorType = 'App.net'
globalTimeline.error = "(##{globalTimeline.meta.code}) #{globalTimeline.meta.error_message}"
# There was an App.net error
globalTimeline.errorType = 'App.net'
globalTimeline.error = "Could not get the public timeline."
# Render the response and ask for the data to be injected into the rendered template
# (we’re going to append to it via Ajax calls on the client‐side to render an
# expanding timeline of App.net posts.)
# Render the response
response.render 'posts-client-side-updates', globalTimeline
response.render 'posts-client-side-updates', { data: globalTimeline, __set: { injectData: yes } }
This diff is collapsed.
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment