-
Notifications
You must be signed in to change notification settings - Fork 7
/
account.py
34 lines (28 loc) · 1007 Bytes
/
account.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import requests
import json
import project
class Account(object):
"""Account wrapper for Sifter"""
def __init__(self, host, token):
self.host = host
self.token = token
self.url = 'https://' + self.host + '.sifterapp.com' + '/api/projects'
def request(self, url):
"""Requests JSON object from Sifter URL"""
req = requests.get(url, headers={'X-Sifter-Token': self.token,
'Accept': 'application/json'})
try:
loadcontent = json.loads(req.content)
except ValueError:
return loadcontent['issue']
else:
return loadcontent
def projects(self):
"""Gets all the projects from sifter"""
projects = []
json_raw = self.request(self.url)
raw_projects = json_raw['projects']
for raw_project in raw_projects:
proj = project.Project(raw_project, self)
projects.append(proj)
return projects