{"action":"created","comment":{"url":"https://api.github.com/repos/janpantel/angular-sails/pulls/comments/23888564","id":23888564,"diff_hunk":"@@ -1,74 +1,168 @@\n-/*jslint sloppy:true*/\n-/*global angular, io */\n-angular.module('ngSails').provider('$sails', function () {\n-    var provider = this,\n-        httpVerbs = ['get', 'post', 'put', 'delete'],\n-        eventNames = ['on', 'once'];\n+(function(angular, io) {\n+  'use strict';\n+  io.sails.autoConnect = false;\n+  window.io.sails.useCORSRouteToGetCookie = false;\n+\n+  /*global angular */\n+  angular.module('ngSails', ['ng']);\n+\n+  /*global angular, io */\n+  angular.module('ngSails').provider('$sails', function() {\n+    var provider = this;\n+\n+    // wrap these socket.io methods with angular promises\n+    this.httpVerbs = ['get', 'post', 'put', 'delete'];\n+\n+    // wrap these events in $evalAsync to fire a digest cycle\n+    this.eventNames = ['on', 'once'];\n \n     this.url = undefined;\n-    this.interceptors = [];\n-    this.responseHandler = undefined;\n-\n-    this.$get = ['$q', '$timeout', function ($q, $timeout) {\n-        var socket = io.connect(provider.url),\n-            defer = function () {\n-                var deferred = $q.defer(),\n-                    promise = deferred.promise;\n-\n-                promise.success = function (fn) {\n-                    promise.then(fn);\n-                    return promise;\n-                };\n-\n-                promise.error = function (fn) {\n-                    promise.then(null, fn);\n-                    return promise;\n-                };\n-\n-                return deferred;\n-            },\n-            resolveOrReject = this.responseHandler || function (deferred, data) {\n-                // Make sure what is passed is an object that has a status that is a number and if that status is no 2xx, reject.\n-                if (data && angular.isObject(data) && data.status && !isNaN(data.status) && Math.floor(data.status / 100) !== 2) {\n-                    deferred.reject(data);\n-                } else {\n-                    deferred.resolve(data);\n-                }\n-            },\n-            angularify = function (cb, data) {\n-                $timeout(function () {\n-                    cb(data);\n-                });\n-            },\n-            promisify = function (methodName) {\n-                socket['legacy_' + methodName] = socket[methodName];\n-                socket[methodName] = function (url, data, cb) {\n-                    var deferred = defer();\n-                    if (cb === undefined && angular.isFunction(data)) {\n-                        cb = data;\n-                        data = null;\n-                    }\n-                    deferred.promise.then(cb);\n-                    socket['legacy_' + methodName](url, data, function (result) {\n-                        resolveOrReject(deferred, result);\n-                    });\n-                    return deferred.promise;\n-                };\n-            },\n-            wrapEvent = function (eventName) {\n-                socket['legacy_' + eventName] = socket[eventName];\n-                socket[eventName] = function (event, cb) {\n-                    if (cb !== null && angular.isFunction(cb)) {\n-                        socket['legacy_' + eventName](event, function (result) {\n-                            angularify(cb, result);\n-                        });\n-                    }\n-                };\n-            };\n-\n-        angular.forEach(httpVerbs, promisify);\n-        angular.forEach(eventNames, wrapEvent);\n-\n-        return socket;\n+    this.base = '';\n+    this.config = {};\n+    this.debug = false;\n+\n+    // like https://docs.angularjs.org/api/ng/service/$http#interceptors\n+    // but with sails.io arguments\n+    var interceptorFactories = this.interceptors = [\n+      /*function($injectables) {\n+         return {\n+           request: function(config) {},\n+           response: function(response) {},\n+           requestError: function(config) {},\n+           responseError: function(response) {}\n+         };\n+       }*/\n+    ];\n+\n+    this.$get = ['$q', '$injector', '$rootScope', '$log', function($q, $injector, $rootScope, $log) {\n+      var socket = (io.sails || io).connect(provider.url, provider.config);","path":"src/service/angular-sails.js","position":114,"original_position":108,"commit_id":"39765c6a4c8b2202ffe335b063d45f0e326174ff","original_commit_id":"ab868baad66ebd3f6fb25d283e8edefc39897ae3","user":{"login":"TheSharpieOne","id":664714,"avatar_url":"https://avatars.githubusercontent.com/u/664714?v=3","gravatar_id":"","url":"https://api.github.com/users/TheSharpieOne","html_url":"https://github.com/TheSharpieOne","followers_url":"https://api.github.com/users/TheSharpieOne/followers","following_url":"https://api.github.com/users/TheSharpieOne/following{/other_user}","gists_url":"https://api.github.com/users/TheSharpieOne/gists{/gist_id}","starred_url":"https://api.github.com/users/TheSharpieOne/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/TheSharpieOne/subscriptions","organizations_url":"https://api.github.com/users/TheSharpieOne/orgs","repos_url":"https://api.github.com/users/TheSharpieOne/repos","events_url":"https://api.github.com/users/TheSharpieOne/events{/privacy}","received_events_url":"https://api.github.com/users/TheSharpieOne/received_events","type":"User","site_admin":false},"body":"Yeah, I ran into this myself with the older sails.io.js","created_at":"2015-01-31T12:24:54Z","updated_at":"2015-01-31T12:24:54Z","html_url":"https://github.com/janpantel/angular-sails/pull/46#discussion_r23888564","pull_request_url":"https://api.github.com/repos/janpantel/angular-sails/pulls/46","_links":{"self":{"href":"https://api.github.com/repos/janpantel/angular-sails/pulls/comments/23888564"},"html":{"href":"https://github.com/janpantel/angular-sails/pull/46#discussion_r23888564"},"pull_request":{"href":"https://api.github.com/repos/janpantel/angular-sails/pulls/46"}}},"pull_request":{"url":"https://api.github.com/repos/janpantel/angular-sails/pulls/46","id":27555995,"html_url":"https://github.com/janpantel/angular-sails/pull/46","diff_url":"https://github.com/janpantel/angular-sails/pull/46.diff","patch_url":"https://github.com/janpantel/angular-sails/pull/46.patch","issue_url":"https://api.github.com/repos/janpantel/angular-sails/issues/46","number":46,"state":"open","locked":false,"title":"Refactoring","user":{"login":"psi-4ward","id":1191572,"avatar_url":"https://avatars.githubusercontent.com/u/1191572?v=3","gravatar_id":"","url":"https://api.github.com/users/psi-4ward","html_url":"https://github.com/psi-4ward","followers_url":"https://api.github.com/users/psi-4ward/followers","following_url":"https://api.github.com/users/psi-4ward/following{/other_user}","gists_url":"https://api.github.com/users/psi-4ward/gists{/gist_id}","starred_url":"https://api.github.com/users/psi-4ward/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/psi-4ward/subscriptions","organizations_url":"https://api.github.com/users/psi-4ward/orgs","repos_url":"https://api.github.com/users/psi-4ward/repos","events_url":"https://api.github.com/users/psi-4ward/events{/privacy}","received_events_url":"https://api.github.com/users/psi-4ward/received_events","type":"User","site_admin":false},"body":"Hi came up with a refactored version of angular-sails and set it open for discussion:\r\n\r\n* Set `io.sails.autoConnect = false;` to false to be able to use angular.config\r\n* Full request and response interceptor support\r\n* configureable `base` url as counterpart of `sails.config.blueprint.prefix`\r\n* breaking change! Killed the `cb` param and added a config/meta obj which gets attached to the `req` and `res`. Using a promise here is the angular-way\r\n* helper method to listen/react on/for model-updates (currently depends  on lodash)","created_at":"2015-01-17T12:08:19Z","updated_at":"2015-01-31T12:24:54Z","closed_at":null,"merged_at":null,"merge_commit_sha":null,"assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/janpantel/angular-sails/pulls/46/commits","review_comments_url":"https://api.github.com/repos/janpantel/angular-sails/pulls/46/comments","review_comment_url":"https://api.github.com/repos/janpantel/angular-sails/pulls/comments/{number}","comments_url":"https://api.github.com/repos/janpantel/angular-sails/issues/46/comments","statuses_url":"https://api.github.com/repos/janpantel/angular-sails/statuses/39765c6a4c8b2202ffe335b063d45f0e326174ff","head":{"label":"psi-4ward:refactor-psi","ref":"refactor-psi","sha":"39765c6a4c8b2202ffe335b063d45f0e326174ff","user":{"login":"psi-4ward","id":1191572,"avatar_url":"https://avatars.githubusercontent.com/u/1191572?v=3","gravatar_id":"","url":"https://api.github.com/users/psi-4ward","html_url":"https://github.com/psi-4ward","followers_url":"https://api.github.com/users/psi-4ward/followers","following_url":"https://api.github.com/users/psi-4ward/following{/other_user}","gists_url":"https://api.github.com/users/psi-4ward/gists{/gist_id}","starred_url":"https://api.github.com/users/psi-4ward/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/psi-4ward/subscriptions","organizations_url":"https://api.github.com/users/psi-4ward/orgs","repos_url":"https://api.github.com/users/psi-4ward/repos","events_url":"https://api.github.com/users/psi-4ward/events{/privacy}","received_events_url":"https://api.github.com/users/psi-4ward/received_events","type":"User","site_admin":false},"repo":{"id":28365644,"name":"angular-sails","full_name":"psi-4ward/angular-sails","owner":{"login":"psi-4ward","id":1191572,"avatar_url":"https://avatars.githubusercontent.com/u/1191572?v=3","gravatar_id":"","url":"https://api.github.com/users/psi-4ward","html_url":"https://github.com/psi-4ward","followers_url":"https://api.github.com/users/psi-4ward/followers","following_url":"https://api.github.com/users/psi-4ward/following{/other_user}","gists_url":"https://api.github.com/users/psi-4ward/gists{/gist_id}","starred_url":"https://api.github.com/users/psi-4ward/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/psi-4ward/subscriptions","organizations_url":"https://api.github.com/users/psi-4ward/orgs","repos_url":"https://api.github.com/users/psi-4ward/repos","events_url":"https://api.github.com/users/psi-4ward/events{/privacy}","received_events_url":"https://api.github.com/users/psi-4ward/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/psi-4ward/angular-sails","description":"An angular module for using the sails socket.io api","fork":true,"url":"https://api.github.com/repos/psi-4ward/angular-sails","forks_url":"https://api.github.com/repos/psi-4ward/angular-sails/forks","keys_url":"https://api.github.com/repos/psi-4ward/angular-sails/keys{/key_id}","collaborators_url":"https://api.github.com/repos/psi-4ward/angular-sails/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/psi-4ward/angular-sails/teams","hooks_url":"https://api.github.com/repos/psi-4ward/angular-sails/hooks","issue_events_url":"https://api.github.com/repos/psi-4ward/angular-sails/issues/events{/number}","events_url":"https://api.github.com/repos/psi-4ward/angular-sails/events","assignees_url":"https://api.github.com/repos/psi-4ward/angular-sails/assignees{/user}","branches_url":"https://api.github.com/repos/psi-4ward/angular-sails/branches{/branch}","tags_url":"https://api.github.com/repos/psi-4ward/angular-sails/tags","blobs_url":"https://api.github.com/repos/psi-4ward/angular-sails/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/psi-4ward/angular-sails/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/psi-4ward/angular-sails/git/refs{/sha}","trees_url":"https://api.github.com/repos/psi-4ward/angular-sails/git/trees{/sha}","statuses_url":"https://api.github.com/repos/psi-4ward/angular-sails/statuses/{sha}","languages_url":"https://api.github.com/repos/psi-4ward/angular-sails/languages","stargazers_url":"https://api.github.com/repos/psi-4ward/angular-sails/stargazers","contributors_url":"https://api.github.com/repos/psi-4ward/angular-sails/contributors","subscribers_url":"https://api.github.com/repos/psi-4ward/angular-sails/subscribers","subscription_url":"https://api.github.com/repos/psi-4ward/angular-sails/subscription","commits_url":"https://api.github.com/repos/psi-4ward/angular-sails/commits{/sha}","git_commits_url":"https://api.github.com/repos/psi-4ward/angular-sails/git/commits{/sha}","comments_url":"https://api.github.com/repos/psi-4ward/angular-sails/comments{/number}","issue_comment_url":"https://api.github.com/repos/psi-4ward/angular-sails/issues/comments/{number}","contents_url":"https://api.github.com/repos/psi-4ward/angular-sails/contents/{+path}","compare_url":"https://api.github.com/repos/psi-4ward/angular-sails/compare/{base}...{head}","merges_url":"https://api.github.com/repos/psi-4ward/angular-sails/merges","archive_url":"https://api.github.com/repos/psi-4ward/angular-sails/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/psi-4ward/angular-sails/downloads","issues_url":"https://api.github.com/repos/psi-4ward/angular-sails/issues{/number}","pulls_url":"https://api.github.com/repos/psi-4ward/angular-sails/pulls{/number}","milestones_url":"https://api.github.com/repos/psi-4ward/angular-sails/milestones{/number}","notifications_url":"https://api.github.com/repos/psi-4ward/angular-sails/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/psi-4ward/angular-sails/labels{/name}","releases_url":"https://api.github.com/repos/psi-4ward/angular-sails/releases{/id}","created_at":"2014-12-22T23:39:57Z","updated_at":"2014-12-22T23:39:57Z","pushed_at":"2015-01-21T19:04:34Z","git_url":"git://github.com/psi-4ward/angular-sails.git","ssh_url":"git@github.com:psi-4ward/angular-sails.git","clone_url":"https://github.com/psi-4ward/angular-sails.git","svn_url":"https://github.com/psi-4ward/angular-sails","homepage":"","size":167,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"janpantel:master","ref":"master","sha":"77309966f7179971e1cb7271b70ed9513499a8c8","user":{"login":"janpantel","id":1828275,"avatar_url":"https://avatars.githubusercontent.com/u/1828275?v=3","gravatar_id":"","url":"https://api.github.com/users/janpantel","html_url":"https://github.com/janpantel","followers_url":"https://api.github.com/users/janpantel/followers","following_url":"https://api.github.com/users/janpantel/following{/other_user}","gists_url":"https://api.github.com/users/janpantel/gists{/gist_id}","starred_url":"https://api.github.com/users/janpantel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/janpantel/subscriptions","organizations_url":"https://api.github.com/users/janpantel/orgs","repos_url":"https://api.github.com/users/janpantel/repos","events_url":"https://api.github.com/users/janpantel/events{/privacy}","received_events_url":"https://api.github.com/users/janpantel/received_events","type":"User","site_admin":false},"repo":{"id":12803627,"name":"angular-sails","full_name":"janpantel/angular-sails","owner":{"login":"janpantel","id":1828275,"avatar_url":"https://avatars.githubusercontent.com/u/1828275?v=3","gravatar_id":"","url":"https://api.github.com/users/janpantel","html_url":"https://github.com/janpantel","followers_url":"https://api.github.com/users/janpantel/followers","following_url":"https://api.github.com/users/janpantel/following{/other_user}","gists_url":"https://api.github.com/users/janpantel/gists{/gist_id}","starred_url":"https://api.github.com/users/janpantel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/janpantel/subscriptions","organizations_url":"https://api.github.com/users/janpantel/orgs","repos_url":"https://api.github.com/users/janpantel/repos","events_url":"https://api.github.com/users/janpantel/events{/privacy}","received_events_url":"https://api.github.com/users/janpantel/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/janpantel/angular-sails","description":"An angular module for using the sails socket.io api","fork":false,"url":"https://api.github.com/repos/janpantel/angular-sails","forks_url":"https://api.github.com/repos/janpantel/angular-sails/forks","keys_url":"https://api.github.com/repos/janpantel/angular-sails/keys{/key_id}","collaborators_url":"https://api.github.com/repos/janpantel/angular-sails/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/janpantel/angular-sails/teams","hooks_url":"https://api.github.com/repos/janpantel/angular-sails/hooks","issue_events_url":"https://api.github.com/repos/janpantel/angular-sails/issues/events{/number}","events_url":"https://api.github.com/repos/janpantel/angular-sails/events","assignees_url":"https://api.github.com/repos/janpantel/angular-sails/assignees{/user}","branches_url":"https://api.github.com/repos/janpantel/angular-sails/branches{/branch}","tags_url":"https://api.github.com/repos/janpantel/angular-sails/tags","blobs_url":"https://api.github.com/repos/janpantel/angular-sails/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/janpantel/angular-sails/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/janpantel/angular-sails/git/refs{/sha}","trees_url":"https://api.github.com/repos/janpantel/angular-sails/git/trees{/sha}","statuses_url":"https://api.github.com/repos/janpantel/angular-sails/statuses/{sha}","languages_url":"https://api.github.com/repos/janpantel/angular-sails/languages","stargazers_url":"https://api.github.com/repos/janpantel/angular-sails/stargazers","contributors_url":"https://api.github.com/repos/janpantel/angular-sails/contributors","subscribers_url":"https://api.github.com/repos/janpantel/angular-sails/subscribers","subscription_url":"https://api.github.com/repos/janpantel/angular-sails/subscription","commits_url":"https://api.github.com/repos/janpantel/angular-sails/commits{/sha}","git_commits_url":"https://api.github.com/repos/janpantel/angular-sails/git/commits{/sha}","comments_url":"https://api.github.com/repos/janpantel/angular-sails/comments{/number}","issue_comment_url":"https://api.github.com/repos/janpantel/angular-sails/issues/comments/{number}","contents_url":"https://api.github.com/repos/janpantel/angular-sails/contents/{+path}","compare_url":"https://api.github.com/repos/janpantel/angular-sails/compare/{base}...{head}","merges_url":"https://api.github.com/repos/janpantel/angular-sails/merges","archive_url":"https://api.github.com/repos/janpantel/angular-sails/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/janpantel/angular-sails/downloads","issues_url":"https://api.github.com/repos/janpantel/angular-sails/issues{/number}","pulls_url":"https://api.github.com/repos/janpantel/angular-sails/pulls{/number}","milestones_url":"https://api.github.com/repos/janpantel/angular-sails/milestones{/number}","notifications_url":"https://api.github.com/repos/janpantel/angular-sails/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/janpantel/angular-sails/labels{/name}","releases_url":"https://api.github.com/repos/janpantel/angular-sails/releases{/id}","created_at":"2013-09-13T07:10:53Z","updated_at":"2015-01-27T06:29:29Z","pushed_at":"2015-01-17T01:57:28Z","git_url":"git://github.com/janpantel/angular-sails.git","ssh_url":"git@github.com:janpantel/angular-sails.git","clone_url":"https://github.com/janpantel/angular-sails.git","svn_url":"https://github.com/janpantel/angular-sails","homepage":"","size":487,"stargazers_count":203,"watchers_count":203,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":41,"mirror_url":null,"open_issues_count":9,"forks":41,"open_issues":9,"watchers":203,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/janpantel/angular-sails/pulls/46"},"html":{"href":"https://github.com/janpantel/angular-sails/pull/46"},"issue":{"href":"https://api.github.com/repos/janpantel/angular-sails/issues/46"},"comments":{"href":"https://api.github.com/repos/janpantel/angular-sails/issues/46/comments"},"review_comments":{"href":"https://api.github.com/repos/janpantel/angular-sails/pulls/46/comments"},"review_comment":{"href":"https://api.github.com/repos/janpantel/angular-sails/pulls/comments/{number}"},"commits":{"href":"https://api.github.com/repos/janpantel/angular-sails/pulls/46/commits"},"statuses":{"href":"https://api.github.com/repos/janpantel/angular-sails/statuses/39765c6a4c8b2202ffe335b063d45f0e326174ff"}}}}