File tree Expand file tree Collapse file tree 3 files changed +66
-2
lines changed Expand file tree Collapse file tree 3 files changed +66
-2
lines changed Original file line number Diff line number Diff line change 1
1
# 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 ```
Original file line number Diff line number Diff line change
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 )
Original file line number Diff line number Diff line change 6
6
url = 'https://github.com/codebottle-io/codebottle-python' ,
7
7
author = 'Luke J.' ,
8
8
author_email = 'support@codebottle.io' ,
9
- license = 'GNL ' ,
9
+ license = 'GNU ' ,
10
10
packages = ['codebottle' ],
11
11
install_requires = ['requests' ],
12
12
include_package_data = True ,
You can’t perform that action at this time.
0 commit comments