Permalink
Browse files

user search should now work.

  • Loading branch information...
DDKnoll committed Jun 9, 2014
1 parent 1d87717 commit b8e83b11ab3af5e4454714afbb6cdcacfdd46c92
Showing with 49 additions and 15 deletions.
  1. +13 −8 js/instagram.js
  2. +2 −2 js/instagram.min.js
  3. +34 −5 test/tests.js
View
@@ -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) {
@@ -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 + "'.");
@@ -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;
@@ -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 {
@@ -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);
},
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View
@@ -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
@@ -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.