-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit ec64056
Showing
12 changed files
with
193 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
*.pyc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
The MIT License | ||
|
||
Copyright (c) 2011 Matthew Hokanson | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# PyneCone | ||
|
||
A Python wrapper for the [Forrst API](http://forrst.com/api). | ||
|
||
## Requirements | ||
|
||
* Python 2.6+ | ||
* simplejson | ||
* httplib2 | ||
* urllib | ||
|
||
## Example | ||
|
||
~~~ python | ||
from pynecone.pynecone import Post | ||
|
||
# Get a beer by ID. | ||
print Post.all() | ||
~~~ | ||
|
||
Checkout `example.py` for more. | ||
|
||
## License | ||
|
||
PyneCone uses the MIT license. See LICENSE for more details. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
from pynecone.pynecone import User, Post | ||
|
||
print User.info(username='h0ke') | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
import pynecone |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
from request import Request | ||
|
||
class Post(object): | ||
|
||
@classmethod | ||
def show(self, **kwargs): | ||
return Request.get("posts/show", kwargs) | ||
|
||
@classmethod | ||
def all(self, **kwargs): | ||
return Request.get("posts/all", kwargs) | ||
|
||
@classmethod | ||
def list(self, **kwargs): | ||
return Request.get("posts/list", kwargs) | ||
|
||
@classmethod | ||
def comments(self, **kwargs): | ||
return Request.get("post/comments", kwargs) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
""" | ||
Pynecone is a Python client that wraps the Forrst API. | ||
Questions, comments? m@h0ke.com | ||
""" | ||
|
||
__author__ = "Matthew Hokanson <m@h0ke.com>" | ||
__version__ = "0.1.0" | ||
|
||
from stat import Stat | ||
from user import User | ||
from post import Post |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
from httplib2 import Http | ||
from urllib import quote | ||
from simplejson import dumps, loads | ||
from settings import Settings | ||
|
||
class Request(object): | ||
|
||
# Handle GET requests | ||
@classmethod | ||
def get(self, path, parameters = {}): | ||
# dict to query string from: http://bit.ly/k1fAsx | ||
query_string = '&'.join([k+'='+quote(str(v)) for (k,v) in parameters.items()]) | ||
path = "%s%s?%s" % (Settings.host, path, query_string,) | ||
|
||
return self.request(path) | ||
|
||
# Handle POST requests | ||
@classmethod | ||
def post(self, path, parameters={}): | ||
path = "%s%s" % (Settings.host, path,) | ||
options = { | ||
'request_type' : 'POST', | ||
'body' : dumps(parameters), | ||
'headers' : {'Content-Type': 'application/json'} | ||
} | ||
|
||
return self.request(path, options) | ||
|
||
# Handle DELETE requests | ||
@classmethod | ||
def delete(self, path): | ||
path = "%s%s" % (Settings.host, path,) | ||
options = { | ||
'request_type' : 'DELETE', | ||
'body' : dumps({'token': Settings.private_token}), | ||
'headers' : {'Content-Type': 'application/json'} | ||
} | ||
|
||
return self.request(path, options) | ||
|
||
@classmethod | ||
def request(self, path, options = {}): | ||
client = Http() | ||
|
||
if len(options) == 0: | ||
resp, content = client.request(path) | ||
else: | ||
resp, content = client.request( | ||
path, | ||
options['request_type'], | ||
body = options['body'], | ||
headers = options['headers'] | ||
) | ||
|
||
return loads(content) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
class Settings(object): | ||
|
||
host = 'http://forrst.com/api/v2/' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
from request import Request | ||
|
||
class Stat(object): | ||
|
||
@classmethod | ||
def stats(self, **kwargs): | ||
return Request.get("stats", kwargs) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
from request import Request | ||
|
||
class User(object): | ||
|
||
@classmethod | ||
def auth(self, **kwargs): | ||
return Request.post("users/auth", kwargs) | ||
|
||
@classmethod | ||
def info(self, **kwargs): | ||
return Request.get("users/info", kwargs) | ||
|
||
@classmethod | ||
def posts(self, **kwargs): | ||
return Request.get("user/posts", kwargs) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#!/usr/bin/python | ||
|
||
import sys, os | ||
from setuptools import setup | ||
from setuptools import find_packages | ||
|
||
__author__ = 'Matthew Hokanson <m@h0ke.com>' | ||
__version__ = '0.1.0' | ||
|
||
setup( | ||
name = 'pynecone', | ||
version = __version__, | ||
|
||
install_requires = ['simplejson', 'httplib2', 'urllib'], | ||
|
||
author = 'Matthew Hokanson', | ||
author_email = 'm@h0ke.com', | ||
license = 'MIT License', | ||
url = 'http://github.com/h0ke/pynecone/tree/master', | ||
keywords = 'forrst api python wrapper pynecone', | ||
description = 'Pynecone is a Python client that wraps the Forrst API.', | ||
long_description = open('README.markdown').read(), | ||
classifiers = [ | ||
'Development Status :: 1 - Planning', | ||
'Intended Audience :: Developers', | ||
'License :: OSI Approved :: MIT License', | ||
'Topic :: Internet' | ||
] | ||
) |