gittycent 0.0.3 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG +2 -0
- data/Rakefile +0 -6
- data/gittycent.gemspec +4 -4
- data/lib/gittycent.rb +66 -11
- metadata +9 -4
data/CHANGELOG
CHANGED
data/Rakefile
CHANGED
data/gittycent.gemspec
CHANGED
@@ -2,11 +2,11 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{gittycent}
|
5
|
-
s.version = "0.0.
|
5
|
+
s.version = "0.0.4"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["Elijah Miller"]
|
9
|
-
s.date = %q{2010-
|
9
|
+
s.date = %q{2010-05-24}
|
10
10
|
s.description = %q{A GitHub wrapper in Ruby.}
|
11
11
|
s.email = %q{elijah.miller@gmail.com}
|
12
12
|
s.extra_rdoc_files = ["CHANGELOG", "LICENSE", "README.rdoc", "lib/gittycent.rb"]
|
@@ -15,14 +15,14 @@ Gem::Specification.new do |s|
|
|
15
15
|
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Gittycent", "--main", "README.rdoc"]
|
16
16
|
s.require_paths = ["lib"]
|
17
17
|
s.rubyforge_project = %q{gittycent}
|
18
|
-
s.rubygems_version = %q{1.3.
|
18
|
+
s.rubygems_version = %q{1.3.7}
|
19
19
|
s.summary = %q{A GitHub wrapper in Ruby.}
|
20
20
|
|
21
21
|
if s.respond_to? :specification_version then
|
22
22
|
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
23
23
|
s.specification_version = 3
|
24
24
|
|
25
|
-
if Gem::Version.new(Gem::
|
25
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
26
26
|
else
|
27
27
|
end
|
28
28
|
else
|
data/lib/gittycent.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'active_support'
|
2
|
+
require 'active_support/all'
|
2
3
|
require 'httparty'
|
3
4
|
require 'pp'
|
4
5
|
|
@@ -9,6 +10,10 @@ class GitHub
|
|
9
10
|
|
10
11
|
attr_accessor :options
|
11
12
|
|
13
|
+
# Connects to GitHub using login/token. Yields or returns the new
|
14
|
+
# connection.
|
15
|
+
#
|
16
|
+
# GitHub.connect(:login => 'jqr', :token => 'somesecretstuff123')
|
12
17
|
def self.connect(options)
|
13
18
|
connection = new(options)
|
14
19
|
if block_given?
|
@@ -18,20 +23,33 @@ class GitHub
|
|
18
23
|
end
|
19
24
|
end
|
20
25
|
|
21
|
-
|
26
|
+
# Simplified method for connecting with git config specified credentials.
|
27
|
+
# Also allows for using an alternate section for easy handling of multiple
|
28
|
+
# credentials. Just like connect this yields or returns the new connection.
|
29
|
+
#
|
30
|
+
# github = GitHub.connect_with_git_config
|
31
|
+
def self.connect_with_git_config(section = :github, options = {}, &block)
|
22
32
|
config = Hash[*`git config -l`.scan(/^(.*?)=(.*)$/).flatten]
|
23
|
-
connect(:login => config["#{section}.user"], :token => config["#{section}.token"], &block)
|
33
|
+
connect(options.merge(:login => config["#{section}.user"], :token => config["#{section}.token"]), &block)
|
24
34
|
end
|
25
35
|
|
36
|
+
# Returns a new GitHub connection object, requires :login and :token
|
37
|
+
# options.
|
38
|
+
#
|
39
|
+
# github = GitHub.new(:login => 'jqr', :token => 'somesecretstuff123')
|
26
40
|
def initialize(options)
|
27
41
|
self.options = options
|
28
42
|
debug "Login using login #{options[:login]} with token #{options[:token]}"
|
29
43
|
end
|
30
44
|
|
45
|
+
# Returns the verbosity level.
|
31
46
|
def verbosity
|
32
47
|
options[:verbosity] || NONE
|
33
48
|
end
|
34
49
|
|
50
|
+
# Finds a GitHub user by login.
|
51
|
+
#
|
52
|
+
# user = github.user('jqr')
|
35
53
|
def user(login)
|
36
54
|
if login == options[:login]
|
37
55
|
AuthenticatedUser.new(self, :login => options[:login])
|
@@ -40,15 +58,17 @@ class GitHub
|
|
40
58
|
end
|
41
59
|
end
|
42
60
|
|
61
|
+
# Finds GitHub users by a query string.
|
43
62
|
def user_search(query)
|
44
63
|
get("/user/search/#{query}")['users'].map { |u| User.new(self, u) }
|
45
64
|
end
|
46
65
|
|
66
|
+
# Returns the currently authenticated user.
|
47
67
|
def authenticated_user
|
48
68
|
@authenticated_user ||= user(options[:login])
|
49
69
|
end
|
50
70
|
|
51
|
-
def inspect
|
71
|
+
def inspect # :nodoc:
|
52
72
|
"#<#{self.class}#{' ' + options[:login] if options[:login].present?}>"
|
53
73
|
end
|
54
74
|
|
@@ -61,6 +81,9 @@ class GitHub
|
|
61
81
|
}
|
62
82
|
end
|
63
83
|
|
84
|
+
# Performs a GET request on path, automatically prepending api version and
|
85
|
+
# format paramters. Will automatically retry if the request rate limiting is
|
86
|
+
# hit.
|
64
87
|
def get(path)
|
65
88
|
with_retry do
|
66
89
|
url = "http://github.com/api/#{API_VERSION}/#{FORMAT}#{path}"
|
@@ -73,6 +96,9 @@ class GitHub
|
|
73
96
|
end
|
74
97
|
end
|
75
98
|
|
99
|
+
# Performs a POST request on path, automatically prepending api version and
|
100
|
+
# format paramters. Will automatically retry if the request rate limiting is
|
101
|
+
# hit.
|
76
102
|
def post(path, params = {})
|
77
103
|
with_retry do
|
78
104
|
url = "http://github.com/api/#{API_VERSION}/#{FORMAT}#{path}"
|
@@ -98,6 +124,8 @@ class GitHub
|
|
98
124
|
debug object.pretty_inspect
|
99
125
|
end
|
100
126
|
|
127
|
+
# Automatically retries a block of code if the returned value is rate
|
128
|
+
# limited (HTTP Code 403) by GitHub.
|
101
129
|
def with_retry
|
102
130
|
count = 0
|
103
131
|
loop do
|
@@ -146,7 +174,7 @@ class GitHub
|
|
146
174
|
def self.loadable_attributes(*attributes)
|
147
175
|
(attributes - [identified_by]).each do |attribute|
|
148
176
|
define_method(attribute) do
|
149
|
-
if !@attributes.include?(
|
177
|
+
if !@attributes.include?(attribute)
|
150
178
|
load
|
151
179
|
end
|
152
180
|
@attributes[attribute]
|
@@ -167,28 +195,27 @@ class GitHub
|
|
167
195
|
login.to_s
|
168
196
|
end
|
169
197
|
|
198
|
+
# Returns this user's repositories.
|
170
199
|
def repos
|
171
200
|
@repos ||= get("/repos/show/#{login}")['repositories'].map { |r| Repo.new(connection, r) }
|
172
201
|
end
|
173
202
|
|
203
|
+
# Returns a list of all public repos thi user is watching.
|
174
204
|
def watched_repos
|
175
205
|
@repos ||= get("/repos/watched/#{login}")['repositories'].map { |r| Repo.new(connection, r) }
|
176
206
|
end
|
177
207
|
|
178
|
-
#
|
179
|
-
def create_repo(options)
|
180
|
-
options = options.dup
|
181
|
-
Repo.new(connection, post("/repos/create", options)['repository'])
|
182
|
-
end
|
183
|
-
|
208
|
+
# Loads lazily-fetched attributes.
|
184
209
|
def load
|
185
210
|
@attributes = get("/user/show/#{login}")['user'].symbolize_keys
|
186
211
|
end
|
187
212
|
|
213
|
+
# Returns all the users that follow this user.
|
188
214
|
def followers
|
189
215
|
@followers ||= get("/user/show/#{login}/followers")['users'].map { |u| User.new(connection, :login => u) }
|
190
216
|
end
|
191
217
|
|
218
|
+
# Returns all the users that this user is following.
|
192
219
|
def following
|
193
220
|
@following||= get("/user/show/#{login}/following")['users'].map { |u| User.new(connection, :login => u) }
|
194
221
|
end
|
@@ -200,6 +227,20 @@ class GitHub
|
|
200
227
|
:total_private_repo_count, :public_repo_count, :location, :email,
|
201
228
|
:collaborators, :public_gist_count, :blog, :name, :following_count,
|
202
229
|
:disk_usage
|
230
|
+
|
231
|
+
# Returns a list of all repos this user is watching.
|
232
|
+
def watched_repos
|
233
|
+
super
|
234
|
+
end
|
235
|
+
|
236
|
+
# Adds a new repository for this user. Supported options include: :name,
|
237
|
+
# :description, :homepage, :public.
|
238
|
+
#
|
239
|
+
# repo = user.create_repo(:name => 'hello', :public => false)
|
240
|
+
def create_repo(options)
|
241
|
+
options = options.dup
|
242
|
+
Repo.new(connection, post("/repos/create", options)['repository'])
|
243
|
+
end
|
203
244
|
end
|
204
245
|
|
205
246
|
class Repo < Connectable
|
@@ -207,20 +248,23 @@ class GitHub
|
|
207
248
|
self.identified_by = :name
|
208
249
|
|
209
250
|
loadable_attributes :owner, :open_issues, :description, :fork, :forks,
|
210
|
-
:private, :url, :homepage, :watchers
|
251
|
+
:private, :url, :homepage, :watchers, :has_wiki, :has_downloads, :has_issues
|
211
252
|
|
212
253
|
def to_s
|
213
254
|
name.to_s
|
214
255
|
end
|
215
256
|
|
257
|
+
# Returns the owner of this repository.
|
216
258
|
def owner
|
217
259
|
@owner ||= User.new(connection, :login => @attributes[:owner])
|
218
260
|
end
|
219
261
|
|
262
|
+
# Returns a list of all collaborators.
|
220
263
|
def collaborators
|
221
264
|
@collaborators ||= get("/repos/show/#{owner.login}/#{name}/collaborators")['collaborators'] || []
|
222
265
|
end
|
223
266
|
|
267
|
+
# Sets the list of collaborators.
|
224
268
|
def collaborators=(value)
|
225
269
|
value = value.dup.uniq
|
226
270
|
removals = collaborators - value
|
@@ -236,6 +280,8 @@ class GitHub
|
|
236
280
|
@collaborators = nil
|
237
281
|
end
|
238
282
|
|
283
|
+
# Returns the shell commands used to do an initial push of this project to
|
284
|
+
# GitHub.
|
239
285
|
def initial_push_command
|
240
286
|
"git remote add origin git@github.com:#{owner.login}/#{name}.git &&\n" +
|
241
287
|
"git push origin master &&\n" +
|
@@ -243,18 +289,27 @@ class GitHub
|
|
243
289
|
"git config --add branch.master.merge refs/heads/master"
|
244
290
|
end
|
245
291
|
|
292
|
+
# Returns repositories in this repository's network.
|
246
293
|
def network
|
247
294
|
@network ||= get("/repos/show/#{owner.login}/#{name}/network")['network'].map { |r| Repo.new(connection, r) }
|
248
295
|
end
|
249
296
|
|
297
|
+
# Returns the languages detected.
|
250
298
|
def languages
|
251
299
|
get("/repos/show/#{owner.login}/#{name}/languages")['languages']
|
252
300
|
end
|
253
301
|
|
302
|
+
# Loads lazily-fetched attributes.
|
303
|
+
def load
|
304
|
+
@attributes = get("/repos/show/#{owner.login}/#{name}")['repository'].symbolize_keys
|
305
|
+
end
|
306
|
+
|
307
|
+
# Returns all tags of this repository.
|
254
308
|
def tags
|
255
309
|
get("/repos/show/#{owner.login}/#{name}/tags")['tags']
|
256
310
|
end
|
257
311
|
|
312
|
+
# Returns all branches of this repository.
|
258
313
|
def branches
|
259
314
|
get("/repos/show/#{owner.login}/#{name}/branches")['branches']
|
260
315
|
end
|
metadata
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gittycent
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
+
hash: 23
|
4
5
|
prerelease: false
|
5
6
|
segments:
|
6
7
|
- 0
|
7
8
|
- 0
|
8
|
-
-
|
9
|
-
version: 0.0.
|
9
|
+
- 4
|
10
|
+
version: 0.0.4
|
10
11
|
platform: ruby
|
11
12
|
authors:
|
12
13
|
- Elijah Miller
|
@@ -14,7 +15,7 @@ autorequire:
|
|
14
15
|
bindir: bin
|
15
16
|
cert_chain: []
|
16
17
|
|
17
|
-
date: 2010-
|
18
|
+
date: 2010-05-24 00:00:00 -04:00
|
18
19
|
default_executable:
|
19
20
|
dependencies: []
|
20
21
|
|
@@ -52,16 +53,20 @@ rdoc_options:
|
|
52
53
|
require_paths:
|
53
54
|
- lib
|
54
55
|
required_ruby_version: !ruby/object:Gem::Requirement
|
56
|
+
none: false
|
55
57
|
requirements:
|
56
58
|
- - ">="
|
57
59
|
- !ruby/object:Gem::Version
|
60
|
+
hash: 3
|
58
61
|
segments:
|
59
62
|
- 0
|
60
63
|
version: "0"
|
61
64
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
62
66
|
requirements:
|
63
67
|
- - ">="
|
64
68
|
- !ruby/object:Gem::Version
|
69
|
+
hash: 11
|
65
70
|
segments:
|
66
71
|
- 1
|
67
72
|
- 2
|
@@ -69,7 +74,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
69
74
|
requirements: []
|
70
75
|
|
71
76
|
rubyforge_project: gittycent
|
72
|
-
rubygems_version: 1.3.
|
77
|
+
rubygems_version: 1.3.7
|
73
78
|
signing_key:
|
74
79
|
specification_version: 3
|
75
80
|
summary: A GitHub wrapper in Ruby.
|