PluginProbe
Depicter — Popup & Slider Builder / 1.9.2
Depicter — Popup & Slider Builder v1.9.2
4.8.1 trunk 1.0.0 1.1.0 1.1.2 1.1.4 1.1.6 1.1.7 1.1.8 1.1.9 1.2.0 1.3.0 1.3.1 1.3.2 1.3.3 1.3.5 1.3.8 1.5.0 1.5.1 1.5.2 1.5.5 1.6.0 1.6.1 1.6.2 1.7.0 All 76 releases
← All changes | app/src/Services/AssetsAPIService.php +76 -44 1.3.81.9.2 View file →
@@ -1,8 +1,9 @@
1 1 <?php
2 2 namespace Depicter\Services;
3 3
4 4 use Averta\WordPress\Utility\JSON;
5 +use Depicter\GuzzleHttp\Exception\GuzzleException;
5 6
6 7 /**
7 8 * A bridge for fetching assets from averta assets API
8 9 *
@@ -16,11 +17,11 @@
16 17 * @param string $assetType
17 18 * @param array $options
18 19 *
19 20 * @return array|mixed
20 - * @throws \Depicter\GuzzleHttp\Exception\GuzzleException
21 + * @throws GuzzleException
21 22 */
22 - public static function searchAssets( $assetType = 'photos', $options = [] )
23 + public static function searchAssets( string $assetType = 'photos', array $options = [] )
23 24 {
24 25 $availableTypes = ['photos', 'videos', 'vectors'];
25 26 if ( !in_array( $assetType, $availableTypes ) ) {
26 27 return [];
@@ -25,10 +26,9 @@
25 26 if ( !in_array( $assetType, $availableTypes ) ) {
26 27 return [];
27 28 }
28 29
29 - $endpoint = \Depicter::remote()->endpoint(1) . 'v1/search/' . $assetType;
30 - $response = \Depicter::remote()->get("$endpoint?" . http_build_query($options));
30 + $response = \Depicter::remote()->get( 'v1/search/'. $assetType, [ "query" => $options ] );
31 31
32 32 return JSON::decode( $response->getBody(), true );
33 33 }
34 34
@@ -37,14 +37,13 @@
37 37 *
38 38 * @param string $id Media ID
39 39 * @param string $size Media size to return
40 40 *
41 - * @param array $args
41 + * @param array $args
42 42 *
43 43 * @return mixed
44 44 */
45 - public static function getHotlink( $id, $size = 'full', $args = [ 'forcePreview' => 'false' ] )
46 - {
45 + public static function getHotlink( $id, string $size = 'full', array $args = [ 'forcePreview' => 'false' ] ){
47 46 $endpointNumber = 1;
48 47
49 48 /**
50 49 * Regex to find possible endpoint number other than default one (1)
@@ -66,20 +65,35 @@
66 65 return $endpoint;
67 66 }
68 67
69 68 /**
69 + * Get Urls of an asset
70 + *
71 + * @param string $id Asset ID
72 + *
73 + * @return mixed
74 + * @throws GuzzleException
75 + */
76 + public static function getAssetUrls( $id ){
77 + $response = \Depicter::remote()->get( 'v1/asset/' . $id . '/urls' );
78 + return JSON::decode( $response->getBody(), true );
79 + }
80 +
81 + /**
70 82 * Search Elements
71 83 *
72 84 * @param array $options
73 85 *
74 86 * @return mixed
75 - * @throws \Depicter\GuzzleHttp\Exception\GuzzleException
87 + * @throws GuzzleException
76 88 */
77 - public static function searchElements( $options = [] ) {
89 + public static function searchElements( array $options = [] ) {
90 + $response = \Depicter::remote()->get(
91 + 'v1/curated/elements',
92 + [ 'query' => $options ],
93 + $options['directory'] ?? 1
94 + );
78 95
79 - $endpoint = \Depicter::remote()->endpoint(1) . 'v1/curated/elements';
80 - $response = \Depicter::remote()->get( "$endpoint?" . http_build_query($options) );
81 -
82 96 return JSON::decode( $response->getBody(), true );
83 97 }
84 98
85 99 /**
@@ -87,15 +101,17 @@
87 101 *
88 102 * @param array $options
89 103 *
90 104 * @return mixed
91 - * @throws \Depicter\GuzzleHttp\Exception\GuzzleException
105 + * @throws GuzzleException
92 106 */
93 - public static function searchDocumentTemplates( $options = [] ) {
107 + public static function searchDocumentTemplates( array $options = [] ) {
108 + $response = \Depicter::remote()->get(
109 + 'v1/curated/document/templates',
110 + [ 'query' => $options ],
111 + $options['directory'] ?? 2
112 + );
94 113
95 - $endpoint = \Depicter::remote()->endpoint(2) . 'v1/curated/document/templates';
96 - $response = \Depicter::remote()->get( "$endpoint?" . http_build_query($options) );
97 -
98 114 return JSON::decode( $response->getBody(), true );
99 115 }
100 116
101 117 /**
@@ -103,15 +119,17 @@
103 119 *
104 120 * @param array $options
105 121 *
106 122 * @return mixed
107 - * @throws \Depicter\GuzzleHttp\Exception\GuzzleException
123 + * @throws GuzzleException
108 124 */
109 - public static function getDocumentTemplateCategories( $options = [] ) {
125 + public static function getDocumentTemplateCategories( array $options = [] ) {
126 + $response = \Depicter::remote()->get(
127 + 'v1/curated/document/templates/categories',
128 + [ 'query' => $options ],
129 + $options['directory'] ?? 2
130 + );
110 131
111 - $endpoint = \Depicter::remote()->endpoint(2) . 'v1/curated/document/templates/categories';
112 - $response = \Depicter::remote()->get( "$endpoint?" . http_build_query($options) );
113 -
114 132 return JSON::decode( $response->getBody(), true );
115 133 }
116 134
117 135 /**
@@ -116,31 +134,41 @@
116 134
117 135 /**
118 136 * Get Template Data
119 137 *
120 - * @param $templateID
138 + * @param int $templateID Template ID
139 + * @param array $options
140 + * @param bool $associative
121 141 *
122 142 * @return mixed
123 - * @throws \Depicter\GuzzleHttp\Exception\GuzzleException
143 + * @throws GuzzleException
124 144 */
125 - public static function getDocumentTemplateData( $templateID ) {
126 - $endpoint = \Depicter::remote()->endpoint(2) . 'v1/curated/document/templates/' . $templateID;
127 - $response = \Depicter::remote()->get( $endpoint );
145 + public static function getDocumentTemplateData( $templateID, $options = [], $associative = false ) {
146 + $response = \Depicter::remote()->get(
147 + 'v1/curated/document/templates/' . $templateID,
148 + [ 'query' => $options ],
149 + $options['directory'] ?? 2
150 + );
128 151
129 - return JSON::decode( $response->getBody(), false );
152 + return JSON::decode( $response->getBody(), $associative );
130 153 }
131 154
132 155 /**
133 156 * Preview a Document Template
134 157 *
135 - * @param $templateID
158 + * @param int $templateID
159 + * @param int|null $directory
136 160 *
137 161 * @return mixed
138 - * @throws \Depicter\GuzzleHttp\Exception\GuzzleException
162 + * @throws GuzzleException
139 163 */
140 - public static function previewDocumentTemplate( $templateID ) {
141 - $endpoint = \Depicter::remote()->endpoint(2) . 'v1/curated/document/templates/preview/?id=' . $templateID;
142 - $response = \Depicter::remote()->get( $endpoint );
164 + public static function previewDocumentTemplate( $templateID, $directory = null ) {
165 + $directory = $directory ?? 2;
166 + $response = \Depicter::remote()->get(
167 + 'v1/curated/document/templates/preview',
168 + [ "query" => [ "id" => $templateID, "directory" => $directory ] ],
169 + $directory
170 + );
143 171
144 172 return $response->getBody();
145 173 }
146 174
@@ -149,30 +177,34 @@
149 177 *
150 178 * @param array $options
151 179 *
152 180 * @return mixed
153 - * @throws \Depicter\GuzzleHttp\Exception\GuzzleException
181 + * @throws GuzzleException
154 182 */
155 - public static function searchAnimations( $options = [] ) {
183 + public static function searchAnimations( array $options = [] ) {
184 + $response = \Depicter::remote()->get(
185 + 'v1/curated/animations',
186 + [ 'query' => $options ],
187 + $options['directory'] ?? 1
188 + );
156 189
157 - $endpoint = \Depicter::remote()->endpoint(1) . 'v1/curated/animations';
158 - $response = \Depicter::remote()->get( "$endpoint?" . http_build_query($options) );
159 -
160 190 return JSON::decode( $response->getBody(), true );
161 191 }
162 192
163 193 /**
164 - * retrieving animation phases
194 + * Retrieving animation phases
165 195 *
166 196 * @param array $options
167 197 *
168 198 * @return mixed
169 - * @throws \Depicter\GuzzleHttp\Exception\GuzzleException
199 + * @throws GuzzleException
170 200 */
171 - public static function getAnimationsCategories( $options = [] ) {
172 -
173 - $endpoint = \Depicter::remote()->endpoint(1) . 'v1/curated/animations/categories';
174 - $response = \Depicter::remote()->get( "$endpoint?" . http_build_query($options) );
201 + public static function getAnimationsCategories( array $options = [] ) {
202 + $response = \Depicter::remote()->get(
203 + 'v1/curated/animations/categories',
204 + [ 'query' => $options ],
205 + $options['directory'] ?? 1
206 + );
175 207
176 208 return JSON::decode( $response->getBody(), true );
177 209 }
178 210 }