Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def preview_create(self, obj, include_link=gr_source.OMIT_LINK,
ignore_formatting=False):
if obj.get('verb') == 'like':
return gr_source.creation_result(
abort=True, error_plain='Cannot publish likes',
error_html='Cannot publish likes')
content = self._content_for_create(obj, ignore_formatting=ignore_formatting)
if include_link == gr_source.INCLUDE_LINK:
content += ' - %s' % obj['url']
content = 'preview of ' + content
images = self._images(obj)
if images:
content += ' with images %s' % ','.join(images)
def create(self, obj, include_link=gr_source.OMIT_LINK,
ignore_formatting=False):
verb = obj.get('verb')
type = obj.get('objectType')
if verb == 'like':
return gr_source.creation_result(
abort=True, error_plain='Cannot publish likes',
error_html='Cannot publish likes')
if 'content' not in obj:
return gr_source.creation_result(
abort=False, error_plain='No content',
error_html='No content')
if type == 'comment':
base_url = self.base_object(obj).get('url')
if not base_url:
return gr_source.creation_result(
def _create(self, obj, preview=None, include_link=source.OMIT_LINK,
ignore_formatting=False):
"""Creates a new post, comment, like, or RSVP.
https://developers.facebook.com/docs/graph-api/reference/user/feed#publish
https://developers.facebook.com/docs/graph-api/reference/object/comments#publish
https://developers.facebook.com/docs/graph-api/reference/object/likes#publish
https://developers.facebook.com/docs/graph-api/reference/event#attending
Args:
obj: ActivityStreams object
preview: boolean
include_link: string
ignore_formatting: boolean
Returns:
a CreationResult
def include_link(self, item):
val = self.request.get('bridgy_omit_link', None)
if val is None:
# _run has already parsed and validated the target URL
vals = urllib.parse.parse_qs(urllib.parse.urlparse(self.target_url()).query)\
.get('bridgy_omit_link')
val = vals[0] if vals else None
if val is None:
vals = item.get('properties', {}).get('bridgy-omit-link')
val = vals[0] if vals else None
result = (gr_source.INCLUDE_LINK if val is None or val.lower() == 'false'
else gr_source.INCLUDE_IF_TRUNCATED if val.lower() == 'maybe'
else gr_source.OMIT_LINK)
return result
def _create(self, obj, include_link=source.OMIT_LINK, preview=None,
ignore_formatting=False):
"""Creates a new comment or like.
The OAuth access token must have been created with scope=comments+likes (or
just one, respectively).
http://instagram.com/developer/authentication/#scope
To comment, you need to apply for access:
https://docs.google.com/spreadsheet/viewform?formkey=dFNydmNsUUlEUGdySWFWbGpQczdmWnc6MQ
http://instagram.com/developer/endpoints/comments/#post_media_comments
http://instagram.com/developer/endpoints/likes/#post_likes
Args:
obj: ActivityStreams object
include_link: string
def preview_create(self, obj, include_link=source.OMIT_LINK,
ignore_formatting=False):
"""Previews creating an issue or comment.
Args:
obj: ActivityStreams object
include_link: string
ignore_formatting: boolean
Returns:
a CreationResult whose contents will be a unicode string HTML snippet
or None
"""
return self._create(obj, preview=True, include_link=include_link,
ignore_formatting=ignore_formatting)
def _create(self, obj, preview=None, include_link=source.OMIT_LINK,
ignore_formatting=False):
"""Creates or previews creating a tweet, reply tweet, retweet, or favorite.
https://dev.twitter.com/docs/api/1.1/post/statuses/update
https://dev.twitter.com/docs/api/1.1/post/statuses/retweet/:id
https://dev.twitter.com/docs/api/1.1/post/favorites/create
Args:
obj: ActivityStreams object
preview: boolean
include_link: string
ignore_formatting: boolean
Returns:
a CreationResult
def create(self, obj, include_link=source.OMIT_LINK,
ignore_formatting=False):
"""Creates a photo, comment, or favorite.
Args:
obj: ActivityStreams object
include_link: string
ignore_formatting: boolean
Returns:
a CreationResult whose content will be a dict with 'id', 'url',
and 'type' keys (all optional) for the newly created Flickr
object (or None)
"""
return self._create(obj, preview=False, include_link=include_link,
ignore_formatting=ignore_formatting)
def include_link(self, item):
val = self.request.get('bridgy_omit_link', None)
if val is None:
# _run has already parsed and validated the target URL
vals = urlparse.parse_qs(urlparse.urlparse(self.target_url()).query)\
.get('bridgy_omit_link')
val = vals[0] if vals else None
if val is None:
vals = item.get('properties', {}).get('bridgy-omit-link')
val = vals[0] if vals else None
result = (gr_source.INCLUDE_LINK if val is None or val.lower() == 'false'
else gr_source.INCLUDE_IF_TRUNCATED if val.lower() == 'maybe'
else gr_source.OMIT_LINK)
return result