Skip to content
This repository has been archived by the owner on Jul 19, 2018. It is now read-only.

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
Manuel Mazzuola committed Mar 23, 2016
1 parent 889c9ba commit 1797dde
Show file tree
Hide file tree
Showing 8 changed files with 95 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .babelrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"presets": ["es2015", "stage-0"],
"plugins": ["transform-undefined-to-void"]
"plugins": ["transform-undefined-to-void", "transform-object-assign"]
}
35 changes: 34 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,28 @@ var products = client.product.all()
# API Usage
# Options

Options that can be passed to the api methods

**Properties**

- `pageSize` **[Number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** Size of the page to retrieve.
- `pageNumber` **[Number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** Number of the page to retrieve.

**Examples**

```javascript
// Retrieve the second page of the results
var options = {
pageSize: 6,
pageNumber 2
};
var client = new cloudesire.Client()
var products = client.product.all(options);
```

# PaginatedResponse

An array plus the the pagination properties
An array object that contains the current pagination informations

**Properties**

Expand All @@ -59,10 +73,29 @@ An array plus the the pagination properties
- `The` **totalItems** number of the total pages
- `The` **pageNumber** of the current page

**Examples**

```javascript
var client = new cloudesire.Client()
var productsArray = client.product.all() // This returns a PaginatedResponse array object
var totalPages = productsArray.totalPages
var pageSize = productsArray.pageSize
var totalItems = productsArray.totalItems
var pageNumber = productsArray.pageNumber
```

# Category

**Extends BaseResource**

**Examples**

```javascript
var client = new cloudesire.Client()
var categories = client.category.all()
var categoryWithID2 = client.category.one(2)
```

# Product

**Extends BaseResource**
Expand Down
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
"compile": "babel src -d lib && browserify src/client.js -t [babelify --no-sourceMaps] -p [minifyify --no-map] -s cloudesire -o lib/client.web.js",
"prepublish": "npm run compile",
"docs": "cat README.md.template > README.md && documentation build src/resources/*.js -f md -c config.json >> README.md",
"test": "npm run eslint && npm run compile && istanbul cover _mocha -- --compilers js:babel-register -R spec test/ && cat ./coverage/lcov.info | coveralls",
"test": "npm run eslint && npm run compile && istanbul cover _mocha -- --compilers js:babel-register -R spec test/flow.spec.js && cat ./coverage/lcov.info | coveralls && mocha-phantomjs test/flow.spec.html",
"eslint": "eslint src",
"test-dev": "npm run eslint && npm run compile && mocha --compilers js:babel-register"
"test-dev": "npm run eslint && npm run compile && mocha --compilers js:babel-register test/flow.spec.js && mocha-phantomjs test/flow.spec.html"
},
"repository": {
"type": "git",
Expand All @@ -31,6 +31,7 @@
"devDependencies": {
"babel-cli": "^6.6.5",
"babel-eslint": "^6.0.0-beta.6",
"babel-plugin-transform-object-assign": "^6.5.0",
"babel-plugin-transform-undefined-to-void": "^6.5.0",
"babel-preset-es2015": "^6.6.0",
"babel-preset-stage-0": "^6.5.0",
Expand All @@ -46,6 +47,7 @@
"istanbul": "^1.0.0-alpha.2",
"minifyify": "^7.3.2",
"mocha": "^2.4.5",
"mocha-phantomjs": "^4.0.2",
"mockery": "^1.4.1"
},
"dependencies": {
Expand Down
9 changes: 9 additions & 0 deletions src/BaseResource.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,17 @@

/**
* @typedef {Object} Options
* @description Options that can be passed to the api methods
* @property {Number} pageSize - Size of the page to retrieve.
* @property {Number} pageNumber - Number of the page to retrieve.
* @example
* // Retrieve the second page of the results
* var options = {
* pageSize: 6,
* pageNumber 2
* };
* var client = new cloudesire.Client()
* var products = client.product.all(options);
*/

import PaginatedResponse from './PaginatedResponse'
Expand Down
9 changes: 8 additions & 1 deletion src/PaginatedResponse.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
'use strict';

/**
* An array plus the the pagination properties
* An array object that contains the current pagination informations
* @property {totalPages} The on the server
* @property {pageSize} The of the current page
* @property {totalItems} The number of the total pages
* @property {pageNumber} The of the current page
* @example
* var client = new cloudesire.Client()
* var productsArray = client.product.all() // This returns a PaginatedResponse array object
* var totalPages = productsArray.totalPages
* var pageSize = productsArray.pageSize
* var totalItems = productsArray.totalItems
* var pageNumber = productsArray.pageNumber
*/
export default class PaginatedResponse extends Array {
constructor(args, headers) {
Expand Down
4 changes: 4 additions & 0 deletions src/resources/Category.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ import BaseResource from './../BaseResource'

/**
* @class
* @example
* var client = new cloudesire.Client()
* var categories = client.category.all()
* var categoryWithID2 = client.category.one(2)
*/
class Category extends BaseResource {
constructor(self) {
Expand Down
20 changes: 20 additions & 0 deletions test/flow.spec.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<html>
<head>
<meta charset="utf-8">
</head>
<body>
<script src="../node_modules/mocha/mocha.js"></script>
<script src="../node_modules/chai/chai.js"></script>
<script src="../node_modules/chai-as-promised/lib/chai-as-promised.js"></script>
<script>
mocha.ui('bdd')
expect = chai.expect
chai.use(chaiAsPromised)
</script>
<script src="../lib/client.web.js"></script>
<script src="web.spec.js"></script>
<script>
mocha.run()
</script>
</body>
</html>
15 changes: 15 additions & 0 deletions test/web.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
(function() {
var client

describe('Works in the browser ?', function() {
before(function() {
client = new cloudesire.Client()
})

it('should list all the products', function() {
return expect(client.product.all({pageSize: 2, pageNumber: 1}))
.to.eventually.is.an('array')
.with.length.be(2)
});
})
}())

0 comments on commit 1797dde

Please sign in to comment.