Skip to content

Commit 557b6f6

Browse files
committed
1.0.0
1 parent 6daa631 commit 557b6f6

27 files changed

+6116
-2
lines changed

.eslintrc

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// Use this file as a starting point for your projects .eslintrc.
2+
// Copy this file, and add rule overrides as needed.
3+
{
4+
"extends": "airbnb",
5+
"env": {
6+
es6: true,
7+
node: true,
8+
browser: true
9+
},
10+
"rules" : {
11+
// enforce indentation of 4 spaces
12+
// http://eslint.org/docs/rules/indent
13+
"indent": ["error", 4],
14+
15+
// enforce the max line length to be 120 chars
16+
// http://eslint.org/docs/rules/max-len
17+
"max-len": ["error", 120],
18+
19+
// disallowing comma trailing
20+
// http://eslint.org/docs/rules/max-len
21+
"comma-dangle": ["error", "never"],
22+
23+
// disallowing space after function name
24+
// http://eslint.org/docs/rules/space-before-function-paren
25+
"space-before-function-paren": "error",
26+
27+
// allowing unary operators
28+
// http://eslint.org/docs/rules/no-plusplus
29+
"no-plusplus": "off",
30+
31+
// Forbid the use of dev packages
32+
// https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/no-extraneous-dependencies.md
33+
"import/no-extraneous-dependencies": ["error",
34+
{
35+
"devDependencies": false
36+
}
37+
],
38+
39+
// enforce braces in arrow function bodies
40+
// http://eslint.org/docs/rules/arrow-body-style
41+
"arrow-body-style": ["error", "always"]
42+
},
43+
"globals" : {
44+
"window": true
45+
}
46+
}

.gitignore

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
.DS_Store
2+
node_modules/
3+
dist/
4+
secret.json
5+
docs/
6+
.idea/
7+
coverage

LICENSE

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
Copyright (c) 2017 Bynder B.V.
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a
4+
copy of this software and associated documentation files (the
5+
"Software"), to deal in the Software without restriction, including
6+
without limitation the rights to use, copy, modify, merge, publish,
7+
distribute, sublicense, and/or sell copies of the Software, and to
8+
permit persons to whom the Software is furnished to do so, subject to
9+
the following conditions:
10+
11+
The above copyright notice and this permission notice shall be included
12+
in all copies or substantial portions of the Software.
13+
14+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15+
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
18+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
19+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
20+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

README.md

+116-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,116 @@
1-
# bynder-js-sdk
2-
Bynder javascript SDK
1+
# Bynder JavaScript SDK
2+
This SDK aims to help the development of integrations with Bynder that use JavaScript, providing an easy interface to communicate with Bynder's REST API and request the information required.
3+
For that purpose, many ES2015 features were used, as well as Promises notation to help dealing with asynchronous code.
4+
5+
## Requirements
6+
In order to use this SDK, the only thing needed is an updated version of Node.js:
7+
* [Node.js v6.3.0 or above](https://nodejs.org/)
8+
* [Yarn](https://yarnpkg.com/)
9+
10+
Node installation will include NPM, which is responsible for the dependencies management.
11+
12+
## Installation
13+
14+
### Node.js
15+
TBD
16+
17+
`npm install bynder-js-sdk`
18+
19+
### Browser
20+
TBD
21+
22+
`<script src="path/to/bynder-js-sdk.js"></script>`
23+
24+
## Usage
25+
As said before, this SDK relies heavily on [Promises](https://developers.google.com/web/fundamentals/getting-started/primers/promises), making it easier to handle the asynchronous requests made to the API.
26+
Besides that, it provides a `Bynder` object containing several methods corresponding to the calls to be performed, which accept the parameters exactly according [Bynder's API documentation](http://docs.bynder.apiary.io/).
27+
28+
This is a generic example of how to use the SDK, if you need specific details for a specific module, refer to [samples folder](https://github.com/Bynder/bynder-js-sdk-private/tree/develop/samples).
29+
30+
Before executing any request, you need to call the constructor passing your credentials as parameters, making it possible to authorize the calls to the API:
31+
32+
```js
33+
const bynder = new Bynder({
34+
consumer: {
35+
public: "<public_consumer_key>",
36+
secret: "<secret_consumer_key>"
37+
},
38+
accessToken: {
39+
public: "<public_access_key>",
40+
secret: "<secret_access_key>"
41+
},
42+
baseURL: "http://api-url.bynder.io/api/"
43+
});
44+
```
45+
46+
From this point on, you just need to call the methods made available to call the API and retrieve the data your looking for. Following the Promises notation, you should use `.then()/.catch()` to handle respectively the successful and failed requests.
47+
Except for some special cases, most of the calls only take an object as parameter. After that, you'll need to refer to the API to tune the query as intended.
48+
49+
```js
50+
bynder.getMediaList({
51+
type: 'image',
52+
limit: 9,
53+
page: 1
54+
})
55+
.then((data) => {
56+
// TODO stuff
57+
})
58+
.catch((error) => {
59+
// TODO Handle the error
60+
});
61+
```
62+
63+
## Methods available
64+
Here's a list of all the methods available, separated by module:
65+
66+
### Authentication
67+
* `userLogin()`
68+
* `getRequestToken()`
69+
* `getAuthorisedURL(token, callback)`
70+
* `getAccessToken(token, secret)`
71+
72+
### Media items
73+
* `getMediaList(queryObject)`
74+
* `getMediaInfo(queryObject)`
75+
* `getAllMediaItems(queryObject)`
76+
* `getMediaTotal(queryObject)`
77+
* `editMedia(object)`
78+
79+
### Metaproperties
80+
* `getMetaproperties(queryObject)`
81+
* `getMetaproperty(queryObject)`
82+
* `saveNewMetaproperty(object)`
83+
* `deleteMetaproperty(object)`
84+
85+
### Tags
86+
* `getTags()`
87+
88+
### Categories
89+
* `getCategories()`
90+
91+
## Contribute to the SDK
92+
If you wish to contribute to this repository and further extend the API coverage of the SDK, here are the steps necessary to prepare your environment:
93+
94+
1. Clone the repository
95+
2. In the root folder, run `npm install` to install all the dependencies.
96+
3. Use the file named 'secret.json' for the tokens with this structure:
97+
```json
98+
{
99+
"consumer": {
100+
"public": "<public_consumer_key>",
101+
"secret": "<secret_consumer_key>"
102+
},
103+
"accessToken": {
104+
"public": "<public_access_key>",
105+
"secret": "<secret_access_key>"
106+
},
107+
"baseURL": "http://api-url.bynder.io/api/"
108+
}
109+
```
110+
4. Use any of these gulp tasks to:
111+
1. `gulp lint` - Run ESlint and check the code.
112+
2. `gulp build` - Run webpack to bundle the code in order to run in a browser.
113+
3. `gulp babel` - Run Babel to create a folder 'dist' with ES2015 compatible code.
114+
4. `gulp jasmine` - Run Jasmine for all the spec files inside 'tests'.
115+
5. `gulp doc` - Run JSDoc to create a 'doc' folder with automatically generated documentation for the source code.
116+
6. `gulp webserver` - Deploy a web server from the root folder at `localhost:8080` to run the html samples (in order to avoid CORS problems).

gulpfile.js

+89
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
const gulp = require('gulp');
2+
const eslint = require('gulp-eslint');
3+
const babel = require('gulp-babel');
4+
const jasmine = require('gulp-jasmine');
5+
const jsdoc = require('gulp-jsdoc3');
6+
const connect = require('gulp-connect');
7+
const webpack = require('webpack');
8+
const path = require('path');
9+
10+
gulp.task('default', () => {
11+
gulp.start('lint', 'jasmine', 'babel', 'doc');
12+
});
13+
14+
gulp.task('lint', () => {
15+
return gulp.src(['src/*.js', '!node_modules/**'])
16+
.pipe(eslint())
17+
.pipe(eslint.format());
18+
});
19+
20+
gulp.task('babel', () => {
21+
gulp.src('src/*.js')
22+
.pipe(babel({
23+
presets: ['env']
24+
}))
25+
.pipe(gulp.dest('dist'));
26+
});
27+
28+
gulp.task('build', () => {
29+
webpack({
30+
entry: [
31+
'babel-polyfill',
32+
path.join(__dirname, 'src/bynder-js-sdk')
33+
],
34+
output: {
35+
path: './dist/',
36+
filename: 'bundle.js',
37+
library: 'Bynder'
38+
},
39+
module: {
40+
loaders: [
41+
{
42+
test: /\.js$/,
43+
exclude: /node_modules/,
44+
loader: 'babel-loader',
45+
query: {
46+
presets: ['env']
47+
}
48+
},
49+
{
50+
test: /\.json$/,
51+
loader: 'json-loader'
52+
}
53+
]
54+
},
55+
resolve: {
56+
extensions: ['', '.js']
57+
}
58+
}).run((err, stat) => {
59+
if (err) {
60+
console.log('Error building application - ', err);
61+
return;
62+
}
63+
const statJson = stat.toJson();
64+
if (statJson.errors.length > 0) {
65+
console.log('Error building application - ', statJson.errors);
66+
return;
67+
}
68+
console.log('Application built successfully !');
69+
});
70+
});
71+
72+
gulp.task('jasmine', () => {
73+
gulp.src('tests/*.js')
74+
// gulp-jasmine works on filepaths so you can't have any plugins before it
75+
.pipe(jasmine({
76+
verbose: true
77+
}));
78+
});
79+
80+
gulp.task('doc', (cb) => {
81+
gulp.src(['README.md', 'src/*.js'], { read: false })
82+
.pipe(jsdoc(cb));
83+
});
84+
85+
gulp.task('webserver', () => {
86+
connect.server({
87+
port: 8080
88+
});
89+
});

package.json

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
{
2+
"name": "bynder-js-sdk",
3+
"version": "1.0.0",
4+
"description": "Bynder Javascript SDK",
5+
"main": "bynder-js-sdk.js",
6+
"scripts": {
7+
"test": "jasmine tests/*"
8+
},
9+
"author": "Bynder",
10+
"license": "MIT",
11+
"devDependencies": {
12+
"babel": "^6.5.2",
13+
"babel-core": "^6.20.0",
14+
"babel-loader": "^6.2.9",
15+
"babel-polyfill": "^6.20.0",
16+
"babel-preset-env": "^1.1.1",
17+
"eslint": "~3.7.1",
18+
"eslint-config-airbnb": "~12.0.0",
19+
"eslint-plugin-import": "~1.16.0",
20+
"eslint-plugin-jsx-a11y": "~2.2.3",
21+
"eslint-plugin-react": "~6.4.1",
22+
"gulp": "^3.9.1",
23+
"gulp-babel": "^6.1.2",
24+
"gulp-connect": "^5.0.0",
25+
"gulp-eslint": "^3.0.1",
26+
"gulp-jasmine": "^2.4.0",
27+
"gulp-jsdoc3": "^0.3.0",
28+
"istanbul": "^0.4.5",
29+
"jasmine": "^2.6.0",
30+
"json-loader": "^0.5.4",
31+
"path": "^0.12.7",
32+
"webpack": "^1.14.0"
33+
},
34+
"dependencies": {
35+
"axios": "^0.15.3",
36+
"node-fetch": "^1.6.0",
37+
"oauth-1.0a": "^1.0.1"
38+
},
39+
"repository": "[email protected]:Bynder/bynder-js-sdk.git"
40+
}

samples/categories.html

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<html>
2+
<head>
3+
<meta charset="UTF-8">
4+
<title>Categories sample</title>
5+
<script src="../dist/bundle.js"></script>
6+
</head>
7+
<body>
8+
<ul id="categories-container">
9+
</ul>
10+
11+
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
12+
<script src="https://unpkg.com/babel-standalone@6/babel.min.js"></script>
13+
<script src="https://cdnjs.cloudflare.com/ajax/libs/dompurify/0.9.0/purify.min.js"></script>
14+
<script type="text/babel">
15+
const Bynder = Bynder.default;
16+
17+
function appendCategories(categories) {
18+
const categoriesContainer = document.getElementById('categories-container');
19+
for (const category of categories) {
20+
categoriesContainer.innerHTML += `<li>${DOMPurify.sanitize(category.name)}</li>`;
21+
}
22+
}
23+
24+
axios('../secret.json')
25+
.then((response) => {
26+
if (response.status < 300) {
27+
return response.data;
28+
}
29+
return Promise.reject(response);
30+
})
31+
.then((configs) => {
32+
const bynder = new Bynder(configs);
33+
return bynder.getCategories();
34+
})
35+
.then((data) => {
36+
appendCategories(data);
37+
console.log(data);
38+
})
39+
.catch((error) => {
40+
console.error(error);
41+
});
42+
</script>
43+
</body>
44+
</html>

samples/categories.js

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
const Bynder = require('../dist/bynder-js-sdk.js').default;
2+
const configs = require('../secret.json');
3+
4+
const bynder = new Bynder(configs);
5+
6+
bynder.getCategories()
7+
.then((data) => {
8+
console.log(data);
9+
})
10+
.catch((error) => {
11+
console.error(error);
12+
});

0 commit comments

Comments
 (0)