Skip to content

Commit b556c1f

Browse files
authored
added javascript (#9)
* added browser javascript * removed unneed theme configuration file * added dependences * new js version based on js/main.js * changes to js * test global variable * added main file to generated js file * Added NGSI V2 JavaScript SDK example * Fixed documentation for js generation
1 parent 12a6c0c commit b556c1f

File tree

3 files changed

+48
-1
lines changed

3 files changed

+48
-1
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ the above steps with Node.js and installing browserify with `npm install -g brow
3939
perform the following (assuming *main.js* is your entry file):
4040

4141
```shell
42-
browserify src/index.js > bundle.js
42+
browserify js/main.js --require superagent --exports require -o js/ngsi.js
4343
```
4444

4545
Then include *bundle.js* in the HTML pages.

examples/javascript/README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# A simple NGSI V2 JavaScript SDK example
2+
3+
A simple html page that call retrieveAPIResources. To use correctly the example you have to generate a new token and replace it. For example, you can use this [script](https://github.com/fgalan/oauth2-example-orion-client/blob/master/token_script.sh).
4+
5+
6+
## Requirements
7+
* None
8+
9+
## Installation
10+
* Replace the token with a correct one
11+
12+
## Execution
13+
* Open index.html in your browser

examples/javascript/index.html

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>NGSI V2 JavaScript SDK example</title>
5+
</head>
6+
<body>
7+
<script src="https://raw.githubusercontent.com/smartsdk/ngsi-sdk-javascript/master/js/ngsi.js"></script>
8+
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
9+
<script>
10+
var NgsiV2 = FIWARE.NgsiV2;
11+
var defaultClient = NgsiV2.ApiClient.instance;
12+
13+
// Configure API key authorization: fiware_token
14+
var fiware_token = defaultClient.authentications['fiware_token'];
15+
fiware_token.apiKey = "My Token"
16+
// Uncomment the following line to set a prefix for the API key, e.g. "Token" (defaults to null)
17+
//fiware_token.apiKeyPrefix['X-Auth-Token'] = "Token"
18+
var api = new NgsiV2.APIEntryPointApi()
19+
20+
var callback = function(error, data, response) {
21+
if (error) {
22+
console.error(error);
23+
$("#results").html(JSON.stringify(error, null, '\t'));
24+
} else {
25+
console.log('API called successfully. Returned data: ' + JSON.stringify(data, null, '\t'));
26+
$("#results").html(JSON.stringify(data, null, '\t'));
27+
}
28+
};
29+
api.retrieveAPIResources(callback);
30+
</script>
31+
</body>
32+
To use correctly the example you have to generate a new token and replace it. For example, you can use this <a href="https://github.com/fgalan/oauth2-example-orion-client/blob/master/token_script.sh">script</a>.
33+
<pre id="results"></pre>
34+
</html>

0 commit comments

Comments
 (0)