Skip to content

Instantly share code, notes, and snippets.

@pmav99
Created June 30, 2016 12:54
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pmav99/3460e4b97e084b5ab6d16137758f3445 to your computer and use it in GitHub Desktop.
Save pmav99/3460e4b97e084b5ab6d16137758f3445 to your computer and use it in GitHub Desktop.
An example of using circle CI with hammock
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# module: circle_ci_example.py
# author: Panagiotis Mavrogiorgos (pmav99)
"""
An example of using Circle-CI's REST API using hammock.
For more info on how to use hammock check the documentation:
https://github.com/kadirpekel/hammock
"""
import pprint
import hammock
CIRCLE_TOKEN = "Replace this with your own"
circle = hammock.Hammock(
name="https://circleci.com/api/v1", # the API endpoint
params={"circle-token": CIRCLE_TOKEN}, # append 'circle-token' to every request
headers={"Accept": "application/json"}, # receive compact JSON
)
print("Check the circle object")
print(circle)
print(type(circle))
print()
print("Construct a URL")
print(circle.me)
print(type(circle.me))
print()
print("make an actual request")
response = circle.me.GET()
print(type(response))
print(response.url)
print()
print("check the response")
pprint.pprint(response.json())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment