go_cd_feed 1.1.1 → 1.1.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- go_cd_feed (1.1.0)
4
+ go_cd_feed (1.1.1)
5
5
  nokogiri
6
6
 
7
7
  GEM
@@ -3,7 +3,7 @@ $:.push File.expand_path("../lib", __FILE__)
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "go_cd_feed"
6
- s.version = '1.1.1'
6
+ s.version = '1.1.2'
7
7
  s.authors = ["Nikhil Mungel", "Ketan Padegaonkar", "Shishir Das", "Bill DePhillips"]
8
8
  s.email = ["hyfather@gmail.com", "KetanPadegaonkar@gmail.com", "shishir.das@gmail.com", "bill.dephillips@gmail.com"]
9
9
  s.homepage = "http://github.com/rearadmiral/go-api-client.git"
@@ -4,16 +4,34 @@ require 'net/https'
4
4
  module GoApiClient
5
5
  class HttpFetcher
6
6
 
7
+ attr_reader :status_reporter
8
+
9
+ class StatusReporter
10
+ def on_request_start(url, options)
11
+ @start_time = Time.now
12
+ puts "[GoApiClient] fetching #{url}"
13
+ end
14
+
15
+ def on_request_success(response, url, options)
16
+ seconds = Time.now - @start_time
17
+ puts "[GoApiClient] fetched #{url} in #{seconds}sec"
18
+ end
19
+ end
20
+
21
+ class QuietStatusReporter
22
+ def on_request_start(*args); end
23
+ def on_request_success(*args); end
24
+ end
25
+
7
26
  def initialize(options={})
8
27
  @username = options[:username]
9
28
  @password = options[:password]
29
+ @status_reporter = options[:status_reporter] || ENV['QUIET'] ? QuietStatusReporter.new : StatusReporter.new
10
30
  end
11
31
 
12
32
  def get(url, options={})
13
33
  uri = URI.parse(url)
14
34
 
15
- puts "[DEBUG] fetching #{url}" unless ENV['QUIET']
16
-
17
35
  password = options[:password] || uri.password || @password
18
36
  username = options[:username] || uri.user || @username
19
37
  params = options[:params] || {}
@@ -23,6 +41,8 @@ module GoApiClient
23
41
  http = Net::HTTP.new(uri.host, uri.port)
24
42
  http.use_ssl = uri.scheme == 'https'
25
43
 
44
+ status_reporter.on_request_start(uri, options)
45
+
26
46
  res = http.start do |http|
27
47
  req = Net::HTTP::Get.new(uri.request_uri)
28
48
  req.basic_auth(username, password) if username || password
@@ -31,6 +51,7 @@ module GoApiClient
31
51
 
32
52
  case res
33
53
  when Net::HTTPSuccess
54
+ status_reporter.on_request_success(res, uri, options.merge(:url => uri))
34
55
  return res
35
56
  end
36
57
  res.error!
@@ -13,7 +13,12 @@ module GoApiClient
13
13
  assert_equal (25+4), feed.entries.count
14
14
  end
15
15
 
16
- test "should stop at first page if entry id not specified" do
16
+ test "should stop after page limit if specified" do
17
+ feed = GoApiClient::Atom::Feed.new('https://go-server.example.com/go/api/pipelines/tlb/stages.xml', nil, 1).fetch!
18
+ assert_equal 25, feed.entries.count
19
+ end
20
+
21
+ test "should not stop until first page if entry id not specified" do
17
22
  stub_request(:get, "https://go-server.example.com/go/api/pipelines/tlb/stages.xml?before=7916973").to_return(:body => file_contents("pagination/stages_before_7916973.xml"))
18
23
 
19
24
  feed = GoApiClient::Atom::Feed.new('https://go-server.example.com/go/api/pipelines/tlb/stages.xml').fetch!
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: go_cd_feed
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.1.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -12,7 +12,7 @@ authors:
12
12
  autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
- date: 2014-07-13 00:00:00.000000000 Z
15
+ date: 2014-07-28 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: webmock