Skip to content

Commit 3310e67

Browse files
Merge pull request #138 from renderforest/template-svg
✨ release 0.3.5
2 parents 2a0c21a + 95dcd04 commit 3310e67

File tree

15 files changed

+202
-96
lines changed

15 files changed

+202
-96
lines changed

.npmignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Renderforest SDK usage examples
2+
examples

README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ Welcome to the Renderforest API! You can use our API to:
6464
- [Get Pluggable-Screens of the Template](#get-pluggable-screens-of-the-template)
6565
- [Get Recommended-Custom-Colors of the Template](#get-recommended-custom-colors-of-the-template)
6666
- [Get Template-Presets of the Template](#get-template-presets-of-the-template)
67+
- [Get SVG Content of the Template](#get-svg-content-of-the-template)
6768
- [Get Theme of the Template](#get-theme-of-the-template)
6869
- [Get Transitions of the Template](#get-transitions-of-the-template)
6970
* [Users API](#users-api)
@@ -861,6 +862,23 @@ Template-presets are ready-made stories created from this template to fasten you
861862
[See example](https://github.com/renderforest/renderforest-sdk-node/blob/master/examples/templates/get-template-presets.js)
862863

863864

865+
### Get SVG Content of the Template
866+
Retrieves SVG content of the template.
867+
868+
```js
869+
const Renderforest = require('@renderforest/sdk-node')
870+
871+
const payload = {
872+
templateId: 701
873+
}
874+
Renderforest.getTemplateSVGContent(payload)
875+
.then(console.log) // handle the success
876+
.catch(console.error) // handle the error
877+
```
878+
879+
[See example](https://github.com/renderforest/renderforest-sdk-node/blob/master/examples/templates/get-template-svg-content.js)
880+
881+
864882
### Get Theme of the Template
865883

866884
Retrieves theme of the template.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/**
2+
* Copyright (c) 2018-present, Renderforest, LLC.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the license found in the
6+
* LICENSE file in the root directory.
7+
*/
8+
9+
const Renderforest = require('../../src/lib/renderforest')
10+
11+
const payload = {
12+
templateId: 701
13+
}
14+
Renderforest.getTemplateSVGContent(payload)
15+
.then(console.log) // handle the success
16+
.catch(console.error) // handle the error

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@renderforest/sdk-node",
33
"description": "Renderforest SDK for Node.js",
4-
"version": "0.3.4",
4+
"version": "0.3.5",
55
"author": "RenderForest LLC",
66
"bugs": {
77
"url": "https://github.com/renderforest/renderforest-sdk-node/issues"

src/config/config.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
const PackageJson = require('../../package.json')
2+
3+
const config = {
4+
API_HOST: 'https://api.renderforest.com',
5+
API_PREFIX: '/api/v1',
6+
HTTP_DEFAULT_OPTIONS: {
7+
method: 'GET',
8+
json: true,
9+
headers: {
10+
'Accept': 'application/json',
11+
'User-Agent': `renderforest/sdk-node/${PackageJson.version}`
12+
}
13+
},
14+
PROJECT_DATA_API_PREFIX: '/api/v5',
15+
WEB_HOST: 'https://www.renderforest.com',
16+
WEB_PREFIX: '/api/v1'
17+
}
18+
19+
module.exports = config

src/lib/renderforest.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* LICENSE file in the root directory.
77
*/
88

9-
const Http = require('./http/http')
9+
const ApiRequest = require('./request/api')
1010

1111
const ProjectData = require('./resources/project-data')
1212
const Projects = require('./resources/projects')
@@ -23,7 +23,7 @@ class Renderforest {
2323
* @param {number} options.clientId
2424
*/
2525
constructor (options) {
26-
Http.setConfig(options.signKey, options.clientId)
26+
ApiRequest.setConfig(options.signKey, options.clientId)
2727
}
2828

2929
/**
@@ -232,6 +232,15 @@ class Renderforest {
232232
return Templates.getTemplateRecommendedCustomColors(payload)
233233
}
234234

235+
/**
236+
* @param {Object} payload
237+
* @returns {Promise.<Array>}
238+
* @description Get Template-SVG-Content of the Template.
239+
*/
240+
static getTemplateSVGContent (payload) {
241+
return Templates.getTemplateSVGContent(payload)
242+
}
243+
235244
/**
236245
* @param {Object} payload
237246
* @returns {Promise.<Array>}

src/lib/http/http.js renamed to src/lib/request/api.js

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ const RequestPromise = require('request-promise')
1212

1313
const Auth = require('../auth/auth')
1414

15-
const PackageJson = require('../../../package.json')
15+
const { API_HOST, HTTP_DEFAULT_OPTIONS } = require('../../config/config')
1616

17-
class Http {
17+
class ApiRequest {
1818
/**
1919
* @constructor
2020
*/
@@ -50,16 +50,16 @@ class Http {
5050
* @description Append URI.
5151
*/
5252
static appendURI (options) {
53-
options.uri = `${Http.HOST}${options.endpoint}`
53+
options.uri = `${API_HOST}${options.endpoint}`
5454
}
5555

5656
/**
5757
* @param {Object} options
5858
* @description Prepare request.
5959
*/
6060
static prepareRequest (options) {
61-
Http.appendQueryParams(options)
62-
Http.appendURI(options)
61+
ApiRequest.appendQueryParams(options)
62+
ApiRequest.appendURI(options)
6363
}
6464

6565
/**
@@ -78,11 +78,11 @@ class Http {
7878
* @description Unauthorized request.
7979
*/
8080
unauthorizedRequest (options) {
81-
const _options = Object.assign({}, Http.DEFAULT_OPTIONS, options)
81+
const _options = Object.assign({}, HTTP_DEFAULT_OPTIONS, options)
8282

83-
Http.prepareRequest(_options)
83+
ApiRequest.prepareRequest(_options)
8484

85-
return Http.request(_options)
85+
return ApiRequest.request(_options)
8686
}
8787

8888
/**
@@ -91,23 +91,13 @@ class Http {
9191
* @description Authorized request.
9292
*/
9393
authorizedRequest (options) {
94-
const _options = Object.assign({}, Http.DEFAULT_OPTIONS, options)
94+
const _options = Object.assign({}, HTTP_DEFAULT_OPTIONS, options)
9595

96-
Http.prepareRequest(_options)
96+
ApiRequest.prepareRequest(_options)
9797
Auth.setAuthorization(_options, this.signKey, this.clientId)
9898

99-
return Http.request(_options)
99+
return ApiRequest.request(_options)
100100
}
101101
}
102102

103-
Http.HOST = 'https://api.renderforest.com'
104-
Http.DEFAULT_OPTIONS = {
105-
method: 'GET',
106-
json: true,
107-
headers: {
108-
'Accept': 'application/json',
109-
'User-Agent': `renderforest/sdk-node/${PackageJson.version}`
110-
}
111-
}
112-
113-
module.exports = new Http()
103+
module.exports = new ApiRequest()

src/lib/request/web.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/**
2+
* Copyright (c) 2018-present, Renderforest, LLC.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the license found in the
6+
* LICENSE file in the root directory.
7+
*/
8+
9+
const RequestPromise = require('request-promise')
10+
11+
const { HTTP_DEFAULT_OPTIONS, WEB_HOST } = require('../../config/config')
12+
13+
class WebRequest {
14+
/**
15+
* @param {Object} options
16+
* @description Append URI.
17+
*/
18+
static appendURI (options) {
19+
options.uri = `${WEB_HOST}${options.endpoint}`
20+
}
21+
22+
/**
23+
* @param {Object} options
24+
* @returns {Promise.<>}
25+
* @description Appends URI and makes request with default options.
26+
*/
27+
request (options) {
28+
const _options = Object.assign({}, HTTP_DEFAULT_OPTIONS, options)
29+
30+
WebRequest.appendURI(_options)
31+
32+
return RequestPromise(_options)
33+
}
34+
}
35+
36+
module.exports = new WebRequest()

src/lib/resources/project-data.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@
66
* LICENSE file in the root directory.
77
*/
88

9-
const Http = require('../http/http')
9+
const ApiRequest = require('../request/api')
1010

1111
const ProjectDataClass = require('../../classes/project-data')
1212

1313
const Params = require('../../util/params')
1414

15+
const { PROJECT_DATA_API_PREFIX } = require('../../config/config')
16+
1517
class ProjectData {
1618
/**
1719
* @param {Object} payload
@@ -22,9 +24,9 @@ class ProjectData {
2224
const projectId = Params.destructURLParam(payload, 'projectId')
2325

2426
const options = {
25-
endpoint: `${ProjectData.API_PREFIX}/project-data/${projectId}`
27+
endpoint: `${PROJECT_DATA_API_PREFIX}/project-data/${projectId}`
2628
}
27-
return Http.authorizedRequest(options)
29+
return ApiRequest.authorizedRequest(options)
2830
.then((projectDataJson) => new ProjectDataClass(projectDataJson))
2931
}
3032

@@ -39,13 +41,11 @@ class ProjectData {
3941

4042
const options = {
4143
method: 'PATCH',
42-
endpoint: `${ProjectData.API_PREFIX}/project-data/${projectId}`,
44+
endpoint: `${PROJECT_DATA_API_PREFIX}/project-data/${projectId}`,
4345
body
4446
}
45-
return Http.authorizedRequest(options)
47+
return ApiRequest.authorizedRequest(options)
4648
}
4749
}
4850

49-
ProjectData.API_PREFIX = '/api/v5'
50-
5151
module.exports = ProjectData

0 commit comments

Comments
 (0)