1
+ <?php
2
+
3
+ /**
4
+ * Simple PHP GitHub API
5
+ *
6
+ * @tutorial http://github.com/ornicar/php-github-api/blob/master/README.markdown
7
+ * @version 2.6
8
+ * @author Brent Shaffer <bshafs at gmail dot com>
9
+ * @license MIT License
10
+ *
11
+ * Website: http://github.com/ornicar/php-github-api
12
+ * Tickets: http://github.com/ornicar/php-github-api/issues
13
+ */
14
+ class EchoNestApi
15
+ {
16
+ /**
17
+ * The request instance used to communicate with GitHub
18
+ * @var EchoNestApiRequest
19
+ */
20
+ protected $ request = null ;
21
+
22
+ /**
23
+ * The list of loaded API instances
24
+ * @var array
25
+ */
26
+ protected $ apis = array ();
27
+
28
+ /**
29
+ * Use debug mode (prints debug messages)
30
+ * @var bool
31
+ */
32
+ protected $ debug ;
33
+
34
+ /**
35
+ * Instanciate a new GitHub API
36
+ *
37
+ * @param bool $debug print debug messages
38
+ */
39
+ public function __construct ($ debug = false )
40
+ {
41
+ $ this ->debug = $ debug ;
42
+ }
43
+
44
+ /**
45
+ * Authenticate a user for all next requests
46
+ *
47
+ * @param string $apiKey EchoNest API key
48
+ * @return EchoNestApi fluent interface
49
+ */
50
+ public function authenticate ($ apiKey )
51
+ {
52
+ $ this ->getRequest ()
53
+ ->setOption ('api_key ' , $ apiKey );
54
+
55
+ return $ this ;
56
+ }
57
+
58
+ /**
59
+ * Deauthenticate a user for all next requests
60
+ *
61
+ * @return EchoNestApi fluent interface
62
+ */
63
+ public function deAuthenticate ()
64
+ {
65
+ return $ this ->authenticate (null );
66
+ }
67
+
68
+ /**
69
+ * Call any route, GET method
70
+ * Ex: $api->get('repos/show/my-username/my-repo')
71
+ *
72
+ * @param string $route the GitHub route
73
+ * @param array $parameters GET parameters
74
+ * @param array $requestOptions reconfigure the request
75
+ * @return array data returned
76
+ */
77
+ public function get ($ route , array $ parameters = array (), $ requestOptions = array ())
78
+ {
79
+ return $ this ->getRequest ()->get ($ route , $ parameters , $ requestOptions );
80
+ }
81
+
82
+ /**
83
+ * Call any route, POST method
84
+ * Ex: $api->post('repos/show/my-username', array('email' => '[email protected] '))
85
+ *
86
+ * @param string $route the GitHub route
87
+ * @param array $parameters POST parameters
88
+ * @param array $requestOptions reconfigure the request
89
+ * @return array data returned
90
+ */
91
+ public function post ($ route , array $ parameters = array (), $ requestOptions = array ())
92
+ {
93
+ return $ this ->getRequest ()->post ($ route , $ parameters , $ requestOptions );
94
+ }
95
+
96
+ /**
97
+ * Get the request
98
+ *
99
+ * @return EchoNestApiRequest a request instance
100
+ */
101
+ public function getRequest ()
102
+ {
103
+ if (!isset ($ this ->request ))
104
+ {
105
+ require_once (dirname (__FILE__ ).'/request/EchoNestApiRequest.php ' );
106
+ $ this ->request = new EchoNestApiRequest (array (
107
+ 'debug ' => $ this ->debug
108
+ ));
109
+ }
110
+
111
+ return $ this ->request ;
112
+ }
113
+
114
+ /**
115
+ * Inject another request
116
+ *
117
+ * @param EchoNestApiRequest a request instance
118
+ * @return EchoNestApi fluent interface
119
+ */
120
+ public function setRequest (EchoNestApiRequest $ request )
121
+ {
122
+ $ this ->request = $ request ;
123
+
124
+ return $ this ;
125
+ }
126
+
127
+ /**
128
+ * Get the artist API
129
+ *
130
+ * @return EchoNestApiArtist the artist API
131
+ */
132
+ public function getArtistApi ()
133
+ {
134
+ if (!isset ($ this ->apis ['artist ' ]))
135
+ {
136
+ require_once (dirname (__FILE__ ).'/api/EchoNestApiArtist.php ' );
137
+ $ this ->apis ['artist ' ] = new EchoNestApiArtist ($ this );
138
+ }
139
+
140
+ return $ this ->apis ['artist ' ];
141
+ }
142
+
143
+ /**
144
+ * Get the song API
145
+ *
146
+ * @return EchoNestApiSong the song API
147
+ */
148
+ public function getSongApi ()
149
+ {
150
+ if (!isset ($ this ->apis ['song ' ]))
151
+ {
152
+ require_once (dirname (__FILE__ ).'/api/EchoNestApiSong.php ' );
153
+ $ this ->apis ['song ' ] = new EchoNestApiSong ($ this );
154
+ }
155
+
156
+ return $ this ->apis ['song ' ];
157
+ }
158
+
159
+ /**
160
+ * Get the track API
161
+ *
162
+ * @return EchoNestApiTrack the track API
163
+ */
164
+ public function getCommitApi ()
165
+ {
166
+ if (!isset ($ this ->apis ['track ' ]))
167
+ {
168
+ require_once (dirname (__FILE__ ).'/api/EchoNestApiTrack.php ' );
169
+ $ this ->apis ['track ' ] = new EchoNestApiTrack ($ this );
170
+ }
171
+
172
+ return $ this ->apis ['track ' ];
173
+ }
174
+
175
+ /**
176
+ * Get the playlist API
177
+ *
178
+ * @return EchoNestApiPlaylist the playlist API
179
+ */
180
+ public function getPlaylistApi ()
181
+ {
182
+ if (!isset ($ this ->apis ['playlist ' ]))
183
+ {
184
+ require_once (dirname (__FILE__ ).'/api/EchoNestApiPlaylist.php ' );
185
+ $ this ->apis ['playlist ' ] = new EchoNestApiPlaylist ($ this );
186
+ }
187
+
188
+ return $ this ->apis ['playlist ' ];
189
+ }
190
+
191
+ /**
192
+ * Get the catalog API
193
+ *
194
+ * @return EchoNestApiCatalog the catalog API
195
+ */
196
+ public function getCatalogApi ()
197
+ {
198
+ if (!isset ($ this ->apis ['catalog ' ]))
199
+ {
200
+ require_once (dirname (__FILE__ ).'/api/EchoNestApiCatalog.php ' );
201
+ $ this ->apis ['catalog ' ] = new EchoNestApiCatalog ($ this );
202
+ }
203
+
204
+ return $ this ->apis ['catalog ' ];
205
+ }
206
+
207
+ /**
208
+ * Inject another API instance
209
+ *
210
+ * @param string $name the API name
211
+ * @param EchoNestApiAbstract $api the API instance
212
+ * @return EchoNestApi fluent interface
213
+ */
214
+ public function setApi ($ name , EchoNestApiAbstract $ instance )
215
+ {
216
+ $ this ->apis [$ name ] = $ instance ;
217
+
218
+ return $ this ;
219
+ }
220
+
221
+ /**
222
+ * Get any API
223
+ *
224
+ * @param string $name the API name
225
+ * @return EchoNestApiAbstract the API instance
226
+ */
227
+ public function getApi ($ name )
228
+ {
229
+ return $ this ->apis [$ name ];
230
+ }
231
+ }
0 commit comments