Code coverage report for src/targets/curl.js

Statements: 89.47% (17 / 19)      Branches: 84.62% (22 / 26)      Functions: 66.67% (2 / 3)      Lines: 89.47% (17 / 19)      Ignored: none     

All files » src/targets/ » curl.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52    1   1 13         13   13   13   13 1       13 13     13 4       13 8       13           13     1              
'use strict'
 
var util = require('util')
 
module.exports = function (source, options) {
  var opts = util._extend({
    short: false,
    indent: '  '
  }, options)
 
  var code = []
 
  code.push(util.format('curl %s %s', opts.short ? '-X' : '--request', source.method))
 
  code.push(util.format('%s"%s"', opts.short ? '' : '--url ', source.fullUrl))
 
  if (source.httpVersion === 'HTTP/1.0') {
    code.push(opts.short ? '-0' : '--http1.0')
  }
 
  // construct headers
  Object.keys(source.headersObj).sort().map(function (key) {
    code.push(util.format('%s "%s: %s"', opts.short ? '-H' : '--header', key, source.headersObj[key]))
  })
 
  if (source.allHeaders.cookie) {
    code.push(util.format('%s "%s"', opts.short ? '-b' : '--cookie', source.allHeaders.cookie))
  }
 
  // request body
  if (source.postData.text) {
    code.push(util.format('%s %s', opts.short ? '-d' : '--data', JSON.stringify(source.postData.text)))
  }
 
  // construct post params
  Iif (!source.postData.text && source.postData.params) {
    source.postData.params.map(function (param) {
      code.push(util.format('%s "%s=%s"', opts.short ? '-F' : '--form', param.name, param.value))
    })
  }
 
  return code.join(opts.indent !== false ? ' \\\n' + opts.indent : ' ')
}
 
module.exports.info = {
  key: 'curl',
  title: 'cURL',
  link: 'http://curl.haxx.se/',
  description: 'curl is a command line tool and library for transferring data with URL syntax',
  extname: '.sh'
}