Class: Octopussy::Client
- Inherits:
-
Object
- Object
- Octopussy::Client
- Includes:
- HTTParty
- Defined in:
- lib/octopussy/client.rb
Instance Attribute Summary collapse
-
#login ⇒ Object
readonly
Returns the value of attribute login.
-
#token ⇒ Object
readonly
Returns the value of attribute token.
Instance Method Summary collapse
- #add_collaborator(repo, collaborator) ⇒ Object
- #add_comment(repo, number, comment) ⇒ Object
- #add_deploy_key(repo, key, title = '') ⇒ Object
- #add_email(email) ⇒ Object
- #add_key(title, key) ⇒ Object
- #add_label(repo, number, label) ⇒ Object
- #blob(repo, sha, path) ⇒ Object
- #branches(repo) ⇒ Object
- #close_issue(repo, number) ⇒ Object
- #collaborators(repo) ⇒ Object
- #commit(repo, sha) ⇒ Object
- #confirm_delete(repo, delete_token) ⇒ Object
- #contributors(repo) ⇒ Object
-
#create(options) ⇒ Object
:name, :description, :homepage, :public.
- #delete(repo, delete_token = {}) ⇒ Object
- #deploy_keys(repo) ⇒ Object
- #emails ⇒ Object
- #follow!(username) ⇒ Object
- #followers(login = self.login) ⇒ Object
- #following(login = self.login) ⇒ Object
- #follows?(*args) ⇒ Boolean
- #fork(repo) ⇒ Object
-
#initialize(auth = {}) ⇒ Client
constructor
:login => ‘pengwynn’, :token => ‘your_github_api_key’.
- #issue(repo, id) ⇒ Object
- #issues(repo, state) ⇒ Object
- #keys ⇒ Object
- #labels(repo) ⇒ Object
- #languages(repo) ⇒ Object
-
#list_commits(repo, branch = "master") ⇒ Object
Commits.
- #list_repos(username = nil) ⇒ Object
- #network(repo) ⇒ Object
- #network_data(repo, nethash) ⇒ Object
-
#network_meta(repo) ⇒ Object
Network.
- #open_issue(repo, title, body) ⇒ Object
- #raw(repo, sha) ⇒ Object
- #remove_collaborator(repo, collaborator) ⇒ Object
- #remove_deploy_key(repo, id) ⇒ Object
- #remove_email(email) ⇒ Object
- #remove_key(id) ⇒ Object
- #remove_label(repo, number, label) ⇒ Object
- #reopen_issue(repo, number) ⇒ Object
- #repo(repo) ⇒ Object
-
#search_issues(repo, state, q) ⇒ Object
Issues.
-
#search_repos(q) ⇒ Object
Repos.
- #search_users(q) ⇒ Object
- #set_private(repo) ⇒ Object
- #set_public(repo) ⇒ Object
- #tags(repo) ⇒ Object
-
#tree(repo, sha) ⇒ Object
Trees.
- #unfollow!(username) ⇒ Object
- #unwatch(repo) ⇒ Object
- #update_issue(repo, number, title, body) ⇒ Object
- #update_user(values = {}) ⇒ Object
- #user(login = self.login) ⇒ Object
- #watch(repo) ⇒ Object
- #watched(login = self.login) ⇒ Object
Constructor Details
#initialize(auth = {}) ⇒ Client
:login => ‘pengwynn’, :token => ‘your_github_api_key’
11 12 13 14 |
# File 'lib/octopussy/client.rb', line 11 def initialize(auth={}) @login = auth[:login] @token = auth[:token] end |
Instance Attribute Details
#login ⇒ Object (readonly)
Returns the value of attribute login.
8 9 10 |
# File 'lib/octopussy/client.rb', line 8 def login @login end |
#token ⇒ Object (readonly)
Returns the value of attribute token.
8 9 10 |
# File 'lib/octopussy/client.rb', line 8 def token @token end |
Instance Method Details
#add_collaborator(repo, collaborator) ⇒ Object
264 265 266 267 268 |
# File 'lib/octopussy/client.rb', line 264 def add_collaborator(repo, collaborator) repo = Repo.new(repo) response = self.class.post("/repos/collaborators/#{repo.name}/add/#{collaborator}", :query => auth_params) Hashie::Mash.new(response).collaborators end |
#add_comment(repo, number, comment) ⇒ Object
158 159 160 161 162 |
# File 'lib/octopussy/client.rb', line 158 def add_comment(repo, number, comment) repo = Repo.new(repo) response = self.class.post("/issues/comment/#{repo.username}/#{repo.name}/#{number}", :body => {:comment => comment}) Hashie::Mash.new(response).comment end |
#add_deploy_key(repo, key, title = '') ⇒ Object
224 225 226 227 228 |
# File 'lib/octopussy/client.rb', line 224 def add_deploy_key(repo, key, title='') repo = Repo.new(repo) response = self.class.post("/repos/key/#{repo.name}/add", :query => auth_params, :body => {:title => title, :key => key}) Hashie::Mash.new(response).public_keys end |
#add_email(email) ⇒ Object
71 72 73 74 |
# File 'lib/octopussy/client.rb', line 71 def add_email(email) response = self.class.post("/user/email/add", :query => auth_params, :body => {:email => email}) Hashie::Mash.new(response).emails end |
#add_key(title, key) ⇒ Object
86 87 88 89 |
# File 'lib/octopussy/client.rb', line 86 def add_key(title, key) response = self.class.post("/user/key/add", :query => auth_params, :body => {:title => title, :key => key}) Hashie::Mash.new(response).public_keys end |
#add_label(repo, number, label) ⇒ Object
146 147 148 149 150 |
# File 'lib/octopussy/client.rb', line 146 def add_label(repo, number, label) repo = Repo.new(repo) response = self.class.post("/issues/label/add/#{repo.username}/#{repo.name}/#{label}/#{number}") Hashie::Mash.new(response).labels end |
#blob(repo, sha, path) ⇒ Object
322 323 324 325 326 |
# File 'lib/octopussy/client.rb', line 322 def blob(repo, sha, path) repo = Repo.new(repo) response = self.class.get("http://github.com/api/v2/json/blob/show/#{repo.username}/#{repo.name}/#{sha}/#{path}", :query => auth_params) Hashie::Mash.new(response).blob end |
#branches(repo) ⇒ Object
294 295 296 297 298 |
# File 'lib/octopussy/client.rb', line 294 def branches(repo) repo = Repo.new(repo) response = self.class.get("/repos/show/#{repo.username}/#{repo.name}/branches", :query => auth_params) Hashie::Mash.new(response).branches end |
#close_issue(repo, number) ⇒ Object
122 123 124 125 126 |
# File 'lib/octopussy/client.rb', line 122 def close_issue(repo, number) repo = Repo.new(repo) response = self.class.post("/issues/close/#{repo.username}/#{repo.name}/#{number}") Hashie::Mash.new(response).issue end |
#collaborators(repo) ⇒ Object
236 237 238 239 240 |
# File 'lib/octopussy/client.rb', line 236 def collaborators(repo) repo = Repo.new(repo) response = self.class.post("/repos/show/#{repo.username}/#{repo.name}/collaborators", :query => auth_params) Hashie::Mash.new(response).collaborators end |
#commit(repo, sha) ⇒ Object
342 343 344 345 346 |
# File 'lib/octopussy/client.rb', line 342 def commit(repo, sha) repo = Repo.new(repo) response = self.class.get("http://github.com/api/v2/json/commits/show/#{repo.username}/#{repo.name}/#{sha}") Hashie::Mash.new(response).commit end |
#confirm_delete(repo, delete_token) ⇒ Object
202 203 204 |
# File 'lib/octopussy/client.rb', line 202 def confirm_delete(repo, delete_token) delete(repo, delete_token) end |
#contributors(repo) ⇒ Object
242 243 244 245 246 |
# File 'lib/octopussy/client.rb', line 242 def contributors(repo) repo = Repo.new(repo) response = self.class.get("/repos/show/#{repo.username}/#{repo.name}/contributors") Hashie::Mash.new(response).contributors end |
#create(options) ⇒ Object
:name, :description, :homepage, :public
191 192 193 194 |
# File 'lib/octopussy/client.rb', line 191 def create() response = self.class.post("/repos/create", :query => auth_params, :body => ) Hashie::Mash.new(response).repository end |
#delete(repo, delete_token = {}) ⇒ Object
196 197 198 199 200 |
# File 'lib/octopussy/client.rb', line 196 def delete(repo, delete_token={}) repo = Repo.new(repo) response = self.class.post("/repos/delete/#{repo.name}", :query => auth_params, :body => {:delete_token => delete_token}) Hashie::Mash.new(response).repository end |
#deploy_keys(repo) ⇒ Object
218 219 220 221 222 |
# File 'lib/octopussy/client.rb', line 218 def deploy_keys(repo) repo = Repo.new(repo) response = self.class.get("/repos/keys/#{repo.name}", :query => auth_params) Hashie::Mash.new(response).public_keys end |
#emails ⇒ Object
66 67 68 69 |
# File 'lib/octopussy/client.rb', line 66 def emails response = self.class.get("/user/emails", :query => auth_params) Hashie::Mash.new(response).emails end |
#follow!(username) ⇒ Object
43 44 45 46 |
# File 'lib/octopussy/client.rb', line 43 def follow!(username) response = self.class.post("/user/follow/#{username}", :query => auth_params) Hashie::Mash.new(response).users end |
#followers(login = self.login) ⇒ Object
33 34 35 36 |
# File 'lib/octopussy/client.rb', line 33 def followers(login=self.login) response = self.class.get("/user/show/#{login}/followers") Hashie::Mash.new(response).users end |
#following(login = self.login) ⇒ Object
38 39 40 41 |
# File 'lib/octopussy/client.rb', line 38 def following(login=self.login) response = self.class.get("/user/show/#{login}/following") Hashie::Mash.new(response).users end |
#follows?(*args) ⇒ Boolean
53 54 55 56 57 58 59 |
# File 'lib/octopussy/client.rb', line 53 def follows?(*args) target = args.pop username = args.first username ||= self.login return if username.nil? self.following(username).include?(target) end |
#fork(repo) ⇒ Object
184 185 186 187 188 |
# File 'lib/octopussy/client.rb', line 184 def fork(repo) repo = Repo.new(repo) response = self.class.post("/repos/fork/#{repo.username}/#{repo.name}", :query => auth_params) Hashie::Mash.new(response).repository end |
#issue(repo, id) ⇒ Object
110 111 112 113 114 |
# File 'lib/octopussy/client.rb', line 110 def issue(repo, id) repo = Repo.new(repo) response = self.class.get("/issues/show/#{repo.username}/#{repo.name}/#{id}") Hashie::Mash.new(response).issue end |
#issues(repo, state) ⇒ Object
104 105 106 107 108 |
# File 'lib/octopussy/client.rb', line 104 def issues(repo, state) repo = Repo.new(repo) response = self.class.get("/issues/list/#{repo.username}/#{repo.name}/#{state}") Hashie::Mash.new(response).issues end |
#keys ⇒ Object
81 82 83 84 |
# File 'lib/octopussy/client.rb', line 81 def keys response = self.class.get("/user/keys", :query => auth_params) Hashie::Mash.new(response).public_keys end |
#labels(repo) ⇒ Object
140 141 142 143 144 |
# File 'lib/octopussy/client.rb', line 140 def labels(repo) repo = Repo.new(repo) response = self.class.get("/issues/labels/#{repo.username}/#{repo.name}") Hashie::Mash.new(response).labels end |
#languages(repo) ⇒ Object
282 283 284 285 286 |
# File 'lib/octopussy/client.rb', line 282 def languages(repo) repo = Repo.new(repo) response = self.class.get("/repos/show/#{repo.username}/#{repo.name}/languages") Hashie::Mash.new(response).languages end |
#list_commits(repo, branch = "master") ⇒ Object
Commits
336 337 338 339 340 |
# File 'lib/octopussy/client.rb', line 336 def list_commits(repo, branch="master") repo = Repo.new(repo) response = self.class.get("http://github.com/api/v2/json/commits/list/#{repo.username}/#{repo.name}/#{branch}") Hashie::Mash.new(response).commits end |
#list_repos(username = nil) ⇒ Object
254 255 256 257 258 259 260 261 262 |
# File 'lib/octopussy/client.rb', line 254 def list_repos(username = nil) if username.nil? && !@login.nil? username = login elsif username.nil? raise ArgumentError, 'you must provide a username' end response = self.class.get("/repos/show/#{username}", :query => auth_params) Hashie::Mash.new(response).repositories end |
#network(repo) ⇒ Object
276 277 278 279 280 |
# File 'lib/octopussy/client.rb', line 276 def network(repo) repo = Repo.new(repo) response = self.class.get("/repos/show/#{repo.username}/#{repo.name}/network") Hashie::Mash.new(response).network end |
#network_data(repo, nethash) ⇒ Object
308 309 310 311 312 |
# File 'lib/octopussy/client.rb', line 308 def network_data(repo, nethash) repo = Repo.new(repo) response = self.class.get("http://github.com/#{repo.username}/#{repo.name}/network_data_chunk", :query => {:nethash => nethash}) Hashie::Mash.new(response).commits end |
#network_meta(repo) ⇒ Object
Network
302 303 304 305 306 |
# File 'lib/octopussy/client.rb', line 302 def (repo) repo = Repo.new(repo) response = self.class.get("http://github.com/#{repo.username}/#{repo.name}/network_meta") Hashie::Mash.new(response) end |
#open_issue(repo, title, body) ⇒ Object
116 117 118 119 120 |
# File 'lib/octopussy/client.rb', line 116 def open_issue(repo, title, body) repo = Repo.new(repo) response = self.class.post("/issues/open/#{repo.username}/#{repo.name}", :body => {:title => title, :body => body}) Hashie::Mash.new(response).issue end |
#raw(repo, sha) ⇒ Object
328 329 330 331 332 |
# File 'lib/octopussy/client.rb', line 328 def raw(repo, sha) repo = Repo.new(repo) response = self.class.get("http://github.com/api/v2/yaml/blob/show/#{repo.username}/#{repo.name}/#{sha}", :query => auth_params) response.body end |
#remove_collaborator(repo, collaborator) ⇒ Object
270 271 272 273 274 |
# File 'lib/octopussy/client.rb', line 270 def remove_collaborator(repo, collaborator) repo = Repo.new(repo) response = self.class.post("/repos/collaborators/#{repo.name}/remove/#{collaborator}", :query => auth_params) Hashie::Mash.new(response).collaborators end |
#remove_deploy_key(repo, id) ⇒ Object
230 231 232 233 234 |
# File 'lib/octopussy/client.rb', line 230 def remove_deploy_key(repo, id) repo = Repo.new(repo) response = self.class.post("/repos/key/#{repo.name}/remove", :query => auth_params, :body => {:id => id}) Hashie::Mash.new(response).public_keys end |
#remove_email(email) ⇒ Object
76 77 78 79 |
# File 'lib/octopussy/client.rb', line 76 def remove_email(email) response = self.class.post("/user/email/remove", :query => auth_params, :body => {:email => email}) Hashie::Mash.new(response).emails end |
#remove_key(id) ⇒ Object
91 92 93 94 |
# File 'lib/octopussy/client.rb', line 91 def remove_key(id) response = self.class.post("/user/key/remove", :query => auth_params, :body => {:id => id}) Hashie::Mash.new(response).public_keys end |
#remove_label(repo, number, label) ⇒ Object
152 153 154 155 156 |
# File 'lib/octopussy/client.rb', line 152 def remove_label(repo, number, label) repo = Repo.new(repo) response = self.class.post("/issues/label/remove/#{repo.username}/#{repo.name}/#{label}/#{number}") Hashie::Mash.new(response).labels end |
#reopen_issue(repo, number) ⇒ Object
128 129 130 131 132 |
# File 'lib/octopussy/client.rb', line 128 def reopen_issue(repo, number) repo = Repo.new(repo) response = self.class.post("/issues/reopen/#{repo.username}/#{repo.name}/#{number}") Hashie::Mash.new(response).issue end |
#repo(repo) ⇒ Object
248 249 250 251 252 |
# File 'lib/octopussy/client.rb', line 248 def repo(repo) repo = Repo.new(repo) response = self.class.get("/repos/show/#{repo.username}/#{repo.name}", :query => auth_params) Hashie::Mash.new(response).repository end |
#search_issues(repo, state, q) ⇒ Object
Issues
98 99 100 101 102 |
# File 'lib/octopussy/client.rb', line 98 def search_issues(repo, state, q) repo = Repo.new(repo) response = self.class.get("/issues/search/#{repo.username}/#{repo.name}/#{state}/#{q}") Hashie::Mash.new(response).issues end |
#search_repos(q) ⇒ Object
Repos
166 167 168 169 170 |
# File 'lib/octopussy/client.rb', line 166 def search_repos(q) q = CGI.escape(q) response = self.class.get("/repos/search/#{q}") Hashie::Mash.new(response).repositories end |
#search_users(q) ⇒ Object
16 17 18 19 20 |
# File 'lib/octopussy/client.rb', line 16 def search_users(q) q = CGI.escape(q) response = self.class.get("/user/search/#{q}") Hashie::Mash.new(response).users end |
#set_private(repo) ⇒ Object
206 207 208 209 210 |
# File 'lib/octopussy/client.rb', line 206 def set_private(repo) repo = Repo.new(repo) response = self.class.post("/repos/set/private/#{repo.name}", :query => auth_params) Hashie::Mash.new(response).repository end |
#set_public(repo) ⇒ Object
212 213 214 215 216 |
# File 'lib/octopussy/client.rb', line 212 def set_public(repo) repo = Repo.new(repo) response = self.class.post("/repos/set/public/#{repo.name}", :query => auth_params) Hashie::Mash.new(response).repository end |
#tags(repo) ⇒ Object
288 289 290 291 292 |
# File 'lib/octopussy/client.rb', line 288 def (repo) repo = Repo.new(repo) response = self.class.get("/repos/show/#{repo.username}/#{repo.name}/tags") Hashie::Mash.new(response). end |
#tree(repo, sha) ⇒ Object
Trees
316 317 318 319 320 |
# File 'lib/octopussy/client.rb', line 316 def tree(repo, sha) repo = Repo.new(repo) response = self.class.get("http://github.com/api/v2/json/tree/show/#{repo.username}/#{repo.name}/#{sha}", :query => auth_params) Hashie::Mash.new(response).tree end |
#unfollow!(username) ⇒ Object
48 49 50 51 |
# File 'lib/octopussy/client.rb', line 48 def unfollow!(username) response = self.class.post("/user/unfollow/#{username}", :query => auth_params) Hashie::Mash.new(response).users end |
#unwatch(repo) ⇒ Object
178 179 180 181 182 |
# File 'lib/octopussy/client.rb', line 178 def unwatch(repo) repo = Repo.new(repo) response = self.class.post("/repos/unwatch/#{repo.username}/#{repo.name}", :query => auth_params) Hashie::Mash.new(response).repository end |
#update_issue(repo, number, title, body) ⇒ Object
134 135 136 137 138 |
# File 'lib/octopussy/client.rb', line 134 def update_issue(repo, number, title, body) repo = Repo.new(repo) response = self.class.post("/issues/edit/#{repo.username}/#{repo.name}/#{number}", :body => {:title => title, :body => body}) Hashie::Mash.new(response).issue end |
#update_user(values = {}) ⇒ Object
28 29 30 31 |
# File 'lib/octopussy/client.rb', line 28 def update_user(values={}) response = self.class.post("/user/show/#{self.login}", :query => auth_params, :body => {:values => values}) Hashie::Mash.new(response).user end |
#user(login = self.login) ⇒ Object
22 23 24 25 |
# File 'lib/octopussy/client.rb', line 22 def user(login=self.login) response = self.class.get("/user/show/#{login}", :query => auth_params) Hashie::Mash.new(response).user end |
#watch(repo) ⇒ Object
172 173 174 175 176 |
# File 'lib/octopussy/client.rb', line 172 def watch(repo) repo = Repo.new(repo) response = self.class.post("/repos/watch/#{repo.username}/#{repo.name}", :query => auth_params) Hashie::Mash.new(response).repository end |
#watched(login = self.login) ⇒ Object
61 62 63 64 |
# File 'lib/octopussy/client.rb', line 61 def watched(login=self.login) response = self.class.get("/repos/watched/#{login}") Hashie::Mash.new(response).repositories end |