Skip to content

Commit d59f8b2

Browse files
committed
Squashed commit of the following:
commit 0589ad8eec2c6367e4b9da7d796c122ee23e015b Author: Michelangelo <[email protected]> Date: Wed Apr 20 00:05:19 2011 +0200 Getting user details from the API commit bd28c04bde9efa151489bdb0e9f296f03bde341b Author: Michelangelo <[email protected]> Date: Tue Apr 19 23:32:55 2011 +0200 updating data commit 44dbaf8ef1a1eeea3ba6ef40fbcdc47e5f6db56f Author: Michelangelo <[email protected]> Date: Sun Apr 17 13:59:46 2011 +0200 Updated test database commit 3e850ccc60ba3060df4239c6e9d1ad834fe11752 Author: Michelangelo <[email protected]> Date: Sun Apr 17 13:59:08 2011 +0200 Creating a branch for joindin webservice testing Signed-off-by: Michelangelo <[email protected]>
1 parent 2dd0361 commit d59f8b2

File tree

13 files changed

+480
-0
lines changed

13 files changed

+480
-0
lines changed

application/data/db/zftest-test.db

0 Bytes
Binary file not shown.

library/Zftest/Service/Joindin.php

Lines changed: 185 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,185 @@
1+
<?php
2+
class Zftest_Service_Joindin
3+
{
4+
const JOINDIN_API_BASE = 'http://joind.in/api';
5+
const JOINDIN_DEF_TYPE = 'xml';
6+
const JOINDIN_OUT_XML = 'xml';
7+
const JOINDIN_OUT_JSON = 'json';
8+
9+
/**
10+
* @var Zend_Http_Client A client to connect with Joind.in
11+
*/
12+
protected $_client;
13+
/**
14+
* @var string The username to connect to Joind.in
15+
*/
16+
protected $_username;
17+
/**
18+
* @var string The password to connect to Joind.in
19+
*/
20+
protected $_password;
21+
/**
22+
* @var string The output type of request
23+
*/
24+
protected $_output;
25+
/**
26+
* @var SimpleXMLElement
27+
*/
28+
protected $_message;
29+
/**
30+
* @var Zftest_Service_Joindin_Site
31+
*/
32+
protected $_site;
33+
/**
34+
* @var Zftest_Service_Joindin_Event
35+
*/
36+
protected $_event;
37+
/**
38+
* @var Zftest_Service_Joindin_Talk
39+
*/
40+
protected $_talk;
41+
/**
42+
* @var Zftest_Service_Joindin_User
43+
*/
44+
protected $_user;
45+
/**
46+
* @var Zftest_Service_Joindin_Comment
47+
*/
48+
protected $_comment;
49+
/**
50+
* Constructor for this joindin class
51+
*
52+
* @param null|string $username
53+
* @param null|string $password
54+
* @param string $output
55+
*/
56+
public function __construct($username = null, $password = null, $output = self::JOINDIN_DEF_TYPE)
57+
{
58+
if (null !== $username) {
59+
$this->setUsername($username);
60+
}
61+
if (null !== $password) {
62+
$this->setPassword($password);
63+
}
64+
$this->setOutput($output);
65+
$this->setMessage(new SimpleXMLElement('<request></request>'));
66+
$this->_site = new Zftest_Service_Joindin_Site();
67+
$this->_event = new Zftest_Service_Joindin_Event();
68+
$this->_talk = new Zftest_Service_Joindin_Talk();
69+
$this->_user = new Zftest_Service_Joindin_User();
70+
$this->_comment = new Zftest_Service_Joindin_Comment();
71+
}
72+
/**
73+
* Sets the HTTP client
74+
*
75+
* @param Zend_Http_Client $client
76+
* @return Zftest_Service_Joindin
77+
*/
78+
public function setClient(Zend_Http_Client $client)
79+
{
80+
$this->_client = $client;
81+
return $this;
82+
}
83+
/**
84+
* Retrieves the HTTP client
85+
*
86+
* @return Zend_Http_Client
87+
*/
88+
public function getClient()
89+
{
90+
if (null === $this->_client) {
91+
$this->_client = new Zend_Http_Client();
92+
}
93+
return $this->_client;
94+
}
95+
/**
96+
* Sets the username for this joindin
97+
*
98+
* @param string $username
99+
* @return Zftest_Service_Joindin
100+
*/
101+
public function setUsername($username)
102+
{
103+
$this->_username = (string) $username;
104+
return $this;
105+
}
106+
/**
107+
* Retrieves the username from this joindin class
108+
*
109+
* @return string
110+
*/
111+
public function getUsername()
112+
{
113+
if (null === $this->_username) {
114+
throw new Zftest_Service_Joindin_Exception('Username is not set');
115+
}
116+
return $this->_username;
117+
}
118+
/**
119+
* Sets the password for this joindin account
120+
*
121+
* @param string $password
122+
* @return Zftest_Service_Joindin
123+
*/
124+
public function setPassword($password)
125+
{
126+
$this->_password = (string) $password;
127+
return $this;
128+
}
129+
/**
130+
* Retrieves the password from this joindin account
131+
*
132+
* @return string
133+
*/
134+
public function getPassword()
135+
{
136+
return $this->_password;
137+
}
138+
public function setOutput($output)
139+
{
140+
$types = array ('json', 'xml');
141+
if (!in_array($output, $types)) {
142+
$output = self::JOINDIN_DEF_TYPE;
143+
}
144+
$this->_output = (string) $output;
145+
return $this;
146+
}
147+
public function getOutput()
148+
{
149+
return $this->_output;
150+
}
151+
public function setMessage(SimpleXmlElement $message)
152+
{
153+
$this->_message = $message;
154+
}
155+
public function getMessage()
156+
{
157+
if (null === $this->_message) {
158+
throw new Zftest_Service_Joindin_Exception('Request message is not set');
159+
}
160+
return $this->_message;
161+
}
162+
public function user()
163+
{
164+
$this->_user->setJoindin($this);
165+
return $this->_user;
166+
}
167+
public function site()
168+
{
169+
$this->_site->setJoindin($this);
170+
return $this->_site;
171+
}
172+
public function connect(SimpleXMLElement $message, $apiEnd = null)
173+
{
174+
$this->getClient()
175+
->setUri(self::JOINDIN_API_BASE . $apiEnd)
176+
->setMethod(Zend_Http_Client::POST);
177+
if (self::JOINDIN_OUT_XML === $this->getOutput()) {
178+
$this->getClient()
179+
->setHeaders('Content-Type', 'text/xml')
180+
->setRawData($message->asXML());
181+
}
182+
$request = $this->getClient()->request();
183+
return $this->getClient()->getLastResponse();
184+
}
185+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
abstract class Zftest_Service_Joindin_Abstract
3+
{
4+
/**
5+
* Sets the joindin instance
6+
*
7+
* @param Zftest_Service_Joindin $joindin
8+
* @return Zftest_Service_Joindin_Abstract
9+
*/
10+
abstract public function setJoindin(Zftest_Service_Joindin $joindin);
11+
/**
12+
* Retrieves the joindin instance
13+
*
14+
* @return Zftest_Service_Joindin
15+
*/
16+
abstract public function getJoindin();
17+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
class Zftest_Service_Joindin_Comment extends Zftest_Service_Joindin_Abstract
3+
{
4+
const JOINDIN_API_END = '/comment';
5+
/**
6+
* @var Zftest_Service_Joindin
7+
*/
8+
protected $_joindin;
9+
/**
10+
* Sets the joindin instance
11+
*
12+
* @see Zftest_Service_Joindin_Abstract::setJoindin()
13+
* @param Zftest_Service_Joindin
14+
* @return Zftest_Service_Joindin_Event
15+
*/
16+
public function setJoindin(Zftest_Service_Joindin $joindin)
17+
{
18+
$this->_joindin = $joindin;
19+
return $this;
20+
}
21+
/**
22+
* Retrieves the joindin instance
23+
*
24+
* @see Zftest_Service_Joindin_Abstract::getJoindin()
25+
* @return Zftest_Service_Joindin
26+
*/
27+
public function getJoindin()
28+
{
29+
return $this->_joindin;
30+
}
31+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
class Zftest_Service_Joindin_Event extends Zftest_Service_Joindin_Abstract
3+
{
4+
const JOINDIN_API_END = '/event';
5+
/**
6+
* @var Zftest_Service_Joindin
7+
*/
8+
protected $_joindin;
9+
/**
10+
* Sets the joindin instance
11+
*
12+
* @see Zftest_Service_Joindin_Abstract::setJoindin()
13+
* @param Zftest_Service_Joindin
14+
* @return Zftest_Service_Joindin_Event
15+
*/
16+
public function setJoindin(Zftest_Service_Joindin $joindin)
17+
{
18+
$this->_joindin = $joindin;
19+
return $this;
20+
}
21+
/**
22+
* Retrieves the joindin instance
23+
*
24+
* @see Zftest_Service_Joindin_Abstract::getJoindin()
25+
* @return Zftest_Service_Joindin
26+
*/
27+
public function getJoindin()
28+
{
29+
return $this->_joindin;
30+
}
31+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?php
2+
class Zftest_Service_Joindin_Exception extends Zend_Exception
3+
{
4+
5+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?php
2+
class Zftest_Service_Joindin_Site extends Zftest_Service_Joindin_Abstract
3+
{
4+
const JOINDIN_API_END = '/site';
5+
/**
6+
* @var Zftest_Service_Joindin
7+
*/
8+
protected $_joindin;
9+
/**
10+
* Sets the joindin instance
11+
*
12+
* @see Zftest_Service_Joindin_Abstract::setJoindin()
13+
* @param Zftest_Service_Joindin
14+
* @return Zftest_Service_Joindin_Event
15+
*/
16+
public function setJoindin(Zftest_Service_Joindin $joindin)
17+
{
18+
$this->_joindin = $joindin;
19+
return $this;
20+
}
21+
/**
22+
* Retrieves the joindin instance
23+
*
24+
* @see Zftest_Service_Joindin_Abstract::getJoindin()
25+
* @return Zftest_Service_Joindin
26+
*/
27+
public function getJoindin()
28+
{
29+
return $this->_joindin;
30+
}
31+
/**
32+
* Call the joindin status RPC
33+
*
34+
* @param null|string $test
35+
* @return string
36+
*/
37+
public function getStatus($test = null)
38+
{
39+
$status = $this->getJoindin()
40+
->getMessage()
41+
->addChild('action');
42+
$status->addAttribute('type', 'status');
43+
$status->addAttribute('output', $this->getJoindin()->getOutput());
44+
if (null !== $test) {
45+
$status->addChild('test_string', $test);
46+
}
47+
48+
$response = $this->getJoindin()->connect(
49+
$this->getJoindin()->getMessage(), self::JOINDIN_API_END);
50+
if ($response->isError()) {
51+
throw new Zftest_Service_Joindin_Exception($response->getMessage());
52+
}
53+
return $response->getBody();
54+
}
55+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
class Zftest_Service_Joindin_Talk extends Zftest_Service_Joindin_Abstract
3+
{
4+
const JOINDIN_API_END = '/talk';
5+
/**
6+
* @var Zftest_Service_Joindin
7+
*/
8+
protected $_joindin;
9+
/**
10+
* Sets the joindin instance
11+
*
12+
* @see Zftest_Service_Joindin_Abstract::setJoindin()
13+
* @param Zftest_Service_Joindin
14+
* @return Zftest_Service_Joindin_Event
15+
*/
16+
public function setJoindin(Zftest_Service_Joindin $joindin)
17+
{
18+
$this->_joindin = $joindin;
19+
return $this;
20+
}
21+
/**
22+
* Retrieves the joindin instance
23+
*
24+
* @see Zftest_Service_Joindin_Abstract::getJoindin()
25+
* @return Zftest_Service_Joindin
26+
*/
27+
public function getJoindin()
28+
{
29+
return $this->_joindin;
30+
}
31+
}

0 commit comments

Comments
 (0)