Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class Mal_API {
- private $username;
- private $password;
- private $user_id;
- private $curl;
- private $queryurl;
- function __construct()
- {
- $a = func_get_args();
- $i = func_num_args();
- if($i!=2)
- {
- throw "Please enter a username and password";
- }
- $this->username=$a[0];
- $this->password=$a[1];
- $this->curl = curl_init();
- curl_setopt($this->curl, CURLOPT_USERPWD, $this->username.":".$this->password);
- curl_setopt($this->curl,CURLOPT_RETURNTRANSFER,true);
- curl_setopt($this->curl, CURLOPT_SSL_VERIFYPEER, 0); // setting this to false so SSL stuff doesn't bug you
- curl_setopt($this->curl, CURLOPT_VERBOSE, true);
- curl_setopt($this->curl,CURLOPT_CONNECTTIMEOUT ,1000);
- curl_setopt($this->curl,CURLOPT_TIMEOUT ,1000);
- curl_setopt($this->curl,CURLOPT_MAXREDIRS,10);
- curl_setopt($this->curl, CURLOPT_ENCODING ,"");
- $this->queryurl="https://myanimelist.net/api/account/verify_credentials.xml";
- $res=$this->send_query();
- if($res==-1)
- {
- throw "error Wrong Credidentials";
- }
- else {
- $user_id= $res->id;
- }
- }
- public function search_for_anime($title)
- {
- echo $title;
- $title=curl_escape($this->curl,$title);
- $this->queryurl='https://myanimelist.net/api/anime/search.xml?q='.$title; //todo maybe lowercase everything don't know how this would work with japanese titles
- echo $this->queryurl;
- return $this->send_query();
- }
- private function send_query() {
- curl_setopt($this->curl,CURLOPT_URL,$this->queryurl);
- $result = curl_exec($this->curl);
- $last = curl_getinfo($this->curl, CURLINFO_EFFECTIVE_URL);
- $status = curl_getinfo($this->curl,CURLINFO_HTTP_CODE);
- $xml = new SimpleXMLElement($result);
- if($status==200) //todo add message check
- {
- // echo $result;
- return $xml;
- }
- else {
- echo "Status:".$status;
- return -1;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement