Skip to content

Commit c40c334

Browse files
committed
sample rewrite
1 parent 402e457 commit c40c334

File tree

9 files changed

+208
-155
lines changed

9 files changed

+208
-155
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ node_modules
2929

3030
# API credentials file
3131
credentials.js
32-
credentials-stg.js
3332

3433
# webstorm project files
3534
.idea

README-option.md

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# Autodesk View and Data API Node.js Basic Sample
2+
3+
4+
## Description
5+
A sample demonstrating how to view a model in a web application with the Autodesk View & Data API. This web application has a basic Node.js
6+
server and JavaScript/HTML5 client. This sample does not demonstrate how to upload a model to the Autodesk server for translation. See instructions below
7+
to prepare a model to be consumed in this sample.
8+
9+
10+
## Dependencies
11+
Install Node.js on your machine and clone this repo. Download the project dependencies using npm before running the app by running
12+
the following command in the project root directory
13+
```
14+
npm install
15+
```
16+
on the node.js console. This will install the following node.js modules in the project:
17+
- express
18+
- request
19+
- serve-favicon
20+
21+
This sample does not include the workflow of uploading models. on the server It depends on other workflow samples to upload models and
22+
get model URNs - as explained in the Setup/Usage Instructions.
23+
24+
25+
## Setup/Usage Instructions
26+
27+
* Apply for your own credentials (API keys) from [http://developer.autodesk.com](http://developer.autodesk.com)
28+
* From the sample root folder, rename or copy the ./credentials_.js file into ./credentials.js <br />
29+
* Windows <br />
30+
```
31+
copy credentials_.js credentials.js
32+
```
33+
* OSX/Linux <br />
34+
```
35+
cp credentials_.js credentials.js
36+
```
37+
* Replace the placeholder with your own keys in credentials.js, line #29 and #30 <br />
38+
```
39+
credentials.ClientId = '<replace with consumer key>';
40+
41+
credentials.ClientSecret = '<replace with consumer secret>';
42+
```
43+
* The [upload tool](http://still-spire-1606.herokuapp.com) provides some existing models. Choose any one of them, or upload one of your own
44+
models with [upload tool](http://still-spire-1606.herokuapp.com). The [upload tool](http://still-spire-1606.herokuapp.com) will generate a URN of the model that you need later.
45+
* Copy the URN which was generated in the previous step in file /www/index.js at line #18 <br />
46+
```
47+
var defaultUrn = '<replace with your encoded urn>';
48+
```
49+
* In /www/index.js, at line #21, replace the entire line by the following code: <br />
50+
```
51+
var tokenurl ='http://still-spire-1606.herokuapp.com/api/rawtoken';
52+
```
53+
* Run the server from the Node.js console, by running the following command: <br />
54+
```
55+
node server.js
56+
```
57+
* Connect to you local server using a WebGL-compatible browser: [http://localhost:3000/](http://localhost:3000/)
58+
59+
60+
## License
61+
62+
That samples are licensed under the terms of the [MIT License](http://opensource.org/licenses/MIT). Please see the [LICENSE](LICENSE) file for full details.
63+
64+
65+
## Written by
66+
67+
Written by [Philippe Leefsma](http://adndevblog.typepad.com/cloud_and_mobile/philippe-leefsma.html) <br />
68+
(Autodesk Developer Network)

README-stg.md

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
# Autodesk View and Data API Node.js Basic Sample
2+
3+
This setup is only available for people having access to the staging server. If you do not have credentials for the staging server, do not use these instructions.
4+
5+
6+
## Description
7+
A sample demonstrating how to view a model in a web application with the Autodesk View & Data API. This web application has a basic Node.js
8+
server and JavaScript/HTML5 client. This sample does not demonstrate how to upload a model to the Autodesk server for translation. See instructions below
9+
to prepare a model to be consumed in this sample.
10+
11+
This README explains how to setup the sample to use the Staging environment vs Production.
12+
13+
14+
## Dependencies
15+
Install Node.js on your machine and clone this repo. Download the project dependencies using npm before running the app by running
16+
the following command in the project root directory
17+
```
18+
npm install
19+
```
20+
on the node.js console. This will install the following node.js modules in the project:
21+
- express
22+
- request
23+
- serve-favicon
24+
25+
This sample does not include the workflow of uploading models. on the server It depends on other workflow samples to upload models and
26+
get model URNs - as explained in the Setup/Usage Instructions.
27+
28+
29+
## Setup/Usage Instructions
30+
31+
* Apply for your own credentials (API keys) from [http://developer-stg.autodesk.com](http://developer-stg.autodesk.com)
32+
* From the sample root folder, rename or copy the ./credentials_.js file into ./credentials.js <br />
33+
* Windows <br />
34+
```
35+
copy credentials_.js credentials.js
36+
```
37+
* OSX/Linux <br />
38+
```
39+
cp credentials_.js credentials.js
40+
```
41+
* Replace the placeholder with your own keys in credentials.js, line #29 and #30 <br />
42+
```
43+
credentials.ClientId = '<replace with consumer key>';
44+
45+
credentials.ClientSecret = '<replace with consumer secret>';
46+
```
47+
* In file credentials.js, comment out line #23, and uncomment line #24
48+
* Upload one of your models to your account and get its URN using another workflow sample, for example,
49+
- [this workflow sample in .net winform application](https://github.com/Developer-Autodesk/workflow-dotnet-winform-view.and.data.api/) if you are using windows
50+
- or [this workflow sample in Mac OS Swift](https://github.com/Developer-Autodesk/workflow-macos-swift-view.and.data.api) if you are using Mac
51+
- or this [WEB page](http://javalmvwalkthrough-vq2mmximxb.elasticbeanstalk.com/)
52+
* Copy the URN which was generated in the previous step in file /www/index.js at line #18 <br />
53+
```
54+
var defaultUrn = '<replace with your encoded urn>';
55+
```
56+
* In file /www/index.html (line #33 and #34), use the viewer3D.min.js and style.css files from the staging server, but using the code below <br />
57+
```
58+
<link type="text/css" rel="stylesheet" href="https://developer-stg.api.autodesk.com/viewingservice/v1/viewers/style.css"/>
59+
60+
<script src="https://developer-stg.api.autodesk.com/viewingservice/v1/viewers/viewer3D.min.js"></script>
61+
```
62+
* In file /www/index.js, comment out line #23, and uncomment line #24
63+
* Run the server from the Node.js console, by running the following command: <br />
64+
```
65+
node server.js
66+
```
67+
* Connect to you local server using a WebGL-compatible browser: [http://localhost:3000/](http://localhost:3000/)
68+
69+
70+
## License
71+
72+
That samples are licensed under the terms of the [MIT License](http://opensource.org/licenses/MIT). Please see the [LICENSE](LICENSE) file for full details.
73+
74+
75+
## Written by
76+
77+
Written by [Philippe Leefsma](http://adndevblog.typepad.com/cloud_and_mobile/philippe-leefsma.html) <br />
78+
(Autodesk Developer Network)
79+
80+

README.md

Lines changed: 30 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,14 @@
22

33

44
## Description
5-
A sample demonstrating how to view a model in a web application with the Autodesk View & Data API. This web application has a basic Node.js server and JavaScript/HTML5 client. This sample does not demonstrate how to upload a model to the Autodesk server for translation.
5+
A sample demonstrating how to view a model in a web application with the Autodesk View & Data API. This web application has a basic Node.js
6+
server and JavaScript/HTML5 client. This sample does not demonstrate how to upload a model to the Autodesk server for translation. See instructions below
7+
to prepare a model to be consumed in this sample.
8+
69

710
## Dependencies
8-
Install Node.js on your machine and clone this repo. Download the project dependencies using npm before running the app by running the following command
11+
Install Node.js on your machine and clone this repo. Download the project dependencies using npm before running the app by running
12+
the following command in the project root directory
913
```
1014
npm install
1115
```
@@ -14,25 +18,35 @@ on the node.js console. This will install the following node.js modules in the p
1418
- request
1519
- serve-favicon
1620

17-
This sample does not include the workflow of uploading models. It depends on other workflow samples to upload models and get model URNs - as explained in the Setup/Usage Instructions.
21+
This sample does not include the workflow of uploading models. on the server It depends on other workflow samples to upload models and
22+
get model URNs - as explained in the Setup/Usage Instructions.
23+
1824

1925
## Setup/Usage Instructions
20-
Use your own credentials to upload models to your account
2126

2227
* Apply for your own credentials (API keys) from [http://developer.autodesk.com](http://developer.autodesk.com)
23-
* Replace the placeholder with your own keys in credentials.js, line #23 and #25 <br />
24-
```
25-
credentials.ClientId = '<replace with clientId>';
28+
* From the sample root folder, rename or copy the ./credentials_.js file into ./credentials.js <br />
29+
* Windows <br />
30+
```
31+
copy credentials_.js credentials.js
32+
```
33+
* OSX/Linux <br />
34+
```
35+
cp credentials_.js credentials.js
36+
```
37+
* Replace the placeholder with your own keys in credentials.js, line #29 and #30 <br />
38+
```
39+
credentials.ClientId = '<replace with consumer key>';
2640

27-
credentials.ClientSecret = '<replace with clientSecret>';
41+
credentials.ClientSecret = '<replace with consumer secret>';
2842
```
2943
* Upload one of your models to your account and get its URN using another workflow sample, for example,
3044
- [this workflow sample in .net winform application](https://github.com/Developer-Autodesk/workflow-dotnet-winform-view.and.data.api/) if you are using windows
3145
- or [this workflow sample in Mac OS Swift](https://github.com/Developer-Autodesk/workflow-macos-swift-view.and.data.api) if you are using Mac
3246
- or this [WEB page](http://javalmvwalkthrough-vq2mmximxb.elasticbeanstalk.com/)
33-
* Copy this URN in /www/views/index.js at line #18 <br />
47+
* Copy the URN which was generated in the previous step in file /www/index.js at line #18 <br />
3448
```
35-
var urnprod = 'your_urn_here';
49+
var defaultUrn = '<replace with your encoded urn>';
3650
```
3751
* Run the server from the Node.js console, by running the following command: <br />
3852
```
@@ -48,56 +62,21 @@ By default, the project is setup with the production server, and use your own cr
4862
4963
You can work with production or staging Autodesk View and Data environments. By default, the project is setup with the production server.
5064
51-
### Option A: Production server option: Use [upload tool](http://still-spire-1606.herokuapp.com) online service to upload model.
65+
* Instructions to setup this sample to use the Autodesk View & Data staging server are [here](https://github.com/Developer-Autodesk/workflow-node.js-view.and.data.api/blob/master/README-stg.md)
5266
53-
* The [upload tool](http://still-spire-1606.herokuapp.com) provides some existing models. Choose any one of them, or upload one of your own models with [upload tool](http://still-spire-1606.herokuapp.com). The [upload tool](http://still-spire-1606.herokuapp.com) will generate a URN of the model that you need later.
54-
* Copy this URN in /www/views/index.js at line #18 <br />
55-
```
56-
var urnprod = 'your_urn_here';
57-
```
58-
* In /www/views/index.js, at line #36, change value of tokenurl to the access token you can generate from 'http://still-spire-1606.herokuapp.com/api/rawtoken'
59-
* Run the server from the Node.js console, by running the following command: <br />
60-
```
61-
node server.js
62-
```
63-
* Connect to your local server using a WebGL-compatible browser: [http://localhost:3000/](http://localhost:3000/)
6467
68+
You can also use someone else credentials to view models using this sample.
6569
66-
### Option B: To work with the staging environment, you need to use your own credentials vs the option above.
67-
* Apply your own credentials from [http://developer-stg.autodesk.com](http://developer-stg.autodesk.com)
68-
* Replace the place holder with your own keys in credentials-stg.js, line #23 and #25 <br />
69-
```
70-
credentials.ClientId = '<replace with clientId>';
71-
72-
credentials.ClientSecret = '<replace with clientSecret>';
73-
```
74-
* Upload one of your models to your account and get its URN using another workflow sample, for example,
75-
- [this workflow sample in .net winform application](https://github.com/Developer-Autodesk/workflow-dotnet-winform-view.and.data.api/) if you are using windows
76-
- or [this workflow sample in Mac OS Swift](https://github.com/Developer-Autodesk/workflow-macos-swift-view.and.data.api) if you are using Mac <br />
77-
But please use [staging URL](https://developer-stg.api.autodesk.com) to proceed with the workflows.
78-
* Copy this URN in /www/views/index.js at line #19 <br />
79-
```
80-
var urnstg = 'your_urn_here';
81-
```
82-
* In /www/views/index.js, around line #24, make sure the variable staging is true.
83-
* In /www/views/index.html (line $33 and #34), use viewer3D.min.js and style.css from the staging environment <br />
84-
```
85-
<link type="text/css" rel="stylesheet" href="https://developer-stg.api.autodesk.com/viewingservice/v1/viewers/style.css"/>
86-
87-
<script src="https://developer-stg.api.autodesk.com/viewingservice/v1/viewers/viewer3D.min.js"></script>
88-
```
89-
* Run the server from the Node.js console, by running the following command: <br />
90-
```
91-
node server.js
92-
```
93-
* Connect to you local server using a WebGL-compatible browser: [http://localhost:3000/](http://localhost:3000/)
70+
* Instructions to setup this sample using someone else credentials are available [here](https://github.com/Developer-Autodesk/workflow-node.js-view.and.data.api/blob/master/README-option.md)
9471
9572
9673
## License
9774
9875
That samples are licensed under the terms of the [MIT License](http://opensource.org/licenses/MIT). Please see the [LICENSE](LICENSE) file for full details.
9976
77+
10078
## Written by
10179
102-
Written by [Philippe Leefsma](http://adndevblog.typepad.com/cloud_and_mobile/philippe-leefsma.html)
80+
Written by [Philippe Leefsma](http://adndevblog.typepad.com/cloud_and_mobile/philippe-leefsma.html) <br />
81+
(Autodesk Developer Network)
10382

credentials.js

Lines changed: 0 additions & 27 deletions
This file was deleted.
Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,17 @@
1616
// UNINTERRUPTED OR ERROR FREE.
1717
/////////////////////////////////////////////////////////////////////////////////
1818

19-
var credentials = {};
19+
var credentials ={} ;
2020

21-
credentials.BaseUrl = 'https://developer.api.autodesk.com';
21+
// If you which to use the Autodesk View & Data API on the staging server,
22+
// comment out the line #23 and uncomment line #24
23+
credentials.BaseUrl = 'https://developer.api.autodesk.com' ;
24+
//credentials.BaseUrl = 'https://developer-stg.api.autodesk.com' ;
2225

23-
credentials.ClientId = '<replace with clientId staging>';
24-
25-
credentials.ClientSecret = '<replace with clientSecret staging>';
26-
27-
module.exports = credentials;
26+
// Replace placeholder below by the Consumer Key and Consumer secret you got from
27+
// http://developer.autodesk.com/ for the production server
28+
// or http://developer-stg.autodesk.com/ for the staging server
29+
credentials.ClientId ='<replace with consumer key>' ;
30+
credentials.ClientSecret ='<replace with consumer secret>' ;
2831

32+
module.exports =credentials ;

routes/api.js

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -16,49 +16,22 @@
1616
// UNINTERRUPTED OR ERROR FREE.
1717
/////////////////////////////////////////////////////////////////////////////////
1818
var credentials = require('../credentials');
19-
var credentialsStg = require('../credentials-stg');
2019

2120
var express = require('express');
2221
var request = require('request');
2322

2423
var router = express.Router();
2524

2625
///////////////////////////////////////////////////////////////////////////////
27-
// Generates access token (production)
28-
//
26+
// Generates access token
2927
///////////////////////////////////////////////////////////////////////////////
3028
router.get('/token', function (req, res) {
31-
3229
var params = {
3330
client_id: credentials.ClientId,
3431
client_secret: credentials.ClientSecret,
3532
grant_type: 'client_credentials'
3633
}
3734

38-
request.post(
39-
credentials.BaseUrl + '/authentication/v1/authenticate',
40-
{ form: params },
41-
42-
function (error, response, body) {
43-
44-
if (!error && response.statusCode == 200) {
45-
res.send(body);
46-
}
47-
});
48-
});
49-
50-
///////////////////////////////////////////////////////////////////////////////
51-
// Generates access token (staging)
52-
//
53-
///////////////////////////////////////////////////////////////////////////////
54-
router.get('/tokenstg', function (req, res) {
55-
56-
var params = {
57-
client_id: credentialsStg.ClientId,
58-
client_secret: credentialsStg.ClientSecret,
59-
grant_type: 'client_credentials'
60-
}
61-
6235
request.post(
6336
credentials.BaseUrl + '/authentication/v1/authenticate',
6437
{ form: params },

0 commit comments

Comments
 (0)