This repository has been archived by the owner on Nov 13, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Note.php
executable file
·125 lines (117 loc) · 3.17 KB
/
Note.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
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
122
123
124
125
<?php
/**
* @version $Id$
* @author Brian Smith <[email protected]>
* @package ABS
*/
/*
* Include the ABS Api, core classes.
*/
require_once 'Api.php';
/*
* Include the ABS Base object class, core classes.
*/
require_once 'Base.php';
class ABS_Note extends ABS_Base {
/**
* The name of the XML element in the response that defines the object.
*
* @var string
*/
const XML_RESPONSE_ELEMENT = 'note';
/**
* The id of a specific note
*
* @var integer
*/
protected $_note_id;
function __construct(ABS_Api $api) {
parent::__construct($api, self::XML_RESPONSE_ELEMENT);
}
/*
* Method to return the appropriate URL ending based on the method being executed
*
* @param string $method
* @return string
* @throws ABS_Exception
*/
protected function getUrl($method) {
switch($method) {
case 'list':
return 'user/notes.xml';
break;
case 'show':
return 'notes/' . $this->_note_id . '.xml';
break;
case 'create':
return 'user/notes.xml';
break;
case 'update':
return 'notes/' . $this->_note_id . '.xml';
break;
case 'delete':
return 'notes/' . $this->_note_id . '.xml';
break;
default:
throw new ABS_Exception('Invalid method ' . $method);
}
}
/*
* Method to list all notes the api user has created
*
* @param string $method
* @return xml SimpleXML object
*/
public function listNotes() {
return $this->requestXml('list');
}
/*
* Show specific note
*
* @param integer $note_id
* @return xml SimpleXML object
*/
public function show($note_id) {
$this->_note_id = $note_id;
return $this->requestXml('show');
}
/*
* Create a new note
*
* @param string $xml
* @return xml SimpleXML object
*/
public function addNote($xml) {
$test = simplexml_load_string($xml);
if (false === $test) {
throw new ABS_XmlParseException('Could not parse XML.', $xml);
}
$this->setRestMethod('POST');
$this->setRequestData($xml);
return $this->requestXml('create');
}
/*
* Update a note
*
* @param integer $note_id
* @param string $xml
* @return xml SimpleXML object
*/
public function updateNote($note_id, $xml) {
$this->_note_id = $note_id;
$this->setRestMethod('PUT');
$this->setRequestData($xml);
return $this->requestXml('update');
}
/*
* Create a new note
*
* @param string $method
* @return xml SimpleXML object
*/
public function deleteNote($note_id) {
$this->_note_id = $note_id;
$this->setRestMethod('DELETE');
return $this->requestXml('delete', false);
}
}