forge-oss
Version:
Asynchronous Javascript/Node.js library for the Autodesk Forge OSS API.
196 lines (179 loc) • 10 kB
JavaScript
/*
* The MIT License (MIT)
*
* Copyright (c) 2016
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
* NOTE: This class is auto generated by the swagger code generator program.
* https://github.com/swagger-api/swagger-codegen.git
* Do not edit the class manually.
*
*/
(function(root, factory) {
if (typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module.
define(['ApiClient', 'model/PostBucketsPayload', 'model/Bucket', 'model/Reason', 'model/InlineResponse200'], factory);
} else if (typeof module === 'object' && module.exports) {
// CommonJS-like environments that support module.exports, like Node.
module.exports = factory(require('../ApiClient'), require('../model/PostBucketsPayload'), require('../model/Bucket'), require('../model/Reason'), require('../model/InlineResponse200'));
} else {
// Browser globals (root is window)
if (!root.ForgeOss) {
root.ForgeOss = {};
}
root.ForgeOss.BucketsApi = factory(root.ForgeOss.ApiClient, root.ForgeOss.PostBucketsPayload, root.ForgeOss.Bucket, root.ForgeOss.Reason, root.ForgeOss.InlineResponse200);
}
}(this, function(ApiClient, PostBucketsPayload, Bucket, Reason, InlineResponse200) {
'use strict';
/**
* Buckets service.
* @module api/BucketsApi
*/
/**
* Constructs a new BucketsApi.
* @alias module:api/BucketsApi
* @class
* @param {module:ApiClient} apiClient Optional API client implementation to use,
* default to {@link module:ApiClient#instance} if unspecified.
*/
var ForgeSDK = require('forge-apis');
var exports = function(apiClient) {
this.apiClient = apiClient || ApiClient.instance;
this.mdClient = new ForgeSDK.BucketsApi();
this.oauth2_application = new ForgeSDK.AuthClientTwoLegged('1234', '1234', ['data:read'], false);
/**
* Callback function to receive the result of the createBucket operation.
* @callback module:api/BucketsApi~createBucketCallback
* @param {String} error Error message, if any.
* @param {module:model/Bucket} data The data returned by the service call.
* @param {String} response The complete HTTP response.
*/
/**
* Use this endpoint to create a bucket. Buckets are arbitrary spaces created and owned by applications. Bucket keys are globally unique across all regions, regardless of where they were created, and they cannot be changed. The application creating the bucket is the owner of the bucket.
* @param {module:model/PostBucketsPayload} postBuckets Body Structure
* @param {Object} opts Optional parameters
* @param {module:model/String} opts.xAdsRegion The region where the bucket resides Acceptable values: `US`, `EMEA` Default is `US` (default to US)
* @param {module:api/BucketsApi~createBucketCallback} callback The callback function, accepting three arguments: error, data, response
* data is of type: {@link module:model/Bucket}
* @return {Promise} a {@link https://www.promisejs.org/|Promise}, with data of type {@link module:model/Bucket}
*/
this.createBucketEndPoint ='/oss/v2/buckets' ;
this.createBucket = function(postBuckets, opts, callback) {
//this.apiClient.applyToAuthObjects (this.oauth2_access_code, this.oauth2_application, ['oauth2_application']) ;
var oauth = this.apiClient.getAuthObject(this.oauth2_access_code, this.oauth2_application, ['oauth2_application']);
var pr = this.mdClient.createBucket(postBuckets, opts, oauth, oauth.getCredentials());
if (callback === undefined) {
return (new Promise(function (resolve, reject) {
pr.then(function (result) { resolve(result.body); })
.catch(function (err) { reject(err); });
})) ;
}
pr.then(function (result) { callback(null, result.body); })
.catch(function (err) { callback(err, null); });
};
/**
* Callback function to receive the result of the deleteBucket operation.
* @callback module:api/BucketsApi~deleteBucketCallback
* @param {String} error Error message, if any.
* @param data This operation does not return a value.
* @param {String} response The complete HTTP response.
*/
/**
* This endpoint will delete a bucket.
* @param {String} bucketKey URL-encoded bucket key
* @param {module:api/BucketsApi~deleteBucketCallback} callback The callback function, accepting three arguments: error, data, response
* @return {Promise} a {@link https://www.promisejs.org/|Promise}
*/
this.deleteBucketEndPoint ='/oss/v2/buckets/{bucketKey}' ;
this.deleteBucket = function(bucketKey, callback) {
//this.apiClient.applyToAuthObjects (this.oauth2_access_code, this.oauth2_application, ['oauth2_application']) ;
var oauth = this.apiClient.getAuthObject(this.oauth2_access_code, this.oauth2_application, ['oauth2_application']);
var pr = this.mdClient.deleteBucket(bucketKey, oauth, oauth.getCredentials());
if (callback === undefined) {
return (new Promise(function (resolve, reject) {
pr.then(function (result) { resolve(result.body); })
.catch(function (err) { reject(err); });
})) ;
}
pr.then(function (result) { callback(null, result.body); })
.catch(function (err) { callback(err, null); });
};
/**
* Callback function to receive the result of the getBucketDetails operation.
* @callback module:api/BucketsApi~getBucketDetailsCallback
* @param {String} error Error message, if any.
* @param {module:model/Bucket} data The data returned by the service call.
* @param {String} response The complete HTTP response.
*/
/**
* This endpoint will return the buckets owned by the application. This endpoint supports pagination.
* @param {String} bucketKey URL-encoded bucket key
* @param {module:api/BucketsApi~getBucketDetailsCallback} callback The callback function, accepting three arguments: error, data, response
* data is of type: {@link module:model/Bucket}
* @return {Promise} a {@link https://www.promisejs.org/|Promise}, with data of type {@link module:model/Bucket}
*/
this.getBucketDetailsEndPoint ='/oss/v2/buckets/{bucketKey}/details' ;
this.getBucketDetails = function(bucketKey, callback) {
//this.apiClient.applyToAuthObjects (this.oauth2_access_code, this.oauth2_application, ['oauth2_application']) ;
var oauth = this.apiClient.getAuthObject(this.oauth2_access_code, this.oauth2_application, ['oauth2_application']);
var pr = this.mdClient.getBucketDetails(bucketKey, oauth, oauth.getCredentials());
if (callback === undefined) {
return (new Promise(function (resolve, reject) {
pr.then(function (result) { resolve(result.body); })
.catch(function (err) { reject(err); });
})) ;
}
pr.then(function (result) { callback(null, result.body); })
.catch(function (err) { callback(err, null); });
};
/**
* Callback function to receive the result of the getBuckets operation.
* @callback module:api/BucketsApi~getBucketsCallback
* @param {String} error Error message, if any.
* @param {module:model/InlineResponse200} data The data returned by the service call.
* @param {String} response The complete HTTP response.
*/
/**
* This endpoint will return the buckets owned by the application. This endpoint supports pagination.
* @param {Object} opts Optional parameters
* @param {module:model/String} opts.region The region where the bucket resides Acceptable values: `US`, `EMEA` Default is `US` (default to US)
* @param {Integer} opts.limit Limit to the response size, Acceptable values: 1-100 Default = 10 (default to 10)
* @param {String} opts.startAt Key to use as an offset to continue pagination This is typically the last bucket key found in a preceding GET buckets response
* @param {module:api/BucketsApi~getBucketsCallback} callback The callback function, accepting three arguments: error, data, response
* data is of type: {@link module:model/InlineResponse200}
* @return {Promise} a {@link https://www.promisejs.org/|Promise}, with data of type {@link module:model/InlineResponse200}
*/
this.getBucketsEndPoint ='/oss/v2/buckets' ;
this.getBuckets = function(opts, callback) {
//this.apiClient.applyToAuthObjects (this.oauth2_access_code, this.oauth2_application, ['oauth2_application']) ;
var oauth = this.apiClient.getAuthObject(this.oauth2_access_code, this.oauth2_application, ['oauth2_application']);
var pr = this.mdClient.getBuckets(opts, oauth, oauth.getCredentials());
if (callback === undefined) {
return (new Promise(function (resolve, reject) {
pr.then(function (result) { resolve(result.body); })
.catch(function (err) { reject(err); });
})) ;
}
pr.then(function (result) { callback(null, result.body); })
.catch(function (err) { callback(err, null); });
};
};
return exports;
}));