Sha256: 5465530e5fd0b4040c37721a76f6605a39ccea1d29c2bdc5c1fff30d88c294ad

Contents?: true

Size: 1.85 KB

Versions: 35

Compression:

Stored size: 1.85 KB

Contents

var util = require('../util');
var Rest = require('./rest');
var Json = require('./json');
var JsonBuilder = require('../json/builder');
var JsonParser = require('../json/parser');

function populateBody(req) {
  var builder = new JsonBuilder();
  var input = req.service.api.operations[req.operation].input;

  if (input.payload) {
    var params = {};
    var payloadShape = input.members[input.payload];
    params = req.params[input.payload];
    if (params === undefined) return;

    if (payloadShape.type === 'structure') {
      req.httpRequest.body = builder.build(params, payloadShape);
    } else { // non-JSON payload
      req.httpRequest.body = params;
    }
  } else {
    req.httpRequest.body = builder.build(req.params, input);
  }
}

function buildRequest(req) {
  Rest.buildRequest(req);

  // never send body payload on GET/HEAD/DELETE
  if (['GET', 'HEAD', 'DELETE'].indexOf(req.httpRequest.method) < 0) {
    populateBody(req);
  }
}

function extractError(resp) {
  Json.extractError(resp);
}

function extractData(resp) {
  Rest.extractData(resp);

  var req = resp.request;
  var rules = req.service.api.operations[req.operation].output || {};
  if (rules.payload) {
    var payloadMember = rules.members[rules.payload];
    var body = resp.httpResponse.body;
    if (payloadMember.type === 'structure' || payloadMember.type === 'list') {
      var parser = new JsonParser();
      resp.data[rules.payload] = parser.parse(body, payloadMember);
    } else if (payloadMember.type === 'binary' || payloadMember.isStreaming) {
      resp.data[rules.payload] = body;
    } else {
      resp.data[rules.payload] = payloadMember.toType(body);
    }
  } else {
    var data = resp.data;
    Json.extractData(resp);
    resp.data = util.merge(data, resp.data);
  }
}

module.exports = {
  buildRequest: buildRequest,
  extractError: extractError,
  extractData: extractData
};

Version data entries

35 entries across 35 versions & 1 rubygems

Version Path
sumomo-0.10.8 data/sumomo/api_modules/node_modules/aws-sdk/lib/protocol/rest_json.js
sumomo-0.10.4 data/sumomo/api_modules/node_modules/aws-sdk/lib/protocol/rest_json.js
sumomo-0.10.3 data/sumomo/api_modules/node_modules/aws-sdk/lib/protocol/rest_json.js
sumomo-0.10.2 data/sumomo/api_modules/node_modules/aws-sdk/lib/protocol/rest_json.js
sumomo-0.10.1 data/sumomo/api_modules/node_modules/aws-sdk/lib/protocol/rest_json.js
sumomo-0.10.0 data/sumomo/api_modules/node_modules/aws-sdk/lib/protocol/rest_json.js
sumomo-0.9.0 data/sumomo/api_modules/node_modules/aws-sdk/lib/protocol/rest_json.js
sumomo-0.8.22 data/sumomo/api_modules/node_modules/aws-sdk/lib/protocol/rest_json.js
sumomo-0.8.21 data/sumomo/api_modules/node_modules/aws-sdk/lib/protocol/rest_json.js
sumomo-0.8.20 data/sumomo/api_modules/node_modules/aws-sdk/lib/protocol/rest_json.js
sumomo-0.8.17 data/sumomo/api_modules/node_modules/aws-sdk/lib/protocol/rest_json.js
sumomo-0.8.16 data/sumomo/api_modules/node_modules/aws-sdk/lib/protocol/rest_json.js
sumomo-0.8.15 data/sumomo/api_modules/node_modules/aws-sdk/lib/protocol/rest_json.js
sumomo-0.8.14 data/sumomo/api_modules/node_modules/aws-sdk/lib/protocol/rest_json.js
sumomo-0.8.13 data/sumomo/api_modules/node_modules/aws-sdk/lib/protocol/rest_json.js
sumomo-0.8.12 data/sumomo/api_modules/node_modules/aws-sdk/lib/protocol/rest_json.js
sumomo-0.8.11 data/sumomo/api_modules/node_modules/aws-sdk/lib/protocol/rest_json.js
sumomo-0.8.10 data/sumomo/api_modules/node_modules/aws-sdk/lib/protocol/rest_json.js
sumomo-0.8.9 data/sumomo/api_modules/node_modules/aws-sdk/lib/protocol/rest_json.js
sumomo-0.8.8 data/sumomo/api_modules/node_modules/aws-sdk/lib/protocol/rest_json.js