# Path: yak/rest_social_auth/backends/base.py
# class ExtraDataAbstractMixin(object, metaclass=abc.ABCMeta):
#     """
#     Ensure that backends define these methods. Used in pipeline to save extra data on the user model.
#     """
# 
#     @abc.abstractmethod
#     def save_extra_data(response, user):
#         return
# 
#     @abc.abstractmethod
#     def get_profile_image(strategy, details, response, uid, user, social, is_new=False, *args, **kwargs):
#         return
# 
# class ExtraActionsAbstractMixin(object, metaclass=abc.ABCMeta):
# 
#     @abc.abstractmethod
#     def post(user_social_auth, social_obj):
#         return
# 
#     @abc.abstractmethod
#     def get_friends(user_social_auth):
#         return
# 
# Path: yak/settings.py
# def perform_import(val, setting_name):
#     def __getattr__(self, attr):
# class YAKAPISettings(APISettings):
# USER_SETTINGS = getattr(settings, 'YAK', None)
# DEFAULTS = {
#     'USER_APP_LABEL': 'test_app',
#     'USER_MODEL': 'user',
#     'USER_SERIALIZER': "test_app.api.serializers.UserSerializer",
#     'API_SCHEMA': 'api-schema-1.0.json',
#     'SOCIAL_MODEL': "test_app.models.Post",
#     'ALLOW_EMAIL': True,
#     'ALLOW_PUSH': True,
#     'EMAIL_NOTIFICATION_SUBJECT': 'Test Project Notification',
#     'PUSHWOOSH_AUTH_TOKEN': "",
#     'PUSHWOOSH_APP_CODE': "",
#     'PUSH_NOTIFICATION_HANDLER': "yak.rest_notifications.utils.send_pushwoosh_notification",
#     'SOCIAL_SHARE_DELAY': 60,
#     'USE_FACEBOOK_OG': False,
#     'FACEBOOK_OG_NAMESPACE': "",
#     'SERIALIZER_MAPPING': {},
#     'FLAKE8_CONFIG': None,
# }
# IMPORT_STRINGS = (
#     "USER_SERIALIZER",
#     "SOCIAL_MODEL",
#     "SERIALIZER_MAPPING",
# )


from django.contrib.auth import get_user_model
from social_core.backends.facebook import FacebookOAuth2
from yak.rest_social_auth.backends.base import ExtraDataAbstractMixin, ExtraActionsAbstractMixin
from yak.settings import yak_settings
import facebook
    @staticmethod
    def save_extra_data(response, user):
        if 'email' in response:
            user.email = response['email']

        # TODO: better placement of Location model. What do we do with Twitter or other locations?
        # if 'location' in response:
        #     if not user.location:
        #         Location.objects.create(name=response["location"]["name"], facebook_id=response["location"]["id"])
        #     else:
        #         location = user.location
        #         location.name = response['location']['name']
        #         location.facebook_id = response['location']['id']

        if 'bio' in response:
            user.about = response['bio']

        user.save()

    @staticmethod
    def get_profile_image(strategy, details, response, uid, user, social, is_new=False, *args, **kwargs):
        image_url = "https://graph.facebook.com/{}/picture?width=1000&height=1000".format(uid)
        return image_url

    @staticmethod
    def post(user_social_auth, social_obj):
        graph = facebook.GraphAPI(user_social_auth.extra_data['access_token'])

        if yak_settings.USE_FACEBOOK_OG:
            og_info = social_obj.facebook_og_info()

# Path: yak/rest_social_auth/backends/base.py
# class ExtraDataAbstractMixin(object, metaclass=abc.ABCMeta):
#     """
#     Ensure that backends define these methods. Used in pipeline to save extra data on the user model.
#     """
# 
#     @abc.abstractmethod
#     def save_extra_data(response, user):
#         return
# 
#     @abc.abstractmethod
#     def get_profile_image(strategy, details, response, uid, user, social, is_new=False, *args, **kwargs):
#         return
# 
# class ExtraActionsAbstractMixin(object, metaclass=abc.ABCMeta):
# 
#     @abc.abstractmethod
#     def post(user_social_auth, social_obj):
#         return
# 
#     @abc.abstractmethod
#     def get_friends(user_social_auth):
#         return
# 
# Path: yak/settings.py
# def perform_import(val, setting_name):
#     def __getattr__(self, attr):
# class YAKAPISettings(APISettings):
# USER_SETTINGS = getattr(settings, 'YAK', None)
# DEFAULTS = {
#     'USER_APP_LABEL': 'test_app',
#     'USER_MODEL': 'user',
#     'USER_SERIALIZER': "test_app.api.serializers.UserSerializer",
#     'API_SCHEMA': 'api-schema-1.0.json',
#     'SOCIAL_MODEL': "test_app.models.Post",
#     'ALLOW_EMAIL': True,
#     'ALLOW_PUSH': True,
#     'EMAIL_NOTIFICATION_SUBJECT': 'Test Project Notification',
#     'PUSHWOOSH_AUTH_TOKEN': "",
#     'PUSHWOOSH_APP_CODE': "",
#     'PUSH_NOTIFICATION_HANDLER': "yak.rest_notifications.utils.send_pushwoosh_notification",
#     'SOCIAL_SHARE_DELAY': 60,
#     'USE_FACEBOOK_OG': False,
#     'FACEBOOK_OG_NAMESPACE': "",
#     'SERIALIZER_MAPPING': {},
#     'FLAKE8_CONFIG': None,
# }
# IMPORT_STRINGS = (
#     "USER_SERIALIZER",
#     "SOCIAL_MODEL",
#     "SERIALIZER_MAPPING",
# )


# Path: yak/rest_social_auth/backends/yak_facebook.py
from django.contrib.auth import get_user_model
from social_core.backends.facebook import FacebookOAuth2
from yak.rest_social_auth.backends.base import ExtraDataAbstractMixin, ExtraActionsAbstractMixin
from yak.settings import yak_settings
import facebook

    @staticmethod
    def save_extra_data(response, user):
        if 'email' in response:
            user.email = response['email']

        # TODO: better placement of Location model. What do we do with Twitter or other locations?
        # if 'location' in response:
        #     if not user.location:
        #         Location.objects.create(name=response["location"]["name"], facebook_id=response["location"]["id"])
        #     else:
        #         location = user.location
        #         location.name = response['location']['name']
        #         location.facebook_id = response['location']['id']

        if 'bio' in response:
            user.about = response['bio']

        user.save()

    @staticmethod
    def get_profile_image(strategy, details, response, uid, user, social, is_new=False, *args, **kwargs):
        image_url = "https://graph.facebook.com/{}/picture?width=1000&height=1000".format(uid)
        return image_url

    @staticmethod
    def post(user_social_auth, social_obj):
        graph = facebook.GraphAPI(user_social_auth.extra_data['access_token'])

        if yak_settings.USE_FACEBOOK_OG:
            og_info = social_obj.facebook_og_info()

            action_name = "{}:{}".format(yak_settings.FACEBOOK_OG_NAMESPACE, og_info['action'])