Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

added puts method for adding multiple events #2

Closed
wants to merge 3 commits into from

3 participants

@tukan

added puts method for adding multiple events, which is critical for performance

@tsileo tsileo closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jan 10, 2013
  1. @tukan
Commits on Aug 6, 2013
  1. @neoromantic
  2. Transferring blueprint from apiary.io

    Sergey Petrov authored
This page is out of date. Refresh to see the latest.
Showing with 82 additions and 6 deletions.
  1. +35 −0 apiary.apib
  2. +47 −6 cube.py
View
35 apiary.apib
@@ -0,0 +1,35 @@
+HOST: http://hubble.what.ms/
+
+--- What matters API ---
+---
+Welcome to the our sample API documentation. All comments can be written in (support [Markdown](http://daringfireball.net/projects/markdown/syntax) syntax)
+---
+
+--
+Shopping Cart Resources
+The following is a section of resources related to the shopping cart
+--
+List products added into your shopping-cart. (comment block again in Markdown)
+GET /shopping-cart
+< 200
+< Content-Type: application/json
+{ "items": [
+{ "url": "/shopping-cart/1", "product":"2ZY48XPZ", "quantity": 1, "name": "New socks", "price": 1.25 }
+] }
+
+
+Save new products in your shopping cart
+POST /shopping-cart
+> Content-Type: application/json
+{ "product":"1AB23ORM", "quantity": 2 }
+< 201
+< Content-Type: application/json
+{ "status": "created", "url": "/shopping-cart/2" }
+
+
+-- Payment Resources --
+This resource allows you to submit payment information to process your *shopping cart* items
+POST /payment
+{ "cc": "12345678900", "cvc": "123", "expiry": "0112" }
+< 200
+{ "receipt": "/payment/receipt/1" }
View
53 cube.py
@@ -11,27 +11,68 @@ def __init__(self, hostname="localhost", **kwargs):
self.evaluator_url = "http://%s:%s/%s/" % (hostname, \
kwargs.get("evaluator_port", 1081), API_VERSION)
+ @classmethod
+ def build_event(cls, event_type, event_data={}, **kwargs):
+ """
+ Build an event hash ready for putting
+ """
+ event = dict(type=event_type, data=event_data)
+
+ event["time"] = kwargs.get("time", datetime.utcnow().isoformat())
+
+ if kwargs.get("id"):
+ event["id"] = kwargs.get("id")
+
+ return event
+
+ def puts(self, events):
+ """
+ Create/update events
+ """
+ ready_events = []
+ for e in events:
+ if type(e) != dict:
+ event_type = e[0]
+ event_data = {}
+ event_kwargs = {}
+
+ if len(e) > 1:
+ event_data = e[1]
+ if len(e) > 2:
+ event_kwargs = e[2]
+
+ ready_events.append(self.build_event(event_type, event_data, **event_kwargs))
+ else:
+ ready_events.append(e)
+
+ data = json.dumps(ready_events)
+ r = requests.post(self.collector_url + "event/put", data=data,
+ headers={'content-type': 'application/json'})
+ r.raise_for_status()
+
+ return ready_events
+
def put(self, event_type, event_data={}, **kwargs):
"""
Create/update an event.
"""
event = dict(type=event_type, data=event_data)
-
+
event["time"] = kwargs.get("time", datetime.utcnow().isoformat())
-
+
if kwargs.get("id"):
event["id"] = kwargs.get("id")
data = json.dumps([event])
-
+
r = requests.post(self.collector_url + "event/put", data=data,
headers={'content-type': 'application/json'})
r.raise_for_status()
-
+
return [event]
def make_query(self, query_type, expression, **kwargs):
- data = dict(expression=expression,
+ data = dict(expression=expression,
stop=kwargs.get("stop", datetime.utcnow().isoformat()))
if kwargs.get("start"):
@@ -47,7 +88,7 @@ def make_query(self, query_type, expression, **kwargs):
r.raise_for_status()
return r.json
-
+
def event(self, expression, **kwargs):
"""
Query with an event expression
Something went wrong with that request. Please try again.