{"action":"created","comment":{"url":"https://api.github.com/repos/iic-ninjas/PSix-iOS/pulls/comments/28760319","id":28760319,"diff_hunk":"@@ -12,32 +12,61 @@ import Parse\n \n class FacebookService {\n     \n-    private static let FB_EVENT_ATTRIBUTES = \"cover,name,id,start_time,description\"\n+    private static let FB_EVENT_ATTRIBUTES = [\n+        FBReq.Event.ID,\n+        FBReq.Event.NAME,\n+        FBReq.Event.COVER,\n+        FBReq.Event.START_TIME,\n+        FBReq.Event.DESCRIPTION\n+    ]\n     \n     static func getLoggedInUserId(callback: (fbId: String) -> ()) {\n-        if FBSDKAccessToken.currentAccessToken() != nil {\n-            FBSDKGraphRequest(graphPath: \"me\", parameters: [\"fields\": \"id\"]).startWithCompletionHandler() {\n-                (connection, result, error) -> Void in\n-                if let fbId = result[\"id\"] as? String {\n-                    callback(fbId: fbId)\n+        FBUserRequest(fbId: FBReq.User.ME).about([FBReq.User.ID]).execute() { (response) -> Void in\n+            if let fbId = response[FBReq.User.ID] as? String {\n+                callback(fbId: fbId)\n+            }\n+        }\n+    }\n+    \n+    private static func nowAsEpoch() -> Int {\n+        return Int(NSDate.timeIntervalSinceReferenceDate() + NSTimeIntervalSince1970)\n+    }\n+    \n+    private static func extractEventsFromResponse(response: FBResponse, previousEvents: Events = Events(), onCompletionCB: (Events) -> ()) {\n+        println(\"Starting to populate events\")\n+        var events = Events(previousEvents)\n+        if let eventsData = response.data {\n+            for eventData in eventsData {\n+                if let fbId = eventData[FBReq.Event.ID] as? String,\n+                   let currentUser = ParseUserSession.currentUser,\n+                   let name = eventData[\"name\"] as? String {\n+                    \n+                    let event = Event(fbId: fbId, ownerFbId: currentUser.facebookId, name: name)\n+                    event.eventDescription = eventData[FBReq.Event.DESCRIPTION] as? String\n+                    event.location = eventData[FBReq.Event.LOCATION] as? String\n+                    event.saveEventually()\n+                    events.append(event)\n                 }\n             }\n         }\n+        \n+        if let nextReq = response.requestNext() {\n+            nextReq.execute(failure: { (error) -> Void in\n+                println(\"There was an error getting the next page: \\(error)\")\n+                onCompletionCB(events)\n+            }) { (nextResponse) -> Void in\n+                self.extractEventsFromResponse(nextResponse, previousEvents: events, onCompletionCB: onCompletionCB)\n+            }\n+        } else {\n+            onCompletionCB(events)\n+        }\n     }\n     \n-    static func getFutureEventsCreatedByUser(user: User, failure: ((NSError?) -> ())?, success: (result: NSArray) -> ()) {\n-        let params = [\n-            \"fields\": FB_EVENT_ATTRIBUTES,\n-            \"since\":  Int((NSDate.timeIntervalSinceReferenceDate() + NSTimeIntervalSince1970))\n-        ]\n+    static func getFutureEventsCreatedByUser(user: User, callback: (Events) -> ()) {\n         if FBSDKAccessToken.currentAccessToken() != nil {\n-            FBSDKGraphRequest(graphPath: \"\\(user.facebookId)/events/created\", parameters: params as [NSObject : AnyObject]).startWithCompletionHandler() { (connection, result, error) -> Void in\n-                if let eventsData = result as? NSDictionary {\n-                    if let events = eventsData[\"data\"] as? NSArray {\n-                        success(result: events)\n-                    }\n-                } else {\n-                    failure?(error)\n+            FBUserRequest(fbId: user.facebookId).events.created.attributes(FB_EVENT_ATTRIBUTES).since(nowAsEpoch()).execute() { (response) -> Void in","path":"PSix/FacebookService.swift","position":74,"original_position":74,"commit_id":"17578ac90c8016c3ed0732fc5dad5597a9822de7","original_commit_id":"17578ac90c8016c3ed0732fc5dad5597a9822de7","user":{"login":"agelber","id":2394509,"avatar_url":"https://avatars.githubusercontent.com/u/2394509?v=3","gravatar_id":"","url":"https://api.github.com/users/agelber","html_url":"https://github.com/agelber","followers_url":"https://api.github.com/users/agelber/followers","following_url":"https://api.github.com/users/agelber/following{/other_user}","gists_url":"https://api.github.com/users/agelber/gists{/gist_id}","starred_url":"https://api.github.com/users/agelber/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/agelber/subscriptions","organizations_url":"https://api.github.com/users/agelber/orgs","repos_url":"https://api.github.com/users/agelber/repos","events_url":"https://api.github.com/users/agelber/events{/privacy}","received_events_url":"https://api.github.com/users/agelber/received_events","type":"User","site_admin":false},"body":":100: on the api","created_at":"2015-04-21T08:55:10Z","updated_at":"2015-04-21T08:55:10Z","html_url":"https://github.com/iic-ninjas/PSix-iOS/pull/4#discussion_r28760319","pull_request_url":"https://api.github.com/repos/iic-ninjas/PSix-iOS/pulls/4","_links":{"self":{"href":"https://api.github.com/repos/iic-ninjas/PSix-iOS/pulls/comments/28760319"},"html":{"href":"https://github.com/iic-ninjas/PSix-iOS/pull/4#discussion_r28760319"},"pull_request":{"href":"https://api.github.com/repos/iic-ninjas/PSix-iOS/pulls/4"}}},"pull_request":{"url":"https://api.github.com/repos/iic-ninjas/PSix-iOS/pulls/4","id":33738463,"html_url":"https://github.com/iic-ninjas/PSix-iOS/pull/4","diff_url":"https://github.com/iic-ninjas/PSix-iOS/pull/4.diff","patch_url":"https://github.com/iic-ninjas/PSix-iOS/pull/4.patch","issue_url":"https://api.github.com/repos/iic-ninjas/PSix-iOS/issues/4","number":4,"state":"open","locked":false,"title":"Facebook Requests Refactor","user":{"login":"avihut","id":821024,"avatar_url":"https://avatars.githubusercontent.com/u/821024?v=3","gravatar_id":"","url":"https://api.github.com/users/avihut","html_url":"https://github.com/avihut","followers_url":"https://api.github.com/users/avihut/followers","following_url":"https://api.github.com/users/avihut/following{/other_user}","gists_url":"https://api.github.com/users/avihut/gists{/gist_id}","starred_url":"https://api.github.com/users/avihut/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/avihut/subscriptions","organizations_url":"https://api.github.com/users/avihut/orgs","repos_url":"https://api.github.com/users/avihut/repos","events_url":"https://api.github.com/users/avihut/events{/privacy}","received_events_url":"https://api.github.com/users/avihut/received_events","type":"User","site_admin":false},"body":"There are no visual changes. This started as a refactor to simplify the interfaces between the different services and parsers, but grew into something bigger the merits its own pull request.\r\n\r\nI created a chainable Facebook request class that allows for better readability.\r\n\r\nCode like this:\r\n\r\n    let request = FBSDKGraphRequest(graphPath: \"me\", parameters[\"fields\": \"name,id\"])\r\n    request.startWithCompletionHandler() { /* handle response */ }\r\n\r\nTurns into this:\r\n\r\n    FBRequest(forResource: \"me\").addParam(\"fields\", \"name,id\").execute() { /* handle response */ }\r\n\r\nWhich I further simplified by subclassing `FBRequest` with request classes for specific resources:\r\n\r\n    FBUserRequest(fbId: \"me\").attributes([\"name\", \"id\"]).execute() { /* handle response */ }\r\n\r\nThough the biggest change comes to the events request as you'll be able to see in the diff of `FacebookService.swift`\r\n\r\nFurthermore the request execution accepts 2 callback handlers `success` and `failure`. `failure` is given only `NSError?`, and `success` is given an `FBResponse` object. `FBResponse` is wrap around the regular `JSON` response that gives the same basic read interface through `subscript` and also *drumroll* handles paginated requests. Just check if the response has a next page, and it will generate an `FBRequest` for that next page automatically.","created_at":"2015-04-21T08:23:04Z","updated_at":"2015-04-21T08:55:10Z","closed_at":null,"merged_at":null,"merge_commit_sha":"9d5a5f9e9d8a6b7ab35b0c744570f39913b95b41","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/iic-ninjas/PSix-iOS/pulls/4/commits","review_comments_url":"https://api.github.com/repos/iic-ninjas/PSix-iOS/pulls/4/comments","review_comment_url":"https://api.github.com/repos/iic-ninjas/PSix-iOS/pulls/comments{/number}","comments_url":"https://api.github.com/repos/iic-ninjas/PSix-iOS/issues/4/comments","statuses_url":"https://api.github.com/repos/iic-ninjas/PSix-iOS/statuses/17578ac90c8016c3ed0732fc5dad5597a9822de7","head":{"label":"iic-ninjas:FBrequest","ref":"FBrequest","sha":"17578ac90c8016c3ed0732fc5dad5597a9822de7","user":{"login":"iic-ninjas","id":5079491,"avatar_url":"https://avatars.githubusercontent.com/u/5079491?v=3","gravatar_id":"","url":"https://api.github.com/users/iic-ninjas","html_url":"https://github.com/iic-ninjas","followers_url":"https://api.github.com/users/iic-ninjas/followers","following_url":"https://api.github.com/users/iic-ninjas/following{/other_user}","gists_url":"https://api.github.com/users/iic-ninjas/gists{/gist_id}","starred_url":"https://api.github.com/users/iic-ninjas/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/iic-ninjas/subscriptions","organizations_url":"https://api.github.com/users/iic-ninjas/orgs","repos_url":"https://api.github.com/users/iic-ninjas/repos","events_url":"https://api.github.com/users/iic-ninjas/events{/privacy}","received_events_url":"https://api.github.com/users/iic-ninjas/received_events","type":"Organization","site_admin":false},"repo":{"id":33816465,"name":"PSix-iOS","full_name":"iic-ninjas/PSix-iOS","owner":{"login":"iic-ninjas","id":5079491,"avatar_url":"https://avatars.githubusercontent.com/u/5079491?v=3","gravatar_id":"","url":"https://api.github.com/users/iic-ninjas","html_url":"https://github.com/iic-ninjas","followers_url":"https://api.github.com/users/iic-ninjas/followers","following_url":"https://api.github.com/users/iic-ninjas/following{/other_user}","gists_url":"https://api.github.com/users/iic-ninjas/gists{/gist_id}","starred_url":"https://api.github.com/users/iic-ninjas/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/iic-ninjas/subscriptions","organizations_url":"https://api.github.com/users/iic-ninjas/orgs","repos_url":"https://api.github.com/users/iic-ninjas/repos","events_url":"https://api.github.com/users/iic-ninjas/events{/privacy}","received_events_url":"https://api.github.com/users/iic-ninjas/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/iic-ninjas/PSix-iOS","description":"Social payments for Facebook events","fork":false,"url":"https://api.github.com/repos/iic-ninjas/PSix-iOS","forks_url":"https://api.github.com/repos/iic-ninjas/PSix-iOS/forks","keys_url":"https://api.github.com/repos/iic-ninjas/PSix-iOS/keys{/key_id}","collaborators_url":"https://api.github.com/repos/iic-ninjas/PSix-iOS/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/iic-ninjas/PSix-iOS/teams","hooks_url":"https://api.github.com/repos/iic-ninjas/PSix-iOS/hooks","issue_events_url":"https://api.github.com/repos/iic-ninjas/PSix-iOS/issues/events{/number}","events_url":"https://api.github.com/repos/iic-ninjas/PSix-iOS/events","assignees_url":"https://api.github.com/repos/iic-ninjas/PSix-iOS/assignees{/user}","branches_url":"https://api.github.com/repos/iic-ninjas/PSix-iOS/branches{/branch}","tags_url":"https://api.github.com/repos/iic-ninjas/PSix-iOS/tags","blobs_url":"https://api.github.com/repos/iic-ninjas/PSix-iOS/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/iic-ninjas/PSix-iOS/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/iic-ninjas/PSix-iOS/git/refs{/sha}","trees_url":"https://api.github.com/repos/iic-ninjas/PSix-iOS/git/trees{/sha}","statuses_url":"https://api.github.com/repos/iic-ninjas/PSix-iOS/statuses/{sha}","languages_url":"https://api.github.com/repos/iic-ninjas/PSix-iOS/languages","stargazers_url":"https://api.github.com/repos/iic-ninjas/PSix-iOS/stargazers","contributors_url":"https://api.github.com/repos/iic-ninjas/PSix-iOS/contributors","subscribers_url":"https://api.github.com/repos/iic-ninjas/PSix-iOS/subscribers","subscription_url":"https://api.github.com/repos/iic-ninjas/PSix-iOS/subscription","commits_url":"https://api.github.com/repos/iic-ninjas/PSix-iOS/commits{/sha}","git_commits_url":"https://api.github.com/repos/iic-ninjas/PSix-iOS/git/commits{/sha}","comments_url":"https://api.github.com/repos/iic-ninjas/PSix-iOS/comments{/number}","issue_comment_url":"https://api.github.com/repos/iic-ninjas/PSix-iOS/issues/comments{/number}","contents_url":"https://api.github.com/repos/iic-ninjas/PSix-iOS/contents/{+path}","compare_url":"https://api.github.com/repos/iic-ninjas/PSix-iOS/compare/{base}...{head}","merges_url":"https://api.github.com/repos/iic-ninjas/PSix-iOS/merges","archive_url":"https://api.github.com/repos/iic-ninjas/PSix-iOS/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/iic-ninjas/PSix-iOS/downloads","issues_url":"https://api.github.com/repos/iic-ninjas/PSix-iOS/issues{/number}","pulls_url":"https://api.github.com/repos/iic-ninjas/PSix-iOS/pulls{/number}","milestones_url":"https://api.github.com/repos/iic-ninjas/PSix-iOS/milestones{/number}","notifications_url":"https://api.github.com/repos/iic-ninjas/PSix-iOS/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/iic-ninjas/PSix-iOS/labels{/name}","releases_url":"https://api.github.com/repos/iic-ninjas/PSix-iOS/releases{/id}","created_at":"2015-04-12T12:44:37Z","updated_at":"2015-04-15T14:34:32Z","pushed_at":"2015-04-21T08:23:05Z","git_url":"git://github.com/iic-ninjas/PSix-iOS.git","ssh_url":"git@github.com:iic-ninjas/PSix-iOS.git","clone_url":"https://github.com/iic-ninjas/PSix-iOS.git","svn_url":"https://github.com/iic-ninjas/PSix-iOS","homepage":null,"size":11296,"stargazers_count":1,"watchers_count":1,"language":"Swift","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":2,"forks":0,"open_issues":2,"watchers":1,"default_branch":"master"}},"base":{"label":"iic-ninjas:data-model","ref":"data-model","sha":"f1f318dd33675327921ce81bcfbf05e863148571","user":{"login":"iic-ninjas","id":5079491,"avatar_url":"https://avatars.githubusercontent.com/u/5079491?v=3","gravatar_id":"","url":"https://api.github.com/users/iic-ninjas","html_url":"https://github.com/iic-ninjas","followers_url":"https://api.github.com/users/iic-ninjas/followers","following_url":"https://api.github.com/users/iic-ninjas/following{/other_user}","gists_url":"https://api.github.com/users/iic-ninjas/gists{/gist_id}","starred_url":"https://api.github.com/users/iic-ninjas/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/iic-ninjas/subscriptions","organizations_url":"https://api.github.com/users/iic-ninjas/orgs","repos_url":"https://api.github.com/users/iic-ninjas/repos","events_url":"https://api.github.com/users/iic-ninjas/events{/privacy}","received_events_url":"https://api.github.com/users/iic-ninjas/received_events","type":"Organization","site_admin":false},"repo":{"id":33816465,"name":"PSix-iOS","full_name":"iic-ninjas/PSix-iOS","owner":{"login":"iic-ninjas","id":5079491,"avatar_url":"https://avatars.githubusercontent.com/u/5079491?v=3","gravatar_id":"","url":"https://api.github.com/users/iic-ninjas","html_url":"https://github.com/iic-ninjas","followers_url":"https://api.github.com/users/iic-ninjas/followers","following_url":"https://api.github.com/users/iic-ninjas/following{/other_user}","gists_url":"https://api.github.com/users/iic-ninjas/gists{/gist_id}","starred_url":"https://api.github.com/users/iic-ninjas/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/iic-ninjas/subscriptions","organizations_url":"https://api.github.com/users/iic-ninjas/orgs","repos_url":"https://api.github.com/users/iic-ninjas/repos","events_url":"https://api.github.com/users/iic-ninjas/events{/privacy}","received_events_url":"https://api.github.com/users/iic-ninjas/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/iic-ninjas/PSix-iOS","description":"Social payments for Facebook events","fork":false,"url":"https://api.github.com/repos/iic-ninjas/PSix-iOS","forks_url":"https://api.github.com/repos/iic-ninjas/PSix-iOS/forks","keys_url":"https://api.github.com/repos/iic-ninjas/PSix-iOS/keys{/key_id}","collaborators_url":"https://api.github.com/repos/iic-ninjas/PSix-iOS/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/iic-ninjas/PSix-iOS/teams","hooks_url":"https://api.github.com/repos/iic-ninjas/PSix-iOS/hooks","issue_events_url":"https://api.github.com/repos/iic-ninjas/PSix-iOS/issues/events{/number}","events_url":"https://api.github.com/repos/iic-ninjas/PSix-iOS/events","assignees_url":"https://api.github.com/repos/iic-ninjas/PSix-iOS/assignees{/user}","branches_url":"https://api.github.com/repos/iic-ninjas/PSix-iOS/branches{/branch}","tags_url":"https://api.github.com/repos/iic-ninjas/PSix-iOS/tags","blobs_url":"https://api.github.com/repos/iic-ninjas/PSix-iOS/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/iic-ninjas/PSix-iOS/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/iic-ninjas/PSix-iOS/git/refs{/sha}","trees_url":"https://api.github.com/repos/iic-ninjas/PSix-iOS/git/trees{/sha}","statuses_url":"https://api.github.com/repos/iic-ninjas/PSix-iOS/statuses/{sha}","languages_url":"https://api.github.com/repos/iic-ninjas/PSix-iOS/languages","stargazers_url":"https://api.github.com/repos/iic-ninjas/PSix-iOS/stargazers","contributors_url":"https://api.github.com/repos/iic-ninjas/PSix-iOS/contributors","subscribers_url":"https://api.github.com/repos/iic-ninjas/PSix-iOS/subscribers","subscription_url":"https://api.github.com/repos/iic-ninjas/PSix-iOS/subscription","commits_url":"https://api.github.com/repos/iic-ninjas/PSix-iOS/commits{/sha}","git_commits_url":"https://api.github.com/repos/iic-ninjas/PSix-iOS/git/commits{/sha}","comments_url":"https://api.github.com/repos/iic-ninjas/PSix-iOS/comments{/number}","issue_comment_url":"https://api.github.com/repos/iic-ninjas/PSix-iOS/issues/comments{/number}","contents_url":"https://api.github.com/repos/iic-ninjas/PSix-iOS/contents/{+path}","compare_url":"https://api.github.com/repos/iic-ninjas/PSix-iOS/compare/{base}...{head}","merges_url":"https://api.github.com/repos/iic-ninjas/PSix-iOS/merges","archive_url":"https://api.github.com/repos/iic-ninjas/PSix-iOS/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/iic-ninjas/PSix-iOS/downloads","issues_url":"https://api.github.com/repos/iic-ninjas/PSix-iOS/issues{/number}","pulls_url":"https://api.github.com/repos/iic-ninjas/PSix-iOS/pulls{/number}","milestones_url":"https://api.github.com/repos/iic-ninjas/PSix-iOS/milestones{/number}","notifications_url":"https://api.github.com/repos/iic-ninjas/PSix-iOS/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/iic-ninjas/PSix-iOS/labels{/name}","releases_url":"https://api.github.com/repos/iic-ninjas/PSix-iOS/releases{/id}","created_at":"2015-04-12T12:44:37Z","updated_at":"2015-04-15T14:34:32Z","pushed_at":"2015-04-21T08:23:05Z","git_url":"git://github.com/iic-ninjas/PSix-iOS.git","ssh_url":"git@github.com:iic-ninjas/PSix-iOS.git","clone_url":"https://github.com/iic-ninjas/PSix-iOS.git","svn_url":"https://github.com/iic-ninjas/PSix-iOS","homepage":null,"size":11296,"stargazers_count":1,"watchers_count":1,"language":"Swift","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":2,"forks":0,"open_issues":2,"watchers":1,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/iic-ninjas/PSix-iOS/pulls/4"},"html":{"href":"https://github.com/iic-ninjas/PSix-iOS/pull/4"},"issue":{"href":"https://api.github.com/repos/iic-ninjas/PSix-iOS/issues/4"},"comments":{"href":"https://api.github.com/repos/iic-ninjas/PSix-iOS/issues/4/comments"},"review_comments":{"href":"https://api.github.com/repos/iic-ninjas/PSix-iOS/pulls/4/comments"},"review_comment":{"href":"https://api.github.com/repos/iic-ninjas/PSix-iOS/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/iic-ninjas/PSix-iOS/pulls/4/commits"},"statuses":{"href":"https://api.github.com/repos/iic-ninjas/PSix-iOS/statuses/17578ac90c8016c3ed0732fc5dad5597a9822de7"}}}}