-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApi_Version2.php
More file actions
121 lines (99 loc) · 2.64 KB
/
Api_Version2.php
File metadata and controls
121 lines (99 loc) · 2.64 KB
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
<?php
/**
* Api version 2
*
* @author AckimWilliams
* @see ./problem_description
*/
class Api_Version2 extends AbstractWebservice
{
protected $_api_version = "v2";
protected $_attemptToCorrectStatuses = false;
/**
* (non-PHPdoc)
* @see \Webservice\AbstractWebservice::authenticate()
*/
public function authenticate( $username, $password )
{
$this->_attemptToCorrectStatuses = false; //disable correcting statuses
$requestUri = $this->_webserviceRoot . "/" . $this->_api_version . "/auth?user=" .
$username . "&pass=" . $password;
$response = $this->execute( $requestUri, AbstractWebservice::API_METHOD_GET );
$content = $response->getContent();
$this->_attemptToCorrectStatuses = true; //restore correcting statuses
if ( $content->status == self::RESPONSE_OK )
$this->_requestToken = $content->token;
return $response;
}
/**
* Has this object authenticated with remote server?
*
* @return boolean
*/
public function isAuthenticated()
{
if ( $this->_requestToken == "" )
return false;
else
return true;
}
/**
* Delete records
*
* @param string $key
* @throws \Exception
* @return Response
*/
public function delete( $key )
{
$requestUri = $this->_webserviceRoot . "/" . $this->_api_version .
"/key?token=" . $this->_requestToken .
"&key=" . $key;
return $this->execute( $requestUri, AbstractWebservice::API_METHOD_DELETE );
}
/**
* List records
*
* @throws \Exception
* @return Response
*/
public function getList()
{
$requestUri = $this->_webserviceRoot . "/" . $this->_api_version .
"/list?token=" . $this->_requestToken;
return $this->execute( $requestUri, AbstractWebservice::API_METHOD_GET );
}
/**
* Get record
*
* @param string $key
* @throws \Exception
* @return Response
*/
public function get( $key )
{
$requestUri = $this->_webserviceRoot . "/" . $this->_api_version .
"/key?token=" . $this->_requestToken .
"&key=" . $key;
return $this->execute( $requestUri, AbstractWebservice::API_METHOD_GET );
}
/**
* Update record
*
* This method only allows you to set a single value of
* a single key
*
* @param string $key
* @param string $value
* @throws \Exception
* @return Response
*/
public function put( $key, $value )
{
$requestUri = $this->_webserviceRoot . "/" . $this->_api_version .
"/key?token=" . $this->_requestToken .
"&key=" . $key .
"&value=" . $value;
return $this->execute( $requestUri, AbstractWebservice::API_METHOD_PUT );
}
}