Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Renaming excersise and adding some functional app API calls

  • Loading branch information...
commit 2af79482ace755fdbdd7269564193071b6f001d4 1 parent a672192
James Broad authored
View
BIN  .DS_Store
Binary file not shown
View
13 app/app.js
@@ -14,6 +14,8 @@ app.configure(function(){
app.set('views', __dirname + '/views');
app.set('view engine', 'jade');
app.use(express.bodyParser());
+ app.use(express.cookieParser());
+ app.use(express.session({ secret: "Mooving target" }));
app.use(express.methodOverride());
app.use(app.router);
app.use(express.static(__dirname + '/public'));
@@ -27,10 +29,15 @@ app.configure('production', function(){
app.use(express.errorHandler());
});
-// Routes
+app.get('/', routes.index);
-app.get('/card/create', routes.index);
+app.get('/pack/create', routes.createPackForm);
+app.get('/pack/:packId', routes.getPack);
+app.post('/pack/create', routes.createPack);
+
+app.get('/card/create', routes.createCardForm);
+app.post('/card/create', routes.createCard);
app.listen(3000, function(){
- console.log("Express server listening on port %d in %s mode", app.address().port, app.settings.env);
+ console.log("Express server listening on port %d in %s mode", app.address().port, app.settings.env);
});
View
22 app/lib/moo.api.conf.js
@@ -0,0 +1,22 @@
+var OAuth= require('oauth').OAuth;
+
+var liveOAuthKey = '2d10843248b8f0c94a8e41535413e2d904fd07699';
+var liveOAuthSecret = '5bb897bee43d1c9127223cf35d4561a2';
+
+var devOAuthKey = '1e750d389da67315f7f1fda41430820e04fd091a7';
+var devOAuthSecret = 'd5c52a4f9fb0a16e23844a935dfa9d90';
+
+var oAuthClient = new OAuth(
+ null,
+ null,
+ devOAuthKey,
+ devOAuthSecret,
+ "1.0",
+ "http://localhost:3000/",
+ "HMAC-SHA1"
+);
+
+exports.conf = {
+ baseUrl : 'http://uk.testing1.office.moo.com/api/service/',
+ oa: oAuthClient
+}
View
32 app/lib/moo.api.pack.js
@@ -0,0 +1,32 @@
+var appConfig = require('./moo.api.conf.js').conf;
+
+exports.create = function(conf, callback){
+ conf = conf || {};
+ conf.method = 'moo.pack.createPack';
+ conf.product = 'businesscard';
+
+ console.log('Create pack API call', appConfig.baseUrl, conf);
+
+ appConfig.oa.post(
+ appConfig.baseUrl,
+ "",
+ "",
+ conf,
+ function (error, data, response) {
+ callback(error, JSON.parse(data));
+ });
+}
+
+exports.get = function(id, callback){
+ var url = appConfig.baseUrl + "?method=moo.pack.getPack&packId=" + id;
+
+ console.log('Get pack API call', url);
+
+ appConfig.oa.get(
+ url,
+ "",
+ "",
+ function (error, data, response) {
+ callback(error, JSON.parse(data));
+ });
+}
View
1  app/package.json
@@ -6,5 +6,6 @@
"supervisor": "*"
, "express": "2.5.8"
, "jade": ">= 0.0.1"
+ , "oauth": ">= 0.0.1"
}
}
View
BIN  app/public/images/card.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
44 app/routes/index.js
@@ -1,8 +1,44 @@
+var mooPackApi = require('../lib/moo.api.pack.js');
-/*
- * GET home page.
- */
+var titleMap = {
+ businesscard : "Making Business Cards"
+};
exports.index = function(req, res){
- res.render('index', { title: 'Add a card' })
+ res.render('index', {
+ title: 'Add a card',
+ task: titleMap[req.session.task] || 'Starting Out'
+ });
+};
+
+exports.createCardForm = function(req, res){
+ res.render('create_card', { title: 'Create a card' });
+};
+
+exports.createPackForm = function(req, res){
+ res.render('create_pack', { title: 'Create a pack' });
+};
+
+exports.createPack = function(req, res){
+ mooPackApi.create(req.body, function(err, data){
+ if(err){
+ return res.send(err, 500);
+ }
+ req.session.pack = data.packId;
+ req.session.task = data.pack.productCode;
+ res.redirect('/pack/' + data.packId);
+ })
+};
+
+exports.getPack = function(req, res){
+ packId = req.params.packId;
+ mooPackApi.get(packId, function(err, data){
+ if(err){
+ return res.send(err, 500);
+ }
+ res.render('pack', {
+ title: "Pack Details",
+ pack: data
+ });
+ })
};
View
5 app/views/create_card.jade
@@ -0,0 +1,5 @@
+h1= title
+img.sample-card(src="/images/card.png")
+
+form(action="/pack/create")
+ button.create-pack Create Card
View
8 app/views/create_pack.jade
@@ -0,0 +1,8 @@
+h1= title
+
+form(action="/pack/create", method="post")
+ div
+ label Give this pack a friendly name
+ input.name(name="friendlyName", placeholder="MyBank Corp")
+ div
+ button.create-pack Create Pack
View
4 app/views/index.jade
@@ -1,2 +1,4 @@
h1= title
-p Welcome to #{title}
+
+h2.task= task
View
16 app/views/pack.jade
@@ -0,0 +1,16 @@
+h1= title
+
+div#pack-detail
+ p
+ span Pack ID:
+ span#pack-id= pack.packId
+
+ p
+ span Number of Cards:
+ span#pack-num-cards= pack.pack.numCards
+
+#actions
+ a(href="/card/create") Create Card
+
+
+-console.log(pack)
View
8 features/add-card.feature → features/card.feature 100755 → 100644
@@ -1,11 +1,9 @@
@pending
-Feature: Adding a card
+Feature: Creating a card
As a third party developer
I want to be able to allow people to create custom cards based on my webapp
- Background:
- Given I am an authorised user
-
Scenario: Adding a user
When I visit "card/create"
- Then I should get the title "Add a card"
+ And there should be a sample image of a credit card
View
16 features/pack.feature
@@ -0,0 +1,16 @@
+@pending
+Feature: Creating a pack
+ As a third party developer
+ I want to be able to allow people to create custom cards based on my webapp
+
+ Scenario: Creating a pack
+ When I visit "pack/create"
+ Then I should get the title "Create a pack"
+ And I click "Create Pack"
+ Then I should get the title "Pack Details"
+
+ Scenario: Seeing a pack contents
+ Given I have a sample pack
+ When I visit "pack/{{sample_pack_id}}"
+ And I should have a limit of "50" cards I could create
+ And I should see a button or link "Create Card"
View
14 features/step_definitions/pack.rb
@@ -0,0 +1,14 @@
+Then /^there should be a sample image of a credit card$/ do
+ page.find('img.sample-card').should be_true
+end
+
+Given /^I have a sample pack$/ do
+ visit "/pack/create"
+ fill_in 'friendlyName', :with => 'sample'
+ click_on "Create Pack"
+ @sample_pack_id = page.find('#pack-id').text
+end
+
+When /^I should have a limit of "(.*?)" cards I could create$/ do |card_limit|
+ page.should have_css('#pack-num-cards', :text => card_limit)
+end
View
13 features/step_definitions/shared.rb
@@ -3,9 +3,22 @@
end
When /^I visit "(.*?)"$/ do |url|
+ url = url.sub("{{sample_pack_id}}", @sample_pack_id) if url['{{sample_pack_id}}']
visit url
end
Then /^I should get the title "(.*?)"$/ do |title|
page.find('h1').text.should == title
+end
+
+Then /^I click "(.*?)"$/ do |button_or_link_text|
+ click_on button_or_link_text
+end
+
+Then /^I should see "(.*?)" in the task title$/ do |title_text|
+ page.should have_css('h2.task', :text => title_text)
+end
+
+Then /^I should see a button or link "(.*?)"$/ do |button_text|
+ page.should have_css('button,a', :text => button_text)
end
Please sign in to comment.
Something went wrong with that request. Please try again.