-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathyoumagine-php-api-example.php
More file actions
217 lines (175 loc) · 8.57 KB
/
youmagine-php-api-example.php
File metadata and controls
217 lines (175 loc) · 8.57 KB
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
<?php
/**
* YOUMAGINE API PHP EXAMPLE
*
* This example shows how to interact with the YouMagine API using PHP
*
*/
/*--- CONFIGURATION - tweek these settings to have a basic working example ---*/
/**
* The name of the integrated application
*/
define('INTEGRATION', 'my-test-app');
/**
* The application's secret
*/
define('SECRET', 'ybSrSWnsfnTM2SWo');
/**
* Whether or not to use HTTPS.
*
* NOTE: it is highly recommended to use HTTPS because of the
* sensitivity of the data that is sent and received across the API
*/
define('USE_HTTPS', false);
/*--- /CONFIGURATION ---------------------------------------------------------*/
/*--- BOOTSTRAP --------------------------------------------------------------*/
// Include the YouMagine API class
require 'youmagine.php';
// Create an instance of YouMagine, representing the API
$youMagine = new YouMagine(INTEGRATION, array(
'https' => USE_HTTPS,
'secret' => SECRET
));
/*** Some magic to include the right example file
/**/
/**/ $apiActions = array(
/**/ 'authorization' => 'Authorization' ,
/**/ 'retrieve_designs' => 'Retrieve designs',
/**/ 'retrieve_designs_with_context' => 'Retrieve designs with context',
/**/ 'retrieve_design_categories' => 'Retrieve design categories',
/**/ 'create_design' => 'Create design',
/**/ 'publish_design' => 'Publish design'
/**/ );
/**/
/**/ $currentPage = (
/**/ $youMagine->isAuthorized() && isset($_GET['page'])
/**/ ? $_GET['page']
/**/ : 'authorization'
/**/ );
/**/
/**/ $includePath = 'examples/'.preg_replace('/[^A-Z0-9_]/i', '', $currentPage).'.php';
/**/
/**/ $includeFile = (
/**/ file_exists($includePath)
/**/ ? $includePath
/**/ : null
/**/ );
/*--- /BOOTSTRAP -------------------------------------------------------------*/
?>
<html>
<head>
<title><?php echo $apiActions[$currentPage] ?> - YouMagine API PHP example</title>
<link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css" rel="stylesheet">
<style>
body { margin: 20px; }
.nav { margin: 20px 0; }
p + p .btn { margin-top: 20px; }
.nested-form { position: relative; }
#main { margin-top: 20px; }
.nested-form + .nested-form {
border-top: 1px black dashed;
padding-top: 14px;
}
.btn.remove-row {
left: 5px;
padding: 5px 3px;
position: absolute;
top: 5px;
}
.nested-form:only-child .btn.remove-row {
display: none;
}
.navbar-brand img {
float: left;
margin-right: 10px;
}
</style>
</head>
<body>
<nav class="navbar navbar-default">
<div class="container-fluid">
<div class="navbar-header">
<a class="navbar-brand" href="#">
<img alt="YouMagine logo" width="20" height="20" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAYAAACNiR0NAAAABmJLR0QA/wD/AP+gvaeTAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAB3RJTUUH3wMGCzs1KyPlrAAAAuNJREFUOMutlV1ozWEcxz+/5382w6zQxs44O9awWYtJzM6ZKC4IWaRkoZOScoEL5bgQteNKuZRySsqNRqKUJOwgryuv8742B6tpOp1jZ+3/fx4X/ue/Yxfk5Xv19Lx8n+/ze77P9xFchCNREvEY4UhUgGJgMbAVaAKmudM+ALeBU8AdIJ2Ix0xuLYCMIisCVgJtQC2/xgvgAHA5EY9lcxySR1YCHAJ282c4BhxMxGOpcCTqKSwCjvwFWT7p/kQ8lhW3Zi1AO/+G9cB55V5AG4ASQYl4M0RAKeW1R2NUXxtQrIAQUKONoXn+HNYtW4TlktRXV7JxRROFBQWE5tXiaO2tdrQmPK8Wx/H6aoCQcq2B4zhMKilmz+Y1tCxrpHRiCYd3bqKxfhaWJRzZ1cqcqgDDto1tO9RVTefwzk2MLSpEG5Mj3aJcn+Hz+Th79TbX7j9he8tyNixvQkQ4duYS5ZMnAbBt9VIsZWFrzd7WtWhtmFFRhh5RHlJARc6QllLETrZj2zYrFs3lxLkrdL1PUhP0AzB3dpAFddWsCs2neno5IhAsn4KjPYUV6uciC5lslosdDxCBp296cLTDzMoKAAaHhlmzZAFbVi/lU/8AlrII+kvzFaKA5OjbU0q8DWxHUxP0k8oMcvT0BRbWVRP0lxGLt5MZGiLoL8OM1DDpA24BgXzCAp+PsWPGICIUFRYyq9LPu94+7j59xaf+AdLfsjx+3c3Hvi8EppZSMn4cw7aNiNyyAg3NGaA1/9ip9CDP3vXQ1Z1EWQIGbnY+52V3koFUmusPn/Hla5rUt0F6+/p52/uZYdtBRPZJOBKdANxzfTSSGCLeUSxLYbRBG4MSwWAw5sdDEJGcP7uAhQpIu6nhwUB+XXAc7XlNmx9kuXae2aNA2urp7CDQ0PzefYKN/xAOxxPxmK3c+MoCB90B/jK+suFIFKunsyMXsEOBhuYbwCOgHij9DdFzYIerLOMF7P/+Ar4DKoE4K1pVcFkAAAAASUVORK5CYII="/>
YouMagine PHP API Example
</a>
</div>
</div>
</nav>
<?php foreach (array('POST', 'FILES') as $globalName):
$variableName = '$_'.$globalName;
?>
<?php if (isset($$variableName)): ?>
<div class="alert alert-info">
<div class="row">
<div class="col-sm-6 col-md-6 col-lg-6">
There is <?php echo $globalName ?> data available
</div>
<div class="col-sm-6 col-md-6 col-lg-6">
<button class="btn btn-primary" type="button" data-toggle="collapse" data-target="#show<?php echo $globalName ?>">Show <?php echo $globalName ?> data</button>
</div>
</div>
<div class="collapse" id="show<?php echo $globalName ?>">
<br/>
<pre><?php print_r($$variableName) ?></pre>
</div>
</div>
<?php endif ?>
<?php endforeach ?>
<?php if ($youMagine->isAuthorized()): ?>
<?php if (!USE_HTTPS): ?>
<div class="alert alert-warning">
NOTE: it is highly recommended to use HTTPS because of the sensitivity
of the data that is sent and received across the API
</div>
<?php endif ?>
<div class="row">
<div class="col-sm-3 col-md-2 col-lg-2">
<ul class="nav nav-pills nav-stacked">
<?php foreach ($apiActions as $page => $description): ?>
<li
<?php if ($currentPage == $page): ?>
class="active"
<?php endif ?>
>
<a href="?page=<?php echo $page ?>"><?php echo $description ?></a>
</li>
<?php endforeach ?>
</ul>
</div>
<div class="col-sm-9 col-md-10 col-lg-10" id="main">
<?php if ($includeFile) { include $includeFile; } ?>
</div>
</div>
<?php else: ?>
<?php if ($includeFile) { include $includeFile; } ?>
<?php endif ?>
<?php
if (!isset($hideErrors)) {
$lastResponse = $youMagine->getLastResponse();
if ($lastResponse && ($lastResponse->status < 200 || $lastResponse->status >= 300)) {
echo '<div class="alert alert-danger">The request was not succesful. Below are the technical details</div>';
echo '<pre>';
$youMagine->debug();
echo '</pre>';
}
}
?>
<script src="//code.jquery.com/jquery-1.11.2.min.js"></script>
<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.2/js/bootstrap.min.js"></script>
<script>
(function ($, window) {
window.addFileInput = function (triggerButton) {
var container = $(triggerButton).closest('.form-group').children('div'),
inputGroups = container.find('.form-horizontal'),
newInputGroup = inputGroups.first().clone();
newInputGroup.find(':input').val('');
newInputGroup.appendTo(container);
};
window.removeFileInput = function (triggerButton) {
$(triggerButton).closest('.nested-form').remove();
};
}(jQuery, window));
</script>
</body>
</html>