Skip to content

Commit

Permalink
user search should now work.
Browse files Browse the repository at this point in the history
  • Loading branch information
DDKnoll committed Jun 9, 2014
1 parent 1d87717 commit b8e83b1
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 15 deletions.
21 changes: 13 additions & 8 deletions js/instagram.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
var instagramFeed = Ractive.extend({
lazy:true,

makeQuery: function(method) {
makeQuery: function(place) {
var base, endpoint, final, callback;
base = "https://api.instagram.com/v1";
switch (this.data.method) {
Expand All @@ -28,13 +28,14 @@ var instagramFeed = Ractive.extend({
endpoint = "locations/" + this.data.search + "/media/recent";
break;
case "user":
if (typeof this.data.userId !== 'number') {
if (typeof this.data.search !== '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.");
if (typeof this.data.clientID !== 'string') {
throw new Error("Invalid access token. Make sure you have a valid Instagram API access token.");
}
endpoint = "users/" + this.data.search + "/media/recent";
console.log(endpoint);
break;
default:
throw new Error("Invalid option for get: '" + this.data.get + "'.");
Expand All @@ -46,7 +47,7 @@ var instagramFeed = Ractive.extend({
if (this.data.postsPerPage != null) {
final += "&count=" + this.data.postsPerPage;
}
switch(method){
switch(place){
case 'before':
callback = "&callback=instagramReceiverFrontAppend&min_id="+this.data.instagramData.pagination.min_tag_id;
break;
Expand All @@ -66,13 +67,17 @@ var instagramFeed = Ractive.extend({
*
* Loads more instagram data. Either replaces current data, appends data before feed, or appends data after feed
*/
load: function(method){
load: function(place, callback){
if(callback !== undefined){
this.dataCallback = callback;
}
//No older data to load. stop now.
if(method == 'after' && this.data.endOfFeed){
if(place == 'after' && this.data.endOfFeed){
return false;
}
//We're already searching for something... Patience
if(this.data.loading == true) {
console.log('already loading');
return false;
}
else {
Expand All @@ -83,7 +88,7 @@ var instagramFeed = Ractive.extend({
var tag = document.createElement('script');
tag.id = 'instagram-script-loader';
tag.onerror = function(){console.log('unable to reach IG API');};
tag.src = this.makeQuery(method);
tag.src = this.makeQuery(place);
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
},
Expand Down
4 changes: 2 additions & 2 deletions js/instagram.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

39 changes: 34 additions & 5 deletions test/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,31 @@ $.get( '../templates/twitter-feed.rac').then( function ( val ) {
);
});//Get Template

/** Compares the two arrays for any repeated IDs.
*
*/
function hasDuplicates(newData, oldData){
for (var i = newData.data.length - 1; i >= 0; i--) {
for (var j = oldData.length - 1; j >= 0; j--) {
oldData[j];
};
};
return false;
}

function testLoadDuplicates(insta){
insta.load('before', function(returnedData){
test('Checking for duplicated in before method.', function(){
ok(hasDuplicates(insta.data.instagramData, returnedData) == false, 'Load("Before") did not load any duplicate data.');
});
});
insta.load('after', function(returnedData){
test('Checking for loading data with Before and After methods.', function(){
ok(hasDuplicates(insta.data.instagramData, returnedData) == false, 'Load("After") did not load any duplicate data.');
});
});
}

testBadClientID = function(nextTest){
/**
* Initialize our Template
Expand Down Expand Up @@ -46,15 +71,19 @@ makeCorrectFeed = function(nextTest){
instaGood = new instagramFeed({
el: 'template-target',
template: template,
clientID: 'dsa',
clientID: 'fd88310566744275a3d68092d9c175d1',
search: 'dribbble',
dataCallback: function(){

},
complete: function(){
var insta = this;
test('Instagram object created with good Client ID.', function(){
ok(true, "Created!");
});
window.setTimeout(function(){
//wait for a second, then try loading more data.
testLoadDuplicates(insta);
//wait for a second, then try loading more data.
testLoadDuplicates(insta);
}, 1000)
}
});//Ractive init
};
};

0 comments on commit b8e83b1

Please sign in to comment.