Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #38 from msadouni/fix-gh-28

Checking if the protocol has changed to clear connection cache and avoid
  • Loading branch information...
commit ce97c2ae5bb9c6f810d920558e968e1fcc411242 2 parents 2e61422 + 8e89f7a
@jsmestad jsmestad authored
Showing with 20 additions and 1 deletion.
  1. +20 −1 lib/pivotal-tracker/client.rb
View
21 lib/pivotal-tracker/client.rb
@@ -26,7 +26,7 @@ def connection(options={})
@connections ||= {}
- @connections[@token] ||= RestClient::Resource.new("#{protocol}://www.pivotaltracker.com/services/v3", :headers => {'X-TrackerToken' => @token, 'Content-Type' => 'application/xml'})
+ cached_connection? && !protocol_changed? ? cached_connection : new_connection
end
protected
@@ -35,6 +35,25 @@ def protocol
use_ssl ? 'https' : 'http'
end
+ def cached_connection?
+ !@connections[@token].nil?
+ end
+
+ def cached_connection
+ @connections[@token]
+ end
+
+ def new_connection
+ @connections[@token] = RestClient::Resource.new("#{protocol}://www.pivotaltracker.com/services/v3", :headers => {'X-TrackerToken' => @token, 'Content-Type' => 'application/xml'})
+ end
+
+ def protocol_changed?
+ cached_connection? ? (cached_connection_protocol != protocol) : false
+ end
+
+ def cached_connection_protocol
+ cached_connection.url.match(/^(.*):\/\//).captures.first
+ end
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.