PageRenderTime 84ms CodeModel.GetById 45ms app.highlight 2ms RepoModel.GetById 25ms app.codeStats 0ms

/Search/DuckDuckGo.php

https://github.com/bobdia/COLibrary
PHP | 35 lines | 24 code | 10 blank | 1 comment | 2 complexity | 484d0776ba1d940711d2dd6f309c63e5 MD5 | raw file
 1<?php
 2
 3// http://duckduckgo.com/api.html
 4
 5class DuckDuckGo extends HttpReq {
 6
 7	public $data;
 8	
 9	public $query;
10	public $disambig; // disambiguation
11
12	public $url = 'http://api.duckduckgo.com/';
13
14	public function __construct($query, $disambiguation=null) {
15		$this->query = $query;
16		if($disambiguation) {
17			$this->disambig = true;
18		}
19	}
20	
21	protected function before() {
22		$this->args['q'] = $this->query;
23		if($this->disambig) {
24			$this->args['d'] = '1';
25		}
26		$this->args['o'] = 'json';
27	}
28	
29	public function success() {
30		$this->data = json_decode($this->body, true);
31	}
32	
33}
34
35?>