Skip to content

Commit 31ec626

Browse files
committed
Add codebottle.py
1 parent 614f05e commit 31ec626

File tree

3 files changed

+66
-2
lines changed

3 files changed

+66
-2
lines changed

README.md

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,25 @@
11
# codebottle-python
2-
A Python library to interact with CodeBottle's API
2+
A Python library to interact with CodeBottle's API.
3+
This is obviously still in development.
4+
5+
##Example:
6+
```python
7+
import codebottle
8+
9+
#Results of a search
10+
search = codebottle.search(keywords="java").results
11+
12+
#Get a snippet
13+
snippet = codebottle.search(id="373dcc67").data
14+
15+
#Browse
16+
browse = codebottle.browse(limit=10).results
17+
18+
#Verify secure
19+
secure = codebottle.verifysecure(secure_token="Some type of token here")
20+
```
21+
22+
##Installing
23+
24+
From git:
25+
```pip install git+https://github.com/codebottle-io/codebottle-python.git```

codebottle.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import requests
2+
3+
api_version = "v1"
4+
api_url = "https://codebottle.io/api/{0}".format(api_version)
5+
6+
api_search_url = "{0}/search.php".format(api_url)
7+
api_get_snippet_url = "{0}/get.php".format(api_url)
8+
api_browse_url = "{0}/browse.php".format(api_url)
9+
api_verifysecure_url = "{0}/verifysecure.php".format(api_url)
10+
11+
12+
class CodebottleError(Exception):
13+
"""Exception to represent a error sent from the API"""
14+
pass
15+
16+
class Result(object):
17+
"""A class with attributes of a codebottle API result"""
18+
def __init__(self, r):
19+
self.json = r.json()
20+
if self.json["error"] is not "":
21+
raise CodebottleError(self.json["error"])
22+
23+
for k, v in self.json.items():
24+
setattr(self, k, v)
25+
26+
#Functions
27+
def search(**kwargs):
28+
result = requests.get(api_search_url, params=kwargs)
29+
return Result(result)
30+
31+
def get(**kwargs):
32+
result = requests.get(api_get_snippet_url, params=kwargs)
33+
return Result(result)
34+
35+
def browse(**kwargs):
36+
result = requests.get(api_browse_url, params=kwargs)
37+
return Result(result)
38+
39+
def verifysecure(**kwargs):
40+
result = requests.get(api_verifysecure_url, params=kwargs)
41+
return Result(result)

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
url='https://github.com/codebottle-io/codebottle-python',
77
author='Luke J.',
88
author_email='support@codebottle.io',
9-
license='GNL',
9+
license='GNU',
1010
packages=['codebottle'],
1111
install_requires=['requests'],
1212
include_package_data=True,

0 commit comments

Comments
 (0)