Skip to content

Commit

Permalink
Merge pull request googlearchive#34 from firebase/v2
Browse files Browse the repository at this point in the history
V2
  • Loading branch information
asciimike committed Oct 15, 2014
2 parents d8bf485 + d70cd7f commit 3b2c4c1
Show file tree
Hide file tree
Showing 10 changed files with 265 additions and 90 deletions.
53 changes: 53 additions & 0 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
var gulp = require('gulp'),
connect = require('gulp-connect'),
open = require('gulp-open'),
port = process.env.port || 3001;

gulp.task('open', function(){
var options = {
url: 'http://localhost:' + port,
};
gulp.src('./www/index.html')
.pipe(open('', options));
});

gulp.task('connect', function() {
connect.server({
root: 'www',
port: port,
livereload: true
});
});

gulp.task('test', function() {
connect.server({
root: '.',
port: port - 1,
livereload: true
});

var options = {
url: 'http://localhost:' + (port - 1),
};
gulp.src('./test/index.html')
.pipe(open('', options))
});

gulp.task('js', function () {
gulp.src('./www/**/*.js')
.pipe(connect.reload());
});

gulp.task('html', function () {
gulp.src('./www/*.html')
.pipe(connect.reload());
});

gulp.task('watch', function() {
gulp.watch('www/dist/js/*.js', ['js']);
gulp.watch('www/index.html', ['html']);
});

gulp.task('default', ['connect', 'watch']);

gulp.task('serve', ['connect', 'watch', 'open']);
32 changes: 32 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"name": "firefeed",
"version": "0.1.0",
"description": "Firefeed is a web app that lets users post small messages called sparks to their feed. You can follow other users, and their sparks will appear on your feed.",
"main": "gulpfile.js",
"directories": {
"test": "test"
},
"scripts": {
"start": "gulp serve",
"build": "gulp"
},
"repository": {
"type": "git",
"url": "https://github.com/firebase/firefeed.git"
},
"keywords": [
"firebase",
"twitter clone"
],
"author": "Firebase",
"license": "MIT",
"bugs": {
"url": "https://github.com/firebase/firefeed/issues"
},
"homepage": "https://github.com/firebase/firefeed",
"dependencies": {
"gulp": "^3.8.8",
"gulp-connect": "^2.0.6",
"gulp-open": "^0.2.8"
}
}
23 changes: 11 additions & 12 deletions rules.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,29 @@
// A list of users with their names on the site.
"$userid": {
// Only the user can write their own entry into this list.
".write": "$userid == auth.id"
".write": "$userid ==auth.uid"
}
},
"users": {
"$userid": {
// The user is allowed to write everything in their bucket.
".write": "$userid == auth.id",
".write": "$userid ==auth.uid",
"following": {
// The following list should only contain actual ids from the "people" list.
// The following list should only contain actual ids from the "people" list.
"$followingid": {
".validate": "root.child('people').hasChild($followingid)"
}
},
"followers": {
// Anyone can add themself to to this user's followers list.
"$followerid": {
".write": "$followerid == auth.id"
".write": "$followerid ==auth.uid"
}
},
"feed": {
"$sparkid": {
// User A can write in user B's feed, but only if A is following B, and only for sparks for which they are the author.
".write": "root.child('users/' + $userid + '/following').hasChild(auth.id) && root.child('sparks/' + $sparkid + '/author').val() == auth.id"
".write": "root.child('users/' + $userid + '/following').hasChild(auth.uid) && root.child('sparks/' + $sparkid + '/author').val() ==auth.uid"
}
}
}
Expand All @@ -42,7 +42,7 @@
".validate": "newData.hasChildren(['author', 'content'])",
// A user can attribute a spark only to themselves.
"author": {
".validate": "newData.val() == auth.id"
".validate": "newData.val() ==auth.uid"
},
"content": {
".validate": "newData.isString()"
Expand All @@ -52,27 +52,26 @@
"recent-users": {
// Users can add themselves to the list of users with recent activity.
"$userid": {
".write": "$userid == auth.id"
".write": "$userid ==auth.uid"
}
},
"recent-sparks": {
// Authors of sparks can add their sparks to this list.
"$sparkid": {
".write": "root.child('sparks/' + $sparkid + '/author').val() == auth.id"
".write": "root.child('sparks/' + $sparkid + '/author').val() ==auth.uid"
}
},
"search": {
"firstName": {
"$searchKey": {
".write": "auth != null && (root.child('people/' + auth.id + '/firstName').val() + '|' + root.child('people/' + auth.id + '/lastName').val() + '|' + auth.id) == $searchKey && newData.val() == auth.id"
".write": "auth != null && (root.child('people/' +auth.uid + '/firstName').val() + '|' + root.child('people/' +auth.uid + '/lastName').val() + '|' +auth.uid) == $searchKey && newData.val() ==auth.uid"
}
},
"lastName": {
"$searchKey": {
".write": "auth != null && (root.child('people/' + auth.id + '/lastName').val() + '|' + root.child('people/' + auth.id + '/firstName').val() + '|' + auth.id) == $searchKey && newData.val() == auth.id"
".write": "auth != null && (root.child('people/' +auth.uid + '/lastName').val() + '|' + root.child('people/' +auth.uid + '/firstName').val() + '|' +auth.uid) == $searchKey && newData.val() ==auth.uid"
}
}
}
}
}

}
9 changes: 4 additions & 5 deletions test/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,10 @@
<script type="text/javascript" src="lib/jasmine-1.3.1/jasmine-html.js"></script>

<!-- include source files here... -->
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.9.2/jquery-ui.min.js"></script>
<script src="//cdn-staging.firebase.com/v0/firebase.js"></script>
<script src="//cdn-staging.firebase.com/v0/firebase-simple-login.js"></script>
<script src="//cdn-staging.firebase.com/v0/firebase-token-generator.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.9.2/jquery-ui.min.js"></script>
<script src="https://cdn.firebase.com/js/client/1.1.0/firebase.js"></script>
<script src="https://cdn-staging.firebase.com/v0/firebase-token-generator.js"></script>
<script src="../www/js/firefeed.js"></script>

<!-- include spec files here... -->
Expand Down
48 changes: 46 additions & 2 deletions test/spec/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ var USER = "jasmine";
var USER2 = "jasmine2";

var TIMEOUT = 1000;
var BASEURL = "https://firefeed.firebaseio-staging.com";
var BASEURL = "https://firefeed-staging.firebaseio.com";

// Replace $TOP_SECRET with the secret for BASEURL.
var tokenGenerator = new FirebaseTokenGenerator("$TOP_SECRET");
var tokenGenerator = new FirebaseTokenGenerator('uTZgdJmwpcPqHtxqZ0gpNvqaODY2ELUYyGBfh3rb');

// We create a new context so we can auth independently.
var makeAndLoginAs = function(user, cb) {
Expand All @@ -32,3 +32,47 @@ var makeAndLoginAs = function(user, cb) {
cb(ff);
});
};

var helpers = {

tokenGenerator: new FirebaseTokenGenerator('uTZgdJmwpcPqHtxqZ0gpNvqaODY2ELUYyGBfh3rb'),

BASEURL: 'https://firefeed-staging.firebaseio.com',

userOne: {
id: 1,
facebook: {
displayName: 'David East',
id: 100
}
},

userTwo: {
id: 2,
facebook: {
displayName: 'Kato Wulf',
id: 200
}
},

createFeed: function(params) {
return new Firefeed(this.BASEURL);
},
setUserToLocalStorage: function(user, token) {
localStorage.clear();
localStorage.setItem('authToken', token);
localStorage.setItem('userid', user);
localStorage.setItem('name', user);
localStorage.setItem('fullName', user);
},
createUserToken: function(user) {
return this.tokenGenerator.createToken({id: user});
},
authenticate: function(feed, user, cb) {
debugger;
var token = this.createUserToken(user);
this.setUserToLocalStorage(user, token);
feed._firebase.authWithCustomToken(token, cb.bind(feed));
}
};

38 changes: 15 additions & 23 deletions test/spec/initialization.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,30 @@
describe("Initialization:", function() {
var firefeed = null;

beforeEach(function() {
firefeed = helpers.createFeed();
});

afterEach(function() {
firefeed.unload();
firefeed = null;
});

it("Constructor", function() {
firefeed = new Firefeed(BASEURL);
expect(typeof firefeed).toBe(typeof {});
expect(firefeed._baseURL).toBe(BASEURL);
});

it("Login", function() {
var flag = false;

runs(function() {
makeAndLoginAs(USER, function(ff) {
expect(ff).toNotBe(null);
firefeed = ff;
flag = true;
});
});

waitsFor(function() {
return flag;
}, "Login callback should be called", TIMEOUT);
spyOn(firefeed._firebase, 'authWithOAuthPopup');
firefeed.login('facebook');
expect(firefeed._firebase.authWithOAuthPopup).toHaveBeenCalled();
});

it("Logout", function() {
spyOn(firefeed._firebase, 'unauth');
firefeed.logout();
expect(firefeed._firebase).toBe(null);
expect(firefeed._userid).toBe(null);
expect(firefeed._fullName).toBe(null);
expect(firefeed._name).toBe(null);
expect(firefeed._mainUser).toBe(null);
expect(localStorage.getItem("authToken")).toBe(null);
expect(localStorage.getItem("userid")).toBe(null);
expect(localStorage.getItem("name")).toBe(null);
expect(localStorage.getItem("fullName")).toBe(null);
expect(firefeed._firebase.unauth).toHaveBeenCalled();
});

});
16 changes: 8 additions & 8 deletions www/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ <h2 class="pushv">{{fullName}}</h2>
<p class="big-copy pushv">{{location}}</p>
<p class="big-copy end">{{bio}}</p>
<div class="pushv4">
<a href="#" id="followBtn-{{id}}" class="btn default pushv4">Follow</a>
<a href="#" id="followBtn-{{id}}" class="btn default pushv4 btn-follow" data-id="{{id}}">Follow</a>
</div>
</script>

Expand Down Expand Up @@ -254,7 +254,7 @@ <h2 class="pushv">{{fullName}}</h2>
<a class="profile-link" href="/?profile={{id}}">{{fullName}}</a>
</p>
<p class="copy pushv">{{bio}}</p>
<a href="#" id="followBtn-{{id}}" class="btn default small">Follow</a>
<a href="#" id="followBtn-{{id}}" data-id="{{id}}" class="btn default small btn-follow">Follow</a>
</div>
</div>
</script>
Expand All @@ -272,6 +272,7 @@ <h2 class="pushv">{{fullName}}</h2>
<script src="./libs/jquery.jeditable.mini.js"></script>
<script src="./libs/history.adapter.jquery.js"></script>
<script src="./libs/history.js"></script>
<script src="./libs/bind-polyfill.js"></script>
<!--[if (gte IE 6)&(lte IE 8)]>
<script src="//cdnjs.cloudflare.com/ajax/libs/selectivizr/1.0.2/selectivizr-min.js"></script>
<![endif]-->
Expand All @@ -281,25 +282,24 @@ <h2 class="pushv">{{fullName}}</h2>
<script src="//cdnjs.cloudflare.com/ajax/libs/spin.js/1.2.7/spin.min.js"></script>

<!-- Firebase.js and auth client must be included before Firefeed -->
<script src="//cdn.firebase.com/v0/firebase.js"></script>
<script src="//cdn.firebase.com/v0/firebase-simple-login.js"></script>
<script src="https://cdn.firebase.com/js/client/1.1.2/firebase.js"></script>

<!-- Finally, the Firefeed code -->
<script src="js/firefeed-search.js"></script>
<script src="js/firefeed.js"></script>
<script src="js/firefeed-ui.js"></script>


<!-- Google Analytics Tracking, change this for your website-->
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');

ga('create', 'UA-37029006-1', 'firefeed.io');
ga('send', 'pageview');
</script>
</script>

</body>
</html>
Loading

0 comments on commit 3b2c4c1

Please sign in to comment.