Skip to content

Commit

Permalink
Done basic usage
Browse files Browse the repository at this point in the history
  • Loading branch information
maikudou committed Apr 14, 2013
1 parent 24b050e commit 12078e4
Show file tree
Hide file tree
Showing 10 changed files with 1,199 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Typograph
=========
59 changes: 59 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
var ac = require('argchecker').check({
expect: {
'-p': {},
'-br': {},
'-mn': {param: 'maxNobr', default: 0},
'text': {must: true}
}
});

var xmlRequest =
'<?xml version="1.0" encoding="UTF-8"?>' +
'<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ' +
'xmlns:xsd="http://www.w3.org/2001/XMLSchema" ' +
'xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">' +
'<soap:Body>' +
'<ProcessText xmlns="http://typograf.artlebedev.ru/webservices/">' +
'<text>' + ac.get('text') + '</text>' +
'<entityType>4</entityType>' +
'<useP>'+ac.isOn('-p')+'</useP>' +
'<useBr>'+ac.isOn('-br')+'</useBr>' +
'<maxNobr>'+ac.get('-mn')+'</maxNobr>' +
'</ProcessText>' +
'</soap:Body>' +
'</soap:Envelope>';

http = require('http');

function lengthInUtf8Bytes(str) {
var m = encodeURIComponent(str).match(/%[89ABab]/g);
return str.length + (m ? m.length : 0);
}

var options = {
hostname: 'typograf.artlebedev.ru',
port: 80,
path: '/webservices/typograf.asmx',
method: 'POST',
headers: {
'Content-length': lengthInUtf8Bytes(xmlRequest),
"content-type":"text/xml; charset=UTF-8"
}
};

var req = http.request(options, function(res) {
res.setEncoding('utf8');
res.on('data', function (chunk) {
var start = chunk.indexOf('ProcessTextResult')+18;
var length = chunk.indexOf('</ProcessTextResult') - start;
console.log(chunk.substr(chunk.indexOf('ProcessTextResult')+18, length));
});
});

req.on('error', function(e) {
console.log('problem with request: ' + e.message);
});

// write data to request body
req.write(xmlRequest);
req.end();
2 changes: 2 additions & 0 deletions node_modules/argchecker/.npmignore

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

22 changes: 22 additions & 0 deletions node_modules/argchecker/LICENSE

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

182 changes: 182 additions & 0 deletions node_modules/argchecker/README.md

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

Loading

0 comments on commit 12078e4

Please sign in to comment.