├── hackpad_api ├── __init__.py └── hackpad.py ├── MANIFEST ├── requirements.txt ├── example └── example1.py ├── .gitignore ├── setup.py ├── README.md └── LICENSE /hackpad_api/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /MANIFEST: -------------------------------------------------------------------------------- 1 | # file GENERATED by distutils, do NOT edit 2 | hackpad.py 3 | setup.py 4 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | argparse==1.2.1 2 | httplib2==0.8 3 | requests_oauthlib==0.4.2 4 | requests==2.2.1 5 | wsgiref==0.1.2 6 | -------------------------------------------------------------------------------- /example/example1.py: -------------------------------------------------------------------------------- 1 | import os 2 | from hackpad_api.hackpad import Hackpad 3 | 4 | hackpad = Hackpad(os.getenv('team') ,consumer_key = os.getenv('consumer_key'), consumer_secret = os.getenv('consumer_secret')) 5 | 6 | print(hackpad.do_api_request('pads/all', 'GET')) 7 | 8 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.py[cod] 2 | .env 3 | # C extensions 4 | *.so 5 | 6 | # Packages 7 | *.egg 8 | *.egg-info 9 | dist 10 | build 11 | eggs 12 | parts 13 | bin 14 | var 15 | sdist 16 | develop-eggs 17 | .installed.cfg 18 | lib 19 | lib64 20 | __pycache__ 21 | 22 | # Installer logs 23 | pip-log.txt 24 | 25 | # Unit test / coverage reports 26 | .coverage 27 | .tox 28 | nosetests.xml 29 | 30 | # Translations 31 | *.mo 32 | 33 | # Mr Developer 34 | .mr.developer.cfg 35 | .project 36 | .pydevproject 37 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | from distutils.core import setup 2 | 3 | setup(name='python_hackpad_api', 4 | version='beta', 5 | description='A simple wrapper library for the Hackpad API', 6 | url='https://github.com/Falicon/Python-Hackpad-API', 7 | package_dir={'python_hackpad_api': 'hackpad_api'}, 8 | packages=['hackpad_api'], 9 | install_requires=[ 10 | 'argparse==1.2.1', 11 | 'httplib2==0.8', 12 | 'requests-oauthlib==0.4.2', 13 | 'requests==2.2.1', 14 | 'wsgiref==0.1.2'] 15 | ) 16 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Python-Hackpad-API 2 | ================== 3 | 4 | A simple wrapper library for the Hackpad API. [Hackpad API Documentation](https://hackpad.com/Public-Hackpad-API-Draft-nGhsrCJFlP7) 5 | 6 | Installation 7 | ================== 8 | 9 | Navigate to the folder where you have downloaded this repo, and type 10 | 11 | ``` 12 | easy_install . 13 | ``` 14 | 15 | into your terminal / command prompt. 16 | 17 | Usage 18 | ================== 19 | 20 | ```python 21 | temp = Hackpad('your_hackpad_subdomain','your_hackpad_client_id','your_hackpad_secret') 22 | my_hackpads = temp.list_all() 23 | ```` 24 | 25 | Note: 26 | 27 | * For `your_hackpad_subdomain`, just type the stem, not the full domain name (i.e. `mysubdomain`, not `http://mysubdomain.hackpad.com`, etc). 28 | * Your Client ID and Secret for the different subdomains you are signed into. Make sure to use the correct keys for the subdomain you are signing into. 29 | 30 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2013 Kevin Marshall 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software is furnished to do so, 10 | subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /hackpad_api/hackpad.py: -------------------------------------------------------------------------------- 1 | """ 2 | Simple wrapper for the Hackpad API v1.0 3 | API Documentation: https://hackpad.com/Public-Hackpad-API-Draft-nGhsrCJFlP7 4 | """ 5 | 6 | import requests 7 | import sys 8 | import time 9 | 10 | from requests_oauthlib import OAuth1Session 11 | from urlparse import urljoin 12 | 13 | class Hackpad(object): 14 | def __init__(self, sub_domain='', consumer_key='', consumer_secret=''): 15 | self.sub_domain = sub_domain 16 | self.consumer_key = consumer_key 17 | self.consumer_secret = consumer_secret 18 | return 19 | 20 | def create_blank_hackpad(self, asUser='', content_type='text/plain'): 21 | return self.create_hackpad('Hackpad Title', 'Auto-generated Hackpad contents.', 22 | asUser, content_type) 23 | 24 | def create_hackpad(self, title, content, asUser='', content_type='text/plain'): 25 | api_link = 'pad/create' 26 | params = {} 27 | if asUser != '': 28 | params['asUser'] = asUser 29 | return self.do_api_request(api_link, 'POST', params, '%s\n%s' % (title, content), content_type) 30 | 31 | def get_pad_content(self, padId, revision='latest', response_format='txt', asUser=''): 32 | api_link = 'pad/%s/content/%s.%s' % (padId, revision, response_format) 33 | params = {} 34 | if asUser != '': 35 | params['asUser'] = asUser 36 | return self.do_api_request(api_link, 'GET', params) 37 | 38 | def update_pad_content(self, padId, content='', asUser='', content_type='text/plain'): 39 | api_link = 'pad/%s/content' % padId 40 | params = {} 41 | if asUser != '': 42 | params['asUser'] = asUser 43 | return self.do_api_request(api_link, 'POST', params, content, content_type) 44 | 45 | def search_for_pads(self, q='', start=0, limit=10, asUser=''): 46 | api_link = 'search' 47 | params = {'q':q, 'start':start, 'limit':limit} 48 | if asUser != '': 49 | params['asUser'] = asUser 50 | return self.do_api_request(api_link, 'GET', params) 51 | 52 | def list_updated_pads(self, timestamp): 53 | api_link = 'edited-since%s' % timestamp 54 | params = {} 55 | return self.do_api_request(api_link, 'GET', params) 56 | 57 | def pad_revisions(self, padId, asUser=''): 58 | api_link = 'pad/%s/revisions' % padId 59 | params = {} 60 | if asUser != '': 61 | params['asUser'] = asUser 62 | return self.do_api_request(api_link, 'GET', params) 63 | 64 | def revert_pad(self, padId, revision, asUser=''): 65 | api_link = 'pad/%s/revert-to/%s' % (padId, revision) 66 | params = {} 67 | if asUser != '': 68 | params['asUser'] = asUser 69 | return self.do_api_request(api_link, 'POST', params) 70 | 71 | def revoke_access(self, padId, user, asUser=''): 72 | api_link = 'pad/%s/revoke-access/%s' % (padId, user) 73 | params = {} 74 | if asUser != '': 75 | params['asUser'] = asUser 76 | return self.do_api_request(api_link, 'POST', params) 77 | 78 | def pad_options(self, padId, asUser=''): 79 | api_link = 'pad/%s/options' % padId 80 | params = {} 81 | if asUser != '': 82 | params['asUser'] = asUser 83 | return self.do_api_request(api_link, 'GET', params) 84 | 85 | def set_pad_options(self, padId, settings={}, asUser=''): 86 | api_link = 'pad/%s/options' % padId 87 | params = {} 88 | if asUser != '': 89 | params['asUser'] = asUser 90 | for key in settings.keys(): 91 | params[key] = settings[key] 92 | return self.do_api_request(api_link, 'POST', params) 93 | 94 | def user_settings(self, user, settings={}): 95 | api_link = 'user/%s/settings' % user 96 | params = {} 97 | for key in settings.keys(): 98 | params[key] = settings[key] 99 | return self.do_api_request(api_link, 'POST', params) 100 | 101 | def user_deletion(self, user): 102 | api_link = 'user/%s/remove' % user 103 | return self.do_api_request(api_link, 'POST') 104 | 105 | def user_creation(self, name, email): 106 | api_link = 'user/create' 107 | params = {'email':email, 'name':name} 108 | return self.do_api_request(api_link, 'POST', params) 109 | 110 | def list_all(self): 111 | api_link = 'pads/all' 112 | return self.do_api_request(api_link, 'GET') 113 | 114 | def site_options(self): 115 | api_link = 'options' 116 | return self.do_api_request(api_link, 'GET') 117 | 118 | def do_api_request(self, path, method, post_data={}, body='', content_type=None): 119 | method = method.upper() 120 | hackpad = {} 121 | try: 122 | if self.sub_domain: 123 | path = urljoin('https://%s.hackpad.com/api/1.0/' % self.sub_domain, path) 124 | else: 125 | path = urljoin('https://hackpad.com/api/1.0/', path) 126 | 127 | params = { 128 | 'client_key': self.consumer_key, 129 | 'client_secret': self.consumer_secret 130 | } 131 | 132 | headers = {} 133 | if content_type: 134 | headers['content-type'] = content_type 135 | 136 | for key in post_data.keys(): 137 | params[key] = post_data[key] 138 | 139 | hackpad_api = OAuth1Session(**params) 140 | 141 | if method == 'POST': 142 | r = hackpad_api.post(path, data=body, headers=headers) 143 | hackpad = r.json() 144 | else: 145 | r = hackpad_api.get(path, headers=headers) 146 | 147 | try: 148 | hackpad = r.json() 149 | except: 150 | hackpad = r.content 151 | except: 152 | print sys.exc_info()[0] 153 | 154 | return hackpad 155 | 156 | --------------------------------------------------------------------------------