{"action":"created","comment":{"url":"https://api.github.com/repos/edx/edx-platform/pulls/comments/24060677","id":24060677,"diff_hunk":"@@ -0,0 +1,96 @@\n+\"\"\"\n+Views for friends info API\n+\"\"\"\n+\n+from rest_framework import generics, permissions, status\n+from rest_framework.authentication import OAuth2Authentication, SessionAuthentication\n+from rest_framework.response import Response\n+from openedx.core.djangoapps.user_api.api.profile import preference_info\n+from opaque_keys.edx.locations import SlashSeparatedCourseKey\n+from social.apps.django_app.default.models import UserSocialAuth\n+from student.models import CourseEnrollment\n+import serializers\n+import urllib2\n+import json\n+import facebook\n+\n+# TODO: change this to final config\n+from ..settings import FB_SETTINGS\n+_FACEBOOK_API_VERSION = FB_SETTINGS['_FACEBOOK_API_VERSION']\n+\n+\n+class FriendsInCourse(generics.ListAPIView):\n+    \"\"\"\n+    **Use Case**\n+\n+        API endpoint that returns all the users friends that are in the course specified.\n+        Note that only friends that allow their courses to be shared will be included.\n+\n+    **Example request**:\n+\n+        GET /api/mobile/v0.5/friends/course/<course_id>\n+\n+        where course_id is in the form of /edX/DemoX/Demo_Course\n+\n+    **Response Values**\n+\n+        {   \"friends\":\n+                [{\n+                    \"name\": \"test\",\n+                    \"id\": \"12345\",\n+                    \"edX_id\": \"678910\"\n+                },\n+                ...\n+                ]\n+            }\n+    \"\"\"\n+    authentication_classes = (OAuth2Authentication, SessionAuthentication)\n+    permission_classes = (permissions.IsAuthenticated,)\n+    serializer_class = serializers.FriendsInCourseSerializer\n+\n+    def list(self, request, *args, **kwargs):\n+        serializer = self.get_serializer(data=request.GET, files=request.FILES)\n+        if serializer.is_valid():\n+            # Get all the users FB friends\n+            graph = facebook.GraphAPI(serializer.object['oauth_token'])\n+            url = _FACEBOOK_API_VERSION + \"me/friends\"\n+            friends = graph.request(url)\n+            data = self.get_pagination(friends)\n+            # For each friend check if they are a linked edX user\n+            friends_that_are_edX_users = []\n+            for friend in data:\n+                query_set = UserSocialAuth.objects.filter(uid=unicode(friend['id']))\n+                if query_set.count() == 1: \n+                    friend['edX_id'] = query_set[0].user_id\n+                    friend['edX_username'] = query_set[0].user.username\n+                    friends_that_are_edX_users.append(friend)\n+            # Filter by sharing preferences\n+            friends_that_are_edX_users_with_sharing = [friend for friend in friends_that_are_edX_users if self.sharing_pref_true(friend)]\n+            if ('course_id' in kwargs) and len(kwargs['course_id'].split('/')) == 3:","path":"lms/djangoapps/mobile_api/friends/views.py","position":null,"original_position":69,"commit_id":"d28f70aa8c21c97be51efa9797547f9a0b0b6664","original_commit_id":"6e0b67eb8dbe708c4e556bef9023415249c95d7c","user":{"login":"nasthagiri","id":6772826,"avatar_url":"https://avatars.githubusercontent.com/u/6772826?v=3","gravatar_id":"","url":"https://api.github.com/users/nasthagiri","html_url":"https://github.com/nasthagiri","followers_url":"https://api.github.com/users/nasthagiri/followers","following_url":"https://api.github.com/users/nasthagiri/following{/other_user}","gists_url":"https://api.github.com/users/nasthagiri/gists{/gist_id}","starred_url":"https://api.github.com/users/nasthagiri/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nasthagiri/subscriptions","organizations_url":"https://api.github.com/users/nasthagiri/orgs","repos_url":"https://api.github.com/users/nasthagiri/repos","events_url":"https://api.github.com/users/nasthagiri/events{/privacy}","received_events_url":"https://api.github.com/users/nasthagiri/received_events","type":"User","site_admin":false},"body":"understood.  thanks for the clarification.","created_at":"2015-02-04T03:29:06Z","updated_at":"2015-02-04T03:29:06Z","html_url":"https://github.com/edx/edx-platform/pull/6788#discussion_r24060677","pull_request_url":"https://api.github.com/repos/edx/edx-platform/pulls/6788","_links":{"self":{"href":"https://api.github.com/repos/edx/edx-platform/pulls/comments/24060677"},"html":{"href":"https://github.com/edx/edx-platform/pull/6788#discussion_r24060677"},"pull_request":{"href":"https://api.github.com/repos/edx/edx-platform/pulls/6788"}}},"pull_request":{"url":"https://api.github.com/repos/edx/edx-platform/pulls/6788","id":28155541,"html_url":"https://github.com/edx/edx-platform/pull/6788","diff_url":"https://github.com/edx/edx-platform/pull/6788.diff","patch_url":"https://github.com/edx/edx-platform/pull/6788.patch","issue_url":"https://api.github.com/repos/edx/edx-platform/issues/6788","number":6788,"state":"open","locked":false,"title":"Bnotions API final PR","user":{"login":"DanielEidan","id":2848363,"avatar_url":"https://avatars.githubusercontent.com/u/2848363?v=3","gravatar_id":"","url":"https://api.github.com/users/DanielEidan","html_url":"https://github.com/DanielEidan","followers_url":"https://api.github.com/users/DanielEidan/followers","following_url":"https://api.github.com/users/DanielEidan/following{/other_user}","gists_url":"https://api.github.com/users/DanielEidan/gists{/gist_id}","starred_url":"https://api.github.com/users/DanielEidan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/DanielEidan/subscriptions","organizations_url":"https://api.github.com/users/DanielEidan/orgs","repos_url":"https://api.github.com/users/DanielEidan/repos","events_url":"https://api.github.com/users/DanielEidan/events{/privacy}","received_events_url":"https://api.github.com/users/DanielEidan/received_events","type":"User","site_admin":false},"body":"Bnotions API implementation\r\n------------------\r\n\r\n1. API endpoint for retrieving all the courses that a users friends are in.Note that only friends that allow their courses to be shared will be included.\r\n\r\n    **Example request**:\r\n    \r\n        GET /api/mobile/v0.5/social/facebook/courses/friends\r\n\r\n        where course_id is in the form of /edX/DemoX/Demo_Course\r\n\r\n    **Response Values**\r\n\r\n       See UserCourseEnrollmentsList in lms/djangoapps/mobile_api/users for the structure of the response values.\r\n\r\n\r\n2.API endpoint that returns all the users friends that are in the course specified.Note that only friends that allow their courses to be shared will be included.\r\n\r\n**Example request**:\r\n            \r\n        GET /api/mobile/v0.5/social/facebook/friends/course/<course_id>\r\n\r\n**Response Values**\r\n\r\n                {   \"friends\":\r\n                [{\r\n                    \"name\": \"test\",\r\n                    \"id\": \"12345\",\r\n                    \"edX_id\": \"678910\"\r\n                },\r\n                ...\r\n                ]\r\n            }\r\n                                    \r\n\r\n3.An API to Create or Delete course groups.\r\n\r\n\r\n**Creation Example request**:\r\n\r\n        POST /api/mobile/v0.5/social/facebook/groups/<group_id>\r\n\r\n        Parameters:  name : string,\r\n                    description : string,\r\n                    privacy : open/closed\r\n\r\n**Creation Response Values**\r\n\r\n    {\"group-id\": group_id}\r\n\r\n\r\n4.An API to Invite and Remove members to a group\r\n\r\n\r\n**Invite Example request**:\r\n\r\n        POST /api/mobile/v0.5/social/facebook/groups/<group_id>/member/<member_id>\r\n\r\n\r\n**Invite Response Values**\r\n\r\n    {\"member_id\" : success/error_message}       A response with each member_id and whether or not\r\n                                        the member was added successfully. If the member was\r\n                                        not added successfully the Facebook error message is provided.\r\n                                        \r\n**Remove Example request**:\r\n\r\n        DELETE /api/mobile/v0.5/social/facebook/groups/<group_id>/member/<member_id>\r\n\r\n**Remove Response Values**\r\n\r\n        {\"success\" : \"true\"}                                   \r\n\r\n\r\n5.An API to retrieve or update the users social sharing settings\r\n\r\n**GET Example request**:\r\n\r\n        GET /api/mobile/v0.5/settings/preferences/\r\n\r\n**GET Response Values**\r\n\r\n        {'share_with_facebook_friends': 'True'}\r\n\r\n**POST Example request**:\r\n\r\n        POST /api/mobile/v0.5/settings/preferences/\r\n\r\n        paramters: share_with_facebook_friends : True\r\n\r\n**POST Response Values**\r\n\r\n        {'share_with_facebook_friends': 'True'}\r\n       \r\n\r\n        \r\n        \r\n        \r\n        \r\n        \r\n        \r\n        \r\n        ","created_at":"2015-01-27T23:39:07Z","updated_at":"2015-02-04T03:29:06Z","closed_at":null,"merged_at":null,"merge_commit_sha":"d310db53466cbc3a83deaff1aec08dce308c882e","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/edx/edx-platform/pulls/6788/commits","review_comments_url":"https://api.github.com/repos/edx/edx-platform/pulls/6788/comments","review_comment_url":"https://api.github.com/repos/edx/edx-platform/pulls/comments/{number}","comments_url":"https://api.github.com/repos/edx/edx-platform/issues/6788/comments","statuses_url":"https://api.github.com/repos/edx/edx-platform/statuses/d28f70aa8c21c97be51efa9797547f9a0b0b6664","head":{"label":"BNOTIONS:master","ref":"master","sha":"d28f70aa8c21c97be51efa9797547f9a0b0b6664","user":{"login":"BNOTIONS","id":721286,"avatar_url":"https://avatars.githubusercontent.com/u/721286?v=3","gravatar_id":"","url":"https://api.github.com/users/BNOTIONS","html_url":"https://github.com/BNOTIONS","followers_url":"https://api.github.com/users/BNOTIONS/followers","following_url":"https://api.github.com/users/BNOTIONS/following{/other_user}","gists_url":"https://api.github.com/users/BNOTIONS/gists{/gist_id}","starred_url":"https://api.github.com/users/BNOTIONS/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/BNOTIONS/subscriptions","organizations_url":"https://api.github.com/users/BNOTIONS/orgs","repos_url":"https://api.github.com/users/BNOTIONS/repos","events_url":"https://api.github.com/users/BNOTIONS/events{/privacy}","received_events_url":"https://api.github.com/users/BNOTIONS/received_events","type":"Organization","site_admin":false},"repo":{"id":26233019,"name":"edx-001-platform","full_name":"BNOTIONS/edx-001-platform","owner":{"login":"BNOTIONS","id":721286,"avatar_url":"https://avatars.githubusercontent.com/u/721286?v=3","gravatar_id":"","url":"https://api.github.com/users/BNOTIONS","html_url":"https://github.com/BNOTIONS","followers_url":"https://api.github.com/users/BNOTIONS/followers","following_url":"https://api.github.com/users/BNOTIONS/following{/other_user}","gists_url":"https://api.github.com/users/BNOTIONS/gists{/gist_id}","starred_url":"https://api.github.com/users/BNOTIONS/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/BNOTIONS/subscriptions","organizations_url":"https://api.github.com/users/BNOTIONS/orgs","repos_url":"https://api.github.com/users/BNOTIONS/repos","events_url":"https://api.github.com/users/BNOTIONS/events{/privacy}","received_events_url":"https://api.github.com/users/BNOTIONS/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/BNOTIONS/edx-001-platform","description":"Open edX, the edX platform that powers http://edx.org","fork":true,"url":"https://api.github.com/repos/BNOTIONS/edx-001-platform","forks_url":"https://api.github.com/repos/BNOTIONS/edx-001-platform/forks","keys_url":"https://api.github.com/repos/BNOTIONS/edx-001-platform/keys{/key_id}","collaborators_url":"https://api.github.com/repos/BNOTIONS/edx-001-platform/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/BNOTIONS/edx-001-platform/teams","hooks_url":"https://api.github.com/repos/BNOTIONS/edx-001-platform/hooks","issue_events_url":"https://api.github.com/repos/BNOTIONS/edx-001-platform/issues/events{/number}","events_url":"https://api.github.com/repos/BNOTIONS/edx-001-platform/events","assignees_url":"https://api.github.com/repos/BNOTIONS/edx-001-platform/assignees{/user}","branches_url":"https://api.github.com/repos/BNOTIONS/edx-001-platform/branches{/branch}","tags_url":"https://api.github.com/repos/BNOTIONS/edx-001-platform/tags","blobs_url":"https://api.github.com/repos/BNOTIONS/edx-001-platform/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/BNOTIONS/edx-001-platform/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/BNOTIONS/edx-001-platform/git/refs{/sha}","trees_url":"https://api.github.com/repos/BNOTIONS/edx-001-platform/git/trees{/sha}","statuses_url":"https://api.github.com/repos/BNOTIONS/edx-001-platform/statuses/{sha}","languages_url":"https://api.github.com/repos/BNOTIONS/edx-001-platform/languages","stargazers_url":"https://api.github.com/repos/BNOTIONS/edx-001-platform/stargazers","contributors_url":"https://api.github.com/repos/BNOTIONS/edx-001-platform/contributors","subscribers_url":"https://api.github.com/repos/BNOTIONS/edx-001-platform/subscribers","subscription_url":"https://api.github.com/repos/BNOTIONS/edx-001-platform/subscription","commits_url":"https://api.github.com/repos/BNOTIONS/edx-001-platform/commits{/sha}","git_commits_url":"https://api.github.com/repos/BNOTIONS/edx-001-platform/git/commits{/sha}","comments_url":"https://api.github.com/repos/BNOTIONS/edx-001-platform/comments{/number}","issue_comment_url":"https://api.github.com/repos/BNOTIONS/edx-001-platform/issues/comments/{number}","contents_url":"https://api.github.com/repos/BNOTIONS/edx-001-platform/contents/{+path}","compare_url":"https://api.github.com/repos/BNOTIONS/edx-001-platform/compare/{base}...{head}","merges_url":"https://api.github.com/repos/BNOTIONS/edx-001-platform/merges","archive_url":"https://api.github.com/repos/BNOTIONS/edx-001-platform/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/BNOTIONS/edx-001-platform/downloads","issues_url":"https://api.github.com/repos/BNOTIONS/edx-001-platform/issues{/number}","pulls_url":"https://api.github.com/repos/BNOTIONS/edx-001-platform/pulls{/number}","milestones_url":"https://api.github.com/repos/BNOTIONS/edx-001-platform/milestones{/number}","notifications_url":"https://api.github.com/repos/BNOTIONS/edx-001-platform/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/BNOTIONS/edx-001-platform/labels{/name}","releases_url":"https://api.github.com/repos/BNOTIONS/edx-001-platform/releases{/id}","created_at":"2014-11-05T18:19:37Z","updated_at":"2015-02-03T21:40:38Z","pushed_at":"2015-02-03T21:40:37Z","git_url":"git://github.com/BNOTIONS/edx-001-platform.git","ssh_url":"git@github.com:BNOTIONS/edx-001-platform.git","clone_url":"https://github.com/BNOTIONS/edx-001-platform.git","svn_url":"https://github.com/BNOTIONS/edx-001-platform","homepage":"http://openedx.org/","size":390043,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"edx:master","ref":"master","sha":"19f676a8d710fb9ca4efa48f21d99e82153e6def","user":{"login":"edx","id":3179841,"avatar_url":"https://avatars.githubusercontent.com/u/3179841?v=3","gravatar_id":"","url":"https://api.github.com/users/edx","html_url":"https://github.com/edx","followers_url":"https://api.github.com/users/edx/followers","following_url":"https://api.github.com/users/edx/following{/other_user}","gists_url":"https://api.github.com/users/edx/gists{/gist_id}","starred_url":"https://api.github.com/users/edx/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/edx/subscriptions","organizations_url":"https://api.github.com/users/edx/orgs","repos_url":"https://api.github.com/users/edx/repos","events_url":"https://api.github.com/users/edx/events{/privacy}","received_events_url":"https://api.github.com/users/edx/received_events","type":"Organization","site_admin":false},"repo":{"id":10391073,"name":"edx-platform","full_name":"edx/edx-platform","owner":{"login":"edx","id":3179841,"avatar_url":"https://avatars.githubusercontent.com/u/3179841?v=3","gravatar_id":"","url":"https://api.github.com/users/edx","html_url":"https://github.com/edx","followers_url":"https://api.github.com/users/edx/followers","following_url":"https://api.github.com/users/edx/following{/other_user}","gists_url":"https://api.github.com/users/edx/gists{/gist_id}","starred_url":"https://api.github.com/users/edx/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/edx/subscriptions","organizations_url":"https://api.github.com/users/edx/orgs","repos_url":"https://api.github.com/users/edx/repos","events_url":"https://api.github.com/users/edx/events{/privacy}","received_events_url":"https://api.github.com/users/edx/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/edx/edx-platform","description":"Open edX, the edX platform that powers http://edx.org","fork":false,"url":"https://api.github.com/repos/edx/edx-platform","forks_url":"https://api.github.com/repos/edx/edx-platform/forks","keys_url":"https://api.github.com/repos/edx/edx-platform/keys{/key_id}","collaborators_url":"https://api.github.com/repos/edx/edx-platform/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/edx/edx-platform/teams","hooks_url":"https://api.github.com/repos/edx/edx-platform/hooks","issue_events_url":"https://api.github.com/repos/edx/edx-platform/issues/events{/number}","events_url":"https://api.github.com/repos/edx/edx-platform/events","assignees_url":"https://api.github.com/repos/edx/edx-platform/assignees{/user}","branches_url":"https://api.github.com/repos/edx/edx-platform/branches{/branch}","tags_url":"https://api.github.com/repos/edx/edx-platform/tags","blobs_url":"https://api.github.com/repos/edx/edx-platform/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/edx/edx-platform/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/edx/edx-platform/git/refs{/sha}","trees_url":"https://api.github.com/repos/edx/edx-platform/git/trees{/sha}","statuses_url":"https://api.github.com/repos/edx/edx-platform/statuses/{sha}","languages_url":"https://api.github.com/repos/edx/edx-platform/languages","stargazers_url":"https://api.github.com/repos/edx/edx-platform/stargazers","contributors_url":"https://api.github.com/repos/edx/edx-platform/contributors","subscribers_url":"https://api.github.com/repos/edx/edx-platform/subscribers","subscription_url":"https://api.github.com/repos/edx/edx-platform/subscription","commits_url":"https://api.github.com/repos/edx/edx-platform/commits{/sha}","git_commits_url":"https://api.github.com/repos/edx/edx-platform/git/commits{/sha}","comments_url":"https://api.github.com/repos/edx/edx-platform/comments{/number}","issue_comment_url":"https://api.github.com/repos/edx/edx-platform/issues/comments/{number}","contents_url":"https://api.github.com/repos/edx/edx-platform/contents/{+path}","compare_url":"https://api.github.com/repos/edx/edx-platform/compare/{base}...{head}","merges_url":"https://api.github.com/repos/edx/edx-platform/merges","archive_url":"https://api.github.com/repos/edx/edx-platform/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/edx/edx-platform/downloads","issues_url":"https://api.github.com/repos/edx/edx-platform/issues{/number}","pulls_url":"https://api.github.com/repos/edx/edx-platform/pulls{/number}","milestones_url":"https://api.github.com/repos/edx/edx-platform/milestones{/number}","notifications_url":"https://api.github.com/repos/edx/edx-platform/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/edx/edx-platform/labels{/name}","releases_url":"https://api.github.com/repos/edx/edx-platform/releases{/id}","created_at":"2013-05-30T20:20:38Z","updated_at":"2015-02-03T21:03:19Z","pushed_at":"2015-02-04T02:41:08Z","git_url":"git://github.com/edx/edx-platform.git","ssh_url":"git@github.com:edx/edx-platform.git","clone_url":"https://github.com/edx/edx-platform.git","svn_url":"https://github.com/edx/edx-platform","homepage":"http://openedx.org/","size":1582008,"stargazers_count":1723,"watchers_count":1723,"language":"Python","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":980,"mirror_url":null,"open_issues_count":141,"forks":980,"open_issues":141,"watchers":1723,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/edx/edx-platform/pulls/6788"},"html":{"href":"https://github.com/edx/edx-platform/pull/6788"},"issue":{"href":"https://api.github.com/repos/edx/edx-platform/issues/6788"},"comments":{"href":"https://api.github.com/repos/edx/edx-platform/issues/6788/comments"},"review_comments":{"href":"https://api.github.com/repos/edx/edx-platform/pulls/6788/comments"},"review_comment":{"href":"https://api.github.com/repos/edx/edx-platform/pulls/comments/{number}"},"commits":{"href":"https://api.github.com/repos/edx/edx-platform/pulls/6788/commits"},"statuses":{"href":"https://api.github.com/repos/edx/edx-platform/statuses/d28f70aa8c21c97be51efa9797547f9a0b0b6664"}}}}