{"action":"created","comment":{"url":"https://api.github.com/repos/etalab/udata/pulls/comments/59271461","id":59271461,"diff_hunk":"@@ -0,0 +1,213 @@\n+import config from 'config';\n+import log from 'logger';\n+\n+\n+export class ApiError extends Error {\n+    constructor(response, data) {\n+        const message = data.hasOwnProperty('message')\n+            ? data.message\n+            : response.statusText || 'API Error';\n+\n+        super(message);\n+\n+        this.response = response;\n+        this.status = response.status;\n+        this.data = data;\n+    }\n+}\n+\n+\n+/**\n+ * Expect JSON by default\n+ */\n+const DEFAULT_HEADERS = {'Accept': 'application/json'};\n+\n+/**\n+ * Write operations need some extras headers:\n+ * Send JSON by default and give the x-csrf token\n+ *\n+ * Credtentials might be needed here but sessions is used\n+ */\n+const WRITE_HEADERS = {\n+    'Content-Type': 'application/json',\n+    'X-CSRFToken': config.csrftoken,\n+};\n+\n+\n+/**\n+ * Wrap fetch() calls with predefined API parameters\n+ */\n+export class Api {\n+    constructor(root) {\n+        // Compute the root once\n+        root = root || '';\n+        this.root = root.endsWith('/')\n+            ? root.substring(0, root.length - 1)\n+            : root;\n+        // Expose ApiError as Vue.api.Error\n+        this.Error = ApiError;\n+    }\n+\n+    /**\n+     * Tells wether or not a given URL is absolute.\n+     * @param  {String}  url The URL to test\n+     * @return {Boolean}     True is the URL is absolute\n+     */\n+    isAbsolute(url) {\n+        return /^https?:\\/\\//.test(url) || url.startsWith('/');\n+    }\n+\n+    /**\n+     * Encode paramaters as Object to querystring\n+     * @param  {Object} params The parameters to encode\n+     * @return {String}        The URL encoded querystring\n+     */\n+    encodeParams(params) {\n+        return Object.keys(params).map(key => {\n+            return [key, params[key]].map(encodeURIComponent).join('=');\n+        }).join('&');\n+    }\n+\n+    /**\n+     * Build a complete URL\n+     * @param  {String} url     An absolute or API root relative URL\n+     * @param  {Object} params  Optionnal query strings parameters\n+     * @return {String}         The full URL\n+     */\n+    build(url, params) {\n+        if (!this.isAbsolute(url)) {\n+            url  = `${this.root}/${url}`;\n+        }\n+        if (params && Object.keys(params).length) {\n+            const parts = [url, this.encodeParams(params)];\n+            url = url.indexOf('?') >= 0 ? parts.join('&') : parts.join('?');\n+        }\n+        return url;\n+    }\n+\n+    /**\n+     * Default handler for JSON response\n+     * Parse the response if OK otherwise throw it\n+     * (let the developper handle it in the catch() handler)\n+     * @param  {Response} response A response with JSON expected body.\n+     * @return {Promise}           A promise for data handling\n+     */\n+    onResponse(response) {\n+        if (response.ok) {","path":"js/plugins/api.js","position":96,"original_position":96,"commit_id":"f25707dd910ff6a5ec143881f4fee9dded5cd86d","original_commit_id":"f25707dd910ff6a5ec143881f4fee9dded5cd86d","user":{"login":"noirbizarre","id":15725,"avatar_url":"https://avatars.githubusercontent.com/u/15725?v=3","gravatar_id":"","url":"https://api.github.com/users/noirbizarre","html_url":"https://github.com/noirbizarre","followers_url":"https://api.github.com/users/noirbizarre/followers","following_url":"https://api.github.com/users/noirbizarre/following{/other_user}","gists_url":"https://api.github.com/users/noirbizarre/gists{/gist_id}","starred_url":"https://api.github.com/users/noirbizarre/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/noirbizarre/subscriptions","organizations_url":"https://api.github.com/users/noirbizarre/orgs","repos_url":"https://api.github.com/users/noirbizarre/repos","events_url":"https://api.github.com/users/noirbizarre/events{/privacy}","received_events_url":"https://api.github.com/users/noirbizarre/received_events","type":"User","site_admin":false},"body":"Yes:\r\nhttps://developer.mozilla.org/en-US/docs/Web/API/Response/ok\r\nhttps://github.com/github/fetch/pull/82\r\nAnd there is a test case.","created_at":"2016-04-11T20:05:16Z","updated_at":"2016-04-11T20:05:16Z","html_url":"https://github.com/etalab/udata/pull/425#discussion_r59271461","pull_request_url":"https://api.github.com/repos/etalab/udata/pulls/425","_links":{"self":{"href":"https://api.github.com/repos/etalab/udata/pulls/comments/59271461"},"html":{"href":"https://github.com/etalab/udata/pull/425#discussion_r59271461"},"pull_request":{"href":"https://api.github.com/repos/etalab/udata/pulls/425"}}},"pull_request":{"url":"https://api.github.com/repos/etalab/udata/pulls/425","id":65121422,"html_url":"https://github.com/etalab/udata/pull/425","diff_url":"https://github.com/etalab/udata/pull/425.diff","patch_url":"https://github.com/etalab/udata/pull/425.patch","issue_url":"https://api.github.com/repos/etalab/udata/issues/425","number":425,"state":"open","locked":false,"title":"Dataset Vue.js","user":{"login":"noirbizarre","id":15725,"avatar_url":"https://avatars.githubusercontent.com/u/15725?v=3","gravatar_id":"","url":"https://api.github.com/users/noirbizarre","html_url":"https://github.com/noirbizarre","followers_url":"https://api.github.com/users/noirbizarre/followers","following_url":"https://api.github.com/users/noirbizarre/following{/other_user}","gists_url":"https://api.github.com/users/noirbizarre/gists{/gist_id}","starred_url":"https://api.github.com/users/noirbizarre/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/noirbizarre/subscriptions","organizations_url":"https://api.github.com/users/noirbizarre/orgs","repos_url":"https://api.github.com/users/noirbizarre/repos","events_url":"https://api.github.com/users/noirbizarre/events{/privacy}","received_events_url":"https://api.github.com/users/noirbizarre/received_events","type":"User","site_admin":false},"body":"This PR migrate the dataset view to Vue.js and jQuery free.\r\n\r\nThis is a proposal for a migration pattern:\r\n- expose `fetch()` through a custom api plugin (with preconfigured settings)\r\n- reuse some components (leaflet-map is extracted from map widget)\r\n- port modals from handlebars templates to Vue.js components\r\n- use a minimalist microdata module\r\n- use Velocity.js instead of jQuery.animate\r\n- use balloon-css instead of bootstrap tooltips\r\n- module is `front/dataset`\r\n\r\nLegacy jQuery components are left untouched (allowing to migrate them one by one later)","created_at":"2016-04-04T10:07:46Z","updated_at":"2016-04-11T20:05:16Z","closed_at":null,"merged_at":null,"merge_commit_sha":"a9116960d9ce7e7b6af3e80aa7fa1fdb8850737f","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/etalab/udata/pulls/425/commits","review_comments_url":"https://api.github.com/repos/etalab/udata/pulls/425/comments","review_comment_url":"https://api.github.com/repos/etalab/udata/pulls/comments{/number}","comments_url":"https://api.github.com/repos/etalab/udata/issues/425/comments","statuses_url":"https://api.github.com/repos/etalab/udata/statuses/f25707dd910ff6a5ec143881f4fee9dded5cd86d","head":{"label":"noirbizarre:dataset-vuejs","ref":"dataset-vuejs","sha":"f25707dd910ff6a5ec143881f4fee9dded5cd86d","user":{"login":"noirbizarre","id":15725,"avatar_url":"https://avatars.githubusercontent.com/u/15725?v=3","gravatar_id":"","url":"https://api.github.com/users/noirbizarre","html_url":"https://github.com/noirbizarre","followers_url":"https://api.github.com/users/noirbizarre/followers","following_url":"https://api.github.com/users/noirbizarre/following{/other_user}","gists_url":"https://api.github.com/users/noirbizarre/gists{/gist_id}","starred_url":"https://api.github.com/users/noirbizarre/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/noirbizarre/subscriptions","organizations_url":"https://api.github.com/users/noirbizarre/orgs","repos_url":"https://api.github.com/users/noirbizarre/repos","events_url":"https://api.github.com/users/noirbizarre/events{/privacy}","received_events_url":"https://api.github.com/users/noirbizarre/received_events","type":"User","site_admin":false},"repo":{"id":45184052,"name":"udata","full_name":"noirbizarre/udata","owner":{"login":"noirbizarre","id":15725,"avatar_url":"https://avatars.githubusercontent.com/u/15725?v=3","gravatar_id":"","url":"https://api.github.com/users/noirbizarre","html_url":"https://github.com/noirbizarre","followers_url":"https://api.github.com/users/noirbizarre/followers","following_url":"https://api.github.com/users/noirbizarre/following{/other_user}","gists_url":"https://api.github.com/users/noirbizarre/gists{/gist_id}","starred_url":"https://api.github.com/users/noirbizarre/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/noirbizarre/subscriptions","organizations_url":"https://api.github.com/users/noirbizarre/orgs","repos_url":"https://api.github.com/users/noirbizarre/repos","events_url":"https://api.github.com/users/noirbizarre/events{/privacy}","received_events_url":"https://api.github.com/users/noirbizarre/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/noirbizarre/udata","description":"Social data platform","fork":true,"url":"https://api.github.com/repos/noirbizarre/udata","forks_url":"https://api.github.com/repos/noirbizarre/udata/forks","keys_url":"https://api.github.com/repos/noirbizarre/udata/keys{/key_id}","collaborators_url":"https://api.github.com/repos/noirbizarre/udata/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/noirbizarre/udata/teams","hooks_url":"https://api.github.com/repos/noirbizarre/udata/hooks","issue_events_url":"https://api.github.com/repos/noirbizarre/udata/issues/events{/number}","events_url":"https://api.github.com/repos/noirbizarre/udata/events","assignees_url":"https://api.github.com/repos/noirbizarre/udata/assignees{/user}","branches_url":"https://api.github.com/repos/noirbizarre/udata/branches{/branch}","tags_url":"https://api.github.com/repos/noirbizarre/udata/tags","blobs_url":"https://api.github.com/repos/noirbizarre/udata/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/noirbizarre/udata/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/noirbizarre/udata/git/refs{/sha}","trees_url":"https://api.github.com/repos/noirbizarre/udata/git/trees{/sha}","statuses_url":"https://api.github.com/repos/noirbizarre/udata/statuses/{sha}","languages_url":"https://api.github.com/repos/noirbizarre/udata/languages","stargazers_url":"https://api.github.com/repos/noirbizarre/udata/stargazers","contributors_url":"https://api.github.com/repos/noirbizarre/udata/contributors","subscribers_url":"https://api.github.com/repos/noirbizarre/udata/subscribers","subscription_url":"https://api.github.com/repos/noirbizarre/udata/subscription","commits_url":"https://api.github.com/repos/noirbizarre/udata/commits{/sha}","git_commits_url":"https://api.github.com/repos/noirbizarre/udata/git/commits{/sha}","comments_url":"https://api.github.com/repos/noirbizarre/udata/comments{/number}","issue_comment_url":"https://api.github.com/repos/noirbizarre/udata/issues/comments{/number}","contents_url":"https://api.github.com/repos/noirbizarre/udata/contents/{+path}","compare_url":"https://api.github.com/repos/noirbizarre/udata/compare/{base}...{head}","merges_url":"https://api.github.com/repos/noirbizarre/udata/merges","archive_url":"https://api.github.com/repos/noirbizarre/udata/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/noirbizarre/udata/downloads","issues_url":"https://api.github.com/repos/noirbizarre/udata/issues{/number}","pulls_url":"https://api.github.com/repos/noirbizarre/udata/pulls{/number}","milestones_url":"https://api.github.com/repos/noirbizarre/udata/milestones{/number}","notifications_url":"https://api.github.com/repos/noirbizarre/udata/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/noirbizarre/udata/labels{/name}","releases_url":"https://api.github.com/repos/noirbizarre/udata/releases{/id}","deployments_url":"https://api.github.com/repos/noirbizarre/udata/deployments","created_at":"2015-10-29T13:15:39Z","updated_at":"2015-10-29T13:15:41Z","pushed_at":"2016-04-11T17:37:20Z","git_url":"git://github.com/noirbizarre/udata.git","ssh_url":"git@github.com:noirbizarre/udata.git","clone_url":"https://github.com/noirbizarre/udata.git","svn_url":"https://github.com/noirbizarre/udata","homepage":null,"size":6040,"stargazers_count":0,"watchers_count":0,"language":"Python","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":"etalab:dev","ref":"dev","sha":"28f4afbfa0abed977876832a679304c173c2ce27","user":{"login":"etalab","id":5313610,"avatar_url":"https://avatars.githubusercontent.com/u/5313610?v=3","gravatar_id":"","url":"https://api.github.com/users/etalab","html_url":"https://github.com/etalab","followers_url":"https://api.github.com/users/etalab/followers","following_url":"https://api.github.com/users/etalab/following{/other_user}","gists_url":"https://api.github.com/users/etalab/gists{/gist_id}","starred_url":"https://api.github.com/users/etalab/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/etalab/subscriptions","organizations_url":"https://api.github.com/users/etalab/orgs","repos_url":"https://api.github.com/users/etalab/repos","events_url":"https://api.github.com/users/etalab/events{/privacy}","received_events_url":"https://api.github.com/users/etalab/received_events","type":"Organization","site_admin":false},"repo":{"id":19141754,"name":"udata","full_name":"etalab/udata","owner":{"login":"etalab","id":5313610,"avatar_url":"https://avatars.githubusercontent.com/u/5313610?v=3","gravatar_id":"","url":"https://api.github.com/users/etalab","html_url":"https://github.com/etalab","followers_url":"https://api.github.com/users/etalab/followers","following_url":"https://api.github.com/users/etalab/following{/other_user}","gists_url":"https://api.github.com/users/etalab/gists{/gist_id}","starred_url":"https://api.github.com/users/etalab/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/etalab/subscriptions","organizations_url":"https://api.github.com/users/etalab/orgs","repos_url":"https://api.github.com/users/etalab/repos","events_url":"https://api.github.com/users/etalab/events{/privacy}","received_events_url":"https://api.github.com/users/etalab/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/etalab/udata","description":"Customizable and skinnable social platform dedicated to (open)data.","fork":false,"url":"https://api.github.com/repos/etalab/udata","forks_url":"https://api.github.com/repos/etalab/udata/forks","keys_url":"https://api.github.com/repos/etalab/udata/keys{/key_id}","collaborators_url":"https://api.github.com/repos/etalab/udata/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/etalab/udata/teams","hooks_url":"https://api.github.com/repos/etalab/udata/hooks","issue_events_url":"https://api.github.com/repos/etalab/udata/issues/events{/number}","events_url":"https://api.github.com/repos/etalab/udata/events","assignees_url":"https://api.github.com/repos/etalab/udata/assignees{/user}","branches_url":"https://api.github.com/repos/etalab/udata/branches{/branch}","tags_url":"https://api.github.com/repos/etalab/udata/tags","blobs_url":"https://api.github.com/repos/etalab/udata/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/etalab/udata/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/etalab/udata/git/refs{/sha}","trees_url":"https://api.github.com/repos/etalab/udata/git/trees{/sha}","statuses_url":"https://api.github.com/repos/etalab/udata/statuses/{sha}","languages_url":"https://api.github.com/repos/etalab/udata/languages","stargazers_url":"https://api.github.com/repos/etalab/udata/stargazers","contributors_url":"https://api.github.com/repos/etalab/udata/contributors","subscribers_url":"https://api.github.com/repos/etalab/udata/subscribers","subscription_url":"https://api.github.com/repos/etalab/udata/subscription","commits_url":"https://api.github.com/repos/etalab/udata/commits{/sha}","git_commits_url":"https://api.github.com/repos/etalab/udata/git/commits{/sha}","comments_url":"https://api.github.com/repos/etalab/udata/comments{/number}","issue_comment_url":"https://api.github.com/repos/etalab/udata/issues/comments{/number}","contents_url":"https://api.github.com/repos/etalab/udata/contents/{+path}","compare_url":"https://api.github.com/repos/etalab/udata/compare/{base}...{head}","merges_url":"https://api.github.com/repos/etalab/udata/merges","archive_url":"https://api.github.com/repos/etalab/udata/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/etalab/udata/downloads","issues_url":"https://api.github.com/repos/etalab/udata/issues{/number}","pulls_url":"https://api.github.com/repos/etalab/udata/pulls{/number}","milestones_url":"https://api.github.com/repos/etalab/udata/milestones{/number}","notifications_url":"https://api.github.com/repos/etalab/udata/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/etalab/udata/labels{/name}","releases_url":"https://api.github.com/repos/etalab/udata/releases{/id}","deployments_url":"https://api.github.com/repos/etalab/udata/deployments","created_at":"2014-04-25T09:57:34Z","updated_at":"2016-04-09T23:01:00Z","pushed_at":"2016-04-11T17:37:21Z","git_url":"git://github.com/etalab/udata.git","ssh_url":"git@github.com:etalab/udata.git","clone_url":"https://github.com/etalab/udata.git","svn_url":"https://github.com/etalab/udata","homepage":"http://udata.readthedocs.org","size":6131,"stargazers_count":33,"watchers_count":33,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":14,"mirror_url":null,"open_issues_count":25,"forks":14,"open_issues":25,"watchers":33,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/etalab/udata/pulls/425"},"html":{"href":"https://github.com/etalab/udata/pull/425"},"issue":{"href":"https://api.github.com/repos/etalab/udata/issues/425"},"comments":{"href":"https://api.github.com/repos/etalab/udata/issues/425/comments"},"review_comments":{"href":"https://api.github.com/repos/etalab/udata/pulls/425/comments"},"review_comment":{"href":"https://api.github.com/repos/etalab/udata/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/etalab/udata/pulls/425/commits"},"statuses":{"href":"https://api.github.com/repos/etalab/udata/statuses/f25707dd910ff6a5ec143881f4fee9dded5cd86d"}}}}