File: Zend_Service_Delicious.xml

package info (click to toggle)
zendframework 1.12.9%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: jessie-kfreebsd
  • size: 133,584 kB
  • sloc: xml: 1,311,829; php: 570,173; sh: 170; makefile: 125; sql: 121
file content (476 lines) | stat: -rw-r--r-- 16,917 bytes parent folder | download | duplicates (2)
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
<?xml version="1.0" encoding="UTF-8"?>
<!-- Reviewed: no -->
<sect1 id="zend.service.delicious">
    <title>Zend_Service_Delicious</title>

    <sect2 id="zend.service.delicious.introduction">
        <title>Introduction</title>

        <para>
            <classname>Zend_Service_Delicious</classname> is simple <acronym>API</acronym> for using
            <ulink url="http://del.icio.us">del.icio.us</ulink> <acronym>XML</acronym> and
            <acronym>JSON</acronym> web services. This component gives you read-write access to
            posts at del.icio.us if you provide credentials. It also allows read-only access to
            public data of all users.
        </para>

        <example id="zend.service.delicious.introduction.getAllPosts">
            <title>Get all posts</title>

            <programlisting language="php"><![CDATA[
$delicious = new Zend_Service_Delicious('username', 'password');
$posts = $delicious->getAllPosts();

foreach ($posts as $post) {
    echo "--\n";
    echo "Title: {$post->getTitle()}\n";
    echo "Url: {$post->getUrl()}\n";
}
]]></programlisting>
        </example>
    </sect2>

    <sect2 id="zend.service.delicious.retrieving_posts">
        <title>Retrieving posts</title>

        <para>
            <classname>Zend_Service_Delicious</classname> provides three methods for retrieving
            posts: <methodname>getPosts()</methodname>, <methodname>getRecentPosts()</methodname>
            and <methodname>getAllPosts()</methodname>. All of these methods return an instance of
            <classname>Zend_Service_Delicious_PostList</classname>, which holds all retrieved posts.
        </para>

        <programlisting language="php"><![CDATA[
/**
 * Get posts matching the arguments. If no date or url is given,
 * most recent date will be used.
 *
 * @param string $tag Optional filtering by tag
 * @param Zend_Date $dt Optional filtering by date
 * @param string $url Optional filtering by url
 * @return Zend_Service_Delicious_PostList
 */
public function getPosts($tag = null, $dt = null, $url = null);

/**
 * Get recent posts
 *
 * @param string $tag   Optional filtering by tag
 * @param string $count Maximal number of posts to be returned
 *                      (default 15)
 * @return Zend_Service_Delicious_PostList
 */
public function getRecentPosts($tag = null, $count = 15);

/**
 * Get all posts
 *
 * @param string $tag Optional filtering by tag
 * @return Zend_Service_Delicious_PostList
 */
public function getAllPosts($tag = null);
]]></programlisting>
    </sect2>

    <sect2 id="zend.service.delicious.postlist">
        <title>Zend_Service_Delicious_PostList</title>

        <para>
            Instances of this class are returned by the <methodname>getPosts()</methodname>,
            <methodname>getAllPosts()</methodname>, <methodname>getRecentPosts()</methodname>, and
            <methodname>getUserPosts()</methodname> methods of
            <classname>Zend_Service_Delicious</classname>.
        </para>

        <para>
            For easier data access this class implements the <code>Countable</code>,
            <code>Iterator</code>, and <code>ArrayAccess</code> interfaces.
        </para>

        <example id="zend.service.delicious.postlist.accessing_post_lists">
            <title>Accessing post lists</title>

            <programlisting language="php"><![CDATA[
$delicious = new Zend_Service_Delicious('username', 'password');
$posts = $delicious->getAllPosts();

// count posts
echo count($posts);

// iterate over posts
foreach ($posts as $post) {
    echo "--\n";
    echo "Title: {$post->getTitle()}\n";
    echo "Url: {$post->getUrl()}\n";
}

// get post using array access
echo $posts[0]->getTitle();
]]></programlisting>
        </example>

        <note>
            <para>
                The <methodname>ArrayAccess::offsetSet()</methodname> and
                <methodname>ArrayAccess::offsetUnset()</methodname> methods throw exceptions in this
                implementation. Thus, code like <code>unset($posts[0]);</code> and
                <code>$posts[0] = 'A';</code> will throw exceptions because these properties are
                read-only.
            </para>
        </note>

        <para>
            Post list objects have two built-in filtering capabilities. Post lists may be filtered
            by tags and by <acronym>URL</acronym>.
        </para>

        <example id="zend.service.delicious.postlist.example.withTags">
            <title>Filtering a Post List with Specific Tags</title>

            <para>
                Posts may be filtered by specific tags using <methodname>withTags()</methodname>. As
                a convenience, <methodname>withTag()</methodname> is also provided for when only a
                single tag needs to be specified.
            </para>

            <programlisting language="php"><![CDATA[
$delicious = new Zend_Service_Delicious('username', 'password');
$posts = $delicious->getAllPosts();

// Print posts having "php" and "zend" tags
foreach ($posts->withTags(array('php', 'zend')) as $post) {
    echo "Title: {$post->getTitle()}\n";
    echo "Url: {$post->getUrl()}\n";
}
]]></programlisting>
        </example>

        <example id="zend.service.delicious.postlist.example.byUrl">
            <title>Filtering a Post List by URL</title>

            <para>
                Posts may be filtered by <acronym>URL</acronym> matching a specified regular
                expression using the <methodname>withUrl()</methodname> method:
            </para>

            <programlisting language="php"><![CDATA[
$delicious = new Zend_Service_Delicious('username', 'password');
$posts = $delicious->getAllPosts();

// Print posts having "help" in the URL
foreach ($posts->withUrl('/help/') as $post) {
    echo "Title: {$post->getTitle()}\n";
    echo "Url: {$post->getUrl()}\n";
}
]]></programlisting>
        </example>
    </sect2>

    <sect2 id="zend.service.delicious.editing_posts">
        <title>Editing posts</title>

        <example id="zend.service.delicious.editing_posts.post_editing">
            <title>Post editing</title>

            <programlisting language="php"><![CDATA[
$delicious = new Zend_Service_Delicious('username', 'password');
$posts = $delicious->getPosts();

// set title
$posts[0]->setTitle('New title');
// save changes
$posts[0]->save();
]]></programlisting>
        </example>

        <example id="zend.service.delicious.editing_posts.method_call_chaining">
            <title>Method call chaining</title>

            <para>
               Every setter method returns the post object so that you can chain method calls using
               a fluent interface.
            </para>

            <programlisting language="php"><![CDATA[
$delicious = new Zend_Service_Delicious('username', 'password');
$posts = $delicious->getPosts();

$posts[0]->setTitle('New title')
         ->setNotes('New notes')
         ->save();
]]></programlisting>
        </example>
    </sect2>

    <sect2 id="zend.service.delicious.deleting_posts">
        <title>Deleting posts</title>

        <para>
            There are two ways to delete a post, by specifying the post <acronym>URL</acronym> or by
            calling the <methodname>delete()</methodname> method upon a post object.
        </para>

        <example id="zend.service.delicious.deleting_posts.deleting_posts">
            <title>Deleting posts</title>

            <programlisting language="php"><![CDATA[
$delicious = new Zend_Service_Delicious('username', 'password');

// by specifying URL
$delicious->deletePost('http://framework.zend.com');

// or by calling the method upon a post object
$posts = $delicious->getPosts();
$posts[0]->delete();

// another way of using deletePost()
$delicious->deletePost($posts[0]->getUrl());
]]></programlisting>
        </example>
    </sect2>

    <sect2 id="zend.service.delicious.adding_posts">
        <title>Adding new posts</title>

        <para>
            To add a post you first need to call the <methodname>createNewPost()</methodname>
            method, which returns a <classname>Zend_Service_Delicious_Post</classname> object. When
            you edit the post, you need to save it to the del.icio.us database by calling the
            <methodname>save()</methodname> method.
        </para>

        <example id="zend.service.delicious.adding_posts.adding_a_post">
            <title>Adding a post</title>

            <programlisting language="php"><![CDATA[
$delicious = new Zend_Service_Delicious('username', 'password');

// create a new post and save it (with method call chaining)
$delicious->createNewPost('Zend Framework', 'http://framework.zend.com')
          ->setNotes('Zend Framework Homepage')
          ->save();

// create a new post and save it  (without method call chaining)
$newPost = $delicious->createNewPost('Zend Framework',
                                     'http://framework.zend.com');
$newPost->setNotes('Zend Framework Homepage');
$newPost->save();
]]></programlisting>
        </example>
    </sect2>

    <sect2 id="zend.service.delicious.tags">
        <title>Tags</title>

        <example id="zend.service.delicious.tags.tags">
            <title>Tags</title>

            <programlisting language="php"><![CDATA[
$delicious = new Zend_Service_Delicious('username', 'password');

// get all tags
print_r($delicious->getTags());

// rename tag ZF to zendFramework
$delicious->renameTag('ZF', 'zendFramework');
]]></programlisting>
        </example>
    </sect2>

    <sect2 id="zend.service.delicious.bundles">
        <title>Bundles</title>

        <example id="zend.service.delicious.bundles.example">
            <title>Bundles</title>

            <programlisting language="php"><![CDATA[
$delicious = new Zend_Service_Delicious('username', 'password');

// get all bundles
print_r($delicious->getBundles());

// delete bundle someBundle
$delicious->deleteBundle('someBundle');

// add bundle
$delicious->addBundle('newBundle', array('tag1', 'tag2'));
]]></programlisting>
        </example>
    </sect2>

    <sect2 id="zend.service.delicious.public_data">
        <title>Public data</title>

        <para>
            The del.icio.us web <acronym>API</acronym> allows access to the public data of all
            users.
        </para>

        <table id="zend.service.delicious.public_data.functions_for_retrieving_public_data">
            <title>Methods for retrieving public data</title>

            <tgroup cols="3">
                <thead>
                    <row>
                        <entry>Name</entry>
                        <entry>Description</entry>
                        <entry>Return type</entry>
                    </row>
                </thead>

                <tbody>
                    <row>
                        <entry><methodname>getUserFans()</methodname></entry>
                        <entry>Retrieves fans of a user</entry>
                        <entry>Array</entry>
                    </row>

                    <row>
                        <entry><methodname>getUserNetwork()</methodname></entry>
                        <entry>Retrieves network of a user</entry>
                        <entry>Array</entry>
                    </row>

                    <row>
                        <entry><methodname>getUserPosts()</methodname></entry>
                        <entry>Retrieves posts of a user</entry>
                        <entry>Zend_Service_Delicious_PostList</entry>
                    </row>

                    <row>
                        <entry><methodname>getUserTags()</methodname></entry>
                        <entry>Retrieves tags of a user</entry>
                        <entry>Array</entry>
                    </row>
                </tbody>
            </tgroup>
        </table>

        <note>
            <para>
                When using only these methods, a username and password combination is not required
                when constructing a new <classname>Zend_Service_Delicious</classname> object.
            </para>
        </note>

        <example id="zend.service.delicious.public_data.retrieving_public_data">
            <title>Retrieving public data</title>

            <programlisting language="php"><![CDATA[
// username and password are not required
$delicious = new Zend_Service_Delicious();

// get fans of user someUser
print_r($delicious->getUserFans('someUser'));

// get network of user someUser
print_r($delicious->getUserNetwork('someUser'));

// get tags of user someUser
print_r($delicious->getUserTags('someUser'));
]]></programlisting>
        </example>

        <sect3 id="zend.service.delicious.public_data.posts">
            <title>Public posts</title>

            <para>
                When retrieving public posts with the <methodname>getUserPosts()</methodname>
                method, a <classname>Zend_Service_Delicious_PostList</classname> object is returned,
                and it contains <classname>Zend_Service_Delicious_SimplePost</classname> objects,
                which contain basic information about the posts, including <acronym>URL</acronym>,
                title, notes, and tags.
            </para>

            <table id="zend.service.delicious.public_data.posts.SimplePost_methods">
                <title>Methods of the Zend_Service_Delicious_SimplePost class</title>

                <tgroup cols="3">
                    <thead>
                        <row>
                            <entry>Name</entry>
                            <entry>Description</entry>
                            <entry>Return type</entry>
                        </row>
                    </thead>

                    <tbody>
                        <row>
                            <entry><methodname>getNotes()</methodname></entry>
                            <entry>Returns notes of a post</entry>
                            <entry>String</entry>
                        </row>

                        <row>
                            <entry><methodname>getTags()</methodname></entry>
                            <entry>Returns tags of a post</entry>
                            <entry>Array</entry>
                        </row>

                        <row>
                            <entry><methodname>getTitle()</methodname></entry>
                            <entry>Returns title of a post</entry>
                            <entry>String</entry>
                        </row>

                        <row>
                            <entry><methodname>getUrl()</methodname></entry>
                            <entry>Returns <acronym>URL</acronym> of a post</entry>
                            <entry>String</entry>
                        </row>
                    </tbody>
                </tgroup>
            </table>
        </sect3>
    </sect2>

    <sect2 id="zend.service.delicious.httpclient">
        <title>HTTP client</title>

        <para>
            <classname>Zend_Service_Delicious</classname> uses
            <classname>Zend_Rest_Client</classname> for making <acronym>HTTP</acronym> requests to
            the del.icio.us web service. To change which <acronym>HTTP</acronym> client
            <classname>Zend_Service_Delicious</classname> uses, you need to change the
            <acronym>HTTP</acronym> client of <classname>Zend_Rest_Client</classname>.
        </para>

        <example id="zend.service.delicious.httpclient.changing">
            <title>Changing the HTTP client of Zend_Rest_Client</title>

            <programlisting language="php"><![CDATA[
$myHttpClient = new My_Http_Client();
Zend_Rest_Client::setHttpClient($myHttpClient);
]]></programlisting>
        </example>

        <para>
            When you are making more than one request with
            <classname>Zend_Service_Delicious</classname> to speed your requests, it's better to
            configure your <acronym>HTTP</acronym> client to keep connections alive.
        </para>

        <example id="zend.service.delicious.httpclient.keepalive">
            <title>Configuring your HTTP client to keep connections alive</title>

            <programlisting language="php"><![CDATA[
Zend_Rest_Client::getHttpClient()->setConfig(array(
        'keepalive' => true
));
]]></programlisting>
        </example>

        <note>
            <para>
                When a <classname>Zend_Service_Delicious</classname> object is constructed, the
                <acronym>SSL</acronym> transport of <classname>Zend_Rest_Client</classname> is set
                to <code>'ssl'</code> rather than the default of <code>'ssl2'</code>. This is
                because del.icio.us has some problems with <code>'ssl2'</code>, such as requests
                taking a long time to complete (around 2 seconds).
            </para>
        </note>
    </sect2>
</sect1>
<!--
vim:se ts=4 sw=4 et:
-->