Skip to content

Commit

Permalink
Prefix PumpObject.add_link and .add_links with _
Browse files Browse the repository at this point in the history
relates to #61
  • Loading branch information
kabniel committed Oct 3, 2014
1 parent 0c1d6b7 commit dee2dcc
Show file tree
Hide file tree
Showing 9 changed files with 16 additions and 15 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
0.6
===
- PumpObject.add_link and .add_links renamed to ._add_link and ._add_links
- Recipients can now be set for Comment, Person objects
- Recipient properties (.to, .cc, .bto, .bcc) has been moved from Activity to Activity.obj
- Feeds (inbox, followers, etc) can now be sliced by object or object_id.
Expand Down
14 changes: 7 additions & 7 deletions pypump/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,40 +117,40 @@ def __str__(self):
def _striptags(self, html):
return re.sub(r'<[^>]+>', '', html)

def add_link(self, name, link):
def _add_link(self, name, link):
""" Adds a link to the model """

self.links[name] = link
return True

def add_links(self, links, key="href", proxy_key="proxyURL", endpoints=None):
def _add_links(self, links, key="href", proxy_key="proxyURL", endpoints=None):
""" Parses and adds block of links """
if endpoints is None:
endpoints = ["likes", "replies", "shares", "self", "followers",
"following", "lists", "favorites", "members"]

if links.get("links"):
for endpoint in links['links']:
self.add_link(endpoint, links['links'][endpoint]["href"])
self._add_link(endpoint, links['links'][endpoint]["href"])

for endpoint in endpoints:
if links.get(endpoint, None) is None:
continue

if "pump_io" in links[endpoint]:
self.add_link(endpoint, links[endpoint]["pump_io"][proxy_key])
self._add_link(endpoint, links[endpoint]["pump_io"][proxy_key])
elif "url" in links[endpoint]:
self.add_link(endpoint, links[endpoint]["url"])
self._add_link(endpoint, links[endpoint]["url"])
else:
self.add_link(endpoint, links[endpoint][key])
self._add_link(endpoint, links[endpoint][key])

return self.links

def unserialize(self, data):
Mapper(pypump=self._pump).parse_map(self, mapping=PumpObject._mapping,
ignore_attr=PumpObject._ignore_attr,
data=data)
self.add_links(data)
self._add_links(data)
return self

class Mapper(object):
Expand Down
2 changes: 1 addition & 1 deletion pypump/models/activity.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def unserialize(self, data):
data["object"][key] = data[key]

Mapper(pypump=self._pump).parse_map(self, data=data)
self.add_links(data)
self._add_links(data)

return self

2 changes: 1 addition & 1 deletion pypump/models/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def __repr__(self):

def unserialize(self, data):
Mapper(pypump=self._pump).parse_map(self, data=data)
self.add_links(data)
self._add_links(data)
return self


Expand Down
2 changes: 1 addition & 1 deletion pypump/models/comment.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,6 @@ def serialize(self):
def unserialize(self, data):
""" from JSON -> Comment """
Mapper(pypump=self._pump).parse_map(self, data=data)
self.add_links(data)
self._add_links(data)
return self

2 changes: 1 addition & 1 deletion pypump/models/feed.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ def _request(self, url, offset=None, since=None, before=None):

def unserialize(self, data={}):
Mapper(pypump=self._pump).parse_map(self, data=data)
self.add_links(data)
self._add_links(data)
self.url = data.get('pump_io', {}).get('proxyURL') or self.url
return self

Expand Down
2 changes: 1 addition & 1 deletion pypump/models/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,6 @@ def get_fileurl(data):
width=thumbnail.get("width")
))
Mapper(pypump=self._pump).parse_map(self, data=data)
self.add_links(data)
self._add_links(data)

return self
2 changes: 1 addition & 1 deletion pypump/models/note.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,5 +80,5 @@ def __unicode__(self):
def unserialize(self, data):
""" Goes from JSON -> Note object """
Mapper(pypump=self._pump).parse_map(self, data=data)
self.add_links(data)
self._add_links(data)
return self
4 changes: 2 additions & 2 deletions pypump/models/person.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def __init__(self, webfinger=None, summary=None, username=None,
self.image = image #TODO set proper image object
self.location = location #TODO set proper Place object

self.add_link('self', "{0}://{1}/api/user/{2}/profile".format(
self._add_link('self', "{0}://{1}/api/user/{2}/profile".format(
self._pump.protocol, self.server, self.username)
)
try:
Expand Down Expand Up @@ -164,6 +164,6 @@ def unserialize(self, data):
""" Goes from JSON -> Person object """

Mapper(pypump=self._pump).parse_map(self, data=data)
self.add_links(data)
self._add_links(data)

return self

0 comments on commit dee2dcc

Please sign in to comment.