{"action":"created","comment":{"url":"https://api.github.com/repos/samsara/samsara/pulls/comments/72206855","id":72206855,"diff_hunk":"@@ -0,0 +1,136 @@\n+# -*- coding: utf-8 -*-\n+\"\"\"\n+    samsara-sdk.client\n+    ~~~~~~~~~~~~~~~~~~\n+\n+    Samsara SDK client\n+\"\"\"\n+\n+from cerberus import Validator\n+import gzip\n+import json\n+import time\n+import requests\n+\n+\n+class InvalidEvent(Exception):\n+    pass\n+\n+\n+class InvalidArguement(Exception):\n+    pass\n+\n+\n+class COMPRESSION(object):\n+    GZIP = \"gzip\"\n+\n+    @staticmethod\n+    def compress_none(s):\n+        return json.dumps(s)\n+\n+    @staticmethod\n+    def compress_gzip(s):\n+        return gzip.compress(bytes(json.dumps(s), 'utf-8'))\n+\n+    COMPRESS = {\n+        GZIP: compress_gzip,\n+        None: compress_none\n+    }\n+\n+    @staticmethod\n+    def get_compressor(compression):\n+        if compression not in COMPRESSION.COMPRESS.keys():\n+            raise InvalidArguement(\n+                \"Compression has to be one of {}\"\n+                .format(COMPRESSION.COMPRESS.keys()))\n+\n+        return COMPRESSION.COMPRESS.get(compression)\n+\n+\n+PUBLISHED_TIMESTAMP = \"X-Samsara-publishedTimestamp\"\n+DEFAULT_CONFIG = {\n+    # a samsara ingestion api endpoint  \"http://samsara.io/\"\n+    # url  - REQUIRED\n+\n+    # the identifier of the source of these events\n+    # source_id  - OPTIONAL only for record-event\n+\n+    # whether to start the publishing thread.\n+    \"start_publishing_thread\": True,\n+\n+    # how often should the events being sent to samsara\n+    # in milliseconds\n+    # default 30s\n+    \"publish_interval\": 30000,\n+\n+    # max size of the buffer, when buffer is full\n+    # older events are dropped.\n+    \"max_buffer_size\": 10000,\n+\n+    # minimum number of events to that must be in the buffer\n+    # before attempting to publish them\n+    \"min_buffer_size\": 100,\n+\n+    # network timeout for send operations (in seconds)\n+    # default 30s\n+    \"send_timeout\": 30,\n+\n+    # whether of not the payload should be compressed\n+    # allowed values \"gzip\" \"none\"\n+    \"compression\": COMPRESSION.GZIP\n+\n+    # add samsara client statistics events\n+    # this helps you to understand whether the\n+    # buffer size and publish-intervals are\n+    # adequately configured.\n+    # \"send_client_stats\": True\n+}\n+\n+\n+event_validator = Validator(\n+    schema={\n+        'source_id': {'required': True, 'type': 'string'},\n+        'timestamp': {'required': True, 'type': 'integer', 'min': 0},\n+        'event_name': {'required': True, 'type': 'string'}\n+    }, allow_unknown=True)","path":"clients/python/samsara-sdk/client.py","position":95,"original_position":95,"commit_id":"96d7b13c9f030d7c69994bde2a5d80201b0562b7","original_commit_id":"96d7b13c9f030d7c69994bde2a5d80201b0562b7","user":{"login":"BrunoBonacci","id":1639862,"avatar_url":"https://avatars.githubusercontent.com/u/1639862?v=3","gravatar_id":"","url":"https://api.github.com/users/BrunoBonacci","html_url":"https://github.com/BrunoBonacci","followers_url":"https://api.github.com/users/BrunoBonacci/followers","following_url":"https://api.github.com/users/BrunoBonacci/following{/other_user}","gists_url":"https://api.github.com/users/BrunoBonacci/gists{/gist_id}","starred_url":"https://api.github.com/users/BrunoBonacci/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/BrunoBonacci/subscriptions","organizations_url":"https://api.github.com/users/BrunoBonacci/orgs","repos_url":"https://api.github.com/users/BrunoBonacci/repos","events_url":"https://api.github.com/users/BrunoBonacci/events{/privacy}","received_events_url":"https://api.github.com/users/BrunoBonacci/received_events","type":"User","site_admin":false},"body":"Here fields must be `sourceId` and `eventName` exactly, otherwise the `ingestion-api` will reject the request.\r\n","created_at":"2016-07-26T08:21:56Z","updated_at":"2016-07-26T08:21:56Z","html_url":"https://github.com/samsara/samsara/pull/62#discussion_r72206855","pull_request_url":"https://api.github.com/repos/samsara/samsara/pulls/62","_links":{"self":{"href":"https://api.github.com/repos/samsara/samsara/pulls/comments/72206855"},"html":{"href":"https://github.com/samsara/samsara/pull/62#discussion_r72206855"},"pull_request":{"href":"https://api.github.com/repos/samsara/samsara/pulls/62"}}},"pull_request":{"url":"https://api.github.com/repos/samsara/samsara/pulls/62","id":78749057,"html_url":"https://github.com/samsara/samsara/pull/62","diff_url":"https://github.com/samsara/samsara/pull/62.diff","patch_url":"https://github.com/samsara/samsara/pull/62.patch","issue_url":"https://api.github.com/repos/samsara/samsara/issues/62","number":62,"state":"open","locked":false,"title":"Add Python client","user":{"login":"puhrez","id":6732397,"avatar_url":"https://avatars.githubusercontent.com/u/6732397?v=3","gravatar_id":"","url":"https://api.github.com/users/puhrez","html_url":"https://github.com/puhrez","followers_url":"https://api.github.com/users/puhrez/followers","following_url":"https://api.github.com/users/puhrez/following{/other_user}","gists_url":"https://api.github.com/users/puhrez/gists{/gist_id}","starred_url":"https://api.github.com/users/puhrez/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/puhrez/subscriptions","organizations_url":"https://api.github.com/users/puhrez/orgs","repos_url":"https://api.github.com/users/puhrez/repos","events_url":"https://api.github.com/users/puhrez/events{/privacy}","received_events_url":"https://api.github.com/users/puhrez/received_events","type":"User","site_admin":false},"body":"address #2 ","created_at":"2016-07-25T20:47:37Z","updated_at":"2016-07-26T08:21:56Z","closed_at":null,"merged_at":null,"merge_commit_sha":"8bb278747ecd3b597bd40de4e11ae7888125bec0","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/samsara/samsara/pulls/62/commits","review_comments_url":"https://api.github.com/repos/samsara/samsara/pulls/62/comments","review_comment_url":"https://api.github.com/repos/samsara/samsara/pulls/comments{/number}","comments_url":"https://api.github.com/repos/samsara/samsara/issues/62/comments","statuses_url":"https://api.github.com/repos/samsara/samsara/statuses/96d7b13c9f030d7c69994bde2a5d80201b0562b7","head":{"label":"puhrez:issue-02","ref":"issue-02","sha":"96d7b13c9f030d7c69994bde2a5d80201b0562b7","user":{"login":"puhrez","id":6732397,"avatar_url":"https://avatars.githubusercontent.com/u/6732397?v=3","gravatar_id":"","url":"https://api.github.com/users/puhrez","html_url":"https://github.com/puhrez","followers_url":"https://api.github.com/users/puhrez/followers","following_url":"https://api.github.com/users/puhrez/following{/other_user}","gists_url":"https://api.github.com/users/puhrez/gists{/gist_id}","starred_url":"https://api.github.com/users/puhrez/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/puhrez/subscriptions","organizations_url":"https://api.github.com/users/puhrez/orgs","repos_url":"https://api.github.com/users/puhrez/repos","events_url":"https://api.github.com/users/puhrez/events{/privacy}","received_events_url":"https://api.github.com/users/puhrez/received_events","type":"User","site_admin":false},"repo":{"id":62837829,"name":"samsara","full_name":"puhrez/samsara","owner":{"login":"puhrez","id":6732397,"avatar_url":"https://avatars.githubusercontent.com/u/6732397?v=3","gravatar_id":"","url":"https://api.github.com/users/puhrez","html_url":"https://github.com/puhrez","followers_url":"https://api.github.com/users/puhrez/followers","following_url":"https://api.github.com/users/puhrez/following{/other_user}","gists_url":"https://api.github.com/users/puhrez/gists{/gist_id}","starred_url":"https://api.github.com/users/puhrez/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/puhrez/subscriptions","organizations_url":"https://api.github.com/users/puhrez/orgs","repos_url":"https://api.github.com/users/puhrez/repos","events_url":"https://api.github.com/users/puhrez/events{/privacy}","received_events_url":"https://api.github.com/users/puhrez/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/puhrez/samsara","description":"Samsara is a real-time analytics platform","fork":true,"url":"https://api.github.com/repos/puhrez/samsara","forks_url":"https://api.github.com/repos/puhrez/samsara/forks","keys_url":"https://api.github.com/repos/puhrez/samsara/keys{/key_id}","collaborators_url":"https://api.github.com/repos/puhrez/samsara/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/puhrez/samsara/teams","hooks_url":"https://api.github.com/repos/puhrez/samsara/hooks","issue_events_url":"https://api.github.com/repos/puhrez/samsara/issues/events{/number}","events_url":"https://api.github.com/repos/puhrez/samsara/events","assignees_url":"https://api.github.com/repos/puhrez/samsara/assignees{/user}","branches_url":"https://api.github.com/repos/puhrez/samsara/branches{/branch}","tags_url":"https://api.github.com/repos/puhrez/samsara/tags","blobs_url":"https://api.github.com/repos/puhrez/samsara/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/puhrez/samsara/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/puhrez/samsara/git/refs{/sha}","trees_url":"https://api.github.com/repos/puhrez/samsara/git/trees{/sha}","statuses_url":"https://api.github.com/repos/puhrez/samsara/statuses/{sha}","languages_url":"https://api.github.com/repos/puhrez/samsara/languages","stargazers_url":"https://api.github.com/repos/puhrez/samsara/stargazers","contributors_url":"https://api.github.com/repos/puhrez/samsara/contributors","subscribers_url":"https://api.github.com/repos/puhrez/samsara/subscribers","subscription_url":"https://api.github.com/repos/puhrez/samsara/subscription","commits_url":"https://api.github.com/repos/puhrez/samsara/commits{/sha}","git_commits_url":"https://api.github.com/repos/puhrez/samsara/git/commits{/sha}","comments_url":"https://api.github.com/repos/puhrez/samsara/comments{/number}","issue_comment_url":"https://api.github.com/repos/puhrez/samsara/issues/comments{/number}","contents_url":"https://api.github.com/repos/puhrez/samsara/contents/{+path}","compare_url":"https://api.github.com/repos/puhrez/samsara/compare/{base}...{head}","merges_url":"https://api.github.com/repos/puhrez/samsara/merges","archive_url":"https://api.github.com/repos/puhrez/samsara/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/puhrez/samsara/downloads","issues_url":"https://api.github.com/repos/puhrez/samsara/issues{/number}","pulls_url":"https://api.github.com/repos/puhrez/samsara/pulls{/number}","milestones_url":"https://api.github.com/repos/puhrez/samsara/milestones{/number}","notifications_url":"https://api.github.com/repos/puhrez/samsara/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/puhrez/samsara/labels{/name}","releases_url":"https://api.github.com/repos/puhrez/samsara/releases{/id}","deployments_url":"https://api.github.com/repos/puhrez/samsara/deployments","created_at":"2016-07-07T21:00:34Z","updated_at":"2016-07-07T21:00:35Z","pushed_at":"2016-07-25T20:47:10Z","git_url":"git://github.com/puhrez/samsara.git","ssh_url":"git@github.com:puhrez/samsara.git","clone_url":"https://github.com/puhrez/samsara.git","svn_url":"https://github.com/puhrez/samsara","homepage":null,"size":23580,"stargazers_count":0,"watchers_count":0,"language":"Clojure","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":"samsara:master","ref":"master","sha":"5943873ce8aa054f0b98a7629c29de608d821ed3","user":{"login":"samsara","id":10883161,"avatar_url":"https://avatars.githubusercontent.com/u/10883161?v=3","gravatar_id":"","url":"https://api.github.com/users/samsara","html_url":"https://github.com/samsara","followers_url":"https://api.github.com/users/samsara/followers","following_url":"https://api.github.com/users/samsara/following{/other_user}","gists_url":"https://api.github.com/users/samsara/gists{/gist_id}","starred_url":"https://api.github.com/users/samsara/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/samsara/subscriptions","organizations_url":"https://api.github.com/users/samsara/orgs","repos_url":"https://api.github.com/users/samsara/repos","events_url":"https://api.github.com/users/samsara/events{/privacy}","received_events_url":"https://api.github.com/users/samsara/received_events","type":"Organization","site_admin":false},"repo":{"id":49298335,"name":"samsara","full_name":"samsara/samsara","owner":{"login":"samsara","id":10883161,"avatar_url":"https://avatars.githubusercontent.com/u/10883161?v=3","gravatar_id":"","url":"https://api.github.com/users/samsara","html_url":"https://github.com/samsara","followers_url":"https://api.github.com/users/samsara/followers","following_url":"https://api.github.com/users/samsara/following{/other_user}","gists_url":"https://api.github.com/users/samsara/gists{/gist_id}","starred_url":"https://api.github.com/users/samsara/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/samsara/subscriptions","organizations_url":"https://api.github.com/users/samsara/orgs","repos_url":"https://api.github.com/users/samsara/repos","events_url":"https://api.github.com/users/samsara/events{/privacy}","received_events_url":"https://api.github.com/users/samsara/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/samsara/samsara","description":"Samsara is a real-time analytics platform","fork":false,"url":"https://api.github.com/repos/samsara/samsara","forks_url":"https://api.github.com/repos/samsara/samsara/forks","keys_url":"https://api.github.com/repos/samsara/samsara/keys{/key_id}","collaborators_url":"https://api.github.com/repos/samsara/samsara/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/samsara/samsara/teams","hooks_url":"https://api.github.com/repos/samsara/samsara/hooks","issue_events_url":"https://api.github.com/repos/samsara/samsara/issues/events{/number}","events_url":"https://api.github.com/repos/samsara/samsara/events","assignees_url":"https://api.github.com/repos/samsara/samsara/assignees{/user}","branches_url":"https://api.github.com/repos/samsara/samsara/branches{/branch}","tags_url":"https://api.github.com/repos/samsara/samsara/tags","blobs_url":"https://api.github.com/repos/samsara/samsara/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/samsara/samsara/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/samsara/samsara/git/refs{/sha}","trees_url":"https://api.github.com/repos/samsara/samsara/git/trees{/sha}","statuses_url":"https://api.github.com/repos/samsara/samsara/statuses/{sha}","languages_url":"https://api.github.com/repos/samsara/samsara/languages","stargazers_url":"https://api.github.com/repos/samsara/samsara/stargazers","contributors_url":"https://api.github.com/repos/samsara/samsara/contributors","subscribers_url":"https://api.github.com/repos/samsara/samsara/subscribers","subscription_url":"https://api.github.com/repos/samsara/samsara/subscription","commits_url":"https://api.github.com/repos/samsara/samsara/commits{/sha}","git_commits_url":"https://api.github.com/repos/samsara/samsara/git/commits{/sha}","comments_url":"https://api.github.com/repos/samsara/samsara/comments{/number}","issue_comment_url":"https://api.github.com/repos/samsara/samsara/issues/comments{/number}","contents_url":"https://api.github.com/repos/samsara/samsara/contents/{+path}","compare_url":"https://api.github.com/repos/samsara/samsara/compare/{base}...{head}","merges_url":"https://api.github.com/repos/samsara/samsara/merges","archive_url":"https://api.github.com/repos/samsara/samsara/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/samsara/samsara/downloads","issues_url":"https://api.github.com/repos/samsara/samsara/issues{/number}","pulls_url":"https://api.github.com/repos/samsara/samsara/pulls{/number}","milestones_url":"https://api.github.com/repos/samsara/samsara/milestones{/number}","notifications_url":"https://api.github.com/repos/samsara/samsara/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/samsara/samsara/labels{/name}","releases_url":"https://api.github.com/repos/samsara/samsara/releases{/id}","deployments_url":"https://api.github.com/repos/samsara/samsara/deployments","created_at":"2016-01-08T21:41:38Z","updated_at":"2016-07-24T12:56:23Z","pushed_at":"2016-07-25T20:47:37Z","git_url":"git://github.com/samsara/samsara.git","ssh_url":"git@github.com:samsara/samsara.git","clone_url":"https://github.com/samsara/samsara.git","svn_url":"https://github.com/samsara/samsara","homepage":null,"size":23589,"stargazers_count":37,"watchers_count":37,"language":"Clojure","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":10,"mirror_url":null,"open_issues_count":47,"forks":10,"open_issues":47,"watchers":37,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/samsara/samsara/pulls/62"},"html":{"href":"https://github.com/samsara/samsara/pull/62"},"issue":{"href":"https://api.github.com/repos/samsara/samsara/issues/62"},"comments":{"href":"https://api.github.com/repos/samsara/samsara/issues/62/comments"},"review_comments":{"href":"https://api.github.com/repos/samsara/samsara/pulls/62/comments"},"review_comment":{"href":"https://api.github.com/repos/samsara/samsara/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/samsara/samsara/pulls/62/commits"},"statuses":{"href":"https://api.github.com/repos/samsara/samsara/statuses/96d7b13c9f030d7c69994bde2a5d80201b0562b7"}}}}
{"actor":{"display_login":"BrunoBonacci"}}