octopussy 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.gitignore +21 -0
- data/LICENSE +20 -0
- data/README.markdown +64 -0
- data/Rakefile +59 -0
- data/VERSION +1 -0
- data/changelog.markdown +5 -0
- data/lib/octopussy.rb +134 -0
- data/lib/octopussy/client.rb +393 -0
- data/lib/octopussy/repo.rb +33 -0
- data/test/fixtures/blob.json +10 -0
- data/test/fixtures/branches.json +6 -0
- data/test/fixtures/close_issue.json +1 -0
- data/test/fixtures/collaborators.json +1 -0
- data/test/fixtures/comment.json +1 -0
- data/test/fixtures/emails.json +1 -0
- data/test/fixtures/followers.json +3 -0
- data/test/fixtures/full_user.json +27 -0
- data/test/fixtures/issue.json +14 -0
- data/test/fixtures/issues.json +50 -0
- data/test/fixtures/keys.json +1 -0
- data/test/fixtures/labels.json +1 -0
- data/test/fixtures/languages.json +1 -0
- data/test/fixtures/network.json +26 -0
- data/test/fixtures/network_data.json +1 -0
- data/test/fixtures/network_meta.json +109 -0
- data/test/fixtures/open_issue.json +1 -0
- data/test/fixtures/raw_git_data.json +7 -0
- data/test/fixtures/reopen_issue.json +1 -0
- data/test/fixtures/repo.json +14 -0
- data/test/fixtures/repo_search.json +452 -0
- data/test/fixtures/repos.json +830 -0
- data/test/fixtures/search.json +44 -0
- data/test/fixtures/tags.json +8 -0
- data/test/fixtures/trees.json +140 -0
- data/test/fixtures/user.json +16 -0
- data/test/helper.rb +45 -0
- data/test/test_octopussy.rb +397 -0
- data/test/test_repo.rb +42 -0
- metadata +156 -0
data/.document
ADDED
data/.gitignore
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Wynn Netherland
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.markdown
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
|
2
|
+
# octopussy
|
3
|
+
|
4
|
+
<img src='http://upload.wikimedia.org/wikipedia/en/b/bb/007Octopussyposter.jpg' style='float: right; margin: 0 0 10px 10px'/>
|
5
|
+
|
6
|
+
Simple Ruby wrapper for the GitHub v2 API.
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
|
10
|
+
sudo gem install octopussy
|
11
|
+
|
12
|
+
## Some examples
|
13
|
+
|
14
|
+
### Show a user
|
15
|
+
|
16
|
+
Octopussy.user('pengwynn')
|
17
|
+
=> <#Hashie::Mash blog="http://wynnnetherland.com" company="Orrka" created_at="2008/02/25 10:24:19 -0800" email="wynn.netherland@gmail.com" followers_count=21 following_count=55 id=865 location="Dallas, TX" login="pengwynn" name="Wynn Netherland" public_gist_count=4 public_repo_count=16>
|
18
|
+
|
19
|
+
### Show who a user follows
|
20
|
+
|
21
|
+
Octopussy.following('pengwynn')
|
22
|
+
=> ["cglee", "bryansray", "rails", "zachinglis", "wycats", "obie", "mully", "squeejee", "jderrett", "Shopify", "ReinH", "technoweenie", "errfree", "defunkt", "joshsusser", "hashrocket", "newbamboo", "bigtiger", "github", "jamis", "jeresig", "thoughtbot", "therealadam", "jnunemaker", "seaofclouds", "choan", "llimllib", "kwhinnery", "marshall", "handcrafted", "adamstac", "jashkenas", "dan", "remy", "hayesdavis", "documentcloud", "imathis", "mdeiters", "njonsson", "asenchi", "mattsa", "marclove", "webiest", "brogers", "polomasta", "stephp", "mchelen", "piyush", "davidnorth", "rmetzler", "jferris", "madrobby", "zh", "erikvold", "desandro"]
|
23
|
+
|
24
|
+
## Working with repositories
|
25
|
+
|
26
|
+
For convenience, methods that require a repo argument may be passed in any of the following forms
|
27
|
+
|
28
|
+
* "pengwynn/linked"
|
29
|
+
* {:username => 'pengwynn', :name => 'linkedin'}
|
30
|
+
* {:username => 'pengwynn', :repo => 'linkedin'}
|
31
|
+
* instance of Repo
|
32
|
+
|
33
|
+
### Show a repo
|
34
|
+
|
35
|
+
Octopussy.repo("pengwynn/linkedin")
|
36
|
+
=> <#Hashie::Mash description="Ruby wrapper for the LinkedIn API" fork=false forks=1 homepage="http://bit.ly/ruby-linkedin" name="linkedin" open_issues=2 owner="pengwynn" private=false url="http://github.com/pengwynn/linkedin" watchers=36>
|
37
|
+
|
38
|
+
## Authenticated requests
|
39
|
+
|
40
|
+
Some methods require authentication so you'll need to pass a login and an api_token. You can find your GitHub API token on your [account page](https://github.com/account)
|
41
|
+
|
42
|
+
client = Octopussy::Client.new(:login => 'pengwynn', :token => 'OU812')
|
43
|
+
client.follow!('adamstac')
|
44
|
+
|
45
|
+
Read the full [docs](http://rdoc.info/projects/pengwynn/octopussy) or check out the [examples](http://github.com/pengwynn/octopussy/tree/master/examples)
|
46
|
+
|
47
|
+
## Note on Patches/Pull Requests
|
48
|
+
|
49
|
+
* Fork the project.
|
50
|
+
* Make your feature addition or bug fix.
|
51
|
+
* Add tests for it. This is important so I don't break it in a
|
52
|
+
future version unintentionally.
|
53
|
+
* Commit, do not mess with rakefile, version, or history.
|
54
|
+
(if you want to have your own version, that is fine but
|
55
|
+
bump version in a commit by itself I can ignore when I pull)
|
56
|
+
* Send me a pull request. Bonus points for topic branches.
|
57
|
+
|
58
|
+
## Credits
|
59
|
+
|
60
|
+
Octopussy is inspired by [Octopi](http://github.com/fcoury/octopi) and aims to be a lightweight, less active-resourcey alternative.
|
61
|
+
|
62
|
+
## Copyright
|
63
|
+
|
64
|
+
Copyright (c) 2009 [Wynn Netherland](http://wynnnetherland.com), [Adam Stacoviak](http://adamstacoviak.com/). See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "octopussy"
|
8
|
+
gem.summary = %Q{Simple wrapper for the GitHub API}
|
9
|
+
gem.description = %Q{Simple wrapper for the GitHub API v2}
|
10
|
+
gem.email = "wynn.netherland@gmail.com"
|
11
|
+
gem.homepage = "http://github.com/pengwynn/octopussy"
|
12
|
+
gem.authors = ["Wynn Netherland", "Adam Stacoviak"]
|
13
|
+
|
14
|
+
gem.add_dependency('hashie', '~> 0.1.3')
|
15
|
+
gem.add_dependency('httparty', '~> 0.4.5')
|
16
|
+
|
17
|
+
gem.add_development_dependency('thoughtbot-shoulda', '>= 2.10.1')
|
18
|
+
gem.add_development_dependency('jnunemaker-matchy', '0.4.0')
|
19
|
+
gem.add_development_dependency('mocha', '0.9.4')
|
20
|
+
gem.add_development_dependency('fakeweb', '>= 1.2.5')
|
21
|
+
end
|
22
|
+
Jeweler::GemcutterTasks.new
|
23
|
+
rescue LoadError
|
24
|
+
puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
|
25
|
+
end
|
26
|
+
|
27
|
+
require 'rake/testtask'
|
28
|
+
Rake::TestTask.new(:test) do |test|
|
29
|
+
test.libs << 'lib' << 'test'
|
30
|
+
test.pattern = 'test/**/test_*.rb'
|
31
|
+
test.verbose = true
|
32
|
+
end
|
33
|
+
|
34
|
+
begin
|
35
|
+
require 'rcov/rcovtask'
|
36
|
+
Rcov::RcovTask.new do |test|
|
37
|
+
test.libs << 'test'
|
38
|
+
test.pattern = 'test/**/test_*.rb'
|
39
|
+
test.verbose = true
|
40
|
+
end
|
41
|
+
rescue LoadError
|
42
|
+
task :rcov do
|
43
|
+
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
task :test => :check_dependencies
|
48
|
+
|
49
|
+
task :default => :test
|
50
|
+
|
51
|
+
require 'rake/rdoctask'
|
52
|
+
Rake::RDocTask.new do |rdoc|
|
53
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
54
|
+
|
55
|
+
rdoc.rdoc_dir = 'rdoc'
|
56
|
+
rdoc.title = "octopussy #{version}"
|
57
|
+
rdoc.rdoc_files.include('README*')
|
58
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
59
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.1
|
data/changelog.markdown
ADDED
data/lib/octopussy.rb
ADDED
@@ -0,0 +1,134 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
|
3
|
+
gem 'hashie', '~> 0.1.3'
|
4
|
+
require 'hashie'
|
5
|
+
|
6
|
+
gem 'httparty', '~> 0.4.5'
|
7
|
+
require 'httparty'
|
8
|
+
|
9
|
+
directory = File.expand_path(File.dirname(__FILE__))
|
10
|
+
|
11
|
+
Hash.send :include, Hashie::HashExtensions
|
12
|
+
|
13
|
+
|
14
|
+
module Octopussy
|
15
|
+
class OctopussyError < StandardError
|
16
|
+
attr_reader :data
|
17
|
+
|
18
|
+
def initialize(data)
|
19
|
+
@data = data
|
20
|
+
super
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
class RateLimitExceeded < StandardError; end
|
25
|
+
class Unauthorized < StandardError; end
|
26
|
+
class General < OctopussyError; end
|
27
|
+
|
28
|
+
class Unavailable < StandardError; end
|
29
|
+
class InformOctopussy < StandardError; end
|
30
|
+
class NotFound < StandardError; end
|
31
|
+
|
32
|
+
|
33
|
+
def self.search_users(q)
|
34
|
+
Client.new.search_users(q)
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.user(login)
|
38
|
+
Client.new.user(login)
|
39
|
+
end
|
40
|
+
|
41
|
+
def self.followers(login)
|
42
|
+
Client.new.followers(login)
|
43
|
+
end
|
44
|
+
|
45
|
+
def self.following(login)
|
46
|
+
Client.new.following(login)
|
47
|
+
end
|
48
|
+
|
49
|
+
def self.follows?(username, target)
|
50
|
+
Client.new.follows?(username, target)
|
51
|
+
end
|
52
|
+
|
53
|
+
def self.watched(login)
|
54
|
+
Client.new.watched(login)
|
55
|
+
end
|
56
|
+
|
57
|
+
# Issues
|
58
|
+
|
59
|
+
def self.search_issues(repo, state, q)
|
60
|
+
Client.new.search_issues(repo, state, q)
|
61
|
+
end
|
62
|
+
|
63
|
+
# repo, state
|
64
|
+
def self.issues(repo, state)
|
65
|
+
Client.new.issues(repo, state)
|
66
|
+
end
|
67
|
+
|
68
|
+
# repo, id
|
69
|
+
def self.issue(repo, id)
|
70
|
+
Client.new.issue(repo, id)
|
71
|
+
end
|
72
|
+
|
73
|
+
# Repos
|
74
|
+
|
75
|
+
def self.search_repos(q)
|
76
|
+
Client.new.search_repos(q)
|
77
|
+
end
|
78
|
+
|
79
|
+
def self.repo(repo)
|
80
|
+
Client.new.repo(repo)
|
81
|
+
end
|
82
|
+
|
83
|
+
def self.list_repos(username)
|
84
|
+
Client.new.list_repos(username)
|
85
|
+
end
|
86
|
+
|
87
|
+
def self.collaborators(repo)
|
88
|
+
Client.new.collaborators(repo)
|
89
|
+
end
|
90
|
+
|
91
|
+
def self.network(repo)
|
92
|
+
Client.new.network(repo)
|
93
|
+
end
|
94
|
+
|
95
|
+
def self.languages(repo)
|
96
|
+
Client.new.languages(repo)
|
97
|
+
end
|
98
|
+
|
99
|
+
def self.tags(repo)
|
100
|
+
Client.new.tags(repo)
|
101
|
+
end
|
102
|
+
|
103
|
+
def self.branches(repo)
|
104
|
+
Client.new.branches(repo)
|
105
|
+
end
|
106
|
+
|
107
|
+
# Network Meta
|
108
|
+
|
109
|
+
def self.network_meta(repo)
|
110
|
+
Client.new.network_meta(repo)
|
111
|
+
end
|
112
|
+
|
113
|
+
def self.network_data(repo, nethash)
|
114
|
+
Client.new.network_data(repo, nethash)
|
115
|
+
end
|
116
|
+
|
117
|
+
# Trees
|
118
|
+
|
119
|
+
def self.tree(repo, sha)
|
120
|
+
Client.new.tree(repo, sha)
|
121
|
+
end
|
122
|
+
|
123
|
+
def self.blob(repo, sha, path)
|
124
|
+
Client.new.blob(repo, sha, path)
|
125
|
+
end
|
126
|
+
|
127
|
+
def self.raw(repo, sha)
|
128
|
+
Client.new.raw(repo, sha)
|
129
|
+
end
|
130
|
+
|
131
|
+
end
|
132
|
+
|
133
|
+
require File.join(directory, 'octopussy', 'repo')
|
134
|
+
require File.join(directory, 'octopussy', 'client')
|
@@ -0,0 +1,393 @@
|
|
1
|
+
require 'cgi'
|
2
|
+
module Octopussy
|
3
|
+
class Client
|
4
|
+
include HTTParty
|
5
|
+
format :json
|
6
|
+
base_uri "http://github.com/api/v2/json"
|
7
|
+
|
8
|
+
attr_reader :login, :token
|
9
|
+
|
10
|
+
# :login => 'pengwynn', :token => 'your_github_api_key'
|
11
|
+
def initialize(auth={})
|
12
|
+
@login = auth[:login]
|
13
|
+
@token = auth[:token]
|
14
|
+
end
|
15
|
+
|
16
|
+
def search_users(q)
|
17
|
+
q = CGI.escape(q)
|
18
|
+
response = self.class.get("/user/search/#{q}")
|
19
|
+
handle_response(response)
|
20
|
+
Hashie::Mash.new(response).users
|
21
|
+
end
|
22
|
+
|
23
|
+
def user(login=self.login)
|
24
|
+
response = self.class.get("/user/show/#{login}", :query => auth_params)
|
25
|
+
handle_response(response)
|
26
|
+
Hashie::Mash.new(response).user
|
27
|
+
end
|
28
|
+
|
29
|
+
|
30
|
+
def update_user(values={})
|
31
|
+
response = self.class.post("/user/show/#{self.login}", :query => auth_params, :body => {:values => values})
|
32
|
+
handle_response(response)
|
33
|
+
Hashie::Mash.new(response).user
|
34
|
+
end
|
35
|
+
|
36
|
+
def followers(login=self.login)
|
37
|
+
response = self.class.get("/user/show/#{login}/followers")
|
38
|
+
handle_response(response)
|
39
|
+
Hashie::Mash.new(response).users
|
40
|
+
end
|
41
|
+
|
42
|
+
def following(login=self.login)
|
43
|
+
response = self.class.get("/user/show/#{login}/following")
|
44
|
+
handle_response(response)
|
45
|
+
Hashie::Mash.new(response).users
|
46
|
+
end
|
47
|
+
|
48
|
+
def follow!(username)
|
49
|
+
response = self.class.post("/user/follow/#{username}", :query => auth_params)
|
50
|
+
handle_response(response)
|
51
|
+
Hashie::Mash.new(response).users
|
52
|
+
end
|
53
|
+
|
54
|
+
def unfollow!(username)
|
55
|
+
response = self.class.post("/user/unfollow/#{username}", :query => auth_params)
|
56
|
+
handle_response(response)
|
57
|
+
Hashie::Mash.new(response).users
|
58
|
+
end
|
59
|
+
|
60
|
+
def follows?(*args)
|
61
|
+
target = args.pop
|
62
|
+
username = args.first
|
63
|
+
username ||= self.login
|
64
|
+
return if username.nil?
|
65
|
+
self.following(username).include?(target)
|
66
|
+
end
|
67
|
+
|
68
|
+
def watched(login=self.login)
|
69
|
+
response = self.class.get("/repos/watched/#{login}")
|
70
|
+
handle_response(response)
|
71
|
+
Hashie::Mash.new(response).repositories
|
72
|
+
end
|
73
|
+
|
74
|
+
def emails
|
75
|
+
response = self.class.get("/user/emails", :query => auth_params)
|
76
|
+
handle_response(response)
|
77
|
+
Hashie::Mash.new(response).emails
|
78
|
+
end
|
79
|
+
|
80
|
+
def add_email(email)
|
81
|
+
response = self.class.post("/user/email/add", :query => auth_params, :body => {:email => email})
|
82
|
+
handle_response(response)
|
83
|
+
Hashie::Mash.new(response).emails
|
84
|
+
end
|
85
|
+
|
86
|
+
def remove_email(email)
|
87
|
+
response = self.class.post("/user/email/remove", :query => auth_params, :body => {:email => email})
|
88
|
+
handle_response(response)
|
89
|
+
Hashie::Mash.new(response).emails
|
90
|
+
end
|
91
|
+
|
92
|
+
def keys
|
93
|
+
response = self.class.get("/user/keys", :query => auth_params)
|
94
|
+
handle_response(response)
|
95
|
+
Hashie::Mash.new(response).public_keys
|
96
|
+
end
|
97
|
+
|
98
|
+
def add_key(title, key)
|
99
|
+
response = self.class.post("/user/key/add", :query => auth_params, :body => {:title => title, :key => key})
|
100
|
+
handle_response(response)
|
101
|
+
Hashie::Mash.new(response).public_keys
|
102
|
+
end
|
103
|
+
|
104
|
+
def remove_key(id)
|
105
|
+
response = self.class.post("/user/key/remove", :query => auth_params, :body => {:id => id})
|
106
|
+
handle_response(response)
|
107
|
+
Hashie::Mash.new(response).public_keys
|
108
|
+
end
|
109
|
+
|
110
|
+
# Issues
|
111
|
+
|
112
|
+
def search_issues(repo, state, q)
|
113
|
+
repo = Repo.new(repo)
|
114
|
+
response = self.class.get("/issues/search/#{repo.username}/#{repo.name}/#{state}/#{q}")
|
115
|
+
handle_response(response)
|
116
|
+
Hashie::Mash.new(response).issues
|
117
|
+
end
|
118
|
+
|
119
|
+
def issues(repo, state)
|
120
|
+
repo = Repo.new(repo)
|
121
|
+
response = self.class.get("/issues/list/#{repo.username}/#{repo.name}/#{state}")
|
122
|
+
handle_response(response)
|
123
|
+
Hashie::Mash.new(response).issues
|
124
|
+
end
|
125
|
+
|
126
|
+
def issue(repo, id)
|
127
|
+
repo = Repo.new(repo)
|
128
|
+
response = self.class.get("/issues/show/#{repo.username}/#{repo.name}/#{id}")
|
129
|
+
handle_response(response)
|
130
|
+
Hashie::Mash.new(response).issue
|
131
|
+
end
|
132
|
+
|
133
|
+
def open_issue(repo, title, body)
|
134
|
+
repo = Repo.new(repo)
|
135
|
+
response = self.class.post("/issues/open/#{repo.username}/#{repo.name}", :body => {:title => title, :body => body})
|
136
|
+
handle_response(response)
|
137
|
+
Hashie::Mash.new(response).issue
|
138
|
+
end
|
139
|
+
|
140
|
+
def close_issue(repo, number)
|
141
|
+
repo = Repo.new(repo)
|
142
|
+
response = self.class.post("/issues/close/#{repo.username}/#{repo.name}/#{number}")
|
143
|
+
handle_response(response)
|
144
|
+
Hashie::Mash.new(response).issue
|
145
|
+
end
|
146
|
+
|
147
|
+
def reopen_issue(repo, number)
|
148
|
+
repo = Repo.new(repo)
|
149
|
+
response = self.class.post("/issues/reopen/#{repo.username}/#{repo.name}/#{number}")
|
150
|
+
handle_response(response)
|
151
|
+
Hashie::Mash.new(response).issue
|
152
|
+
end
|
153
|
+
|
154
|
+
def update_issue(repo, number, title, body)
|
155
|
+
repo = Repo.new(repo)
|
156
|
+
response = self.class.post("/issues/edit/#{repo.username}/#{repo.name}/#{number}", :body => {:title => title, :body => body})
|
157
|
+
handle_response(response)
|
158
|
+
Hashie::Mash.new(response).issue
|
159
|
+
end
|
160
|
+
|
161
|
+
def labels(repo)
|
162
|
+
repo = Repo.new(repo)
|
163
|
+
response = self.class.get("/issues/labels/#{repo.username}/#{repo.name}")
|
164
|
+
handle_response(response)
|
165
|
+
Hashie::Mash.new(response).labels
|
166
|
+
end
|
167
|
+
|
168
|
+
def add_label(repo, number, label)
|
169
|
+
repo = Repo.new(repo)
|
170
|
+
response = self.class.post("/issues/label/add/#{repo.username}/#{repo.name}/#{label}/#{number}")
|
171
|
+
handle_response(response)
|
172
|
+
Hashie::Mash.new(response).labels
|
173
|
+
end
|
174
|
+
|
175
|
+
def remove_label(repo, number, label)
|
176
|
+
repo = Repo.new(repo)
|
177
|
+
response = self.class.post("/issues/label/remove/#{repo.username}/#{repo.name}/#{label}/#{number}")
|
178
|
+
handle_response(response)
|
179
|
+
Hashie::Mash.new(response).labels
|
180
|
+
end
|
181
|
+
|
182
|
+
def add_comment(repo, number, comment)
|
183
|
+
repo = Repo.new(repo)
|
184
|
+
response = self.class.post("/issues/comment/#{repo.username}/#{repo.name}/#{number}", :body => {:comment => comment})
|
185
|
+
handle_response(response)
|
186
|
+
Hashie::Mash.new(response).comment
|
187
|
+
end
|
188
|
+
|
189
|
+
# Repos
|
190
|
+
|
191
|
+
def search_repos(q)
|
192
|
+
q = CGI.escape(q)
|
193
|
+
response = self.class.get("/repos/search/#{q}")
|
194
|
+
handle_response(response)
|
195
|
+
Hashie::Mash.new(response).repositories
|
196
|
+
end
|
197
|
+
|
198
|
+
def watch(repo)
|
199
|
+
repo = Repo.new(repo)
|
200
|
+
response = self.class.post("/repos/watch/#{repo.username}/#{repo.name}", :query => auth_params)
|
201
|
+
handle_response(response)
|
202
|
+
Hashie::Mash.new(response).repository
|
203
|
+
end
|
204
|
+
|
205
|
+
def unwatch(repo)
|
206
|
+
repo = Repo.new(repo)
|
207
|
+
response = self.class.post("/repos/unwatch/#{repo.username}/#{repo.name}", :query => auth_params)
|
208
|
+
handle_response(response)
|
209
|
+
Hashie::Mash.new(response).repository
|
210
|
+
end
|
211
|
+
|
212
|
+
def fork(repo)
|
213
|
+
repo = Repo.new(repo)
|
214
|
+
response = self.class.post("/repos/fork/#{repo.username}/#{repo.name}", :query => auth_params)
|
215
|
+
handle_response(response)
|
216
|
+
Hashie::Mash.new(response).repository
|
217
|
+
end
|
218
|
+
|
219
|
+
# :name, :description, :homepage, :public
|
220
|
+
def create(options)
|
221
|
+
response = self.class.post("/repos/create", :query => auth_params, :body => options)
|
222
|
+
handle_response(response)
|
223
|
+
Hashie::Mash.new(response).repository
|
224
|
+
end
|
225
|
+
|
226
|
+
def delete(repo, delete_token={})
|
227
|
+
repo = Repo.new(repo)
|
228
|
+
response = self.class.post("/repos/delete/#{repo.name}", :query => auth_params, :body => {:delete_token => delete_token})
|
229
|
+
handle_response(response)
|
230
|
+
Hashie::Mash.new(response).repository
|
231
|
+
end
|
232
|
+
|
233
|
+
def confirm_delete(repo, delete_token)
|
234
|
+
delete(repo, delete_token)
|
235
|
+
end
|
236
|
+
|
237
|
+
def set_private(repo)
|
238
|
+
repo = Repo.new(repo)
|
239
|
+
response = self.class.post("/repos/set/private/#{repo.name}", :query => auth_params)
|
240
|
+
handle_response(response)
|
241
|
+
Hashie::Mash.new(response).repository
|
242
|
+
end
|
243
|
+
|
244
|
+
def set_public(repo)
|
245
|
+
repo = Repo.new(repo)
|
246
|
+
response = self.class.post("/repos/set/public/#{repo.name}", :query => auth_params)
|
247
|
+
handle_response(response)
|
248
|
+
Hashie::Mash.new(response).repository
|
249
|
+
end
|
250
|
+
|
251
|
+
def deploy_keys(repo)
|
252
|
+
repo = Repo.new(repo)
|
253
|
+
response = self.class.get("/repos/keys/#{repo.name}", :query => auth_params)
|
254
|
+
handle_response(response)
|
255
|
+
Hashie::Mash.new(response).public_keys
|
256
|
+
end
|
257
|
+
|
258
|
+
def add_deploy_key(repo, key, title='')
|
259
|
+
repo = Repo.new(repo)
|
260
|
+
response = self.class.post("/repos/key/#{repo.name}/add", :query => auth_params, :body => {:title => title, :key => key})
|
261
|
+
handle_response(response)
|
262
|
+
Hashie::Mash.new(response).public_keys
|
263
|
+
end
|
264
|
+
|
265
|
+
def remove_deploy_key(repo, id)
|
266
|
+
repo = Repo.new(repo)
|
267
|
+
response = self.class.post("/repos/key/#{repo.name}/remove", :query => auth_params, :body => {:id => id})
|
268
|
+
handle_response(response)
|
269
|
+
Hashie::Mash.new(response).public_keys
|
270
|
+
end
|
271
|
+
|
272
|
+
def collaborators(repo)
|
273
|
+
repo = Repo.new(repo)
|
274
|
+
response = self.class.post("/repos/show/#{repo.username}/#{repo.name}/collaborators", :query => auth_params)
|
275
|
+
handle_response(response)
|
276
|
+
Hashie::Mash.new(response).collaborators
|
277
|
+
end
|
278
|
+
|
279
|
+
def repo(repo)
|
280
|
+
repo = Repo.new(repo)
|
281
|
+
response = self.class.get("/repos/show/#{repo.username}/#{repo.name}")
|
282
|
+
handle_response(response)
|
283
|
+
Hashie::Mash.new(response).repository
|
284
|
+
end
|
285
|
+
|
286
|
+
def list_repos(username)
|
287
|
+
response = self.class.get("/repos/show/#{username}")
|
288
|
+
handle_response(response)
|
289
|
+
Hashie::Mash.new(response).repositories
|
290
|
+
end
|
291
|
+
|
292
|
+
def add_collaborator(repo, collaborator)
|
293
|
+
repo = Repo.new(repo)
|
294
|
+
response = self.class.post("/repos/collaborators/#{repo.name}/add/#{collaborator}", :query => auth_params)
|
295
|
+
handle_response(response)
|
296
|
+
Hashie::Mash.new(response).collaborators
|
297
|
+
end
|
298
|
+
|
299
|
+
def remove_collaborator(repo, collaborator)
|
300
|
+
repo = Repo.new(repo)
|
301
|
+
response = self.class.post("/repos/collaborators/#{repo.name}/remove/#{collaborator}", :query => auth_params)
|
302
|
+
handle_response(response)
|
303
|
+
Hashie::Mash.new(response).collaborators
|
304
|
+
end
|
305
|
+
|
306
|
+
def network(repo)
|
307
|
+
repo = Repo.new(repo)
|
308
|
+
response = self.class.get("/repos/show/#{repo.username}/#{repo.name}/network")
|
309
|
+
handle_response(response)
|
310
|
+
Hashie::Mash.new(response).network
|
311
|
+
end
|
312
|
+
|
313
|
+
def languages(repo)
|
314
|
+
repo = Repo.new(repo)
|
315
|
+
response = self.class.get("/repos/show/#{repo.username}/#{repo.name}/languages")
|
316
|
+
handle_response(response)
|
317
|
+
Hashie::Mash.new(response).languages
|
318
|
+
end
|
319
|
+
|
320
|
+
def tags(repo)
|
321
|
+
repo = Repo.new(repo)
|
322
|
+
response = self.class.get("/repos/show/#{repo.username}/#{repo.name}/tags")
|
323
|
+
handle_response(response)
|
324
|
+
Hashie::Mash.new(response).tags
|
325
|
+
end
|
326
|
+
|
327
|
+
def branches(repo)
|
328
|
+
repo = Repo.new(repo)
|
329
|
+
response = self.class.get("/repos/show/#{repo.username}/#{repo.name}/branches")
|
330
|
+
handle_response(response)
|
331
|
+
Hashie::Mash.new(response).branches
|
332
|
+
end
|
333
|
+
|
334
|
+
# Network
|
335
|
+
|
336
|
+
def network_meta(repo)
|
337
|
+
repo = Repo.new(repo)
|
338
|
+
response = self.class.get("http://github.com/#{repo.username}/#{repo.name}/network_meta")
|
339
|
+
handle_response(response)
|
340
|
+
Hashie::Mash.new(response)
|
341
|
+
end
|
342
|
+
|
343
|
+
def network_data(repo, nethash)
|
344
|
+
repo = Repo.new(repo)
|
345
|
+
response = self.class.get("http://github.com/#{repo.username}/#{repo.name}/network_data_chunk", :query => {:nethash => nethash})
|
346
|
+
handle_response(response)
|
347
|
+
Hashie::Mash.new(response).commits
|
348
|
+
end
|
349
|
+
|
350
|
+
# Trees
|
351
|
+
|
352
|
+
def tree(repo, sha)
|
353
|
+
repo = Repo.new(repo)
|
354
|
+
response = self.class.get("http://github.com/api/v2/json/tree/show/#{repo.username}/#{repo.name}/#{sha}")
|
355
|
+
handle_response(response)
|
356
|
+
Hashie::Mash.new(response).tree
|
357
|
+
end
|
358
|
+
|
359
|
+
def blob(repo, sha, path)
|
360
|
+
repo = Repo.new(repo)
|
361
|
+
response = self.class.get("http://github.com/api/v2/json/blob/show/#{repo.username}/#{repo.name}/#{sha}/#{path}")
|
362
|
+
handle_response(response)
|
363
|
+
Hashie::Mash.new(response).blob
|
364
|
+
end
|
365
|
+
|
366
|
+
def raw(repo, sha)
|
367
|
+
repo = Repo.new(repo)
|
368
|
+
response = self.class.get("http://github.com/api/v2/yaml/blob/show/#{repo.username}/#{repo.name}/#{sha}")
|
369
|
+
handle_response(response)
|
370
|
+
response.body
|
371
|
+
end
|
372
|
+
|
373
|
+
private
|
374
|
+
|
375
|
+
def auth_params
|
376
|
+
@login.nil? ? {} : {:login => @login, :token => @token}
|
377
|
+
end
|
378
|
+
|
379
|
+
def handle_response(response)
|
380
|
+
case response.code
|
381
|
+
when 403
|
382
|
+
raise RateLimitExceeded.new
|
383
|
+
when 401
|
384
|
+
raise Unauthorized.new
|
385
|
+
when 404
|
386
|
+
raise NotFound.new
|
387
|
+
when 500
|
388
|
+
raise OctopussyError.new(500)
|
389
|
+
end
|
390
|
+
end
|
391
|
+
|
392
|
+
end
|
393
|
+
end
|