Skip to content

Commit

Permalink
Roughs in range finding options on NetworkData
Browse files Browse the repository at this point in the history
  • Loading branch information
Julian Coutu authored and Julian Coutu committed Jan 25, 2011
1 parent 879b8e0 commit 624a47c
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 12 deletions.
62 changes: 51 additions & 11 deletions lib/gitnetworkitis/network_data.rb
Expand Up @@ -6,19 +6,59 @@ class NetworkData < Base

def find(options={})
if options.has_key?(:owner) & options.has_key?(:repo) & options.has_key?(:network_meta)
self.network_meta = options[:network_meta]
resp = self.class.get("/#{options[:owner]}/#{options[:repo]}/network_data_chunk?nethash=#{self.network_meta.nethash}&start=0&end=#{self.network_meta.focus}")
json_result = JSON.parse(resp.body.to_s)
result = Array.new
json_result["commits"].each do |commit|
temp_commit = parse_attributes(commit, Commit.new(self.username, self.token))
result.push temp_commit
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
if options.has_key?(:start) & options.has_key?(:end)
find_range(options)
elsif options.has_key?(:start) & !options.has_key?(:end)
find_since(options)
else
find_all(options)
end
else
raise "You must provide an Owner, Repo and Gitnetworkitis:NetworkMeta"
end
end

def find_all(options={})
self.network_meta = options[:network_meta]
resp = self.class.get("/#{options[:owner]}/#{options[:repo]}/network_data_chunk?nethash=#{self.network_meta.nethash}&start=0&end=#{self.network_meta.focus}")
json_result = JSON.parse(resp.body.to_s)
result = Array.new
json_result["commits"].each do |commit|
temp_commit = parse_attributes(commit, Commit.new(self.username, self.token))
result.push temp_commit
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

def find_since(options={})
self.network_meta = options[:network_meta]
resp = self.class.get("/#{options[:owner]}/#{options[:repo]}/network_data_chunk?nethash=#{self.network_meta.nethash}&start=#{options[:start]}&end=#{self.network_meta.focus}")
json_result = JSON.parse(resp.body.to_s)
result = Array.new
json_result["commits"].each do |commit|
temp_commit = parse_attributes(commit, Commit.new(self.username, self.token))
result.push temp_commit
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

def find_range(options={})
self.network_meta = options[:network_meta]
resp = self.class.get("/#{options[:owner]}/#{options[:repo]}/network_data_chunk?nethash=#{self.network_meta.nethash}&start=#{options[:start]}&end=#{options[:end]}")
json_result = JSON.parse(resp.body.to_s)
result = Array.new
json_result["commits"].each do |commit|
temp_commit = parse_attributes(commit, Commit.new(self.username, self.token))
result.push temp_commit
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
41 changes: 41 additions & 0 deletions spec/network_data_spec.rb
Expand Up @@ -26,4 +26,45 @@
test.network_meta.should == network_meta
end
end

context "find with start set and no end" do
let(:tester){GitNetworkitis::NetworkMeta.new(@username, @token)}
let(:network_meta){tester.find({:owner=>"turingstudio", :repo => "loupe"})}
let(:network_data){GitNetworkitis::NetworkData.new(@username, @token)}
let(:test){network_data.find({:owner=>"turingstudio", :repo => "loupe", :network_meta => network_meta, :start => 130})}

before :each do
fake_responses
end

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

it "should set the network_meta" do
test.network_meta.should == network_meta
end
end

context "find with start and end set" do
let(:tester){GitNetworkitis::NetworkMeta.new(@username, @token)}
let(:network_meta){tester.find({:owner=>"turingstudio", :repo => "loupe"})}
let(:network_data){GitNetworkitis::NetworkData.new(@username, @token)}
let(:test){network_data.find({:owner=>"turingstudio", :repo => "loupe", :network_meta => network_meta, :start => 1, :end => 5})}

before :each do
fake_responses
end

it "should set the commits array" do
test.commits.should_not be_empty
test.commits.length.should == 5
end

it "should set the network_meta" do
test.network_meta.should == network_meta
end
end
end
@@ -0,0 +1 @@
{"commits":[{"parents":[["0629e71500e084d41e77cb04c8599dfe2e58534c",0,0]],"author":"Stephen Judkins","time":1,"id":"83c32a570a500207396366c3eabb1deb04a02f05","date":"2010-10-11 15:26:39","gravatar":"b12ead92306a438050ef9001cf8247c0","space":0,"message":"Updated libraries and monkeypatched Rack (until new version is released) to stop spewing warnings during testing","login":"stephenjudkins"},{"parents":[["83c32a570a500207396366c3eabb1deb04a02f05",1,0]],"author":"Stephen Judkins","time":2,"id":"ab748a3806c6c716f5e6de5969846608460eda03","date":"2010-10-13 21:17:43","gravatar":"b12ead92306a438050ef9001cf8247c0","space":0,"message":"Now can associated a project with Pivotal and Harvest projects.","login":"stephenjudkins"},{"parents":[["ab748a3806c6c716f5e6de5969846608460eda03",2,0]],"author":"Stephen Judkins","time":3,"id":"d2f7caf183ae7a5499638ca03bd5efa460707a3b","date":"2010-10-14 14:47:36","gravatar":"b12ead92306a438050ef9001cf8247c0","space":0,"message":"Bump Rails version","login":"stephenjudkins"},{"parents":[["d2f7caf183ae7a5499638ca03bd5efa460707a3b",3,0]],"author":"Stephen Judkins","time":4,"id":"5bb971ddcf2a579df159dca85ca2c18639a91879","date":"2010-10-14 17:18:44","gravatar":"b12ead92306a438050ef9001cf8247c0","space":0,"message":"Upgrade Rspec","login":"stephenjudkins"},{"parents":[["5bb971ddcf2a579df159dca85ca2c18639a91879",4,0]],"author":"Stephen Judkins","time":5,"id":"2f6b33144087f0dd22831d6b161929b8f4b430e7","date":"2010-10-15 16:00:08","gravatar":"b12ead92306a438050ef9001cf8247c0","space":0,"message":"Added new User->Account->Project schema, w\/ CRUD support","login":"stephenjudkins"}]}
@@ -0,0 +1 @@
{"commits":[{"parents":[["2cc2c8f0d1bb17a72ac7e622107b362f3593717d",125,0],["2f045c3f0a4e23831348cac7ca47a99e9161416b",129,1]],"author":"Julian Coutu","time":130,"id":"ad52832a6de54b8afa79c02a0ecebc777365bd7a","date":"2010-12-28 15:51:17","gravatar":"e564097dfa4817087795067cae120937","space":0,"message":"Merge branch 'master' into test_branch_1","login":""},{"parents":[["ad52832a6de54b8afa79c02a0ecebc777365bd7a",130,0]],"author":"Julian Coutu","time":131,"id":"7d3aefe7d02e115ceb164bc582a2af31699c9a73","date":"2010-12-28 16:00:19","gravatar":"e564097dfa4817087795067cae120937","space":0,"message":"Test branch merge","login":""},{"parents":[["ad52832a6de54b8afa79c02a0ecebc777365bd7a",130,0]],"author":"Julian Coutu","time":132,"id":"bdb08e84c91efd1a8b979836646270aa61d94ce7","date":"2010-12-28 16:05:13","gravatar":"e564097dfa4817087795067cae120937","space":2,"message":"testing","login":""},{"parents":[["7d3aefe7d02e115ceb164bc582a2af31699c9a73",131,0]],"author":"Chris Didyk","time":133,"id":"2de226b14260b55c97cb18dedb62167bb38ea0ed","date":"2010-12-28 16:47:16","gravatar":"5c3fdf85d582cd802b60971445eefb59","space":0,"message":"adds happy path for adding\/updating an account admin's remote service credentials, ensures current_user is reset on logout","login":"cdidyk"}]}
3 changes: 2 additions & 1 deletion spec/spec_helper.rb
Expand Up @@ -56,6 +56,7 @@ def fake_responses
FakeWeb.register_uri(:get, "https://#{auth}github.com/api/v2/json/commits/list/turingstudio/loupe/c3aeb61e37f94bbb67c4f14b52c23b8e54d30d0e?page=2", :body => response_file('turingstudio_loupe_c3aeb61e37f94bbb67c4f14b52c23b8e54d30d0e?page=2.json'))
FakeWeb.register_uri(:get, "https://#{auth}github.com/api/v2/json/commits/list/turingstudio/loupe/c3aeb61e37f94bbb67c4f14b52c23b8e54d30d0e?page=3", :body => response_file('turingstudio_loupe_c3aeb61e37f94bbb67c4f14b52c23b8e54d30d0e?page=3.json'))
FakeWeb.register_uri(:get, "https://#{auth}github.com/api/v2/json/commits/list/turingstudio/loupe/c3aeb61e37f94bbb67c4f14b52c23b8e54d30d0e?page=4", :body => response_file('turingstudio_loupe_c3aeb61e37f94bbb67c4f14b52c23b8e54d30d0e?page=4.json'))

FakeWeb.register_uri(:get, "https://#{auth}github.com/turingstudio/loupe/network_data_chunk?nethash=068161e2c05a6b8029a7eb410dd27b1dfa531338&start=130&end=133", :body => response_file('turingstudio_loupe_068161e2c05a6b8029a7eb410dd27b1dfa531338?start=130.json'))
FakeWeb.register_uri(:get, "https://#{auth}github.com/turingstudio/loupe/network_data_chunk?nethash=068161e2c05a6b8029a7eb410dd27b1dfa531338&start=1&end=5", :body => response_file('turingstudio_loupe_068161e2c05a6b8029a7eb410dd27b1dfa531338?start=1&end=5.json'))
end
end

0 comments on commit 624a47c

Please sign in to comment.