forked from balanced/balanced-docs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_main.mako
166 lines (146 loc) · 3.6 KB
/
_main.mako
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
## http://stackoverflow.com/a/6701741/133514
<%def name="route_for_endpoint(endpoint)">
<%
import _utils
method, path = _utils.routify(endpoint)
return method, path
%>
</%def>
<%def name="interpolate_uri(uri, **kwargs)">
<%
# this basically parses :bank_account_id to a string with {bank_account_id}
# for much easier interpolation.
import re
# note that it shouldn't start with a digit!
_uri = re.sub('(:([^\d]\w+))+', r'{\2}', uri)
return _uri.format(**kwargs)
%>
</%def>
<%def name="make_endpoint(endpoint_name)">
<%
return context['Endpoint'](context, endpoint_name)
%>
</%def>
<%def name="php_boilerplate()">
## i'm putting this between an interpolation because pycharm's introspection
## correctly detects that this is an unclosed tag and warns me..annoying.
${"<?php"}
require(__DIR__ . '/vendor/autoload.php');
Httpful\Bootstrap::init();
RESTful\Bootstrap::init();
Balanced\Bootstrap::init();
%if 'api.balancedpayments.com' not in api_location:
Balanced\Settings::configure("${api_location}", "${api_key}");
%else:
Balanced\Settings::$api_key = "${api_key}";
%endif
</%def>
<%def name="python_boilerplate()">
import balanced
%if 'api.balancedpayments.com' not in api_location:
balanced.config.root_uri = "${api_location}"
%endif
balanced.configure("${api_key}")
</%def>
<%def name="ruby_boilerplate()">
require 'balanced'
%if 'api.balancedpayments.com' not in api_location:
<%
import urlparse
parsed_url = urlparse.urlparse(api_location)
_root_url = parsed_url.netloc
if ':' in _root_url:
_root_url, _, _ = parsed_url.netloc.partition(':')
%>
options = {
:scheme => 'http',
:host => '${_root_url}',
:port => 5000,
}
Balanced.configure('${api_key}', options)
%else:
Balanced.configure('${api_key}')
%endif
</%def>
<%def name="curl_show_template(endpoint_name)">
<%
ep = make_endpoint(endpoint_name).force_shortest_url_path()
%>
% if request is UNDEFINED:
${ep.method} ${ep.full_url}
% else:
<%
slash = '\\'
%>
curl ${ep.qualified_url_for(request['uri'])} ${slash}
-u ${api_key}:
% endif
</%def>
<%def name="curl_create_template(endpoint_name, uri='uri', ep=None)">
<%
ep = ep or make_endpoint(endpoint_name).force_shortest_url_path()
%>
%if request is UNDEFINED:
${ep.method} ${ep.full_url}
%else:
<%
slash = '\\'
%>
curl ${ep.qualified_url_for(request[uri])} ${slash}
-u ${api_key}: ${slash}
%if 'payload' in request:
%for k, v, slash in recursive_expand(request['payload']):
-d "${k}=${v}" ${slash}
%endfor
%else:
-X POST
%endif
%endif
</%def>
<%def name="curl_update_template(endpoint_name, uri='uri', ep=None)">
<%
ep = ep or make_endpoint(endpoint_name).force_shortest_url_path()
%>
%if request is UNDEFINED:
${ep.method} ${ep.full_url}
%else:
<%
slash = '\\'
%>
curl ${ep.qualified_url_for(request[uri])} ${slash}
-u ${api_key}: ${slash}
-X PUT ${slash}
%for k, v, slash in recursive_expand(request['payload']):
-d "${k}=${v}" ${slash}
%endfor
%endif
</%def>
<%def name="curl_list_template(endpoint_name, limit=2, ep=None)">
<%
ep = ep or make_endpoint(endpoint_name).force_shortest_url_path()
%>
% if request is UNDEFINED:
${ep.method} ${ep.full_url}
% else:
<%
slash = '\\'
%>
curl ${ep.qualified_url_for(request['uri'], limit=limit)} ${slash}
-u ${api_key}:
% endif
</%def>
<%def name="curl_delete_template(endpoint_name, ep=None)">
<%
ep = ep or make_endpoint(endpoint_name)
%>
% if request is UNDEFINED:
${ep.method} ${ep.full_url}
% else:
<%
slash = '\\'
%>
curl ${ep.qualified_url_for(request['uri'])} ${slash}
-u ${api_key}: ${slash}
-X DELETE
% endif
</%def>