diff --git a/README.md b/README.md index 4217548..5278650 100644 --- a/README.md +++ b/README.md @@ -60,7 +60,7 @@ Sample Usage: el: 'template-target', template: template, clientID: 'Your Instagram Client ID', - hashtag: 'webdesign', + hashtag: query, complete: infiniteScrollBinding }); @@ -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 diff --git a/js/instagram.js b/js/instagram.js index 3f22a29..7e3d2dc 100644 --- a/js/instagram.js +++ b/js/instagram.js @@ -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; }, /** @@ -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); diff --git a/search.md b/search.md new file mode 100644 index 0000000..1d67117 --- /dev/null +++ b/search.md @@ -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. \ No newline at end of file