gitnetworkitis 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE.txt +20 -0
- data/README.rdoc +19 -0
- data/lib/gitnetworkitis.rb +11 -0
- data/lib/gitnetworkitis/base.rb +51 -0
- data/lib/gitnetworkitis/branch.rb +42 -0
- data/lib/gitnetworkitis/commit.rb +8 -0
- data/lib/gitnetworkitis/network_data.rb +62 -0
- data/lib/gitnetworkitis/network_meta.rb +17 -0
- data/lib/gitnetworkitis/repository.rb +45 -0
- metadata +156 -0
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2010 Julian Coutu
|
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.rdoc
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
= gitnetworkitis
|
2
|
+
|
3
|
+
Description goes here.
|
4
|
+
|
5
|
+
== Contributing to gitnetworkitis
|
6
|
+
|
7
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
|
8
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
|
9
|
+
* Fork the project
|
10
|
+
* Start a feature/bugfix branch
|
11
|
+
* Commit and push until you are happy with your contribution
|
12
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
13
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
14
|
+
|
15
|
+
== Copyright
|
16
|
+
|
17
|
+
Copyright (c) 2010 Julian Coutu. See LICENSE.txt for
|
18
|
+
further details.
|
19
|
+
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'httparty'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
# GitNetworkitis stuff
|
5
|
+
# By sorting them we ensure that api and base are loaded first on all sane operating systems
|
6
|
+
Dir[File.join(File.dirname(__FILE__), "gitnetworkitis/*.rb")].sort.each { |f| require f }
|
7
|
+
|
8
|
+
module GitNetworkitis
|
9
|
+
|
10
|
+
|
11
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
module GitNetworkitis
|
2
|
+
class Base
|
3
|
+
include HTTParty
|
4
|
+
attr_accessor :username, :token
|
5
|
+
|
6
|
+
def initialize(username, token, options={})
|
7
|
+
@username = username
|
8
|
+
@token = token
|
9
|
+
self.class.basic_auth "#{username}/token", token
|
10
|
+
options.each do |key, value|
|
11
|
+
method = "#{key}="
|
12
|
+
self.send(method, value) if respond_to? method
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def get url
|
17
|
+
ret = self.class.get(url)
|
18
|
+
if ret.response.code == "200"
|
19
|
+
return ret
|
20
|
+
else
|
21
|
+
raise "Unable to find Github Repository"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def parse_json json
|
26
|
+
begin
|
27
|
+
return JSON.parse(escape_json(json))
|
28
|
+
rescue => e
|
29
|
+
raise "Unable to parse JSON result" #{e.message}
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
|
34
|
+
private
|
35
|
+
def parse_attributes(json, object)
|
36
|
+
json.each do |key, value|
|
37
|
+
method = "#{key}="
|
38
|
+
if object.respond_to? method
|
39
|
+
object.send(method, value)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
object
|
43
|
+
end
|
44
|
+
|
45
|
+
#This is for parsing bad json returned from github
|
46
|
+
def escape_json(json)
|
47
|
+
json.gsub(/(....\[31m)./, '')
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module GitNetworkitis
|
2
|
+
class Branch < Base
|
3
|
+
base_uri 'https://github.com/api/v2/json/'
|
4
|
+
|
5
|
+
attr_accessor :name, :id, :owner, :repo
|
6
|
+
|
7
|
+
#Retrieves all branches based on a specific repo.
|
8
|
+
def find_all(options={})
|
9
|
+
if options.has_key?(:owner) & options.has_key?(:repo)
|
10
|
+
resp = get("/repos/show/#{options[:owner]}/#{options[:repo]}/branches")
|
11
|
+
json_result = parse_json(escape_json(resp.body.to_s))
|
12
|
+
result = Array.new
|
13
|
+
json_result["branches"].each do |branch|
|
14
|
+
result.push Branch.new(self.username, self.token, {:name =>branch[0], :id => branch[1], :owner => options[:owner], :repo => options[:repo]})
|
15
|
+
end
|
16
|
+
return result
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
|
21
|
+
#Loops pages and returns all commits specific to a branch
|
22
|
+
def commits
|
23
|
+
pages = true
|
24
|
+
counter = 0
|
25
|
+
result = Array.new
|
26
|
+
while pages do
|
27
|
+
resp = self.get("/commits/list/#{self.owner}/#{self.repo}/#{self.id}?page=#{counter}")
|
28
|
+
json_result = parse_json(escape_json(resp.body.to_s))
|
29
|
+
if !json_result.has_key?("error")
|
30
|
+
json_result["commits"].each do |commit|
|
31
|
+
temp_commit = parse_attributes(commit, Commit.new(self.username, self.token))
|
32
|
+
result.push temp_commit
|
33
|
+
end
|
34
|
+
else
|
35
|
+
pages = false
|
36
|
+
end
|
37
|
+
counter = counter+1
|
38
|
+
end
|
39
|
+
result
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
module GitNetworkitis
|
2
|
+
class NetworkData < Base
|
3
|
+
base_uri 'https://github.com/'
|
4
|
+
|
5
|
+
attr_accessor :commits, :network_meta
|
6
|
+
|
7
|
+
def find(options={})
|
8
|
+
if options.has_key?(:owner) & options.has_key?(:repo) & options.has_key?(:network_meta)
|
9
|
+
if options.has_key?(:start) & options.has_key?(:end)
|
10
|
+
find_range(options)
|
11
|
+
elsif options.has_key?(:start) & !options.has_key?(:end)
|
12
|
+
find_since(options)
|
13
|
+
else
|
14
|
+
find_all(options)
|
15
|
+
end
|
16
|
+
else
|
17
|
+
raise "You must provide an Owner, Repo and Gitnetworkitis:NetworkMeta"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def find_all(options={})
|
22
|
+
self.network_meta = options[:network_meta]
|
23
|
+
return find_range(options.merge!({:start => 0, :end => self.network_meta.focus}))
|
24
|
+
end
|
25
|
+
|
26
|
+
def find_since(options={})
|
27
|
+
self.network_meta = options[:network_meta]
|
28
|
+
return find_range(options.merge!({:end => self.network_meta.focus}))
|
29
|
+
end
|
30
|
+
|
31
|
+
def find_range(options={})
|
32
|
+
#Make this loop through pages so we dont' return huge results in one json calls
|
33
|
+
self.network_meta = options[:network_meta]
|
34
|
+
self.commits = Array.new
|
35
|
+
|
36
|
+
current_start = options[:start]
|
37
|
+
current_end = options[:end]
|
38
|
+
while (options[:end] - current_start) > 500 do
|
39
|
+
current_end = current_start + 500
|
40
|
+
resp = get("/#{options[:owner]}/#{options[:repo]}/network_data_chunk?nethash=#{self.network_meta.nethash}&start=#{current_start}&end=#{current_end}")
|
41
|
+
if resp.content_length > 0
|
42
|
+
parse_results(resp)
|
43
|
+
end
|
44
|
+
current_start = current_start + 501
|
45
|
+
end
|
46
|
+
resp = self.get("/#{options[:owner]}/#{options[:repo]}/network_data_chunk?nethash=#{self.network_meta.nethash}&start=#{current_start}&end=#{options[:end]}")
|
47
|
+
parse_results(resp)
|
48
|
+
|
49
|
+
return self
|
50
|
+
end
|
51
|
+
|
52
|
+
private
|
53
|
+
def parse_results(response)
|
54
|
+
json_result = parse_json(escape_json(response.body.to_s))
|
55
|
+
result = Array.new
|
56
|
+
json_result["commits"].each do |commit|
|
57
|
+
self.commits.push(parse_attributes(commit, Commit.new(self.username, self.token)))
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module GitNetworkitis
|
2
|
+
class NetworkMeta < Base
|
3
|
+
base_uri 'https://github.com/'
|
4
|
+
|
5
|
+
attr_accessor :spacemap, :blocks, :url, :nethash, :focus, :dates, :users, :branches
|
6
|
+
|
7
|
+
def find(options={})
|
8
|
+
if options.has_key?(:owner) & options.has_key?(:repo)
|
9
|
+
resp = get("/#{ options[:owner]}/#{ options[:repo]}/network_meta")
|
10
|
+
json_result = parse_json(resp.body.to_s)
|
11
|
+
branch = GitNetworkitis::Branch.new(@username, @token)
|
12
|
+
self.branches = branch.find_all({:owner=>options[:owner], :repo => options[:repo]})
|
13
|
+
parse_attributes(json_result, self)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
module GitNetworkitis
|
2
|
+
class Repository < Base
|
3
|
+
base_uri 'https://github.com/api/v2/json/'
|
4
|
+
|
5
|
+
attr_accessor :description, :has_wiki, :url, :forks, :open_issues, :forks, :name, :homepage, :watchers, :owner, :private, :pledgie, :size, :has_downloads
|
6
|
+
|
7
|
+
def find_all_watched
|
8
|
+
result = Array.new
|
9
|
+
unless !self.username && !self.token
|
10
|
+
resp = get("/repos/watched/#{self.username}")
|
11
|
+
json_result = self.parse_json(resp.body.to_s)
|
12
|
+
json_result["repositories"].each do |repo|
|
13
|
+
result.push parse_attributes(repo, Repository.new(self.username, self.token))
|
14
|
+
end
|
15
|
+
end
|
16
|
+
return result
|
17
|
+
end
|
18
|
+
|
19
|
+
def find_all_owned
|
20
|
+
result = Array.new
|
21
|
+
unless !self.username && !self.token
|
22
|
+
resp = get("/repos/show/#{self.username}")
|
23
|
+
json_result = parse_json(resp.body.to_s)
|
24
|
+
json_result["repositories"].each do |repo|
|
25
|
+
result.push parse_attributes(repo, Repository.new(self.username, self.token))
|
26
|
+
end
|
27
|
+
end
|
28
|
+
return result
|
29
|
+
end
|
30
|
+
|
31
|
+
def find(options={})
|
32
|
+
result = Array.new
|
33
|
+
if options.has_key?(:owner) & options.has_key?(:repo)
|
34
|
+
resp = get("/repos/show/#{options[:owner]}/#{options[:repo]}")
|
35
|
+
json_result = parse_json(resp.body.to_s)
|
36
|
+
parse_attributes(json_result["repository"], Repository.new(self.username, self.token))
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def remote_id
|
41
|
+
return "#{self.owner}/#{self.name}"
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
end
|
metadata
ADDED
@@ -0,0 +1,156 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: gitnetworkitis
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 1
|
8
|
+
- 0
|
9
|
+
version: 0.1.0
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Julian Coutu
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2011-01-12 00:00:00 -05:00
|
18
|
+
default_executable:
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: httparty
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - ">="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
segments:
|
29
|
+
- 0
|
30
|
+
version: "0"
|
31
|
+
type: :runtime
|
32
|
+
version_requirements: *id001
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: rspec
|
35
|
+
prerelease: false
|
36
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
37
|
+
none: false
|
38
|
+
requirements:
|
39
|
+
- - ~>
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
segments:
|
42
|
+
- 2
|
43
|
+
- 1
|
44
|
+
- 0
|
45
|
+
version: 2.1.0
|
46
|
+
type: :development
|
47
|
+
version_requirements: *id002
|
48
|
+
- !ruby/object:Gem::Dependency
|
49
|
+
name: bundler
|
50
|
+
prerelease: false
|
51
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
52
|
+
none: false
|
53
|
+
requirements:
|
54
|
+
- - ~>
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
segments:
|
57
|
+
- 1
|
58
|
+
- 0
|
59
|
+
- 0
|
60
|
+
version: 1.0.0
|
61
|
+
type: :development
|
62
|
+
version_requirements: *id003
|
63
|
+
- !ruby/object:Gem::Dependency
|
64
|
+
name: jeweler
|
65
|
+
prerelease: false
|
66
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
67
|
+
none: false
|
68
|
+
requirements:
|
69
|
+
- - ~>
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
segments:
|
72
|
+
- 1
|
73
|
+
- 5
|
74
|
+
- 1
|
75
|
+
version: 1.5.1
|
76
|
+
type: :development
|
77
|
+
version_requirements: *id004
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: rcov
|
80
|
+
prerelease: false
|
81
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
82
|
+
none: false
|
83
|
+
requirements:
|
84
|
+
- - ">="
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
segments:
|
87
|
+
- 0
|
88
|
+
version: "0"
|
89
|
+
type: :development
|
90
|
+
version_requirements: *id005
|
91
|
+
- !ruby/object:Gem::Dependency
|
92
|
+
name: fakeweb
|
93
|
+
prerelease: false
|
94
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
95
|
+
none: false
|
96
|
+
requirements:
|
97
|
+
- - ">="
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
segments:
|
100
|
+
- 0
|
101
|
+
version: "0"
|
102
|
+
type: :development
|
103
|
+
version_requirements: *id006
|
104
|
+
description: Git API Gem utilizing the Network API
|
105
|
+
email: jcoutu@phaseiiicreations.com
|
106
|
+
executables: []
|
107
|
+
|
108
|
+
extensions: []
|
109
|
+
|
110
|
+
extra_rdoc_files:
|
111
|
+
- LICENSE.txt
|
112
|
+
- README.rdoc
|
113
|
+
files:
|
114
|
+
- lib/gitnetworkitis/base.rb
|
115
|
+
- lib/gitnetworkitis/branch.rb
|
116
|
+
- lib/gitnetworkitis/commit.rb
|
117
|
+
- lib/gitnetworkitis/network_data.rb
|
118
|
+
- lib/gitnetworkitis/network_meta.rb
|
119
|
+
- lib/gitnetworkitis/repository.rb
|
120
|
+
- lib/gitnetworkitis.rb
|
121
|
+
- LICENSE.txt
|
122
|
+
- README.rdoc
|
123
|
+
has_rdoc: true
|
124
|
+
homepage: http://github.com/jcoutu/gitnetworkitis
|
125
|
+
licenses:
|
126
|
+
- MIT
|
127
|
+
post_install_message:
|
128
|
+
rdoc_options: []
|
129
|
+
|
130
|
+
require_paths:
|
131
|
+
- lib
|
132
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
133
|
+
none: false
|
134
|
+
requirements:
|
135
|
+
- - ">="
|
136
|
+
- !ruby/object:Gem::Version
|
137
|
+
segments:
|
138
|
+
- 0
|
139
|
+
version: "0"
|
140
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
141
|
+
none: false
|
142
|
+
requirements:
|
143
|
+
- - ">="
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
segments:
|
146
|
+
- 0
|
147
|
+
version: "0"
|
148
|
+
requirements: []
|
149
|
+
|
150
|
+
rubyforge_project:
|
151
|
+
rubygems_version: 1.3.7
|
152
|
+
signing_key:
|
153
|
+
specification_version: 3
|
154
|
+
summary: Git API Gem utilizing the Network API
|
155
|
+
test_files: []
|
156
|
+
|