Skip to content

Commit

Permalink
add starring and watching repository sub-api
Browse files Browse the repository at this point in the history
  • Loading branch information
tarsius committed Dec 25, 2012
1 parent 07731a6 commit 61867e2
Showing 1 changed file with 77 additions and 1 deletion.
78 changes: 77 additions & 1 deletion gh-repos.el
Expand Up @@ -38,7 +38,8 @@

;;;###autoload
(defclass gh-repos-api (gh-api-v3)
((repo-cls :allocation :class :initform gh-repos-repo))
((repo-cls :allocation :class :initform gh-repos-repo)
(user-cls :allocation :class :initform gh-user))
"Repos API")

;;;###autoload
Expand Down Expand Up @@ -274,6 +275,81 @@
(oref repo :name))
nil (when org `(("org" . ,org)))))

;;; Starring sub-API

(defmethod gh-repos-stargazers ((api gh-repos-api) repo)
(gh-api-authenticated-request
api (gh-object-list-reader (oref api user-cls)) "GET"
(format "/repos/%s/%s/stargazers"
(oref (oref repo :owner) :login)
(oref repo :name))))

(defmethod gh-repos-starred-list ((api gh-repos-api) &optional username)
(gh-api-authenticated-request
api (gh-object-list-reader (oref api repo-cls)) "GET"
(format "/users/%s/starred" (or username (gh-api-get-username api)))))

(defmethod gh-repos-starred-p ((api gh-repos-api) repo)
(eq (oref (gh-api-authenticated-request
api nil "GET"
(format "/user/starred/%s/%s"
(oref (oref repo :owner) :login)
(oref repo :name)))
:http-status)
204))

(defmethod gh-repos-star ((api gh-repos-api) repo)
(gh-api-authenticated-request
api nil "PUT"
(format "/user/starred/%s/%s"
(oref (oref repo :owner) :login)
(oref repo :name))))

(defmethod gh-repos-unstar ((api gh-repos-api) repo)
(gh-api-authenticated-request
api nil "DELETE"
(format "/user/starred/%s/%s"
(oref (oref repo :owner) :login)
(oref repo :name))))

;;; Watching sub-API

(defmethod gh-repos-watchers ((api gh-repos-api) repo)
(gh-api-authenticated-request
api (gh-object-list-reader (oref api user-cls)) "GET"
(format "/repos/%s/%s/subscribers"
(oref (oref repo :owner) :login)
(oref repo :name))))

(defmethod gh-repos-watched-list ((api gh-repos-api) &optional username)
(gh-api-authenticated-request
api (gh-object-list-reader (oref api repo-cls)) "GET"
(format "/users/%s/subscriptions"
(or username (gh-api-get-username api)))))

(defmethod gh-repos-watched-p ((api gh-repos-api) repo)
(eq (oref (gh-api-authenticated-request
api nil "GET"
(format "/user/subscriptions/%s/%s"
(oref (oref repo :owner) :login)
(oref repo :name)))
:http-status)
204))

(defmethod gh-repos-watch ((api gh-repos-api) repo)
(gh-api-authenticated-request
api nil "PUT"
(format "/user/subscriptions/%s/%s"
(oref (oref repo :owner) :login)
(oref repo :name))))

(defmethod gh-repos-unwatch ((api gh-repos-api) repo)
(gh-api-authenticated-request
api nil "DELETE"
(format "/user/subscriptions/%s/%s"
(oref (oref repo :owner) :login)
(oref repo :name))))

(provide 'gh-repos)
;;; gh-repos.el ends here

Expand Down

0 comments on commit 61867e2

Please sign in to comment.