-
Notifications
You must be signed in to change notification settings - Fork 11
/
index.html
304 lines (253 loc) · 6.57 KB
/
index.html
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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
<html>
<head>
<title></title>
<link rel="stylesheet" href="sh_custom.css" type="text/css" />
<style type="text/css">
html {
color: #fff;
margin: 0px;
background: -moz-linear-gradient(0% 100% 90deg,#350a0a, #180505);
background: -webkit-gradient(linear, 0% 0%, 0% 100%, from(#350a0a), to(#180505));
height: 100%;
}
body {
width: 100%;
margin: 0;
}
pre {
background: none;
border: none;
padding: 30px;
font-size: 25px;
font-family: Courier;
outline: none;
}
button {
position: absolute;
bottom: 15px;
right: 15px;
font-size: 20px;
cursor: pointer;
}
.hidden {
display: none;
}
.tabs {
}
.tabs p {
font-family: Georgia;
font-weight: bold;
display: inline-block;
font-size: 25px;
cursor: pointer;
padding: 6px 20px;
color: #888;
margin: 1px;
}
.tabs .active {
color: #fff;
background-color: rgba(255,255,255,0.1);
}
#stage {
position: absolute;
top: 10px;
right: 10px;
width: 30%;
font-size: 17px;
color: #eee;
}
#stage p {
margin: 4px 0px;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.item {
font-size: 20px;
display: inline-block;
margin: 2px 5px;
}
</style>
</head>
<body spellcheck="false">
<div class="tabs"></div>
<pre>
// Create an instance
var api = new APIInterface();
</pre>
<pre>
// Create an instance
var api = new APIInterface();
// Set the domain
api.domain('search.twitter.com');
</pre>
<pre>
// Create an instance
var api = new APIInterface();
// Set the domain
api.domain('search.twitter.com');
// Connect the route
api.connect('search');
</pre>
<pre>
// Create an instance
var api = new APIInterface();
// Set the domain
api.domain('search.twitter.com');
// Connect the route
api.connect('search');
// Run the route
api.getSearch();
</pre>
<pre>
var api = new APIInterface();
api.domain('search.twitter.com');
api.connect('search');
// Only support JSONP
api.cors(false);
api.getSearch({ q: 'cookpad' }, {
// All ajax options passed on to jQuery
success: function(data) {
showResults(data);
}
});
</pre>
<pre>
var api = new APIInterface();
api.domain('search.twitter.com');
api.connect('search');
api.cors(false);
// Returns jQuery deferred objects
api.getSearch({ q: 'cookpad' }).then(showResults);
</pre>
<pre>
var api = new APIInterface();
api.domain('api.iknow.jp');
api.cors(false);
// Allow optional contexts
api.connect('goals/:goal_id/items.json');
api.getItems({ goal_id: 910 }).then(showItems);
</pre>
<pre>
var api = new APIInterface();
api.domain('api.twitter.com');
// Alternate HTTP methods
api.connect('POST :username/favorites');
api.createFavorites({ username: 'budday' });
</pre>
<pre>
var api = new APIInterface();
api.domain('api.twitter.com');
// RESTful resources
api.resource(':username/favorite');
api.getFavorite({ username: 'budday' });
api.createFavorite({ username: 'budday' });
api.updateFavorite({ username: 'budday' });
api.destroyFavorite({ username: 'budday' });
</pre>
<pre>
var api = new APIInterface();
api.domain('api.twitter.com');
// "favorites" indicates a collection
api.resource(':username/favorites');
// index
api.getFavorites({ username: 'budday' });
// show
api.getFavorite({ username: 'budday', id: 3 });
api.createFavorite({ username: 'budday' });
api.updateFavorite({ username: 'budday', id: 3 });
api.destroyFavorite({ username: 'budday', id: 3 });
</pre>
<pre>
var api = new APIInterface();
api.domain('andrewplummer.com');
api.format(false);
api.connect('recipes');
// Allow credentials
api.getRecipes({}).then(showResults);
</pre>
<pre>
api = api || new APIInterface();
api.domain('andrewplummer.com');
api.format(false);
api.connect('recipes');
// Internal caching
api.getRecipes({}, { cache: true }).then(showResults);
</pre>
<pre>
// All routes/options/params in the constructor
var api = new APIInterface({
domain : 'api.twitter.com',
protocol : 'https',
cors : false,
routes : [
'GET /status',
'POST /statuses/update',
'POST direct_messages/destroy/:id AS destroyMessage'
]
});
api.destroyMessage({ id: 7 });
</pre>
<pre>
// Future??
var api = new APIInterface();
api.getManifest(function() {
api.getUserTweets();
// ...
});
</pre>
<div id="stage"></div>
<button>Punch it, Chewie</button>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min.js"></script>
<script src="../lib/main.js"></script>
<!--<script src="https://raw.github.com/andrewplummer/APIInterface/master/lib/main.js"></script>-->
<script src="sh_main.min.js" type="text/javascript"></script>
<script src="sh_javascript.min.js" type="text/javascript"></script>
<script type="text/javascript">
showItems = function(data) {
$('#stage').html(data.items.map(function(i) {
return '<span class="item">' + i.cue.content.text + '</span>';
}).join(''));
}
showResults = function(data) {
$('#stage').html(data.results.map(function(t) {
return '<p>' + t.text + '</p>';
}).join(''));
}
currentTab = 1;
$(document).keydown(function(e) {
if(e.which == 37) {
setTab(currentTab - 1);
} else if (e.which == 39) {
setTab(currentTab + 1);
}
});
$('pre').each(function(i) {
var el = $(this);
el.addClass('sh_javascript').attr('contentEditable', true);
el.toggleClass('hidden', i > 0);
$('<p>' + (i + 1) + '</p>').appendTo($('.tabs')).click(function() {
currentTab = parseInt(i) + 1;
window.location.hash = '#' + (i + 1);
$('pre').hide();
$('.tabs p').removeClass('active');
$(this).addClass('active');
el.show();
}).toggleClass('active', i == 0);
});
$('button').click(function() {
$('#stage').empty();
eval($('pre:visible').text());
});
var match;
if(match = window.location.hash.match(/#(\d+)/)) {
setTab(parseInt(match[1]));
}
function setTab(i) {
currentTab = Math.max(1, Math.min($('.tabs p').length, i));
$('.tabs p').eq(currentTab - 1).click();
}
sh_highlightDocument();
</script>
</body>
</html>