Commit 50749fbe authored by Fabio Pelosin's avatar Fabio Pelosin

[presenter] fix for spec

parent 26742156
...@@ -82,14 +82,11 @@ module Pod ...@@ -82,14 +82,11 @@ module Pod
gh_url, username, reponame = *(url.match(/[:\/]([\w\-]+)\/([\w\-]+)\.git/).to_a) gh_url, username, reponame = *(url.match(/[:\/]([\w\-]+)\/([\w\-]+)\.git/).to_a)
return unless gh_url return unless gh_url
uri = URI.parse("https://api.github.com/repos/#{username}/#{reponame}") response_body = fetch_stats(username, reponame)
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true return unless response_body
http.verify_mode = OpenSSL::SSL::VERIFY_NONE watchers = response_body.match(/"watchers"\W*:\W*([0-9]+)/).to_a[1]
request = Net::HTTP::Get.new(uri.request_uri) forks = response_body.match(/"forks"\W*:\W*([0-9]+)/).to_a[1]
response = http.request(request).body
watchers = response.match(/"watchers"\W*:\W*([0-9]+)/).to_a[1]
forks = response.match(/"forks"\W*:\W*([0-9]+)/).to_a[1]
return unless watchers && forks return unless watchers && forks
cache[set.name] ||= {} cache[set.name] ||= {}
...@@ -98,6 +95,16 @@ module Pod ...@@ -98,6 +95,16 @@ module Pod
set_value(set, :gh_date, Time.now) set_value(set, :gh_date, Time.now)
save_cache save_cache
end end
def fetch_stats(username, reponame)
uri = URI.parse("https://api.github.com/repos/#{username}/#{reponame}")
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
request = Net::HTTP::Get.new(uri.request_uri)
response = http.request(request)
response.body if response.is_a?(Net::HTTPSuccess)
end
end end
end end
end end
...@@ -12,7 +12,7 @@ describe Pod::Command::Presenter do ...@@ -12,7 +12,7 @@ describe Pod::Command::Presenter do
it "presents the name, version, description, homepage and source of a specification set" do it "presents the name, version, description, homepage and source of a specification set" do
presenter = Presenter.new(argv()) presenter = Presenter.new(argv())
output = presenter.render_set(@set) output = presenter.render_set(@set)
output.should.include? 'CocoaLumberjack' output.should.include? 'CocoaLumberjack'
output.should.include? '1.0' output.should.include? '1.0'
output.should.include? '1.1' output.should.include? '1.1'
...@@ -23,13 +23,14 @@ describe Pod::Command::Presenter do ...@@ -23,13 +23,14 @@ describe Pod::Command::Presenter do
it "presents the stats of a specification set" do it "presents the stats of a specification set" do
response = '{"repository":{"homepage":"","url":"https://github.com/robbiehanson/CocoaLumberjack","has_downloads":true,"has_issues":true,"language":"Objective-C","master_branch":"master","forks":42,"fork":false,"created_at":"2011/03/30 19:38:39 -0700","has_wiki":true,"description":"A fast & simple, yet powerful & flexible logging framework for Mac and iOS","size":416,"private":false,"name":"CocoaLumberjack","owner":"robbiehanson","open_issues":4,"watchers":318,"pushed_at":"2012/03/26 12:39:36 -0700"}}% ' response = '{"repository":{"homepage":"","url":"https://github.com/robbiehanson/CocoaLumberjack","has_downloads":true,"has_issues":true,"language":"Objective-C","master_branch":"master","forks":42,"fork":false,"created_at":"2011/03/30 19:38:39 -0700","has_wiki":true,"description":"A fast & simple, yet powerful & flexible logging framework for Mac and iOS","size":416,"private":false,"name":"CocoaLumberjack","owner":"robbiehanson","open_issues":4,"watchers":318,"pushed_at":"2012/03/26 12:39:36 -0700"}}% '
Net::HTTP.expects(:get).with('github.com', '/api/v2/json/repos/show/robbiehanson/CocoaLumberjack').returns(response) Pod::Specification::Statistics.instance.expects(:fetch_stats).with("robbiehanson", "CocoaLumberjack").returns(response)
presenter = Presenter.new(argv('--stats')) presenter = Presenter.new(argv('--stats'))
output = presenter.render_set(@set) output = presenter.render_set(@set)
output.should.include? 'Author: Robbie Hanson'
output.should.include? 'License: BSD' output.should.include? 'License: BSD'
output.should.include? 'Platform: iOS - OS X' output.should.include? 'Platform: iOS - OS X'
output.should.include? 'Watchers: 318' output.should.include? 'Watchers: 318'
output.should.include? 'Forks: 318' output.should.include? 'Forks: 42'
end end
end end
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment