Commits

Ian Cordasco  committed 3ae6223

Work on removing None values from JSON documents

In most instances they're useless and in some cases provide unintended
consequences.

  • Participants
  • Parent commits 47ff243

Comments (0)

Files changed (4)

File github3/github.py

         return self._iter(int(number), url, Issue, params=params)
 
     def iter_repo_issues(self, owner, repository, milestone=None,
-                         state='', assignee='', mentioned='', labels='',
-                         sort='', direction='', since='', number=-1):
+                         state=None, assignee=None, mentioned=None,
+                         labels=None, sort=None, direction=None, since=None,
+                         number=-1):
         """List issues on owner/repository. Only owner and repository are
         required.
 

File github3/models.py

 
         self._session.headers.update(headers)
         self._session.config['base_headers'].update(headers)
-        self._session.hooks = {'args': [json_hook]}
+        self._session.hooks.update({'args': [json_hook]})
 
         # set a sane default
         self._github_url = 'https://api.github.com'
     def __repr__(self):
         return '<github3-core at 0x{0:x}>'.format(id(self))
 
+    def _remove_none(self, data):
+        for (k, v) in list(data.items()):
+            if v is None:
+                del(data[k])
+
     def _json(self, request, status_code):
         ret = None
         if request.status_code == status_code and request.content:

File github3/repos.py

         """
         issue = {'title': title, 'body': body, 'assignee': assignee,
                  'milestone': milestone, 'labels': labels}
+        self._remove_none(issue)
         url = self._build_url('issues', base_url=self._api)
 
         json = self._json(self._post(url, issue), 201)
             state = 'open'
         data = {'title': title, 'state': state,
                 'description': description, 'due_on': due_on}
+        self._remove_none(data)
         json = self._json(self._post(url, data), 201)
         return Milestone(json, self) if json else None
 
             value unchanged.
         :returns: bool -- True if successful, False otherwise
         """
-        edit = {'name': name}
-        if description is not None:
-            edit['description'] = description
-        if homepage is not None:
-            edit['homepage'] = homepage
-        if private is not None:
-            edit['private'] = private
-        if has_issues is not None:
-            edit['has_issues'] = has_issues
-        if has_wiki is not None:
-            edit['has_wiki'] = has_wiki
-        if has_downloads is not None:
-            edit['has_downloads'] = has_downloads
-        if default_branch is not None:
-            edit['default_branch'] = default_branch
-
-        data = edit
-        json = self._json(self._patch(self._api, data=data), 200)
+        edit = {'name': name, 'description': description, 'homepage': homepage,
+                'private': private, 'has_issues': has_issues,
+                'has_wiki': has_wiki, 'has_downloads': has_downloads,
+                'default_branch': default_branch}
+        self._remove_none(edit)
+        json = self._json(self._patch(self._api, data=edit), 200)
         if json:
             self._update_(json)
             return True
             -1 returns all branches
         :returns: list of :class:`Branch <Branch>`\ es
         """
-        # Paginate?
         url = self._build_url('branches', base_url=self._api)
         return self._iter(int(number), url, Branch)
 
             -1 returns all comments
         :returns: list of :class:`RepoComment <RepoComment>`\ s
         """
-        # Paginate?
         url = self._build_url('comments', base_url=self._api)
         return self._iter(int(number), url, RepoComment)
 
             Default: -1 returns all contributors
         :returns: list of :class:`User <github3.users.User>`\ s
         """
-        # Paginate
         url = self._build_url('contributors', base_url=self._api)
         params = {}
         if anon:
         """
         url = self._build_url('issues', base_url=self._api)
 
-        params = {}
+        params = {'assignee': assignee, 'mentioned': mentioned}
         if milestone in ('*', 'none') or isinstance(milestone, int):
             params['milestone'] = milestone
-
-        if assignee:
-            params['assignee'] = assignee
-
-        if mentioned:
-            params['mentioned'] = mentioned
-
+        self._remove_none(params)
         params.update(issue_params(None, state, labels, sort, direction,
             since))  # nopep8
 
             :class:`PullRequest <github3.pulls.PullRequest>`\ s
         """
         url = self._build_url('pulls', base_url=self._api)
+        params = {}
         if state in ('open', 'closed'):
-            url = '{0}?{1}={2}'.format(url, 'state', state)
-        return self._iter(int(number), url, PullRequest)
+            params['state'] = state
+        return self._iter(int(number), url, PullRequest, params=params)
 
     def iter_refs(self, subspace='', number=-1):
         """Iterates over references for this repository.

File github3/users.py

             returns all events available
         :returns: generator of :class:`Event <github3.events.Event>`\ s
         """
-        # Paginate
         path = ['received_events']
         if public:
             path.append('public')
         user = {'name': name, 'email': email, 'blog': blog,
                 'company': company, 'location': location,
                 'hireable': hireable, 'bio': bio}
+        self._remove_none(user)
         url = self._build_url('user')
         json = self._json(self._patch(url, data=user), 200)
         if json: