Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 94 lines (81 sloc) 3.575 kb
0a51ea7 Initial commit
Russ P authored
1 from aweber_api.response import AWeberResponse
b3a20a0 Added ability to delete and update subscribers
Russ P authored
2 from aweber_api.data_dict import DataDict
0a51ea7 Initial commit
Russ P authored
3
4 class AWeberEntry(AWeberResponse):
5 """
6 Represents a single entry in the AWeber API data heirarchy, such as one
7 specific account, list, web form, etc. Built on data that is returned
8 from an id-ed URI, such as:
9 /accounts/XXXX
10 /accounts/XXXX/lists/XXXX
11 Can also be generated from the data in the entries array of a collection
12 object, which is identical to the data return from the URI for that
13 specific entry.
14
15 Provides direct access to properties in the response, such as self.id
16 """
17
18 def __init__(self, url, data, adapter):
b3a20a0 Added ability to delete and update subscribers
Russ P authored
19 self._data = {}
20 self._diff = {}
0a51ea7 Initial commit
Russ P authored
21 AWeberResponse.__init__(self, url, data, adapter)
22 self._child_collections = {}
23
b3a20a0 Added ability to delete and update subscribers
Russ P authored
24 def __setattr__(self, key, value):
25 if not key == '_data' and key in self._data:
26 self._data[key] = value
27 self._diff[key] = value
28 return value
29 return AWeberResponse.__setattr__(self, key, value)
30
31 def delete(self):
5323394 added support for move operation on entries. refactored MockAdapter as a...
Edward F. Long, Jr authored
32 """Invoke the API method to DELETE* this entry resource.
33
34 * Note: Not all entry resources are eligible to be DELETED, please
35 refer to the AWeber API Reference Documentation at
36 https://labs.aweber.com/docs/reference/1.0 for more
37 details on which entry resources may be deleted.
38 """
b3a20a0 Added ability to delete and update subscribers
Russ P authored
39 status = self.adapter.request('DELETE', self.url, response='status')
40 if str(status)[:2] == '20':
41 return True
42 return False
43
5323394 added support for move operation on entries. refactored MockAdapter as a...
Edward F. Long, Jr authored
44 def move(self, list_):
1b329bf fixed typo in location header, updated documentation.
Edward F. Long, Jr authored
45 """Invoke the API method to MOVE an entry resource to a
5323394 added support for move operation on entries. refactored MockAdapter as a...
Edward F. Long, Jr authored
46 different List.
47
1b329bf fixed typo in location header, updated documentation.
Edward F. Long, Jr authored
48 Note: Not all entry resources are eligible to be moved, please
49 refer to the AWeber API Reference Documentation at
50 https://labs.aweber.com/docs/reference/1.0 for more
51 details on which entry resources may be moved and if there
52 are any requirements for moving that resource.
5323394 added support for move operation on entries. refactored MockAdapter as a...
Edward F. Long, Jr authored
53 """
54 params = {'ws.op': 'move',
55 'list_link': list_.self_link}
1a9ca16 updated code to properly initiate the move request.
Edward F. Long, Jr authored
56 response = self.adapter.request('POST', self.url, params,
57 response='headers')
5323394 added support for move operation on entries. refactored MockAdapter as a...
Edward F. Long, Jr authored
58 if response['status'] != '201':
59 return False
1b329bf fixed typo in location header, updated documentation.
Edward F. Long, Jr authored
60 new_resource = response['location']
5323394 added support for move operation on entries. refactored MockAdapter as a...
Edward F. Long, Jr authored
61 self._diff = {}
62 self._data = self.adapter.request('GET', new_resource)
63 return True
64
b3a20a0 Added ability to delete and update subscribers
Russ P authored
65 def save(self):
66 response = self.adapter.request('PATCH', self.url, self._diff,
67 response='status')
68 self._diff = {}
69 if str(response)[:2] == '20':
70 return True
71 return False
0a51ea7 Initial commit
Russ P authored
72
73 def get_web_forms(self):
74 self._method_for('account')
75 data = self.adapter.request('GET',
76 "{0}?ws.op=getWebForms".format(self.url))
77 return self._parseNamedOperation(data)
78
79 def _child_collection(self, attr):
80 if not attr in self._child_collections:
81 url = "{0}/{1}".format(self.url, attr)
82 self._child_collections[attr] = self.load_from_url(url)
83 return self._child_collections[attr]
84
85 def __getattr__(self, attr):
86 if attr in self._data:
58ab4f7 Replaced type() == with isinstance, added comments for DataDict
Russ P authored
87 if isinstance(self._data[attr], dict):
b3a20a0 Added ability to delete and update subscribers
Russ P authored
88 return DataDict(self._data[attr], attr, self)
0a51ea7 Initial commit
Russ P authored
89 return self._data[attr]
90 elif attr in self.collections_map[self.type]:
91 return self._child_collection(attr)
92 else:
93 raise AttributeError(attr)
Something went wrong with that request. Please try again.