lib/wagon/connection.rb in wagon-0.9.2 vs lib/wagon/connection.rb in wagon-0.9.3
- old
+ new
@@ -9,10 +9,11 @@
class AuthenticationFailure < StandardError; end
class Connection
HOST = 'secure.lds.org'
LOGIN_PATH = '/units/a/login/1,21568,779-1,00.html?URL='
+ CACHE_PATH = File.join(File.expand_path('~'), '.wagon_cache')
def initialize(username, password)
response = post(LOGIN_PATH, 'username' => username, 'password' => password)
@cookies = response['set-cookie']
@home_path = URI.parse(response['location']).path
@@ -35,10 +36,11 @@
def get_without_caching(path)
_http.request(Net::HTTP::Get.new(path, {'Cookie' => @cookies || ''})).body
end
def get_with_caching(path)
- cache_path = File.join(Wagon::BASE_PATH, 'cache', Digest::SHA1.hexdigest(path) + ".cache")
+ FileUtils::mkdir(CACHE_PATH) unless File.directory?(CACHE_PATH)
+ cache_path = File.join(CACHE_PATH, Digest::SHA1.hexdigest(path) + ".cache")
return open(cache_path).read if File.exists?(cache_path)
open(cache_path, "w").write(data = get_without_caching(path))
data
end
\ No newline at end of file