-
Notifications
You must be signed in to change notification settings - Fork 1
/
API.php
64 lines (51 loc) · 1.39 KB
/
API.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?php
namespace YandexFotkiAPI;
require_once 'Transport.php';
require_once 'AbstractAtom.php';
require_once 'AlbumCollection.php';
require_once 'Album.php';
require_once 'PhotoCollection.php';
require_once 'Photo.php';
class APIException extends \Exception {}
class API {
const GET = 1;
const POST = 2;
const PUT = 3;
const DELETE = 4;
const API_URL = 'http://api-fotki.yandex.ru/api';
private $transport;
private $user;
private $password;
public function request($method, $url, $params = null) {
$url = preg_replace('/\{user\}/', $this->user, $url);
if (strtolower(substr($url, 0, 7)) != 'http://') $url = $this::API_URL . $url;
return $this->transport->request($method, $url, $params);
}
public function __construct() {
$this->transport = new Transport();
}
public function setUser($user) {
$this->user = $user;
return $this;
}
public function setPassword($password) {
$this->password = $password;
return $this;
}
public function authorize() {
$this->transport->authorize($this->user, $this->password);
return $this;
}
public function getAlbumsCollection() {
return new AlbumCollection($this);
}
public function getAlbum($id = null) {
return new Album($this, $id);
}
public function getPhotoCollection($album_id) {
return new PhotoCollection($this, $album_id);
}
public function getPhoto($photo_id) {
return new Photo($this, $photo_id);
}
}