Skip to content

Commit

Permalink
adding functionality for searching by user id, location, and popular.
Browse files Browse the repository at this point in the history
  • Loading branch information
DDKnoll committed May 20, 2014
1 parent 656be78 commit e22ae8c
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 17 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ Sample Usage:
el: 'template-target',
template: template,
clientID: 'Your Instagram Client ID',
hashtag: 'webdesign',
hashtag: query,
complete: infiniteScrollBinding
});

Expand All @@ -80,5 +80,6 @@ Function Reference
TODO:

1. Minify JS
2. Finish Documentation
3. Develop Testing Framework
2. Generate more query urls (search users, locations, etc.)
3. Finish Documentation
4. Develop Testing Framework
65 changes: 51 additions & 14 deletions js/instagram.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,57 @@
var instagramFeed = Ractive.extend({
lazy:true,

makeQuery: function(method){
var query = '';
var callback = '';
makeQuery: function(method) {
var base, endpoint, final, callback;
base = "https://api.instagram.com/v1";
switch (this.data.method) {
case "popular":
endpoint = "media/popular";
break;
case "tags":
if (typeof this.data.search !== 'string') {
throw new Error("No tag name specified. Use the 'tagName' option.");
}
endpoint = "tags/" + this.data.search + "/media/recent";
break;
case "location":
if (typeof this.data.location !== 'number') {
throw new Error("No location specified. Use the 'locationId' option.");
}
endpoint = "locations/" + this.data.search + "/media/recent";
break;
case "user":
if (typeof this.data.userId !== 'number') {
throw new Error("No user specified. Use the 'userId' option.");
}
if (typeof this.data.accessToken !== 'string') {
throw new Error("No access token. Use the 'accessToken' option.");
}
endpoint = "users/" + this.data.search + "/media/recent";
break;
default:
throw new Error("Invalid option for get: '" + this.data.get + "'.");
}
final = "" + base + "/" + endpoint;
if (this.data.clientID != null) {
final += "?client_id=" + this.data.clientID;
}
if (this.data.postsPerPage != null) {
final += "&count=" + this.data.postsPerPage;
}
switch(method){
case 'before':
callback = "&callback=instagramReceiverFrontAppend&min_id="+this.data.instagramData.pagination.min_tag_id;
break;
case 'after':
callback = "&callback=instagramReceiverRearAppend&max_id="+this.data.instagramData.pagination.next_max_tag_id;
break;
case 'replace':
callback = "&callback=instagramReceiverReplace";
return "https://api.instagram.com/v1/"+this.data.method+"/"+this.data.search+"/media/recent?client_id="+this.data.clientID+"&count="+this.data.postsPerPage+callback;
break;
case 'before':
callback = "&callback=instagramReceiverFrontAppend&min_id="+this.data.instagramData.pagination.min_tag_id;
break;
case 'after':
callback = "&callback=instagramReceiverRearAppend&max_id="+this.data.instagramData.pagination.next_max_tag_id;
break;
case 'replace':
callback = "&callback=instagramReceiverReplace";
break;
}
return "https://api.instagram.com/v1/"+this.data.method+"/"+this.data.searched+"/media/recent?client_id="+this.data.clientID+"&count="+this.data.postsPerPage+callback;
console.log(final+callback);
return final+callback;
},

/**
Expand All @@ -44,6 +79,8 @@ var instagramFeed = Ractive.extend({
this.set('loading', true);
}

console.log('going to load');

var tag = document.createElement('script');
tag.id = 'instagram-script-loader';
tag.src = this.makeQuery(method);
Expand Down
19 changes: 19 additions & 0 deletions search.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
* Search Functions for Instagram Ractive

All search functions require a

** Popular

This is the easiest search because it does not require any parameters.

** Hashtag

This needs just a hashtag. Pretty straightforward.

** Location

Finding a location is tricky. I need to create a search function to allow people to find location IDs. Locations are definitely the trickiest, since locations can also be Facebook or FourSquare pages.

** User

Searching by User ID is also a bit tricky, since most people don't know the user by their numerical ID. I might build a simple search page for finding user IDs for a search page.

0 comments on commit e22ae8c

Please sign in to comment.