|
| 1 | + |
1 | 2 | #!/usr/bin/python |
2 | 3 | # |
3 | 4 | # Copyright (C) 2010-2011 Google Inc. |
|
15 | 16 | # limitations under the License. |
16 | 17 |
|
17 | 18 |
|
18 | | -"""Extend the gdata client for the Content API for Shopping. |
19 | | -
|
20 | | -TODO: |
21 | | -
|
22 | | -1. Proper MCA Support. |
23 | | -2. Add classes for datafeed functions instead of asking for raw XML. |
24 | | -""" |
| 19 | +"""Extend the gdata client for the Content API for Shopping.""" |
25 | 20 |
|
26 | 21 |
|
27 | 22 | __author__ = 'afshar (Ali Afshar), dhermes (Daniel Hermes)' |
28 | 23 |
|
29 | 24 |
|
30 | | -import atom.data |
| 25 | +import urllib |
| 26 | + |
31 | 27 | import gdata.client |
32 | 28 | from gdata.contentforshopping.data import ClientAccount |
33 | 29 | from gdata.contentforshopping.data import ClientAccountFeed |
34 | 30 | from gdata.contentforshopping.data import DatafeedEntry |
35 | 31 | from gdata.contentforshopping.data import DatafeedFeed |
36 | 32 | from gdata.contentforshopping.data import ProductEntry |
37 | 33 | from gdata.contentforshopping.data import ProductFeed |
| 34 | +from gdata.contentforshopping.data import UsersEntry |
| 35 | +from gdata.contentforshopping.data import UsersFeed |
38 | 36 |
|
39 | 37 |
|
40 | 38 | CFS_VERSION = 'v1' |
@@ -75,7 +73,7 @@ def _create_uri(self, account_id, resource, path=(), use_projection=True, |
75 | 73 | segments = [CFS_URI, self.cfs_api_version, account_id, resource] |
76 | 74 | if use_projection: |
77 | 75 | segments.append(CFS_PROJECTION) |
78 | | - segments.extend(path) |
| 76 | + segments.extend(urllib.quote(value) for value in path) |
79 | 77 | result = '/'.join(segments) |
80 | 78 |
|
81 | 79 | request_params = [] |
@@ -482,3 +480,85 @@ def delete_client_account(self, client_account_id, account_id=None, |
482 | 480 | return self.delete(uri, auth_token=auth_token) |
483 | 481 |
|
484 | 482 | DeleteClientAccount = delete_client_account |
| 483 | + |
| 484 | + def get_users_feed(self, account_id=None, auth_token=None): |
| 485 | + """Get the users feed for an account. |
| 486 | +
|
| 487 | + :param account_id: The Merchant Center Account ID. If ommitted the default |
| 488 | + Account ID will be used for this client |
| 489 | + :param auth_token: An object which sets the Authorization HTTP header in its |
| 490 | + modify_request method. |
| 491 | + """ |
| 492 | + |
| 493 | + uri = self._create_uri(account_id, 'users', use_projection=False) |
| 494 | + return self.get_feed(uri, auth_token=auth_token, desired_class=UsersFeed) |
| 495 | + |
| 496 | + GetUsersFeed = get_users_feed |
| 497 | + |
| 498 | + def get_users_entry(self, user_email, account_id=None, auth_token=None): |
| 499 | + """Get a users feed entry for an account. |
| 500 | +
|
| 501 | + :param user_email: Email of the user entry to be retrieved. |
| 502 | + :param account_id: The Merchant Center Account ID. If ommitted the default |
| 503 | + Account ID will be used for this client |
| 504 | + :param auth_token: An object which sets the Authorization HTTP header in its |
| 505 | + modify_request method. |
| 506 | + """ |
| 507 | + uri = self._create_uri( |
| 508 | + account_id, 'users', path=[user_email], use_projection=False) |
| 509 | + return self.get_entry(uri, auth_token=auth_token, desired_class=UsersEntry) |
| 510 | + |
| 511 | + GetUsersEntry = get_users_entry |
| 512 | + |
| 513 | + def insert_users_entry(self, entry, account_id=None, auth_token=None): |
| 514 | + """Insert a users feed entry for an account. |
| 515 | +
|
| 516 | + :param entry: A :class:`gdata.contentforshopping.data.UsersEntry` with |
| 517 | + the required user data. |
| 518 | + :param account_id: The Merchant Center Account ID. If ommitted the default |
| 519 | + Account ID will be used for this client |
| 520 | + :param auth_token: An object which sets the Authorization HTTP header in its |
| 521 | + modify_request method. |
| 522 | + """ |
| 523 | + uri = self._create_uri(account_id, 'users', use_projection=False) |
| 524 | + return self.post(entry, uri=uri, auth_token=auth_token) |
| 525 | + |
| 526 | + InsertUsersEntry = insert_users_entry |
| 527 | + |
| 528 | + def update_users_entry(self, entry, account_id=None, auth_token=None): |
| 529 | + """Update a users feed entry for an account. |
| 530 | +
|
| 531 | + :param entry: A :class:`gdata.contentforshopping.data.UsersEntry` with |
| 532 | + the required user data. |
| 533 | + :param account_id: The Merchant Center Account ID. If ommitted the default |
| 534 | + Account ID will be used for this client |
| 535 | + :param auth_token: An object which sets the Authorization HTTP header in its |
| 536 | + modify_request method. |
| 537 | + """ |
| 538 | + # Could also use entry.find_edit_link() but that is inconsistent |
| 539 | + # with the rest of the module |
| 540 | + user_email = entry.title.text |
| 541 | + uri = self._create_uri( |
| 542 | + account_id, 'users', path=[user_email], use_projection=False) |
| 543 | + return self.update(entry, uri=uri, auth_token=auth_token) |
| 544 | + |
| 545 | + UpdateUsersEntry = update_users_entry |
| 546 | + |
| 547 | + def delete_users_entry(self, entry, account_id=None, auth_token=None): |
| 548 | + """Delete a users feed entry for an account. |
| 549 | +
|
| 550 | + :param entry: A :class:`gdata.contentforshopping.data.UsersEntry` with |
| 551 | + the required user data. |
| 552 | + :param account_id: The Merchant Center Account ID. If ommitted the default |
| 553 | + Account ID will be used for this client |
| 554 | + :param auth_token: An object which sets the Authorization HTTP header in its |
| 555 | + modify_request method. |
| 556 | + """ |
| 557 | + # Could also use entry.find_edit_link() but that is inconsistent |
| 558 | + # with the rest of the module |
| 559 | + user_email = entry.title.text |
| 560 | + uri = self._create_uri( |
| 561 | + account_id, 'users', path=[user_email], use_projection=False) |
| 562 | + return self.delete(uri, auth_token=auth_token) |
| 563 | + |
| 564 | + DeleteUsersEntry = delete_users_entry |
0 commit comments