Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialEgo Team
17,902 PointsI need to make an app prototype for native ios and android with html5/css/js through phonegap.
They want me to add this in but i have no idea how. its a news feed type thing. He said he would email the api so that i can get the feed from their server. This is the email i got from him.
"API Endpoint for Club Flames locker feed.
https://jbfsports.com/api/group/3e331474d42acc4b347f30dc8c4074f547491dda/content/stream?limit=4
javascript and java parsing of the data below:
JAVASCRIPT: <script type="text/javascript"> $(function() { $('#locker-feed').parseTemplateViaAPI('https://www.jbfsports.com{{lockerURI}}', function(data) { console.log('Loaded', data.count, 'locker items'); _.each(data.content, function(post, idx) { post.ownerInfo = data.parents[ post.owner ]; for(var prop in post.ownerInfo) { console.log("lockerfeed.html -> post.ownerInfo."+prop +" = "+post.ownerInfo[prop]); } _.each (post.ownerInfo, function (el) { console.log("lockerfeed.html -> post.owner: "+el); } ) post.timestamp = moment(post.postedOn * 1000).fromNow(); /* NOTE: THE BANNER STUFF NEEDS TO BE IMPLEMENTED PROPERLY TO SUPPORT MANY TEAMS */ post.bannerName = post.ownerInfo.name.toLowerCase().replace(/ /g, '');
post.bannerHost = '{{host.match}}' || (post.bannerName.indexOf('hawk') >= 0 ? 'clubblackhawks.com' : 'clubflames.com');
console.log("lockerfeed.html -> post.bannerHost: "+post.bannerHost);
if (post.type === 'image') {
var ext = post.meta.name.split('.').pop();
var fileSmall = [post.hash, '-s', '.', ext].join('');
var fileMedium = [post.hash, '-m', '.', ext].join('');
var prefix = [post.hash.slice(0,2),
post.hash.slice(2,4),
post.hash.slice(4,6)].join('/');
post.imageuriSmall = ['https://www.jbfsports.com/static/', prefix, fileSmall].join('/');
post.imageuriMedium = ['https://www.jbfsports.com/static/', prefix, fileMedium].join('/');
console.log(post.imageuri)
} else {
post.hidden = true;
}
post.hidden = (post.hide === 1) || post.hidden;
});
});
}); </script>
JAVA public LockerFeed getApplicationLockerFeed(int offset) { LockerFeed feed = null;
String resourceSlug = String.format("/api/group/%s/content/stream?offset=%d&limit=%d",
Config.kApplicationGroupHash, offset, Config.kContentLoadIncrement);
if (Config.L)
Log.i(TAG, resourceSlug);
String lockerFeedContent = executeResourceAsString(OAuthUtils.HTTP_GET, resourceSlug, null);
if (Config.L && lockerFeedContent != null)
Log.i(TAG, lockerFeedContent);
if (lockerFeedContent != null) {
Gson gson = new Gson();
try {
feed = gson.fromJson(lockerFeedContent, LockerFeed.class);
} catch (JsonSyntaxException e) {
Log.e(TAG, "getApplicationLockerFeed", e);
feed = null;
}
// the json for parents is non-standard, so pull that out manually and populate the parent list
Hashtable<String, LockerParent> parentList = new Hashtable<String, LockerParent>();
try {
JSONObject jsonObject = new JSONObject(lockerFeedContent);
JSONObject parent = jsonObject.getJSONObject("parents");
JSONArray parentNames = parent.names();
if (parentNames != null) {
for (int i = 0; i < parentNames.length(); i++) {
JSONObject nextParent = parent.getJSONObject(parentNames.getString(i));
LockerParent lockerParent = new LockerParent();
lockerParent.setHash(nextParent.getString("hash"));
lockerParent.setName(nextParent.getString("name"));
lockerParent.setType(nextParent.getString("type"));
parentList.put(parentNames.getString(i), lockerParent);
}
}
} catch (JSONException e) {
Log.e(TAG, "ERROR: getApplicationLockerFeed", e);
e.printStackTrace();
}
feed.setParentList(parentList);
// loop through our content and set parent and owner
for (LockerContent content : feed.getContent()) {
if (content.getParents() != null && content.getParents().length > 0) {
content.setParentDetail(parentList.get(content.getParents()[0]));
}
if (content.getOwner() != null && content.getOwner().length() > 0) {
content.setOwnerDetail(parentList.get(content.getOwner()));
}
}
}
return feed;
}
Please help!!