Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
techdubb committed Jun 5, 2011
0 parents commit ec64056
Show file tree
Hide file tree
Showing 12 changed files with 193 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.pyc
21 changes: 21 additions & 0 deletions LICENSE
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.
26 changes: 26 additions & 0 deletions README.markdown
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.

4 changes: 4 additions & 0 deletions example.py
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')

1 change: 1 addition & 0 deletions pynecone/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import pynecone
19 changes: 19 additions & 0 deletions pynecone/post.py
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)
12 changes: 12 additions & 0 deletions pynecone/pynecone.py
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
55 changes: 55 additions & 0 deletions pynecone/request.py
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)
3 changes: 3 additions & 0 deletions pynecone/settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class Settings(object):

host = 'http://forrst.com/api/v2/'
7 changes: 7 additions & 0 deletions pynecone/stat.py
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)
15 changes: 15 additions & 0 deletions pynecone/user.py
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)
29 changes: 29 additions & 0 deletions setup.py
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'
]
)

0 comments on commit ec64056

Please sign in to comment.