{"action":"created","comment":{"url":"https://api.github.com/repos/electricimp/TreasureData/pulls/comments/224163176","pull_request_review_id":163464447,"id":224163176,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDIyNDE2MzE3Ng==","diff_hunk":"@@ -0,0 +1,144 @@\n+// MIT License\n+//\n+// Copyright 2018 Electric Imp\n+//\n+// SPDX-License-Identifier: MIT\n+//\n+// Permission is hereby granted, free of charge, to any person obtaining a copy\n+// of this software and associated documentation files (the \"Software\"), to deal\n+// in the Software without restriction, including without limitation the rights\n+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n+// copies of the Software, and to permit persons to whom the Software is\n+// furnished to do so, subject to the following conditions:\n+//\n+// The above copyright notice and this permission notice shall be\n+// included in all copies or substantial portions of the Software.\n+//\n+// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND,\n+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\n+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO\n+// EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES\n+// OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,\n+// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR\n+// OTHER DEALINGS IN THE SOFTWARE.\n+\n+// Internal library constants\n+const _TREASURE_DATA_SEND_ENDPOINT = \"https://in.treasuredata.com\";\n+const _TREASURE_DATA_SEND_PATH = \"/postback/v3/event/%s/%s\";\n+\n+// Error details produced by the library\n+const _TREASURE_DATA_REQUEST_FAILED = \"TreasureData request failed with status code\";\n+\n+// This library allows your agent code to send data to the Treasure Data platform (https://www.treasuredata.com)\n+// via the Treasure Data REST API (https://support.treasuredata.com/hc/en-us/articles/360000675487-Postback-API).\n+class TreasureData {\n+    static VERSION = \"1.0.0\";\n+\n+    _apiKey = null;\n+    _sendHeaders = null;\n+    _debug = null;\n+\n+    // TreasureData class constructor.\n+    //\n+    // Parameters:\n+    //     apiKey : string           Treasure Data API key.\n+    //                               See https://support.treasuredata.com/hc/en-us/articles/360000763288-Get-API-Keys\n+    //\n+    // Returns:                      TreasureData instance created.\n+    constructor(apiKey) {\n+        _apiKey = apiKey;\n+        _sendHeaders = {\n+            \"Content-Type\" : \"application/json\",\n+            \"X-TD-Write-Key\" : _apiKey\n+        };\n+    }\n+\n+    // Sends data record to the specified Treasure Data table.\n+    // See https://support.treasuredata.com/hc/en-us/articles/360000675487-Postback-API#POST%20%2Fpostback%2Fv3%2Fevent%2F%7Bdatabase%7D%2F%7Btable%7D\n+    //\n+    // Parameters:\n+    //     dbName : string           Treasure Data database name.\n+    //     tableName : string        Treasure Data table name.\n+    //     data : table              The data to send - a key-value table,\n+    //                               where a \"key\" is the name of the field (column) in the database table,\n+    //                               the \"value\" is the value to be written into that field.\n+    //     callback : function       Optional callback function executed once the operation\n+    //         (optional)            is completed.\n+    //                               The callback signature:\n+    //                               callback(error, data), where\n+    //                                   error : table               Error details, HTTP response table (see https://electricimp.com/docs/api/httprequest/sendasync/)\n+    //                                                               or null if the operation succeeds.\n+    //                                   data : table                The original data passed to \n+    //                                                               sendData() method.\n+    function sendData(dbName, tableName, data, callback = null) {\n+        _processRequest(\n+            \"POST\",\n+            _TREASURE_DATA_SEND_ENDPOINT,\n+            format(_TREASURE_DATA_SEND_PATH, dbName, tableName),\n+            _sendHeaders,\n+            data,\n+            function (error) {\n+                _invokeDefaultCallback(callback, error, data);\n+            }.bindenv(this));\n+    }\n+\n+    // Enables/disables the library debug output (including errors logging).\n+    // Disabled by default.\n+    //\n+    // Parameters:\n+    //     value : boolean             true to enable, false to disable\n+    function setDebug(value) {\n+        _debug = value;\n+    }\n+\n+    // -------------------- PRIVATE METHODS -------------------- //\n+\n+    // Sends an http request to TreasureData.\n+    function _processRequest(method, endpoint, path, headers, body, callback) {\n+        local url = endpoint + path;\n+        local encodedBody = http.jsonencode(body);\n+        _logDebug(format(\"Doing the request: %s %s, body: %s\", method, url, encodedBody));\n+\n+        local request = http.request(method, url, headers, encodedBody);\n+        request.sendasync(function (response) {\n+            _processResponse(response, callback);\n+        }.bindenv(this));\n+    }\n+\n+    // Processes http response from TreasureData and executes callback.\n+    function _processResponse(response, callback) {\n+        _logDebug(format(\"Response status: %d, body: %s\", response.statuscode, response.body));\n+        local error = null;\n+        local httpStatus = response.statuscode;\n+        if (httpStatus < 200 || httpStatus >= 300) {\n+            error = response;\n+        }\n+        callback(error);\n+    }\n+\n+    // Logs error occurred and invokes callback with default parameters.\n+    function _invokeDefaultCallback(callback, error, data) {\n+        if (error) {\n+            _logError(format(\"%s: %i\", _TREASURE_DATA_REQUEST_FAILED, error.statuscode));\n+        }\n+        if (callback) {\n+            imp.wakeup(0, function () {\n+                callback(error, data);","path":"TreasureData.agent.lib.nut","position":126,"original_position":126,"commit_id":"3bd63611b41ea88855f1a3644213c2aaedf423c3","original_commit_id":"1668bc42999d8a5c549e4602defb6bd2498fd617","user":{"login":"betzrhodes","id":10034302,"node_id":"MDQ6VXNlcjEwMDM0MzAy","avatar_url":"https://avatars1.githubusercontent.com/u/10034302?v=4","gravatar_id":"","url":"https://api.github.com/users/betzrhodes","html_url":"https://github.com/betzrhodes","followers_url":"https://api.github.com/users/betzrhodes/followers","following_url":"https://api.github.com/users/betzrhodes/following{/other_user}","gists_url":"https://api.github.com/users/betzrhodes/gists{/gist_id}","starred_url":"https://api.github.com/users/betzrhodes/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/betzrhodes/subscriptions","organizations_url":"https://api.github.com/users/betzrhodes/orgs","repos_url":"https://api.github.com/users/betzrhodes/repos","events_url":"https://api.github.com/users/betzrhodes/events{/privacy}","received_events_url":"https://api.github.com/users/betzrhodes/received_events","type":"User","site_admin":false},"body":"Great if the response body is empty than this seems fine.","created_at":"2018-10-10T17:06:18Z","updated_at":"2018-10-10T17:06:18Z","html_url":"https://github.com/electricimp/TreasureData/pull/1#discussion_r224163176","pull_request_url":"https://api.github.com/repos/electricimp/TreasureData/pulls/1","author_association":"NONE","_links":{"self":{"href":"https://api.github.com/repos/electricimp/TreasureData/pulls/comments/224163176"},"html":{"href":"https://github.com/electricimp/TreasureData/pull/1#discussion_r224163176"},"pull_request":{"href":"https://api.github.com/repos/electricimp/TreasureData/pulls/1"}},"in_reply_to_id":223954121},"pull_request":{"url":"https://api.github.com/repos/electricimp/TreasureData/pulls/1","id":220960363,"node_id":"MDExOlB1bGxSZXF1ZXN0MjIwOTYwMzYz","html_url":"https://github.com/electricimp/TreasureData/pull/1","diff_url":"https://github.com/electricimp/TreasureData/pull/1.diff","patch_url":"https://github.com/electricimp/TreasureData/pull/1.patch","issue_url":"https://api.github.com/repos/electricimp/TreasureData/issues/1","number":1,"state":"open","locked":false,"title":"Treasuredata integration","user":{"login":"ekaterina-nbl","id":26255813,"node_id":"MDQ6VXNlcjI2MjU1ODEz","avatar_url":"https://avatars0.githubusercontent.com/u/26255813?v=4","gravatar_id":"","url":"https://api.github.com/users/ekaterina-nbl","html_url":"https://github.com/ekaterina-nbl","followers_url":"https://api.github.com/users/ekaterina-nbl/followers","following_url":"https://api.github.com/users/ekaterina-nbl/following{/other_user}","gists_url":"https://api.github.com/users/ekaterina-nbl/gists{/gist_id}","starred_url":"https://api.github.com/users/ekaterina-nbl/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ekaterina-nbl/subscriptions","organizations_url":"https://api.github.com/users/ekaterina-nbl/orgs","repos_url":"https://api.github.com/users/ekaterina-nbl/repos","events_url":"https://api.github.com/users/ekaterina-nbl/events{/privacy}","received_events_url":"https://api.github.com/users/ekaterina-nbl/received_events","type":"User","site_admin":false},"body":"","created_at":"2018-10-07T17:09:27Z","updated_at":"2018-10-10T17:06:18Z","closed_at":null,"merged_at":null,"merge_commit_sha":"92ba26ed24ec916700799d19a18c98303aefb6af","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/electricimp/TreasureData/pulls/1/commits","review_comments_url":"https://api.github.com/repos/electricimp/TreasureData/pulls/1/comments","review_comment_url":"https://api.github.com/repos/electricimp/TreasureData/pulls/comments{/number}","comments_url":"https://api.github.com/repos/electricimp/TreasureData/issues/1/comments","statuses_url":"https://api.github.com/repos/electricimp/TreasureData/statuses/3bd63611b41ea88855f1a3644213c2aaedf423c3","head":{"label":"nobitlost:master","ref":"master","sha":"3bd63611b41ea88855f1a3644213c2aaedf423c3","user":{"login":"nobitlost","id":25421182,"node_id":"MDEyOk9yZ2FuaXphdGlvbjI1NDIxMTgy","avatar_url":"https://avatars2.githubusercontent.com/u/25421182?v=4","gravatar_id":"","url":"https://api.github.com/users/nobitlost","html_url":"https://github.com/nobitlost","followers_url":"https://api.github.com/users/nobitlost/followers","following_url":"https://api.github.com/users/nobitlost/following{/other_user}","gists_url":"https://api.github.com/users/nobitlost/gists{/gist_id}","starred_url":"https://api.github.com/users/nobitlost/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nobitlost/subscriptions","organizations_url":"https://api.github.com/users/nobitlost/orgs","repos_url":"https://api.github.com/users/nobitlost/repos","events_url":"https://api.github.com/users/nobitlost/events{/privacy}","received_events_url":"https://api.github.com/users/nobitlost/received_events","type":"Organization","site_admin":false},"repo":{"id":151746360,"node_id":"MDEwOlJlcG9zaXRvcnkxNTE3NDYzNjA=","name":"TreasureData","full_name":"nobitlost/TreasureData","private":false,"owner":{"login":"nobitlost","id":25421182,"node_id":"MDEyOk9yZ2FuaXphdGlvbjI1NDIxMTgy","avatar_url":"https://avatars2.githubusercontent.com/u/25421182?v=4","gravatar_id":"","url":"https://api.github.com/users/nobitlost","html_url":"https://github.com/nobitlost","followers_url":"https://api.github.com/users/nobitlost/followers","following_url":"https://api.github.com/users/nobitlost/following{/other_user}","gists_url":"https://api.github.com/users/nobitlost/gists{/gist_id}","starred_url":"https://api.github.com/users/nobitlost/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nobitlost/subscriptions","organizations_url":"https://api.github.com/users/nobitlost/orgs","repos_url":"https://api.github.com/users/nobitlost/repos","events_url":"https://api.github.com/users/nobitlost/events{/privacy}","received_events_url":"https://api.github.com/users/nobitlost/received_events","type":"Organization","site_admin":false},"html_url":"https://github.com/nobitlost/TreasureData","description":null,"fork":true,"url":"https://api.github.com/repos/nobitlost/TreasureData","forks_url":"https://api.github.com/repos/nobitlost/TreasureData/forks","keys_url":"https://api.github.com/repos/nobitlost/TreasureData/keys{/key_id}","collaborators_url":"https://api.github.com/repos/nobitlost/TreasureData/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/nobitlost/TreasureData/teams","hooks_url":"https://api.github.com/repos/nobitlost/TreasureData/hooks","issue_events_url":"https://api.github.com/repos/nobitlost/TreasureData/issues/events{/number}","events_url":"https://api.github.com/repos/nobitlost/TreasureData/events","assignees_url":"https://api.github.com/repos/nobitlost/TreasureData/assignees{/user}","branches_url":"https://api.github.com/repos/nobitlost/TreasureData/branches{/branch}","tags_url":"https://api.github.com/repos/nobitlost/TreasureData/tags","blobs_url":"https://api.github.com/repos/nobitlost/TreasureData/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/nobitlost/TreasureData/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/nobitlost/TreasureData/git/refs{/sha}","trees_url":"https://api.github.com/repos/nobitlost/TreasureData/git/trees{/sha}","statuses_url":"https://api.github.com/repos/nobitlost/TreasureData/statuses/{sha}","languages_url":"https://api.github.com/repos/nobitlost/TreasureData/languages","stargazers_url":"https://api.github.com/repos/nobitlost/TreasureData/stargazers","contributors_url":"https://api.github.com/repos/nobitlost/TreasureData/contributors","subscribers_url":"https://api.github.com/repos/nobitlost/TreasureData/subscribers","subscription_url":"https://api.github.com/repos/nobitlost/TreasureData/subscription","commits_url":"https://api.github.com/repos/nobitlost/TreasureData/commits{/sha}","git_commits_url":"https://api.github.com/repos/nobitlost/TreasureData/git/commits{/sha}","comments_url":"https://api.github.com/repos/nobitlost/TreasureData/comments{/number}","issue_comment_url":"https://api.github.com/repos/nobitlost/TreasureData/issues/comments{/number}","contents_url":"https://api.github.com/repos/nobitlost/TreasureData/contents/{+path}","compare_url":"https://api.github.com/repos/nobitlost/TreasureData/compare/{base}...{head}","merges_url":"https://api.github.com/repos/nobitlost/TreasureData/merges","archive_url":"https://api.github.com/repos/nobitlost/TreasureData/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/nobitlost/TreasureData/downloads","issues_url":"https://api.github.com/repos/nobitlost/TreasureData/issues{/number}","pulls_url":"https://api.github.com/repos/nobitlost/TreasureData/pulls{/number}","milestones_url":"https://api.github.com/repos/nobitlost/TreasureData/milestones{/number}","notifications_url":"https://api.github.com/repos/nobitlost/TreasureData/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/nobitlost/TreasureData/labels{/name}","releases_url":"https://api.github.com/repos/nobitlost/TreasureData/releases{/id}","deployments_url":"https://api.github.com/repos/nobitlost/TreasureData/deployments","created_at":"2018-10-05T16:06:23Z","updated_at":"2018-10-10T09:12:03Z","pushed_at":"2018-10-10T09:12:01Z","git_url":"git://github.com/nobitlost/TreasureData.git","ssh_url":"git@github.com:nobitlost/TreasureData.git","clone_url":"https://github.com/nobitlost/TreasureData.git","svn_url":"https://github.com/nobitlost/TreasureData","homepage":null,"size":475,"stargazers_count":0,"watchers_count":0,"language":"Squirrel","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":0,"license":{"key":"mit","name":"MIT License","spdx_id":"MIT","url":"https://api.github.com/licenses/mit","node_id":"MDc6TGljZW5zZTEz"},"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"electricimp:develop","ref":"develop","sha":"1001c0de52c153c09950bdc5b0a10ffa2b1b91fd","user":{"login":"electricimp","id":3960327,"node_id":"MDEyOk9yZ2FuaXphdGlvbjM5NjAzMjc=","avatar_url":"https://avatars0.githubusercontent.com/u/3960327?v=4","gravatar_id":"","url":"https://api.github.com/users/electricimp","html_url":"https://github.com/electricimp","followers_url":"https://api.github.com/users/electricimp/followers","following_url":"https://api.github.com/users/electricimp/following{/other_user}","gists_url":"https://api.github.com/users/electricimp/gists{/gist_id}","starred_url":"https://api.github.com/users/electricimp/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/electricimp/subscriptions","organizations_url":"https://api.github.com/users/electricimp/orgs","repos_url":"https://api.github.com/users/electricimp/repos","events_url":"https://api.github.com/users/electricimp/events{/privacy}","received_events_url":"https://api.github.com/users/electricimp/received_events","type":"Organization","site_admin":false},"repo":{"id":151423181,"node_id":"MDEwOlJlcG9zaXRvcnkxNTE0MjMxODE=","name":"TreasureData","full_name":"electricimp/TreasureData","private":false,"owner":{"login":"electricimp","id":3960327,"node_id":"MDEyOk9yZ2FuaXphdGlvbjM5NjAzMjc=","avatar_url":"https://avatars0.githubusercontent.com/u/3960327?v=4","gravatar_id":"","url":"https://api.github.com/users/electricimp","html_url":"https://github.com/electricimp","followers_url":"https://api.github.com/users/electricimp/followers","following_url":"https://api.github.com/users/electricimp/following{/other_user}","gists_url":"https://api.github.com/users/electricimp/gists{/gist_id}","starred_url":"https://api.github.com/users/electricimp/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/electricimp/subscriptions","organizations_url":"https://api.github.com/users/electricimp/orgs","repos_url":"https://api.github.com/users/electricimp/repos","events_url":"https://api.github.com/users/electricimp/events{/privacy}","received_events_url":"https://api.github.com/users/electricimp/received_events","type":"Organization","site_admin":false},"html_url":"https://github.com/electricimp/TreasureData","description":null,"fork":false,"url":"https://api.github.com/repos/electricimp/TreasureData","forks_url":"https://api.github.com/repos/electricimp/TreasureData/forks","keys_url":"https://api.github.com/repos/electricimp/TreasureData/keys{/key_id}","collaborators_url":"https://api.github.com/repos/electricimp/TreasureData/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/electricimp/TreasureData/teams","hooks_url":"https://api.github.com/repos/electricimp/TreasureData/hooks","issue_events_url":"https://api.github.com/repos/electricimp/TreasureData/issues/events{/number}","events_url":"https://api.github.com/repos/electricimp/TreasureData/events","assignees_url":"https://api.github.com/repos/electricimp/TreasureData/assignees{/user}","branches_url":"https://api.github.com/repos/electricimp/TreasureData/branches{/branch}","tags_url":"https://api.github.com/repos/electricimp/TreasureData/tags","blobs_url":"https://api.github.com/repos/electricimp/TreasureData/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/electricimp/TreasureData/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/electricimp/TreasureData/git/refs{/sha}","trees_url":"https://api.github.com/repos/electricimp/TreasureData/git/trees{/sha}","statuses_url":"https://api.github.com/repos/electricimp/TreasureData/statuses/{sha}","languages_url":"https://api.github.com/repos/electricimp/TreasureData/languages","stargazers_url":"https://api.github.com/repos/electricimp/TreasureData/stargazers","contributors_url":"https://api.github.com/repos/electricimp/TreasureData/contributors","subscribers_url":"https://api.github.com/repos/electricimp/TreasureData/subscribers","subscription_url":"https://api.github.com/repos/electricimp/TreasureData/subscription","commits_url":"https://api.github.com/repos/electricimp/TreasureData/commits{/sha}","git_commits_url":"https://api.github.com/repos/electricimp/TreasureData/git/commits{/sha}","comments_url":"https://api.github.com/repos/electricimp/TreasureData/comments{/number}","issue_comment_url":"https://api.github.com/repos/electricimp/TreasureData/issues/comments{/number}","contents_url":"https://api.github.com/repos/electricimp/TreasureData/contents/{+path}","compare_url":"https://api.github.com/repos/electricimp/TreasureData/compare/{base}...{head}","merges_url":"https://api.github.com/repos/electricimp/TreasureData/merges","archive_url":"https://api.github.com/repos/electricimp/TreasureData/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/electricimp/TreasureData/downloads","issues_url":"https://api.github.com/repos/electricimp/TreasureData/issues{/number}","pulls_url":"https://api.github.com/repos/electricimp/TreasureData/pulls{/number}","milestones_url":"https://api.github.com/repos/electricimp/TreasureData/milestones{/number}","notifications_url":"https://api.github.com/repos/electricimp/TreasureData/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/electricimp/TreasureData/labels{/name}","releases_url":"https://api.github.com/repos/electricimp/TreasureData/releases{/id}","deployments_url":"https://api.github.com/repos/electricimp/TreasureData/deployments","created_at":"2018-10-03T14:09:47Z","updated_at":"2018-10-03T14:09:50Z","pushed_at":"2018-10-10T09:12:03Z","git_url":"git://github.com/electricimp/TreasureData.git","ssh_url":"git@github.com:electricimp/TreasureData.git","clone_url":"https://github.com/electricimp/TreasureData.git","svn_url":"https://github.com/electricimp/TreasureData","homepage":null,"size":0,"stargazers_count":0,"watchers_count":0,"language":null,"has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"archived":false,"open_issues_count":1,"license":null,"forks":1,"open_issues":1,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/electricimp/TreasureData/pulls/1"},"html":{"href":"https://github.com/electricimp/TreasureData/pull/1"},"issue":{"href":"https://api.github.com/repos/electricimp/TreasureData/issues/1"},"comments":{"href":"https://api.github.com/repos/electricimp/TreasureData/issues/1/comments"},"review_comments":{"href":"https://api.github.com/repos/electricimp/TreasureData/pulls/1/comments"},"review_comment":{"href":"https://api.github.com/repos/electricimp/TreasureData/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/electricimp/TreasureData/pulls/1/commits"},"statuses":{"href":"https://api.github.com/repos/electricimp/TreasureData/statuses/3bd63611b41ea88855f1a3644213c2aaedf423c3"}},"author_association":"NONE"}}
{"actor":{"display_login":"betzrhodes"}}