Skip to content

Commit

Permalink
Network Data find, Commit begun
Browse files Browse the repository at this point in the history
  • Loading branch information
Julian Coutu authored and Julian Coutu committed Dec 16, 2010
1 parent b3b186f commit d700a29
Show file tree
Hide file tree
Showing 10 changed files with 75 additions and 5 deletions.
4 changes: 3 additions & 1 deletion lib/gitnetworkitis/base.rb
Expand Up @@ -17,7 +17,9 @@ def initialize(username, token, options={})
def parse_attributes(json, object)
json.each do |key, value|
method = "#{key}="
object.send(method, value) if respond_to? method
if object.respond_to? method
object.send(method, value)
end
end
object
end
Expand Down
8 changes: 8 additions & 0 deletions lib/gitnetworkitis/commit.rb
@@ -0,0 +1,8 @@
module GitNetworkitis
class Commit < Base
base_uri 'https://github.com/'

attr_accessor :parents, :author, :time, :id, :date, :gravatar, :space, :message, :login

end
end
22 changes: 22 additions & 0 deletions lib/gitnetworkitis/network_data.rb
@@ -0,0 +1,22 @@
module GitNetworkitis
class NetworkData < Base
base_uri 'https://github.com/'

attr_accessor :commits


def find(options={})
if options.has_key?(:owner) & options.has_key?(:repo) & options.has_key?(:nethash)
resp = self.class.get("/#{options[:owner]}/#{options[:repo]}/network_data_chunk?nethash=#{options[:nethash]}")
json_result = JSON.parse(resp.body.to_s)
result = Array.new
json_result["commits"].each do |commit|
result.push parse_attributes(commit, Commit.new(self.username, self.token))
end
self.commits = result
#This seems weird but what if later the api adds more data at this level? We could just return commits and change the name.
return self
end
end
end
end
2 changes: 1 addition & 1 deletion lib/gitnetworkitis/network_meta.rb
Expand Up @@ -7,7 +7,7 @@ class NetworkMeta < Base

def find(options={})
if options.has_key?(:owner) & options.has_key?(:repo)
resp = self.class.get("/turingstudio/loupe/network_meta")
resp = self.class.get("/#{ options[:owner]}/#{ options[:repo]}/network_meta")
json_result = JSON.parse(resp.body.to_s)
parse_attributes(json_result, NetworkMeta.new(self.username, self.token))
end
Expand Down
10 changes: 10 additions & 0 deletions spec/commit_spec.rb
@@ -0,0 +1,10 @@
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')

describe "Gitnetworkitis::Commit" do

before :each do
fake_responses
end


end
25 changes: 25 additions & 0 deletions spec/network_data_spec.rb
@@ -0,0 +1,25 @@
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')

describe "Gitnetworkitis::NetworkData" do

before :each do
fake_responses
end

context "find" do
let(:network_meta){GitNetworkitis::NetworkData.new(@username, @token)}
let(:test){network_meta.find({:owner=>"turingstudio", :repo => "loupe", :nethash => "26fb01d365a6f7ea57be92299803cae7b95ae25a"})}

before :each do
fake_responses

end

it "should set the commits array" do
test.commits.should_not be_empty
test.commits.first.parents.should be_empty
test.commits.first.login.should == "stephenjudkins"
end

end
end
4 changes: 2 additions & 2 deletions spec/network_meta_spec.rb
Expand Up @@ -17,13 +17,13 @@

it "should set the nethash" do
test = network_meta.find({:owner=>"turingstudio", :repo => "loupe"})
test.nethash.should == "e6598cce6fa0d71a266dce9ed0c053f0efa016ae"
test.nethash.should == "26fb01d365a6f7ea57be92299803cae7b95ae25a"
end

it "should set the date array" do
test.dates.should_not be_empty
test.dates.first.should == "2010-10-08"
test.dates.last.should == "2010-12-14"
test.dates.last.should == "2010-12-15"
end

it "should set focus" do
Expand Down
1 change: 1 addition & 0 deletions spec/responses/turingstudio_loupe_network_data.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion spec/responses/turingstudio_loupe_network_meta.json
@@ -1 +1 @@
{"spacemap":[[[0,109]],[[97,100],[88,96],[76,81],[50,75],[36,47],[31,35],[23,26]],[[80,97]]],"blocks":[{"name":"turingstudio","count":3,"start":0}],"nethash":"e6598cce6fa0d71a266dce9ed0c053f0efa016ae","focus":109,"dates":["2010-10-08","2010-10-11","2010-10-13","2010-10-14","2010-10-14","2010-10-15","2010-10-25","2010-10-25","2010-10-25","2010-10-25","2010-10-25","2010-10-25","2010-10-25","2010-10-25","2010-10-25","2010-10-25","2010-10-26","2010-10-26","2010-10-26","2010-10-27","2010-11-01","2010-11-01","2010-11-01","2010-11-01","2010-11-01","2010-11-01","2010-11-01","2010-11-02","2010-11-02","2010-11-02","2010-11-02","2010-11-03","2010-11-03","2010-11-03","2010-11-03","2010-11-03","2010-11-04","2010-11-04","2010-11-05","2010-11-08","2010-11-08","2010-11-09","2010-11-09","2010-11-09","2010-11-09","2010-11-10","2010-11-11","2010-11-11","2010-11-11","2010-11-11","2010-11-12","2010-11-12","2010-11-15","2010-11-16","2010-11-16","2010-11-19","2010-11-19","2010-11-19","2010-11-19","2010-11-20","2010-11-20","2010-11-22","2010-11-22","2010-11-22","2010-11-22","2010-11-22","2010-11-22","2010-11-23","2010-11-23","2010-11-24","2010-11-24","2010-11-24","2010-11-24","2010-11-24","2010-11-24","2010-11-24","2010-11-24","2010-11-29","2010-11-29","2010-11-29","2010-11-29","2010-11-29","2010-11-30","2010-11-30","2010-11-30","2010-11-30","2010-11-30","2010-12-01","2010-12-03","2010-12-06","2010-12-06","2010-12-06","2010-12-06","2010-12-06","2010-12-06","2010-12-06","2010-12-06","2010-12-06","2010-12-07","2010-12-07","2010-12-07","2010-12-08","2010-12-08","2010-12-08","2010-12-08","2010-12-09","2010-12-09","2010-12-09","2010-12-10","2010-12-14"],"users":[{"repo":"loupe","name":"turingstudio","heads":[{"name":"master","id":"fa84a5871029fb3f0921d566e6e6300b62632f8f"},{"name":"git_network_api","id":"c3aeb61e37f94bbb67c4f14b52c23b8e54d30d0e"},{"name":"test_branch_1","id":"c3aeb61e37f94bbb67c4f14b52c23b8e54d30d0e"}]}]}
{"spacemap":[[[0,109]],[[97,100],[88,96],[76,81],[50,75],[36,47],[31,35],[23,26],[102,111]],[[80,97]]],"blocks":[{"name":"turingstudio","count":3,"start":0}],"nethash":"26fb01d365a6f7ea57be92299803cae7b95ae25a","focus":109,"dates":["2010-10-08","2010-10-11","2010-10-13","2010-10-14","2010-10-14","2010-10-15","2010-10-25","2010-10-25","2010-10-25","2010-10-25","2010-10-25","2010-10-25","2010-10-25","2010-10-25","2010-10-25","2010-10-25","2010-10-26","2010-10-26","2010-10-26","2010-10-27","2010-11-01","2010-11-01","2010-11-01","2010-11-01","2010-11-01","2010-11-01","2010-11-01","2010-11-02","2010-11-02","2010-11-02","2010-11-02","2010-11-03","2010-11-03","2010-11-03","2010-11-03","2010-11-03","2010-11-04","2010-11-04","2010-11-05","2010-11-08","2010-11-08","2010-11-09","2010-11-09","2010-11-09","2010-11-09","2010-11-10","2010-11-11","2010-11-11","2010-11-11","2010-11-11","2010-11-12","2010-11-12","2010-11-15","2010-11-16","2010-11-16","2010-11-19","2010-11-19","2010-11-19","2010-11-19","2010-11-20","2010-11-20","2010-11-22","2010-11-22","2010-11-22","2010-11-22","2010-11-22","2010-11-22","2010-11-23","2010-11-23","2010-11-24","2010-11-24","2010-11-24","2010-11-24","2010-11-24","2010-11-24","2010-11-24","2010-11-24","2010-11-29","2010-11-29","2010-11-29","2010-11-29","2010-11-29","2010-11-30","2010-11-30","2010-11-30","2010-11-30","2010-11-30","2010-12-01","2010-12-03","2010-12-06","2010-12-06","2010-12-06","2010-12-06","2010-12-06","2010-12-06","2010-12-06","2010-12-06","2010-12-06","2010-12-07","2010-12-07","2010-12-07","2010-12-08","2010-12-08","2010-12-08","2010-12-08","2010-12-09","2010-12-09","2010-12-09","2010-12-10","2010-12-14","2010-12-15","2010-12-15"],"users":[{"repo":"loupe","name":"turingstudio","heads":[{"name":"master","id":"fa84a5871029fb3f0921d566e6e6300b62632f8f"},{"name":"git_network_api","id":"bec7b23dc57b14d89fa2829e8c32a108a18e7248"},{"name":"test_branch_1","id":"c3aeb61e37f94bbb67c4f14b52c23b8e54d30d0e"}]}]}
2 changes: 2 additions & 0 deletions spec/spec_helper.rb
Expand Up @@ -18,6 +18,7 @@

#This will tell the tests to use fakeweb responses or not. Removing this will mostly likely cause test failures
@fake_web_requests = true

}
end

Expand All @@ -35,5 +36,6 @@ def fake_responses
FakeWeb.register_uri(:get, "https://#{auth}github.com/api/v2/json/repos/show/jcoutu", :body => response_file('repos_show_jcoutu.json'))
FakeWeb.register_uri(:get, "https://#{auth}github.com/api/v2/json/repos/show/turingstudio/loupe", :body => response_file('repos_show_turingstudio_loupe.json'))
FakeWeb.register_uri(:get, "https://#{auth}github.com/turingstudio/loupe/network_meta", :body => response_file('turingstudio_loupe_network_meta.json'))
FakeWeb.register_uri(:get, "https://#{auth}github.com/turingstudio/loupe/network_data_chunk?nethash=26fb01d365a6f7ea57be92299803cae7b95ae25a", :body => response_file('turingstudio_loupe_network_data.json'))
end
end

0 comments on commit d700a29

Please sign in to comment.