PageRenderTime 909ms CodeModel.GetById 25ms RepoModel.GetById 1ms 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. // http://duckduckgo.com/api.html
  3. class DuckDuckGo extends HttpReq {
  4. public $data;
  5. public $query;
  6. public $disambig; // disambiguation
  7. public $url = 'http://api.duckduckgo.com/';
  8. public function __construct($query, $disambiguation=null) {
  9. $this->query = $query;
  10. if($disambiguation) {
  11. $this->disambig = true;
  12. }
  13. }
  14. protected function before() {
  15. $this->args['q'] = $this->query;
  16. if($this->disambig) {
  17. $this->args['d'] = '1';
  18. }
  19. $this->args['o'] = 'json';
  20. }
  21. public function success() {
  22. $this->data = json_decode($this->body, true);
  23. }
  24. }
  25. ?>