Hi Shaun,

From the recurring API endpoint names, I'd suggest breaking the API across a 
series of categorised classes. It's the simplest means of dissecting the API, 
building concrete implementations, and testing them. From there, with a few of 
these, you can build up some picture of what the parent class for all of these 
would look like. At a glance it would handle authentication (if needed) and API 
keys to start with. It would likely also handle the HTTP transport.

In place of a giant class, you could also implement a front class which 
lazy-loads each API specific class as needed.

E.g.

$api = new Flickr();
$contactList = $api->contacts()->getList(); (could be a property either)

I'd suggest starting with some idea of what style of API you want to see at the 
end of the day. It'll help frame all your unit tests when implementing it.

Only item I'd be somewhat careful with is authentication. It shouldn't be tied 
into a hierarchy (as an example see Zend_Service_Twitter where this lead to all 
sorts of re-authentication issues because the design made is difficult to reuse 
just one auth transaction and result).

Paddy

 Pádraic Brady

http://blog.astrumfutura.com
http://www.survivethedeepend.com
OpenID Europe Foundation Irish Representative





________________________________
From: Shaun Farrell <farrel...@gmail.com>
To: Zend Framework General <fw-general@lists.zend.com>
Sent: Tue, March 16, 2010 8:56:00 PM
Subject: [fw-general] Creating a Zend_Service_* Component

I have been working on creating some Zend_Service components and I am trying to 
figure out the best way to break out my methods. 

Do I write one long class or do I break out the sections of the API into 
multiple classes.

Take flickr for an example.  There are a lot of API calls.  flickr has them 
grouped very well, you can see them here http://www.flickr.com/services/api/  
If I was going to create a flickr component would I throw all those API calls 
in one class called flickr.php or would you suggest creating the flickr.php to 
have the photo methods and then in the Zend_Service_Flickr folder create 
stats.php for the stats methods, people.php for the people methods, etc.  All 
these classes would extend the main class (flickr.php)

I'm sort of confused right now on what route to go with.  

Suggestions and comments would be great!

Thanks!

Shaun J. Farrell
Washington, DC

Reply via email to