File: Zend_Gdata_Books.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 (520 lines) | stat: -rw-r--r-- 22,160 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
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
<?xml version="1.0" encoding="UTF-8"?>
<!-- Reviewed: no -->
<sect1 id="zend.gdata.books">
    <title>Using the Book Search Data API</title>

    <para>
        The Google Book Search Data <acronym>API</acronym> allows client applications to view
        and update Book Search content in the form of Google Data <acronym>API</acronym> feeds.
    </para>

    <para>
        Your client application can use the Book Search Data <acronym>API</acronym> to issue
        full-text searches for books and to retrieve standard book information,
        ratings, and reviews. You can also access individual users'
        <ulink url="http://books.google.com/googlebooks/mylibrary/">library collections and
            public reviews</ulink>. Finally, your application can submit authenticated requests
        to enable users to create and modify library collections, ratings, labels,
        reviews, and other account-specific entities.
    </para>

    <para>
        For more information on the Book Search Data <acronym>API</acronym>, please refer to the
        official <ulink url="http://code.google.com/apis/books/gdata/developers_guide_php.html">PHP
            Developer's Guide</ulink> on code.google.com.
    </para>

    <sect2 id="zend.gdata.books.authentication">
        <title>Authenticating to the Book Search service</title>

        <para>
            You can access both public and private feeds using the Book Search
            Data <acronym>API</acronym>. Public feeds don't require any authentication, but they are
            read-only. If you want to modify user libraries, submit reviews or
            ratings, or add labels, then your client needs to authenticate before
            requesting private feeds. It can authenticate using either of two
            approaches: AuthSub proxy authentication or ClientLogin username/password
            authentication. Please refer to the <ulink
                url="http://code.google.com/apis/books/gdata/developers_guide_php.html#Authentication">Authentication
                section in the <acronym>PHP</acronym> Developer's Guide</ulink> for more detail.
        </para>
    </sect2>

    <sect2 id="zend.gdata.books.searching_for_books">
        <title>Searching for books</title>

        <para>
            The Book Search Data <acronym>API</acronym> provides a number of feeds that list
            collections of books.
        </para>

        <para>
            The most common action is to retrieve a list of books that match a
            search query. To do so you create a <classname>VolumeQuery</classname> object
            and pass it to the <methodname>Books::getVolumeFeed()</methodname> method.
        </para>

        <para>
            For example, to perform a keyword query, with a filter on
            viewability to restrict the results to partial or full view books, use
            the <methodname>setMinViewability()</methodname> and <methodname>setQuery()</methodname>
            methods of the <classname>VolumeQuery</classname> object. The following code snippet
            prints the title and viewability of all volumes whose metadata or text matches
            the query term "domino":
        </para>

        <programlisting language="php"><![CDATA[
$books = new Zend_Gdata_Books();
$query = $books->newVolumeQuery();

$query->setQuery('domino');
$query->setMinViewability('partial_view');

$feed = $books->getVolumeFeed($query);

foreach ($feed as $entry) {
    echo $entry->getVolumeId();
    echo $entry->getTitle();
    echo $entry->getViewability();
}
]]></programlisting>

        <para>
            The <classname>Query</classname> class, and subclasses like
            <classname>VolumeQuery</classname>, are responsible for constructing feed
            <acronym>URL</acronym>s. The VolumeQuery shown above constructs a <acronym>URL</acronym>
            equivalent to the following:
        </para>

        <programlisting language="php"><![CDATA[
http://www.google.com/books/feeds/volumes?q=keyword&amp;min-viewability=partial
]]></programlisting>

        <para>
            Note: Since Book Search results are
            public, you can issue a Book Search query without authentication.
        </para>

        <para>
            Here are some of the most common <classname>VolumeQuery</classname>
            methods for setting search parameters:
        </para>

        <para>
            <methodname>setQuery()</methodname>: Specifies a search
            query term. Book Search searches all book metadata and full text for
            books matching the term. Book metadata includes titles, keywords,
            descriptions, author names, and subjects.
            Note that any spaces, quotes or other punctuation in the parameter
            value must be <acronym>URL</acronym>-escaped (Use a plus (<emphasis>+</emphasis>) for a
            space). To search for an exact phrase, enclose the phrase in quotation marks.
            For example, to search for books matching the phrase "spy plane", set
            the <property>q</property> parameter to <command>%22spy+plane%22</command>.
            You can also use any of the <ulink url="http://books.google.com/advanced_book_search">
            advanced search operators</ulink> supported by Book Search. For example,
            <command>jane+austen+-inauthor:austen</command> returns matches that mention
            (but are not authored by) Jane Austen.
        </para>

        <para>
            <methodname>setStartIndex()</methodname>: Specifies
            the index of the first matching result that should be included in the
            result set. This parameter uses a one-based index, meaning the first
            result is 1, the second result is 2 and so forth. This parameter works
            in conjunction with the max-results
            parameter to determine which results to return. For example, to
            request the third set of 10 results—results 21-30—set
            the <property>start-index</property> parameter to <emphasis>21</emphasis> and the
            max-results parameter to <emphasis>10</emphasis>.
            Note: This isn't a general cursoring
            mechanism. If you first send a query with
            <command>?start-index=1&amp;max-results=10</command> and then send another
            query with <command>?start-index=11&amp;max-results=10</command>, the
            service cannot guarantee that the results are equivalent to
            <command>?start-index=1&amp;max-results=20</command>, because insertions and
            deletions could have taken place in between the two queries.
        </para>

        <para>
            <methodname>setMaxResults()</methodname>:
            Specifies the maximum number of results that should be included
            in the result set. This parameter works in conjunction with the
            start-index parameter to determine which
            results to return. The default value of this parameter is
            <emphasis>10</emphasis> and the maximum value is <emphasis>20</emphasis>.
        </para>

        <para>
            <methodname>setMinViewability()</methodname>: Allows you to filter the results according
            to the books' <ulink
                url="http://code.google.com/apis/books/docs/dynamic-links.html#terminology">viewability
                status</ulink>. This parameter accepts one of three values:
            <emphasis>'none'</emphasis> (the default, returning all matching books regardless of
            viewability), <emphasis>'partial_view'</emphasis> (returning only books
            that the user can preview or view in their entirety), or
            <emphasis>'full_view'</emphasis> (returning only books that the user can
            view in their entirety).
        </para>

        <sect3 id="zend.gdata.books.partner_restrict">
            <title>Partner Co-Branded Search</title>

            <para>
                Google Book Search provides <ulink
                    url="http://books.google.com/support/partner/bin/answer.py?hl=en&amp;answer=65113">Co-Branded
                    Search</ulink>, which lets content partners provide full-text search of
                their books from their own websites.
            </para>

            <para>
                If you are a partner who wants to do Co-Branded Search using the
                Book Search Data <acronym>API</acronym>, you may do so by modifying the feed
                <acronym>URL</acronym> above to point to your Co-Branded Search implementation. if,
                for example, a Co-Branded Search is available at the following
                <acronym>URL</acronym>:
            </para>

            <programlisting language="php"><![CDATA[
http://www.google.com/books/p/PARTNER_COBRAND_ID?q=ball
]]></programlisting>

            <para>
                then you can obtain the same results using the Book Search Data
                <acronym>API</acronym> at the following <acronym>URL</acronym>:
            </para>

            <programlisting language="php"><![CDATA[
http://www.google.com/books/feeds/p/PARTNER_COBRAND_ID/volumes?q=ball+-soccer
]]></programlisting>

            <para>
                To specify an alternate <acronym>URL</acronym> when querying a volume feed, you can
                provide an extra parameter to <methodname>newVolumeQuery()</methodname>
            </para>

            <programlisting language="php"><![CDATA[
$query =
    $books->newVolumeQuery('http://www.google.com/books/p/PARTNER_COBRAND_ID');
]]></programlisting>

            <para>
                For additional information or support, visit our
                <ulink url="http://books.google.com/support/partner/">Partner help center</ulink>.
            </para>
        </sect3>
    </sect2>

    <sect2 id="zend.gdata.books.community_features">
        <title>Using community features</title>

        <sect3 id="zend.gdata.books.adding_ratings">
            <title>Adding a rating</title>

            <para>
                A user can add a rating to a book. Book Search uses a 1-5
                rating system in which 1 is the lowest rating. Users cannot
                update or delete ratings.
            </para>

            <para>
                To add a rating, add a <classname>Rating</classname> object to a
                <classname>VolumeEntry</classname> and post it to the annotation feed. In the
                example below, we start from an empty <classname>VolumeEntry</classname> object.
            </para>

            <programlisting language="php"><![CDATA[
$entry = new Zend_Gdata_Books_VolumeEntry();
$entry->setId(new Zend_Gdata_App_Extension_Id(VOLUME_ID));
$entry->setRating(new Zend_Gdata_Extension_Rating(3, 1, 5, 1));
$books->insertVolume($entry, Zend_Gdata_Books::MY_ANNOTATION_FEED_URI);
]]></programlisting>
        </sect3>

        <sect3 id="zend.gdata.books.reviews">
            <title>Reviews</title>

            <para>
                In addition to ratings, authenticated users can submit reviews or
                edit their reviews. For information on how to request previously
                submitted reviews, see <ulink
                    url="#zend.gdata.books.retrieving_annotations">Retrieving annotations</ulink>.
            </para>

            <sect4 id="zend.gdata.books.adding_review">
                <title>Adding a review</title>

                <para>
                    To add a review, add a <classname>Review</classname> object to a
                    <classname>VolumeEntry</classname> and post it to the annotation
                    feed. In the example below, we start from an existing
                    <classname>VolumeEntry</classname> object.
                </para>

                <programlisting language="php"><![CDATA[
$annotationUrl = $entry->getAnnotationLink()->href;
$review        = new Zend_Gdata_Books_Extension_Review();

$review->setText("This book is amazing!");
$entry->setReview($review);
$books->insertVolume($entry, $annotationUrl);
]]></programlisting>
            </sect4>

            <sect4 id="zend.gdata.books.editing_review">
                <title>Editing a review</title>

                <para>
                    To update an existing review, first you retrieve the
                    review you want to update, then you modify it, and
                    then you submit it to the annotation feed.
                </para>

                <programlisting language="php"><![CDATA[
$entryUrl = $entry->getId()->getText();
$review   = new Zend_Gdata_Books_Extension_Review();

$review->setText("This book is actually not that good!");
$entry->setReview($review);
$books->updateVolume($entry, $entryUrl);
]]></programlisting>
            </sect4>
        </sect3>

        <sect3 id="zend.gdata.books.labels">
            <title>Labels</title>

            <para>
                You can use the Book Search Data <acronym>API</acronym> to label volumes with
                keywords. A user can submit, retrieve and modify labels. See
                <ulink url="#zend.gdata.books.retrieving_annotations">Retrieving
                    annotations</ulink> for how to read previously submitted labels.
            </para>

            <sect4 id="zend.gdata.books.submitting_labels">
                <title>Submitting a set of labels</title>

                <para>
                    To submit labels, add a <classname>Category</classname> object
                    with the scheme <constant>LABELS_SCHEME</constant> to a
                    <classname>VolumeEntry</classname> and post it to the annotation feed.
                </para>

                <programlisting language="php"><![CDATA[
$annotationUrl = $entry->getAnnotationLink()->href;
$category      = new Zend_Gdata_App_Extension_Category(
    'rated',
    'http://schemas.google.com/books/2008/labels');
$entry->setCategory(array($category));
$books->insertVolume($entry, Zend_Gdata_Books::MY_ANNOTATION_FEED_URI);
]]></programlisting>
            </sect4>
        </sect3>

        <sect3 id="zend.gdata.books.retrieving_annotations">
            <title>Retrieving annotations: reviews, ratings, and labels</title>

            <para>
                You can use the Book Search Data <acronym>API</acronym> to retrieve annotations
                submitted by a given user. Annotations include reviews, ratings, and
                labels. To retrieve any user's annotations, you can send an
                unauthenticated request that includes the user's user ID. To retrieve the
                authenticated user's annotations, use the value <emphasis>me</emphasis> as the user
                ID.
            </para>

            <programlisting language="php"><![CDATA[
$feed = $books->getVolumeFeed(
            'http://www.google.com/books/feeds/users/USER_ID/volumes');
<i>(or)</i>
$feed = $books->getUserAnnotationFeed();

// print title(s) and rating value
foreach ($feed as $entry) {
    foreach ($feed->getTitles() as $title) {
        echo $title;
    }
    if ($entry->getRating()) {
        echo 'Rating: ' . $entry->getRating()->getAverage();
    }
}
]]></programlisting>

            <para>
                For a list of the supported query parameters, see the
                <ulink url="#zend.gdata.books.query_parameters">query parameters</ulink>
                section.
            </para>
        </sect3>

        <sect3 id="zend.gdata.books.deleting_annotations">
            <title>Deleting Annotations</title>

            <para>
                If you retrieved an annotation entry containing ratings,
                reviews, and/or labels, you can remove all annotations
                by calling <methodname>deleteVolume()</methodname> on that entry.
            </para>

            <programlisting language="php"><![CDATA[
$books->deleteVolume($entry);
]]></programlisting>
        </sect3>
    </sect2>

    <sect2 id="zend.gdata.books.sharing_with_my_library">
        <title>Book collections and My Library</title>

        <para>
            Google Book Search provides a number of user-specific
            book collections, each of which has its own feed.
        </para>

        <para>
            The most important collection is the user's My Library, which
            represents the books the user would like to remember, organize, and
            share with others. This is the collection the user sees when accessing
            his or her <ulink url="http://books.google.com/books?op=library">My Library
                page</ulink>.
        </para>

        <sect3 id="zend.gdata.books.retrieving_books_in_library">
            <title>Retrieving books in a user's library</title>

            <para>
                The following sections describe how to retrieve a list
                of books from a user's library, with or without query
                parameters.
            </para>

            <para>
                You can query a Book Search public feed without authentication.
            </para>

            <sect4 id="zend.gdata.books.retrieving_all_books_in_library">
                <title>Retrieving all books in a user's library</title>

                <para>
                    To retrieve the user's books, send a query to the
                    My Library feed. To get the library of the authenticated
                    user, use <emphasis>me</emphasis> in place of <constant>USER_ID</constant>.
                </para>

                <programlisting language="php"><![CDATA[
$feed = $books->getUserLibraryFeed();
]]></programlisting>

                <para>
                    Note: The feed may not contain all of the user's books, because
                    there's a default limit on the number of results returned. For
                    more information, see the <property>max-results</property> query parameter in
                    <ulink url="#zend.gdata.books.searching_for_books">Searching for books</ulink>.
                </para>
            </sect4>

            <sect4 id="zend.gdata.books.retrieving_books_in_library_with_query">
                <title>Searching for books in a user's library</title>

                <para>
                    Just as you can <ulink
                        url="#zend.gdata.books.searching_for_books">search across all books</ulink>,
                    you can do a full-text search over just the books in a
                    user's library. To do this, just set the appropriate
                    paramters on the <classname>VolumeQuery</classname> object.
                </para>

                <para>
                    For example, the following query returns all the books in
                    your library that contain the word "bear":
                </para>

                <programlisting language="php"><![CDATA[
$query = $books->newVolumeQuery(
    'http://www.google.com/books/feeds/users' .
    '/USER_ID/collections/library/volumes');
$query->setQuery('bear');
$feed = $books->getVolumeFeed($query);
]]></programlisting>

                <para>
                    For a list of the supported query parameters, see the
                    <ulink url="#zend.gdata.books.query_pParameters">query parameters</ulink>
                    section. In addition, you can search for books that have been
                    <ulink url="#zend.gdata.books.labels">labeled by the user</ulink>:
                </para>

                <programlisting language="php"><![CDATA[
$query = $books->newVolumeQuery(
    'http://www.google.com/books/feeds/users/' .
    'USER_ID/collections/library/volumes');
$query->setCategory(
$query->setCategory('favorites');
$feed = $books->getVolumeFeed($query);
]]></programlisting>
            </sect4>
        </sect3>

        <sect3 id="zend.gdata.books.updating_library">
            <title>Updating books in a user's library</title>

            <para>
                You can use the Book Search Data <acronym>API</acronym> to add a book to, or remove
                a book from, a user's library. Ratings, reviews, and labels are valid
                across all the collections of a user, and are thus edited using the
                annotation feed (see <ulink
                    url="#zend.gdata.books.community_features">Using community features</ulink>).
            </para>

            <sect4 id="zend.gdata.books.library_book_add">
                <title>Adding a book to a library</title>

                <para>
                    After authenticating, you can add books to the current user's library.
                </para>

                <para>
                    You can either create an entry from scratch if you
                    know the volume ID, or insert an entry read from any feed.
                </para>

                <para>
                    The following example creates a new entry and adds it to the library:
                </para>

                <programlisting language="php"><![CDATA[
$entry = new Zend_Gdata_Books_VolumeEntry();
$entry->setId(new Zend_Gdata_App_Extension_Id(VOLUME_ID));
$books->insertVolume(
    $entry,
    Zend_Gdata_Books::MY_LIBRARY_FEED_URI
);
]]></programlisting>

                <para>
                    The following example adds an existing
                    <classname>VolumeEntry</classname> object to the library:
                </para>

                <programlisting language="php"><![CDATA[
$books->insertVolume(
    $entry,
    Zend_Gdata_Books::MY_LIBRARY_FEED_URI
);
]]></programlisting>
            </sect4>

            <sect4 id="zend.gdata.books.library_book_remove">
                <title>Removing a book from a library</title>

                <para>
                    To remove a book from a user's library, call
                    <methodname>deleteVolume()</methodname> on the
                    <classname>VolumeEntry</classname> object.
                </para>

                <programlisting language="php"><![CDATA[
$books->deleteVolume($entry);
]]></programlisting>
            </sect4>
        </sect3>
    </sect2>
</sect1>