Skip to content

Commit

Permalink
v0.1.0
Browse files Browse the repository at this point in the history
See CHANGELOG.md

* fixes issue #1
* fixes issue #3
  • Loading branch information
GochoMugo committed Mar 24, 2016
2 parents 4a43ae9 + 6d0835c commit 335c1a4
Show file tree
Hide file tree
Showing 31 changed files with 576 additions and 261 deletions.
1 change: 0 additions & 1 deletion .cfignore

This file was deleted.

6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,9 @@

# npm-installed modules
node_modules/

# sass output
web/css/

# vendor files
web/vendor/
5 changes: 5 additions & 0 deletions .openshift/gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# will install with 'npm install'
node_modules/

# will install after 'npm install'
web/vendor/
Empty file added .openshift/markers/use_npm
Empty file.
18 changes: 18 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
language: node_js
node_js:
- '4.2'
- '0.11'
- '0.10'
before_deploy:
- mv .openshift/gitignore .gitignore
deploy:
provider: openshift
user: [email protected]
password:
secure: UeYKxuX479enwcn1rziErDtnHjR5RFu0a4zK83qZKPhgsXbk+NUXw20fMGtRQvfK/YKm5RW3hqQup6d8dinUJeTqANI4xeunhwV331nWUyzzhRZJUXPb0IiD3idJDpiDDH05leQzSp/8uGt1wb9fYPe1OoN3ylq46RT5kW0tQ/CqkjIOkTPgrX0jY1moANse4RfvGD/6hmgL8nrOM6mqNG2n8fpnoRdznAkZkQlV/vjLEn45SpQEWGmCwn4uFFouXaV3WQMgcuuNvKWQBRS9ZY0VwSNdZoTXvFqaHTxHaPADoMtxszHY18q9XiRpr2TBoBjEXQYtFWBTVN7n3kkQXLHzoMJk/LfsWW3z8lUHVU7Q7MJyuFLj4qRP85neLKQ38CahUCCxbr5IaxvS9/PMysYJi34LYR43SiK2WBf6gdH6SB/GHEJA2IU8TjNmfA0LVbhS/zaDCLD+NRxXghhsaIXAb5JIYfYiOKDwA5WVcIk/Tfz5CpM6M8pYbiP3PYn2bYFr7OY9HL78z0+7NqU4YYiIlgfPf0TKz/FDmtgMJErFNbZbu72uPBryUotjC7zTkSQwtRmyFXGmtc/OpLEnTr3jSK1Sx7BbS1IsravMycNQtzygAykT7SotyhinjE+fXY0fXP59UmQvV/SMjbc6j2GSWsyU4JBF2BV7TpHZMAM=
app: mmtcke
domain: forfutureco
on:
repo: forfuturellc/mmtc-ke
branch: master
skip_cleanup: true
26 changes: 26 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Change Log

All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased][Unreleased]


## [0.1.0][0.1.0] - 2016-03-25

Added:

* Update Data File Format Specification to accommodate for USSD codes (issue #1)
* Display USSD codes in network pages
* Update data for networks: safaricom
* Display table for ranges (issue #3)


## [0.0.0][0.0.0] - 2016-03-11

This is the very first version.


[Unreleased]: https://github.com/forfuturellc/mmtc-ke/compare/v0.1.0...HEAD
[0.0.0]: https://github.com/forfuturellc/mmtc-ke/compare/v0.0.0...HEAD
[0.1.0]: https://github.com/forfuturellc/mmtc-ke/compare/v0.1.0...HEAD
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Opening such a duplicate issue, will force us to close it, mark it as

## Code Contribution:

> We are glad that you can take the time and help us improve this SDK.
> We are glad that you can take the time and help us improve this Application.
We are using Git branching model identical to
[this one](http://nvie.com/posts/a-successful-git-branching-model/). Ensure
Expand All @@ -26,7 +26,7 @@ your copy locally:

```bash
$ git clone https://github.com/<YourUsername>/mmtc-ke.git
$ cd node-sdk
$ cd mmtc-ke
```

### 2. Branch
Expand Down
11 changes: 7 additions & 4 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ var pkg = require('./package.json');
// module variables
var app = express();
var debug = Debug('mmtc-ke:app');
var logger = engine.clients.getLogger();
var nunjucksEnv;


Expand Down Expand Up @@ -67,21 +68,23 @@ app.use(routes);

debug('mounting catch-all handler');
app.use(function(req, res, next) {
return next(new Error('404'));
return routes.utils.renderPage(req, res, 'error', {
error: new engine.errors.PageNotFoundError(`page '${req.path}' not found`),
});
});


debug('mounting middleware for error handling');
app.use(function(err, req, res, next) {
console.error(err);
return res.status(500).end();
return routes.utils.renderPage(req, res, 'errors/index', {
logger.error(err);
return routes.utils.renderPage(req, res, 'error', {
error: err,
});
});


debug('starting server');
app.listen(config.get('server.port'), config.get('server.ip'), function() {
logger.info('server listening');
debug('server started at http://%s:%s', config.get('server.ip'), config.get('server.port'));
});
9 changes: 2 additions & 7 deletions config/default.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
// npm-installed modules
var cfenv = require('cfenv');


// module variables
var appEnv = cfenv.getAppEnv();
var config = {};


// server configuration
config.server = {};
config.server.port = appEnv.port;
config.server.ip = '0.0.0.0';
config.server.port = process.env.OPENSHIFT_NODEJS_PORT || 8090;
config.server.ip = process.env.OPENSHIFT_NODEJS_IP || '0.0.0.0';


// site configuration
Expand Down
54 changes: 46 additions & 8 deletions data/SPEC.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

|Aspect|Detail|
|------|------|
|Version|0.0|
|Version|0.2|
|Written by|GochoMugo <[email protected]>|

The data used in the application in its computations is fed through data files
Expand All @@ -11,25 +11,40 @@ independent of the different networks available.

## spec:

The data files are written in JSON format.
The data files are written in [JSON][json] format.

A single file can only hold one [Network](#type-network) object.

<a name="type-network"></a>
### Network

A single data file can **only** hold one [Network](#type-network) object.

|Key|Type|Description|
|---|----|-----------|
|name|[Name](#type-name)|Name of the Network|
|meta|[Metadata](#type-metadata)|Metadata associated with the network|
|transactions|\[[Transaction](#type-transaction)]|Transactions supported by the network|
|ussd_codes|\[[USSDCode](#type-ussdcode)]|The available shortcodes|


<a name="type-metadata"></a>
### Metadata

|Key|Type|Description|
|---|----|-----------|
|name|[Name](#type-name)|The name of the Network|
|transactions|[Transaction](#type-transaction)|The transactions supported by the network|
|spec|String|Specification version the file adheres to|
|date_updated|[Date](#type-date)|Date on which the data was last updated|


<a name="type-transaction"></a>
### Transaction

|Key|Type|Description|
|---|----|-----------|
|name|[Name](#type-name)|Type of the transaction|
|classes|[Class](#type-class)|The different classes of the transaction|
|classes|\[[Class](#type-class)]|The different classes of the transaction|
|amount_input|boolean|`false` if an amount, as input to the transaction, is **not** applicable. *Defaults to `true`.*|


<a name="type-class"></a>
### Class
Expand All @@ -38,11 +53,11 @@ A single file can only hold one [Network](#type-network) object.
|---|----|-----------|
|name|[Name](#type-name)|Name of the class of the transaction|
|ranges|\[[Range](#type-range)]|The ranges in the transaction class|
|amount|boolean|`false` if amount is **not** applicable to the class. Otherwise `false`. Default is `true`|
|amount|[Cost](#type-cost)|Amount charged to the user. *This should be provided __only__ if parent `Transaction` has `amount_input` set to `false`.*|


### Range
<a name="type-range"></a>
### Range

|Key|Type|Description|
|---|----|-----------|
Expand All @@ -63,7 +78,30 @@ This type is based on the native `Number` type in JSON with these few additions:
Therefore, the cost is accurate to **1 KES**.


<a name="type-ussdcode"></a>
### USSDCode

This is a [USSD][ussd] code, supported by the network.

|Key|Type|Description|
|---|----|-----------|
|code|string|The actual USSD code. For example, `*144#`|
|description|string|Describes the use of the code|


<a name="type-name"></a>
### Name

This is a string, **uniquely** identifying the named object.


<a name="type-date"></a>
### Date

Date, in `YYYY-MM-DD` format. See this [W3C document][date] for
more information.


[date]:https://www.w3.org/TR/NOTE-datetime
[json]:http://json.org
[ussd]:https://en.wikipedia.org/wiki/Unstructured_Supplementary_Service_Data
40 changes: 24 additions & 16 deletions data/safaricom.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
{
"name": "safaricom",
"meta": {
"spec": "0.2",
"date_updated": "2016-03-25"
},
"transactions": [
{
"name": "transfer",
Expand Down Expand Up @@ -77,39 +81,43 @@
},
{
"name": "others",
"amount": false,
"amount_input": false,
"classes": [
{
"name": "deposits",
"ranges": [
{ "low": "-Infinity", "high": "+Infinity", "amount": 0 }
]
"amount": 0
},
{
"name": "registration",
"ranges": [
{ "low": "-Infinity", "high": "+Infinity", "amount": 0 }
]
"amount": 0
},
{
"name": "airtime",
"ranges": [
{ "low": "-Infinity", "high": "+Infinity", "amount": 0 }
]
"amount": 0
},
{
"name": "balance enquiry",
"ranges": [
{ "low": "-Infinity", "high": "+Infinity", "amount": 1 }
]
"amount": 1
},
{
"name": "PIN change",
"ranges": [
{ "low": "-Infinity", "high": "+Infinity", "amount": 22 }
]
"amount": 22
}
]
}
],
"ussd_codes": [
{
"code": "*144#",
"description": "credit balance"
},
{
"code": "*544#",
"description": "internet bundles"
},
{
"code": "*131#",
"description": "okoa jahazi"
}
]
}
25 changes: 25 additions & 0 deletions engine/clients.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/**
* The MIT License (MIT)
* Copyright (c) 2016 Forfuture LLC
*
* Client to support services.
*/


exports = module.exports = {
getLogger: getLogger,
};


// npm-installed modules
var winston = require('winston');


/**
* Return the main application logger
*
* @return {Object} logger
*/
function getLogger() {
return winston;
}
27 changes: 27 additions & 0 deletions engine/errors.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/**
* The MIT License (MIT)
* Copyright (c) 2016 Forfuture LLC
*
* Error handling
*/


// npm-installed modules
var errors = require('common-errors');


// module variables
var define = errors.helpers.generateClass;


exports = module.exports = {
// General Errors
PageNotFoundError: define('PageNotFoundError'),

// Calculation Errors
InvalidAmountError: define('InvalidAmountError'),
NetworkNotFoundError: define('NetworkNotFoundError'),
RangeNotFoundError: define('RangeNotFoundError'),
TransactionClassNotFoundError: define('TransactionClassNotFoundError'),
TransactionNotFoundError: define('TransactionNotFoundError'),
};
Loading

2 comments on commit 335c1a4

@BransonGitomeh
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is cool, i love the way you code, the jsdocs comments and all that... so cool

@GochoMugo
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! 😄

Code is Poetry. Code is an expression of Thoughts.

Please sign in to comment.