Skip to content

Instantly share code, notes, and snippets.

@roder
Created December 3, 2014 19:52
Show Gist options
  • Save roder/8087c4288d22aaa7db25 to your computer and use it in GitHub Desktop.
Save roder/8087c4288d22aaa7db25 to your computer and use it in GitHub Desktop.
import porc
# Create client with your API key
client = porc.Client("YOUR_API_KEY")
# Example Data
collection = "users"
key = "test"
data = {
"tax_id": "",
"name": "Test User",
"addresses": {
"home": {
"address": [
"123 Main St",
"Unit 420"
],
"city": "Portland",
"state": "Oregon",
"postal": "97209"
}
}
}
# Create new Test User Object, using the If-None-Match header
item = client.put(collection, key, data, False)
item.raise_for_status()
# Sub document update
patch = porc.Patch()
# Make sure to fail the patch request if the data has changed
patch.test("tax_id", "").replace("tax_id", "123-45-6789")
# Using Patch `test` or a `ref`, we ensure that new data is not overwritten. No data is ever lost, since Orchestrate stores
# each item as an immutable object (aka a `ref`).
client.patch(collection, key, patch, item.ref).raise_for_response()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment