Skip to content

Commit

Permalink
Merge pull request #138 from renderforest/template-svg
Browse files Browse the repository at this point in the history
✨ release 0.3.5
  • Loading branch information
narekhovhannisyan authored Jan 15, 2019
2 parents 2a0c21a + 95dcd04 commit 3310e67
Show file tree
Hide file tree
Showing 15 changed files with 202 additions and 96 deletions.
2 changes: 2 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Renderforest SDK usage examples
examples
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ Welcome to the Renderforest API! You can use our API to:
- [Get Pluggable-Screens of the Template](#get-pluggable-screens-of-the-template)
- [Get Recommended-Custom-Colors of the Template](#get-recommended-custom-colors-of-the-template)
- [Get Template-Presets of the Template](#get-template-presets-of-the-template)
- [Get SVG Content of the Template](#get-svg-content-of-the-template)
- [Get Theme of the Template](#get-theme-of-the-template)
- [Get Transitions of the Template](#get-transitions-of-the-template)
* [Users API](#users-api)
Expand Down Expand Up @@ -861,6 +862,23 @@ Template-presets are ready-made stories created from this template to fasten you
[See example](https://github.com/renderforest/renderforest-sdk-node/blob/master/examples/templates/get-template-presets.js)


### Get SVG Content of the Template
Retrieves SVG content of the template.

```js
const Renderforest = require('@renderforest/sdk-node')

const payload = {
templateId: 701
}
Renderforest.getTemplateSVGContent(payload)
.then(console.log) // handle the success
.catch(console.error) // handle the error
```

[See example](https://github.com/renderforest/renderforest-sdk-node/blob/master/examples/templates/get-template-svg-content.js)


### Get Theme of the Template

Retrieves theme of the template.
Expand Down
16 changes: 16 additions & 0 deletions examples/templates/get-template-svg-content.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/**
* Copyright (c) 2018-present, Renderforest, LLC.
* All rights reserved.
*
* This source code is licensed under the license found in the
* LICENSE file in the root directory.
*/

const Renderforest = require('../../src/lib/renderforest')

const payload = {
templateId: 701
}
Renderforest.getTemplateSVGContent(payload)
.then(console.log) // handle the success
.catch(console.error) // handle the error
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@renderforest/sdk-node",
"description": "Renderforest SDK for Node.js",
"version": "0.3.4",
"version": "0.3.5",
"author": "RenderForest LLC",
"bugs": {
"url": "https://github.com/renderforest/renderforest-sdk-node/issues"
Expand Down
19 changes: 19 additions & 0 deletions src/config/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
const PackageJson = require('../../package.json')

const config = {
API_HOST: 'https://api.renderforest.com',
API_PREFIX: '/api/v1',
HTTP_DEFAULT_OPTIONS: {
method: 'GET',
json: true,
headers: {
'Accept': 'application/json',
'User-Agent': `renderforest/sdk-node/${PackageJson.version}`
}
},
PROJECT_DATA_API_PREFIX: '/api/v5',
WEB_HOST: 'https://www.renderforest.com',
WEB_PREFIX: '/api/v1'
}

module.exports = config
13 changes: 11 additions & 2 deletions src/lib/renderforest.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* LICENSE file in the root directory.
*/

const Http = require('./http/http')
const ApiRequest = require('./request/api')

const ProjectData = require('./resources/project-data')
const Projects = require('./resources/projects')
Expand All @@ -23,7 +23,7 @@ class Renderforest {
* @param {number} options.clientId
*/
constructor (options) {
Http.setConfig(options.signKey, options.clientId)
ApiRequest.setConfig(options.signKey, options.clientId)
}

/**
Expand Down Expand Up @@ -232,6 +232,15 @@ class Renderforest {
return Templates.getTemplateRecommendedCustomColors(payload)
}

/**
* @param {Object} payload
* @returns {Promise.<Array>}
* @description Get Template-SVG-Content of the Template.
*/
static getTemplateSVGContent (payload) {
return Templates.getTemplateSVGContent(payload)
}

/**
* @param {Object} payload
* @returns {Promise.<Array>}
Expand Down
34 changes: 12 additions & 22 deletions src/lib/http/http.js → src/lib/request/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ const RequestPromise = require('request-promise')

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

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

class Http {
class ApiRequest {
/**
* @constructor
*/
Expand Down Expand Up @@ -50,16 +50,16 @@ class Http {
* @description Append URI.
*/
static appendURI (options) {
options.uri = `${Http.HOST}${options.endpoint}`
options.uri = `${API_HOST}${options.endpoint}`
}

/**
* @param {Object} options
* @description Prepare request.
*/
static prepareRequest (options) {
Http.appendQueryParams(options)
Http.appendURI(options)
ApiRequest.appendQueryParams(options)
ApiRequest.appendURI(options)
}

/**
Expand All @@ -78,11 +78,11 @@ class Http {
* @description Unauthorized request.
*/
unauthorizedRequest (options) {
const _options = Object.assign({}, Http.DEFAULT_OPTIONS, options)
const _options = Object.assign({}, HTTP_DEFAULT_OPTIONS, options)

Http.prepareRequest(_options)
ApiRequest.prepareRequest(_options)

return Http.request(_options)
return ApiRequest.request(_options)
}

/**
Expand All @@ -91,23 +91,13 @@ class Http {
* @description Authorized request.
*/
authorizedRequest (options) {
const _options = Object.assign({}, Http.DEFAULT_OPTIONS, options)
const _options = Object.assign({}, HTTP_DEFAULT_OPTIONS, options)

Http.prepareRequest(_options)
ApiRequest.prepareRequest(_options)
Auth.setAuthorization(_options, this.signKey, this.clientId)

return Http.request(_options)
return ApiRequest.request(_options)
}
}

Http.HOST = 'https://api.renderforest.com'
Http.DEFAULT_OPTIONS = {
method: 'GET',
json: true,
headers: {
'Accept': 'application/json',
'User-Agent': `renderforest/sdk-node/${PackageJson.version}`
}
}

module.exports = new Http()
module.exports = new ApiRequest()
36 changes: 36 additions & 0 deletions src/lib/request/web.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/**
* Copyright (c) 2018-present, Renderforest, LLC.
* All rights reserved.
*
* This source code is licensed under the license found in the
* LICENSE file in the root directory.
*/

const RequestPromise = require('request-promise')

const { HTTP_DEFAULT_OPTIONS, WEB_HOST } = require('../../config/config')

class WebRequest {
/**
* @param {Object} options
* @description Append URI.
*/
static appendURI (options) {
options.uri = `${WEB_HOST}${options.endpoint}`
}

/**
* @param {Object} options
* @returns {Promise.<>}
* @description Appends URI and makes request with default options.
*/
request (options) {
const _options = Object.assign({}, HTTP_DEFAULT_OPTIONS, options)

WebRequest.appendURI(_options)

return RequestPromise(_options)
}
}

module.exports = new WebRequest()
14 changes: 7 additions & 7 deletions src/lib/resources/project-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@
* LICENSE file in the root directory.
*/

const Http = require('../http/http')
const ApiRequest = require('../request/api')

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

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

const { PROJECT_DATA_API_PREFIX } = require('../../config/config')

class ProjectData {
/**
* @param {Object} payload
Expand All @@ -22,9 +24,9 @@ class ProjectData {
const projectId = Params.destructURLParam(payload, 'projectId')

const options = {
endpoint: `${ProjectData.API_PREFIX}/project-data/${projectId}`
endpoint: `${PROJECT_DATA_API_PREFIX}/project-data/${projectId}`
}
return Http.authorizedRequest(options)
return ApiRequest.authorizedRequest(options)
.then((projectDataJson) => new ProjectDataClass(projectDataJson))
}

Expand All @@ -39,13 +41,11 @@ class ProjectData {

const options = {
method: 'PATCH',
endpoint: `${ProjectData.API_PREFIX}/project-data/${projectId}`,
endpoint: `${PROJECT_DATA_API_PREFIX}/project-data/${projectId}`,
body
}
return Http.authorizedRequest(options)
return ApiRequest.authorizedRequest(options)
}
}

ProjectData.API_PREFIX = '/api/v5'

module.exports = ProjectData
Loading

0 comments on commit 3310e67

Please sign in to comment.