UNPKG

ask-sdk-v1adapter

Version:
43 lines 1.94 kB
"use strict"; /* * Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved. * Licensed under the Apache License, Version 2.0 (the "License"). * You may not use this file except in compliance with the License. * A copy of the License is located at * http://www.apache.org/licenses/LICENSE-2.0 * * or in the "license" file accompanying this file. This file is distributed * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either * express or implied. See the License for the specific language governing * permissions and limitations under the License. */ Object.defineProperty(exports, "__esModule", { value: true }); exports.DirectiveService = void 0; const serviceError_1 = require("./serviceError"); const v1ApiClient_1 = require("./v1ApiClient"); class DirectiveService { constructor(apiClient) { this.apiClient = apiClient || new v1ApiClient_1.V1ApiClient(); this.directivesApiPath = '/v1/directives'; } enqueue(directive, apiEndpoint, token) { const uri = apiEndpoint + this.directivesApiPath; return this.dispatch(directive, uri, token); } async dispatch(directive, url, token) { const body = JSON.stringify(directive); const headers = [{ key: 'Authorization', value: `Bearer ${token}` }, { key: 'Content-Type', value: 'application/json' }]; const response = await this.apiClient.post(url, headers, body); return this.validateApiResponse(response); } validateApiResponse(apiClientResponse) { const isResponseCodeValid = apiClientResponse.statusCode >= 200 && apiClientResponse.statusCode < 300; if (isResponseCodeValid) { return; } throw new serviceError_1.ServiceError(apiClientResponse.statusCode, JSON.stringify(apiClientResponse.body)); } } exports.DirectiveService = DirectiveService; //# sourceMappingURL=directiveService.js.map