Skip to content
This repository has been archived by the owner on Feb 13, 2019. It is now read-only.

Commit

Permalink
Merge 2ccd990 into 8028d23
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelButkovic committed Jun 6, 2016
2 parents 8028d23 + 2ccd990 commit b2ffe94
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 13 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Expand Up @@ -2,6 +2,10 @@

## Development

## Version 2.5.1

- Added `FACEBOOK_API_DEVELOPMENT_MODE` and `FACEBOOK_API_PUBLISH_ARTICLE` settings flags for instant article testing

## Version 2.5.0

- Added publishing to Facebook's Instant Article API on Content.save(), if the content feature type supports Instant Artices & the content is published.
Expand Down
2 changes: 1 addition & 1 deletion bulbs/__init__.py
@@ -1 +1 @@
__version__ = "2.5.0"
__version__ = "2.5.1"
2 changes: 1 addition & 1 deletion bulbs/content/models.py
Expand Up @@ -603,7 +603,7 @@ def content_deleted(sender, instance=None, **kwargs):


def delete_from_instant_article_api(sender, instance=None, **kwargs):
if getattr(settings, 'FACEBOOK_API_ENV', '').lower() == 'production':
if getattr(settings, 'FACEBOOK_POST_TO_IA', False):
fb_api_url = getattr(settings, 'FACEBOOK_API_BASE_URL', None)
fb_token_path = getattr(settings, 'FACEBOOK_TOKEN_VAULT_PATH', None)

Expand Down
18 changes: 11 additions & 7 deletions bulbs/content/tasks.py
Expand Up @@ -67,7 +67,7 @@ def update_feature_type_rates(featuretype_pk):
role_id=role.pk)


def post_article(content, body, fb_page_id, fb_api_url, fb_token_path):
def post_article(content, body, fb_page_id, fb_api_url, fb_token_path, fb_dev_mode, fb_publish):
fb_access_token = vault.read(fb_token_path)
from .models import Content

Expand All @@ -77,8 +77,8 @@ def post_article(content, body, fb_page_id, fb_api_url, fb_token_path):
data={
'access_token': fb_access_token,
'html_source': body,
'published': 'true',
'development_mode': 'false'
'published': fb_publish,
'development_mode': fb_dev_mode
})

if not post.ok:
Expand Down Expand Up @@ -160,7 +160,9 @@ def post_to_instant_articles_api(content_pk):
fb_page_id = getattr(settings, 'FACEBOOK_PAGE_ID', None)
fb_api_url = getattr(settings, 'FACEBOOK_API_BASE_URL', None)
fb_token_path = getattr(settings, 'FACEBOOK_TOKEN_VAULT_PATH', None)
environment = getattr(settings, 'FACEBOOK_API_ENV', '').lower()
fb_dev_mode = 'true' if getattr(settings, 'FACEBOOK_API_DEVELOPMENT_MODE', None) else 'false'
fb_publish = 'true' if getattr(settings, 'FACEBOOK_API_PUBLISH_ARTICLE', None) else 'false'
should_post = getattr(settings, 'FACEBOOK_POST_TO_IA', False)

if not fb_page_id or not fb_api_url or not fb_token_path:
logger.error('''
Expand Down Expand Up @@ -193,17 +195,19 @@ def post_to_instant_articles_api(content_pk):
'instant_article/base_instant_article.html', context
)

if environment == 'production':
if should_post:
post_article(
content,
source,
fb_page_id,
fb_api_url,
fb_token_path)
fb_token_path,
fb_dev_mode,
fb_publish)

# if article is being unpublished, delete it from IA API
elif not content.is_published and content.instant_article_id:
if environment == 'production':
if should_post:
delete_article(
content,
fb_api_url,
Expand Down
4 changes: 3 additions & 1 deletion example/settings.py
Expand Up @@ -154,7 +154,9 @@
VIDEOHUB_BASE_URL = 'http://www.onionstudios.com'

FACEBOOK_TOKEN_VAULT_PATH = 'facebook/onion_token'
FACEBOOK_API_ENV = 'development'
FACEBOOK_POST_TO_IA = False
FACEBOOK_PAGE_ID = '123456'
FACEBOOK_API_BASE_URL = 'https://graph.facebook.com/v2.6'
FACEBOOK_API_DEVELOPMENT_MODE = True
FACEBOOK_API_PUBLISH_ARTICLE = False
WWW_URL = "www.theonion.com"
6 changes: 3 additions & 3 deletions tests/instant_articles/test_facebook_api.py
Expand Up @@ -18,7 +18,7 @@ def setUp(self):
self.ft = FeatureType.objects.create(name="NIP", instant_article=True)

@override_settings(
FACEBOOK_API_ENV='production',
FACEBOOK_POST_TO_IA=True,
BETTY_FIXED_URL='http://i.onionstatic.com/onion')
@mock_vault({'facebook/onion_token': 'TOKEN'})
def test_publish(self):
Expand Down Expand Up @@ -53,7 +53,7 @@ def test_publish(self):
self.assertEqual(mocker.call_count, 2)

@override_settings(
FACEBOOK_API_ENV='production',
FACEBOOK_POST_TO_IA=True,
BETTY_FIXED_URL='http://i.onionstatic.com/onion')
@mock_vault({'facebook/onion_token': 'TOKEN'})
def test_unpublish(self):
Expand Down Expand Up @@ -97,7 +97,7 @@ def test_unpublish(self):
self.assertEqual(mocker.call_count, 3)

@override_settings(
FACEBOOK_API_ENV='production',
FACEBOOK_POST_TO_IA=True,
BETTY_FIXED_URL='http://i.onionstatic.com/onion')
@mock_vault({'facebook/onion_token': 'TOKEN'})
def test_delete(self):
Expand Down

0 comments on commit b2ffe94

Please sign in to comment.