Skip to content

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
...
  • 4 commits
  • 9 files changed
  • 0 commit comments
  • 2 contributors
Commits on Mar 27, 2012
Mark Mikofski use requests, add comments de07e79
@mikofski mikofski extract issue before comments fed95ca
@mikofski mikofski pep8 and pylint fixes 8250ae6
Commits on Mar 30, 2012
@bryanmikaelian Merge pull request #3 from mikofski/master
use Requests, add comments and fix issues bug
bec601c
Showing with 221 additions and 201 deletions.
  1. +5 −1 .gitignore
  2. +25 −21 account.py
  3. +5 −6 category.py
  4. +12 −0 comment.py
  5. +32 −14 issue.py
  6. +6 −7 milestone.py
  7. +84 −99 project.py
  8. +44 −44 sifter_print.py
  9. +8 −9 user.py
View
6 .gitignore
@@ -1 +1,5 @@
-*.pyc
+*.pyc
+.project
+.pydevproject
+.spyderproject
+/.settings
View
46 account.py
@@ -1,25 +1,29 @@
-import urllib2
+import requests
import json
import project
+
class Account(object):
- """Account wrapper for Sifter"""
- def __init__(self, host, token):
- self.host = host
- self.token = token
-
- def projects(self):
- """Gets all the projects from sifter"""
- projects = []
- url = self.host + '/api/projects'
- req = urllib2.Request(url)
- req.add_header('X-Sifter-Token', self.token)
- req.add_header('Accept', 'application/json')
- json_raw = json.loads(urllib2.urlopen(req).read())
- raw_projects = json_raw['projects']
- for raw_project in raw_projects:
- p = project.Project(raw_project, self.token)
- projects.append(p)
-
- return projects
-
+ """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'})
+
+ return json.loads(req.content)
+
+ 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
View
11 category.py
@@ -1,7 +1,6 @@
class Category(object):
- """Representation of a Category in Sifter"""
- def __init__(self, category):
- self.name = category['name']
- self.issues_url = category['issues_url']
- self.api_issues_url = category['api_issues_url']
-
+ """Representation of a Category in Sifter"""
+ def __init__(self, category):
+ self.name = category['name']
+ self.issues_url = category['issues_url']
+ self.api_issues_url = category['api_issues_url']
View
12 comment.py
@@ -0,0 +1,12 @@
+class Comment(object):
+ """Representation of an Issue in Sifter"""
+ def __init__(self, issue):
+ self.category = issue['category']
+ self.body = issue['body']
+ self.priority = issue['priority']
+ self.commenter = issue['commenter']
+ self.milestone_name = issue['milestone_name']
+ self.assignee_name = issue['assignee_name']
+ self.status = issue['status']
+ self.created_at = issue['created_at']
+ self.updated_at = issue['updated_at']
View
46 issue.py
@@ -1,15 +1,33 @@
+import comment
+
+
class Issue(object):
- """Representation of an Issue in Sifter"""
- def __init__(self, issue):
- self.number = issue['number']
- self.subject = issue['subject']
- self.description = issue['description']
- self.priority = issue['priority']
- self.status = issue['status']
- self.assignee_name = issue['assignee_name']
- self.category_name = issue['category_name']
- self.milestone_name = issue['milestone_name']
- self.opener_name = issue['opener_name']
- self.url = issue['url']
- self.api_url = issue['api_url']
-
+ """Representation of an Issue in Sifter"""
+ def __init__(self, issue, account):
+ self._account = account
+ self.number = issue['number']
+ self.subject = issue['subject']
+ self.description = issue['description']
+ self.priority = issue['priority']
+ self.status = issue['status']
+ self.assignee_name = issue['assignee_name']
+ self.category_name = issue['category_name']
+ self.milestone_name = issue['milestone_name']
+ self.opener_name = issue['opener_name']
+ self.url = issue['url']
+ self.api_url = issue['api_url']
+ self.comment_count = issue['comment_count']
+ self.created_at = issue['created_at']
+ self.updated_at = issue['updated_at']
+
+ def comments(self):
+ """Gets Comments for a given Issue"""
+ comments = []
+ json_raw = self._account.request(self.api_url)
+ raw_issue = json_raw['issue']
+ raw_comments = raw_issue['comments']
+ for raw_comment in raw_comments:
+ c = comment.Comment(raw_comment)
+ comments.append(c)
+
+ return comments
View
13 milestone.py
@@ -1,8 +1,7 @@
class Milestone(object):
- """Representation of a Milestone in Sifter"""
- def __init__(self, milestone):
- self.name = milestone['name']
- self.due_date = milestone['due_date']
- self.issues_url = milestone['issues_url']
- self.api_issues_url = milestone['api_issues_url']
-
+ """Representation of a Milestone in Sifter"""
+ def __init__(self, milestone):
+ self.name = milestone['name']
+ self.due_date = milestone['due_date']
+ self.issues_url = milestone['issues_url']
+ self.api_issues_url = milestone['api_issues_url']
View
183 project.py
@@ -1,105 +1,90 @@
-import urllib2
-import json
import issue
import milestone
import category
import user
+
class Project(object):
- """Representation of a project in Sifter"""
- def __init__(self, project, token):
- self.api_token = token
- self.issues_url = project['issues_url']
- self.archived = project['archived']
- self.url = project['url']
- self.milestones_url = project['milestones_url']
- self.api_people_url = project['api_people_url']
- self.api_issues_url = project['api_issues_url']
- self.api_milestones_url = project['api_milestones_url']
- self.api_categories_url = project['api_categories_url']
- self.name = project['name']
-
- def issues(self):
- """Gets all the issues for a given project"""
- issues = []
- url = self.api_issues_url
- req = urllib2.Request(url)
- req.add_header('X-Sifter-Token', self.api_token)
- req.add_header('Accept', 'application/json')
- # Get page one
- json_raw = json.loads(urllib2.urlopen(req).read())
-
- # Set the next page
- next_page = json_raw['next_page_url']
-
- # Set the number of pages
- number_of_pages = json_raw['total_pages']
-
- for current_page in range(number_of_pages):
- # Create a wrapper for each issue, add it to the list
- raw_issues = json_raw['issues']
- for raw_issue in raw_issues:
- i = issue.Issue(raw_issue)
- issues.append(i)
-
- # Make a request for the next page
- url = next_page
- req = urllib2.Request(url)
- req.add_header('X-Sifter-Token', self.api_token)
- req.add_header('Accept', 'application/json')
- # store the results
- json_raw = json.loads(urllib2.urlopen(req).read())
-
- # set the next page
- if not json_raw['next_page_url']:
- next_page = json_raw['next_page_url']
-
- return issues
-
- def milestones(self):
- """Gets all the milestones for a given project"""
- milestones = []
- url = self.api_milestones_url
- req = urllib2.Request(url)
- req.add_header('X-Sifter-Token', self.api_token)
- req.add_header('Accept', 'application/json')
- json_raw = json.loads(urllib2.urlopen(req).read())
-
- raw_milestones = json_raw['milestones']
- for raw_milestone in raw_milestones:
- m = milestone.Milestone(raw_milestone)
- milestones.append(m)
-
- return milestones
-
- def categories(self):
- """Gets all the categories for a given project"""
- categories = []
- url = self.api_categories_url
- req = urllib2.Request(url)
- req.add_header('X-Sifter-Token', self.api_token)
- req.add_header('Accept', 'application/json')
- json_raw = json.loads(urllib2.urlopen(req).read())
-
- raw_categories = json_raw['categories']
- for raw_category in raw_categories:
- c = category.Category(raw_category)
- categories.append(c)
-
- return categories
-
- def people(self):
- """Gets all the people for a given project"""
- people = []
- url = self.api_people_url
- req = urllib2.Request(url)
- req.add_header('X-Sifter-Token', self.api_token)
- req.add_header('Accept', 'application/json')
- json_raw = json.loads(urllib2.urlopen(req).read())
-
- raw_people = json_raw['people']
- for raw_user in raw_people:
- u = user.User(raw_user)
- people.append(u)
-
- return people
+ """Representation of a project in Sifter"""
+ def __init__(self, project, account):
+ self._account = account
+ self.issues_url = project['issues_url']
+ self.archived = project['archived']
+ self.url = project['url']
+ self.api_url = project['api_url']
+ self.milestones_url = project['milestones_url']
+ self.api_people_url = project['api_people_url']
+ self.api_issues_url = project['api_issues_url']
+ self.api_milestones_url = project['api_milestones_url']
+ self.api_categories_url = project['api_categories_url']
+ self.name = project['name']
+ self.primary_company_name = project['primary_company_name']
+
+ def issues(self):
+ """Gets all the issues for a given project"""
+ issues = []
+
+ # Set per_page to 25 issues per page
+ first_page = self.api_issues_url + '?per_page=25&page=1'
+
+ # Get page one
+ json_raw = self._account.request(first_page)
+
+ # Set the next page
+ next_page = json_raw['next_page_url']
+
+ # Set the number of pages
+ number_of_pages = json_raw['total_pages']
+
+ for current_page in range(number_of_pages):
+ # Create a wrapper for each issue, add it to the list
+ raw_issues = json_raw['issues']
+ for raw_issue in raw_issues:
+ i = issue.Issue(raw_issue, self._account)
+ issues.append(i)
+
+ # Make a request for the next page
+ if current_page < number_of_pages - 1:
+ # store the results
+ json_raw = self._account.request(next_page)
+
+ # set the next page
+ next_page = json_raw['next_page_url']
+
+ return issues
+
+ def milestones(self):
+ """Gets all the milestones for a given project"""
+ milestones = []
+ json_raw = self._account.request(self.api_milestones_url)
+
+ raw_milestones = json_raw['milestones']
+ for raw_milestone in raw_milestones:
+ m = milestone.Milestone(raw_milestone)
+ milestones.append(m)
+
+ return milestones
+
+ def categories(self):
+ """Gets all the categories for a given project"""
+ categories = []
+ json_raw = self._account.request(self.api_categories_url)
+
+ raw_categories = json_raw['categories']
+ for raw_category in raw_categories:
+ c = category.Category(raw_category)
+ categories.append(c)
+
+ return categories
+
+ def people(self):
+ """Gets all the people for a given project"""
+ people = []
+ json_raw = self._account.request(self.api_people_url)
+
+ raw_people = json_raw['people']
+ for raw_user in raw_people:
+ u = user.User(raw_user)
+ people.append(u)
+
+ return people
View
88 sifter_print.py
@@ -25,52 +25,52 @@
import account
def main():
- # ask the user for the host and token
- host = input('Enter your sifterapp url in quotes:')
- token = input('Enter your sifter access key in quotes:')
- # host
- # the complete url to your sifter subdomain
- # i.e.: "https://mycompany.sifterapp.com"
- # token
- # the 32-character hexdex access key from my profile page
+ # ask the user for the host and token
+ host = input('Enter your sifterapp url in quotes:')
+ token = input('Enter your sifter access key in quotes:')
+ # host
+ # the complete url to your sifter subdomain
+ # i.e.: "https://mycompany.sifterapp.com"
+ # token
+ # the 32-character hexdex access key from my profile page
- a = account.Account(host,token) # instantiate and account
-
- projects = a.projects() # use projects method to get projects
-
- # dprint some of your project info to the screen to test that
- # sifter-python is working
- for p in projects:
- print
- print p.name # print project name
- # print issues info
- issues = p.issues()
- for i in issues:
- print i.number, i.status, i.priority, i.subject
-
- print
- print "*** milestones ***"
- milestones = p.milestones()
- for m in milestones:
- print m.name, m.due_date
+ a = account.Account(host, token) # instantiate and account
+
+ projects = a.projects() # use projects method to get projects
+
+ # dprint some of your project info to the screen to test that
+ # sifter-python is working
+ for p in projects:
+ print
+ print p.name # print project name
+ # print issues info
+ issues = p.issues()
+ for i in issues:
+ print i.number, i.status, i.priority, i.subject
+
+ print
+ print "*** milestones ***"
+ milestones = p.milestones()
+ for m in milestones:
+ print m.name, m.due_date
- print
- print "*** categories ***"
- categories = p.categories()
- for c in categories:
- print c.name
-
- print
- print "*** people ***"
- people = p.people()
- for u in people:
- print u.first_name,u.last_name
-
- print
- print "****************************************"
-
- return 0
+ print
+ print "*** categories ***"
+ categories = p.categories()
+ for c in categories:
+ print c.name
+
+ print
+ print "*** people ***"
+ people = p.people()
+ for u in people:
+ print u.first_name, u.last_name
+
+ print
+ print "****************************************"
+
+ return 0
if __name__ == '__main__':
- main()
+ main()
View
17 user.py
@@ -1,10 +1,9 @@
class User(object):
- """Representation of a User in Sifter"""
- def __init__(self, user):
- self.username = user['username']
- self.first_name = user['first_name']
- self.last_name = user['last_name']
- self.email = user['email']
- self.issues_url = user['issues_url']
- self.api_issues_url = user['api_issues_url']
-
+ """Representation of a User in Sifter"""
+ def __init__(self, user):
+ self.username = user['username']
+ self.first_name = user['first_name']
+ self.last_name = user['last_name']
+ self.email = user['email']
+ self.issues_url = user['issues_url']
+ self.api_issues_url = user['api_issues_url']

No commit comments for this range

Something went wrong with that request. Please try again.