| 
									
										
										
										
											2016-02-02 02:27:52 -08:00
										 |  |  | // Create the query string by hand
 | 
					
						
							|  |  |  | // #docregion
 | 
					
						
							| 
									
										
										
										
											2016-05-03 14:06:32 +02:00
										 |  |  | import { Injectable } from '@angular/core'; | 
					
						
							|  |  |  | import { Jsonp }      from '@angular/http'; | 
					
						
							| 
									
										
										
										
											2016-02-02 02:27:52 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  | @Injectable() | 
					
						
							|  |  |  | export class WikipediaService { | 
					
						
							|  |  |  |   constructor(private jsonp: Jsonp) { } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   // TODO: Add error handling
 | 
					
						
							|  |  |  |   search(term: string) { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     let wikiUrl = 'http://en.wikipedia.org/w/api.php'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // #docregion query-string
 | 
					
						
							|  |  |  |     let queryString = | 
					
						
							| 
									
										
										
										
											2016-06-08 01:06:25 +02:00
										 |  |  |       `?search=${term}&action=opensearch&format=json&callback=JSONP_CALLBACK`; | 
					
						
							| 
									
										
										
										
											2016-02-02 02:27:52 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     return this.jsonp | 
					
						
							|  |  |  |                .get(wikiUrl + queryString) | 
					
						
							| 
									
										
										
										
											2016-08-27 01:12:38 +08:00
										 |  |  |                .map(response => <string[]> response.json()[1]); | 
					
						
							| 
									
										
										
										
											2016-02-02 02:27:52 -08:00
										 |  |  |     // #enddocregion query-string
 | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | } |