Exemplo n.º 1
0
 public static function parse($response)
 {
     if (!is_array($response)) {
         $response = Text::parse_json($response);
     }
     $obj = new self();
     return $obj->cp($response);
 }
Exemplo n.º 2
0
 public static function parse_list($response)
 {
     $result = array();
     $res = Text::parse_json($response);
     foreach ($res as $re) {
         $obj = new self();
         $result[] = $obj->cp($re);
     }
     return $result;
 }
Exemplo n.º 3
0
 public static function parse_update($response)
 {
     $result = array();
     $re = Text::parse_json($response);
     if (isset($re["error"])) {
         throw new Exception($res["error"]);
     }
     $obj = new self();
     return $obj->cp($re);
 }
Exemplo n.º 4
0
 public static function parse_list($response)
 {
     $result = array();
     $res = Text::parse_json($response);
     if (!isset($res)) {
         throw new Exception($response);
     }
     if (isset($res["channels"])) {
         foreach ($res["channels"] as $re) {
             $obj = new self();
             $result[] = $obj->cp($re);
         }
     }
     return $result;
 }
Exemplo n.º 5
0
 public static function parse_list($response)
 {
     $result = array();
     $res = Text::parse_json($response);
     if (!isset($res)) {
         throw new Exception($response);
     }
     foreach ($res as $re) {
         $obj = new self();
         $obj->user(WassrUser::parse($re["user"]));
         unset($re["user"]);
         $result[] = $obj->cp($re);
     }
     return $result;
 }
Exemplo n.º 6
0
 public function download($save_dir, $save_filename, $ext = true)
 {
     $b = new Http();
     $b->do_get($this->url() . "&fmt=22");
     if (preg_match("/var[\\s]+swfArgs[\\s]*=[\\s]*(\\{.+?\\})/m", $b->body(), $match)) {
         $json = Text::parse_json($match[1]);
         $base_url = "http://www.youtube.com/get_video?video_id=" . $json["video_id"] . "&t=" . $json["t"];
         $url = $base_url . "&fmt=22";
         if ($b->do_head($url)->status() !== 200) {
             $url = $base_url . "&fmt=18";
         }
         $b->do_download($url, File::absolute($save_dir, $save_filename) . ($ext ? $this->ext : ""));
         return;
     }
     throw new Exception("undef video");
 }
Exemplo n.º 7
0
 public static function parse_list($response)
 {
     $result = array();
     $res = Text::parse_json($response);
     if (!isset($res["responseData"]["results"])) {
         throw new Exception("Invalid data");
     }
     foreach ($res["responseData"]["results"] as $re) {
         $obj = new self();
         $obj->cache_url($re["cacheUrl"]);
         $obj->url($re["unescapedUrl"]);
         $obj->title($re["titleNoFormatting"]);
         $obj->content($re["content"]);
         $result[] = $obj;
     }
     return $result;
 }
Exemplo n.º 8
0
 public static function parse_list($response, $paginator)
 {
     $result = array();
     $res = Text::parse_json($response);
     if (isset($res["error"])) {
         throw new Exception($res["error"]);
     }
     if (!empty($res["pager"])) {
         $paginator = new Paginator($res["pager"]["clips_in_page"], $res["pager"]["current_page"], $res["pager"]["total_entries"]);
     }
     if (!empty($res["entries"])) {
         foreach ($res["entries"] as $re) {
             $obj = new self();
             $obj->id($re["id"]);
             $obj->title($re["title"]);
             $obj->url($re["permalink"]);
             $obj->author(new FlipClipAuthor($re["author"]["id"], $re["author"]["name"], $re["author"]["uri"]));
             $obj->summary($re["summary"]);
             $obj->updated($re["updated"]);
             if (isset($re["category"])) {
                 $obj->category(new FlipClipCategory($re["category"]["term"], $re["category"]["scheme"], $re["category"]["label"]));
             }
             if (isset($re["subcategory"])) {
                 $obj->category(new FlipClipCategory($re["subcategory"]["term"], $re["subcategory"]["scheme"], $re["subcategory"]["label"]));
             }
             if (isset($re["tags"])) {
                 foreach ($re["tags"] as $tag) {
                     $obj->tags(new FlipClipTag($tag["term"], $tag["scheme"], $tag["label"]));
                 }
             }
             $obj->embed_script($re["embed_script"]);
             $obj->latitude($re["latitude"]);
             $obj->longitude($re["longitude"]);
             $obj->privacy($re["privacy"]);
             $obj->duration($re["duration"]);
             $obj->image($re["image"]);
             $obj->image_medium($re["imageMedium"]);
             $obj->image_small($re["imageSmall"]);
             $obj->thumbnail($re["thumbnail"]);
             $result[] = $obj;
         }
     }
     return $result;
 }
Exemplo n.º 9
0
 /**
  * 翻訳
  *  言語コード http://code.google.com/intl/ja-JP/apis/ajaxlanguage/documentation/reference.html#LangNameArray
  *
  * @param 翻訳対象文字列 $word
  * @param 翻訳後言語コード $to
  * @param 翻訳前言語コード $from
  * @return string
  */
 public function trans($word, $to, $from = null)
 {
     $this->vars("q", $word);
     $this->vars("v", "1.0");
     $this->vars("langpair", $from . "|" . $to);
     $this->do_get("language/translate");
     $result = Text::parse_json($this->body());
     if (isset($result["responseStatus"])) {
         if ($result["responseStatus"] !== 200) {
             throw new Exception($result["responseDetails"]);
         }
         return $result["responseData"]["translatedText"];
     }
     throw new Exception("invalid response");
     /***
     			$api = new GoogleAPI();
     			try{
     				$result = $api->trans("frog","ja");
     				eq(true,true);
     			}catch(Exception $e){
     				eq(false,$e->getMessage());
     			}
     		 */
 }
Exemplo n.º 10
0
 private function post($url)
 {
     $this->do_post($url);
     $res = Text::parse_json($this->body());
     if (isset($res["error"])) {
         throw new Exception($res["error"]);
     }
 }