class SCV::HTTPFileStore
Attributes
base_url[R]
Public Class Methods
new(url)
click to toggle source
# File lib/scv/http_file_store.rb, line 9 def initialize(url) @base_url = url.sub(/\/$/, '') end
Public Instance Methods
fetch(path)
click to toggle source
# File lib/scv/http_file_store.rb, line 13 def fetch(path) http_response = HTTParty.get("#{base_url}/#{path}") case http_response.code when 200 http_response.body when 404 raise KeyError, "The file #{base_url}/#{path} cannot be found" else raise "Invalid status code #{http_response.code} for #{base_url}/#{path}" end end
file?(path)
click to toggle source
# File lib/scv/http_file_store.rb, line 34 def file?(path) http_response = HTTParty.head("#{base_url}/#{path}") case http_response.code when 200 true when 404 false else raise "Invalid status code #{http_response.code} for #{base_url}/#{path}" end end
store(path, content)
click to toggle source
# File lib/scv/http_file_store.rb, line 26 def store(path, content) http_response = HTTParty.put("#{base_url}/#{path}", {body: content}) unless http_response.code == 200 raise "Invalid status code #{http_response.code} for #{base_url}/#{path} (put)" end end