Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Paste
P571
conduit_client_for_node.js
Active
Public
Actions
Authored by
epriestley
on Oct 16 2012, 1:44 AM.
Edit Paste
Archive Paste
View Raw File
Subscribe
Mute Notifications
Flag For Later
Award Token
Tags
None
Referenced Files
F21283: conduit_client_for_node.js
Feb 24 2016, 1:31 AM
2016-02-24 01:31:52 (UTC+0)
Subscribers
None
var
https
=
require
(
'https'
);
var
querystring
=
require
(
'querystring'
);
var
crypto
=
require
(
'crypto'
);
var
CONDUIT_HOST
=
"secure.phabricator.com"
;
var
CONDUIT_USER
=
"epriestley"
;
var
CONDUIT_CERT
=
"xxxxx"
;
function
call_conduit
(
method
,
params
)
{
var
post_data
=
querystring
.
stringify
({
params
:
JSON
.
stringify
(
params
),
output
:
"json"
,
__conduit__
:
"true"
,
});
var
request
=
https
.
request
(
{
host
:
CONDUIT_HOST
,
path
:
"/api/"
+
method
,
method
:
"POST"
,
headers
:
{
"Host"
:
CONDUIT_HOST
,
"Content-Type"
:
"application/x-www-form-urlencoded"
,
"Content-Length"
:
post_data
.
length
}
},
function
(
res
)
{
res
.
setEncoding
(
"utf8"
);
res
.
on
(
"data"
,
function
(
chunk
)
{
console
.
log
(
'>>> '
+
chunk
);
});
});
request
.
write
(
post_data
);
request
.
end
();
}
function
get_auth
()
{
var
token
=
parseInt
(
new
Date
()
/
1000
)
+
''
;
var
sig
=
crypto
.
createHash
(
'sha1'
)
.
update
(
token
)
.
update
(
CONDUIT_CERT
)
.
digest
(
'hex'
);
return
{
token
:
token
,
sig
:
sig
};
}
var
auth
=
get_auth
();
call_conduit
(
'conduit.connect'
,
{
client
:
"node.js"
,
clientVersion
:
"0.0001alpha"
,
host
:
"https://"
+
CONDUIT_HOST
+
"/"
,
clientDescription
:
"example node.js script"
,
user
:
CONDUIT_USER
,
authToken
:
auth
.
token
,
authSignature
:
auth
.
sig
});
Event Timeline
epriestley
edited the content of this paste.
(Show Details)
Oct 16 2012, 1:44 AM
2012-10-16 01:44:06 (UTC+0)
Log In to Comment