gitlab
Version:
GitLab API Nodejs library.
203 lines (140 loc) • 8.97 kB
HTML
<html>
<head>
<title>ApiBaseHTTP.coffee</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width, target-densitydpi=160dpi, initial-scale=1.0; maximum-scale=1.0; user-scalable=0;">
<link rel="stylesheet" media="all" href="docco.css" />
</head>
<body>
<div id="container">
<div id="background"></div>
<ul id="jump_to">
<li>
<a class="large" href="javascript:void(0);">Jump To …</a>
<a class="small" href="javascript:void(0);">+</a>
<div id="jump_wrapper">
<div id="jump_page">
<a class="source" href="ApiBase.html">
ApiBase.coffee
</a>
<a class="source" href="ApiBaseHTTP.html">
ApiBaseHTTP.coffee
</a>
<a class="source" href="ApiV3.html">
ApiV3.coffee
</a>
<a class="source" href="BaseModel.html">
BaseModel.coffee
</a>
<a class="source" href="Groups.html">
Groups.coffee
</a>
<a class="source" href="Issues.html">
Issues.coffee
</a>
<a class="source" href="ProjectDeployKeys.html">
ProjectDeployKeys.coffee
</a>
<a class="source" href="ProjectHooks.html">
ProjectHooks.coffee
</a>
<a class="source" href="ProjectIssues.html">
ProjectIssues.coffee
</a>
<a class="source" href="ProjectMembers.html">
ProjectMembers.coffee
</a>
<a class="source" href="ProjectMergeRequests.html">
ProjectMergeRequests.coffee
</a>
<a class="source" href="ProjectMilestones.html">
ProjectMilestones.coffee
</a>
<a class="source" href="ProjectRepository.html">
ProjectRepository.coffee
</a>
<a class="source" href="Projects.html">
Projects.coffee
</a>
<a class="source" href="Users.html">
Users.coffee
</a>
<a class="source" href="Utils.html">
Utils.coffee
</a>
<a class="source" href="index.html">
index.coffee
</a>
</div>
</li>
</ul>
<ul class="sections">
<li id="title">
<div class="annotation">
<h1>ApiBaseHTTP.coffee</h1>
</div>
</li>
<li id="section-1">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-1">¶</a>
</div>
</div>
<div class="content"><div class='highlight'><pre>debug = <span class="hljs-built_in">require</span>(<span class="hljs-string">'debug'</span>) <span class="hljs-string">'gitlab:ApiBaseHTTP'</span>
{ApiBase} = <span class="hljs-built_in">require</span> <span class="hljs-string">'./ApiBase'</span>
querystring = <span class="hljs-built_in">require</span> <span class="hljs-string">'querystring'</span>
slumber = <span class="hljs-built_in">require</span> <span class="hljs-string">'slumber'</span>
<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">module</span>.<span class="hljs-title">exports</span>.<span class="hljs-title">ApiBaseHTTP</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">ApiBase</span></span>
<span class="hljs-attribute">handleOptions</span>: <span class="hljs-function">=></span>
<span class="hljs-keyword">super</span>
<span class="hljs-property">@options</span>.base_url ?= <span class="hljs-string">''</span>
<span class="hljs-keyword">unless</span> <span class="hljs-property">@options</span>.url
<span class="hljs-keyword">throw</span> <span class="hljs-string">"`url` is mandatory"</span>
<span class="hljs-keyword">unless</span> <span class="hljs-property">@options</span>.token
<span class="hljs-keyword">throw</span> <span class="hljs-string">"`private_token` is mandatory"</span>
<span class="hljs-property">@options</span>.slumber ?= {}
<span class="hljs-property">@options</span>.slumber.append_slash ?= <span class="hljs-literal">false</span>
<span class="hljs-keyword">if</span> <span class="hljs-property">@options</span>.auth?
<span class="hljs-property">@options</span>.slumber.auth = <span class="hljs-property">@options</span>.auth
debug <span class="hljs-string">"handleOptions()"</span>
<span class="hljs-attribute">init</span>: <span class="hljs-function">=></span>
<span class="hljs-keyword">super</span>
api = slumber.API <span class="hljs-property">@options</span>.url, <span class="hljs-property">@options</span>.slumber
<span class="hljs-property">@slumber</span> = api(<span class="hljs-property">@options</span>.base_url)
<span class="hljs-attribute">prepare_opts</span>: <span class="hljs-function"><span class="hljs-params">(opts)</span> =></span>
opts.__query ?= {}
opts.__query.private_token = <span class="hljs-property">@options</span>.token
<span class="hljs-keyword">return</span> opts
<span class="hljs-attribute">fn_wrapper</span>: <span class="hljs-function"><span class="hljs-params">(fn)</span> =></span>
<span class="hljs-keyword">return</span> (err, response, ret) =>
<span class="hljs-keyword">if</span> err
debug <span class="hljs-string">'an error has occured'</span>, err
arity = fn.length
<span class="hljs-keyword">switch</span> arity
<span class="hljs-keyword">when</span> <span class="hljs-number">1</span> <span class="hljs-keyword">then</span> fn ret
<span class="hljs-keyword">when</span> <span class="hljs-number">2</span> <span class="hljs-keyword">then</span> fn err, ret || JSON.parse(response.body).message
<span class="hljs-keyword">when</span> <span class="hljs-number">3</span> <span class="hljs-keyword">then</span> fn err, response, ret
<span class="hljs-attribute">get</span>: <span class="hljs-function"><span class="hljs-params">(path, query={}, fn=<span class="hljs-literal">null</span>)</span> =></span>
<span class="hljs-keyword">if</span> <span class="hljs-string">'function'</span> <span class="hljs-keyword">is</span> <span class="hljs-keyword">typeof</span> query
fn = query
query = {}
opts = <span class="hljs-property">@prepare_opts</span> query
<span class="hljs-property">@slumber</span>(path).get opts, <span class="hljs-property">@fn_wrapper</span> fn
<span class="hljs-attribute">delete</span>: <span class="hljs-function"><span class="hljs-params">(path, fn=<span class="hljs-literal">null</span>)</span> =></span>
opts = <span class="hljs-property">@prepare_opts</span> {}
<span class="hljs-property">@slumber</span>(path).<span class="hljs-keyword">delete</span> opts, <span class="hljs-property">@fn_wrapper</span> fn
<span class="hljs-attribute">post</span>: <span class="hljs-function"><span class="hljs-params">(path, data={}, fn=<span class="hljs-literal">null</span>)</span> =></span>
opts = <span class="hljs-property">@prepare_opts</span> data
<span class="hljs-property">@slumber</span>(path).post opts, <span class="hljs-property">@fn_wrapper</span> fn
<span class="hljs-attribute">put</span>: <span class="hljs-function"><span class="hljs-params">(path, data={}, fn=<span class="hljs-literal">null</span>)</span> =></span>
opts = <span class="hljs-property">@prepare_opts</span> data
<span class="hljs-property">@slumber</span>(path).put opts, <span class="hljs-property">@fn_wrapper</span> fn
<span class="hljs-attribute">patch</span>: <span class="hljs-function"><span class="hljs-params">(path, data={}, fn=<span class="hljs-literal">null</span>)</span> =></span>
opts = <span class="hljs-property">@prepare_opts</span> data
<span class="hljs-property">@slumber</span>(path).patch opts, <span class="hljs-property">@fn_wrapper</span> fn</pre></div></div>
</li>
</ul>
</div>
</body>
</html>