Skip to content

Instantly share code, notes, and snippets.

@mwunsch
Forked from adelevie/client.erb.py
Created April 12, 2012 14:37
Show Gist options
  • Save mwunsch/2367785 to your computer and use it in GitHub Desktop.
Save mwunsch/2367785 to your computer and use it in GitHub Desktop.
import requests
class Content(object):
def where(self, params={}):
return Query(self).where(params)
def all(self):
return Query(self).all()
class Query(object):
def __init__(self, klass):
self._klass = klass
self._client = Client()
self._criteria = None
self._request = None
def criteria(self):
if not self._criteria:
self._criteria = {}
return self._criteria
def where(self, params={}):
self.criteria().update(params)
return self
def all(self):
return self.execute()
def request(self):
if not self._request:
self._request = self._client.all(self.criteria())
return self._request
def execute(self):
return self.request().perform()
class Client(object):
def __init__(self):
self._domain = <%= @domain %>
self._params = None
self._url = None
def get(self, id):
self._url = <%= @weary_client.get(:python) %>
return self
def all(self, params={}):
self._params = params
self._url = <%= @weary_client.all(:python) %>
return self
def perform(self):
return requests.get(self._url, params=self._params)
print Content().where({"search_string":"broadband"}).where({"limit":1}).all().text
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment