Skip to content

Commit

Permalink
Merged in move-client-to-separate-file-by-moisadoru (pull request #11)
Browse files Browse the repository at this point in the history
Move client to separate file by moisadoru

Approved-by: Christoffer <christoffer@loop54.com>
  • Loading branch information
Joel Kall committed Dec 12, 2018
2 parents b97f1eb + a1d259b commit 9d902d3
Show file tree
Hide file tree
Showing 11 changed files with 373 additions and 311 deletions.
7 changes: 0 additions & 7 deletions .npmignore

This file was deleted.

39 changes: 29 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,49 @@ Javascript Wrapper for Loop54 JSON V3 API

## How to install

### Using Node Package Manager (NPM):

1. Install the package with `npm install --save loop54-js-connector`
2. Require it in your project with `require('loop54-js-connector')`
3. You should now have access to the global variable `Loop54`

### Using `<script>` tag

1. Download `loop54-js-connector.js` (for development) from
<https://static.loop54.com/lib/js/loop54-js-connector.js> or
`loop54-js-connector.min.js` (for production) from
<https://static.loop54.com/lib/js/loop54-js-connector.min.js>
2. Host the file on your own servers or the CDN on your choice
3. Include a `<script>` tag with an `src` attribute that points to your hosted
file
3. Include a `<script>` tag with an `src` attribute that points to your hosted file
4. You should now have access to the global variable `Loop54`.
5. Create and use a Loop54 client as [explained below](#how-to-use)

### Using Node Package Manager (NPM) as AMD (wg. RequireJS) or CJS (eg. NodeJS):

1. Install the package with `npm install --save loop54-js-connector`
2. Require it in your project with `require('loop54-js-connector');` or with `define(["loop54-js-connector"], function(getClient) { /* ... */ })`
3. Create and use a Loop54 client as [explained below](#how-to-use)

### Using Node Package Manager (NPM) in a ESM environment (eg. Babel):

1. Install the package with `npm install --save loop54-js-connector`
2. Require it in your project with `const getClient = require('loop54-js-connector');` or `import getClient from 'loop54-js-connector';`
3. Create and use a Loop54 client as [explained below](#how-to-use)

## How to use

### Configure

You will need to set the endpoint to match the one you will get from Loop54.
When creating a client, you will need to set the endpoint to match the one you will get from Loop54.

__Configuration example__
If you included `loop54-js-connector.js` (or `loop54-js-connector.min.js`) in a script tag,
you can get a configured client from the global Loop54 object:
__Get client from global Loop54 object__
```
var client = Loop54.getClient('URL_TO_YOUR_ENDPOINT');
```

If you imported the connector as an ECMAScript module (with require('loop54-js-connector') or equivalent),
you can call the getClient function directly:
__Get client from imported function__
```
var client = getClient('URL_TO_YOUR_ENDPOINT');
```

### Making API requests

__Search example with promise__
Expand Down Expand Up @@ -136,3 +152,6 @@ run `npm run bundle` to build the source code into /lib folder
`npm run test` to do check if the tests passes

All tests are located in the `test` folder

### Contributors
Thanks to [Doru Moisa](https://github.com/moisadoru) for [PR #1](https://github.com/LoopFiftyFour/JS-Connector/pull/1)
21 changes: 15 additions & 6 deletions bundle.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
const runAll = require("npm-run-all");
const forever = require("forever");

const runopts = {parallel: true, stdout: process.stdout};
const runopts = {
parallel : true,
stdout : process.stdout,
};

console.log("Running browserify");
runAll(["browserify"], runopts)
.then(() => {console.log("Running uglify"); runAll(["uglify"], runopts)})
.catch(console.error);
console.log("Running clean");
runAll(["clean"], runopts)
.then(() => {
console.log("Running build");
runAll(["build-*"], runopts)
.then(() => {
console.log("Running uglify");
runAll(["uglify"], runopts)
})
})
.catch(console.error);
1 change: 0 additions & 1 deletion launch-dev.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
const runAll = require("npm-run-all");
const forever = require("forever");

const runopts = {parallel: true, stdout: process.stdout};

Expand Down
10 changes: 8 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@
"version": "1.0.5454545454-build-number",
"description": "JS Wrapper for Loop54 JSON API",
"main": "lib/loop54-js-connector.js",
"module": "lib/loop54-js-connector-client.js",
"scripts": {
"clean": "rm -rf ./lib",
"dev": "node launch-dev.js",
"watch": "watchify src/loop54.js -o lib/loop54-js-connector.js -t [ babelify --presets [ @babel/preset-env ] ]",
"server": "node server.js",
"browserify": "browserify src/loop54.js -o lib/loop54-js-connector.js -t [ babelify --presets [ @babel/preset-env ] ]",
"build-connector": "browserify src/loop54.js -o lib/loop54-js-connector.js -t [ babelify --presets [ @babel/preset-env ] ]",
"build-client": "rollup src/client.js -e axios -o lib/loop54-js-connector-client.js -f cjs",
"uglify": "uglifyjs lib/loop54-js-connector.js -o lib/loop54-js-connector.min.js",
"bundle": "node bundle.js",
"test": "mocha --compilers js:@babel/register ./test/lib-test.js"
Expand All @@ -17,6 +20,9 @@
"SaaS",
"Search"
],
"files": [
"lib/*"
],
"author": "Loop54",
"dependencies": {
"@babel/polyfill": "^7.0.0",
Expand All @@ -31,11 +37,11 @@
"chai": "^3.4.1",
"chai-as-promised": "^7.1.1",
"express": "^4.16.2",
"forever": "^0.15.3",
"http": "0.0.0",
"mocha": "^4.0.1",
"nock": "^9.0.22",
"npm-run-all": "^4.1.1",
"rollup": "^0.67.4",
"sinon": "^4.0.1",
"uglify-js": "^3.1.7",
"watchify": "^3.11.0"
Expand Down
5 changes: 3 additions & 2 deletions server.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
var express = require('express'),
app = express(),
http = require('http'),
httpServer = http.Server(app);
http = require('http');

http.Server(app);

app.use(express.static(__dirname + '/lib'));
app.use(express.static(__dirname + '/public'));
Expand Down
Loading

0 comments on commit 9d902d3

Please sign in to comment.