Class: SCV::HTTPFileStore
- Inherits:
-
VCSToolkit::FileStore
- Object
- VCSToolkit::FileStore
- SCV::HTTPFileStore
- Defined in:
- lib/scv/http_file_store.rb
Instance Attribute Summary collapse
-
#base_url ⇒ Object
readonly
Returns the value of attribute base_url.
Instance Method Summary collapse
- #fetch(path) ⇒ Object
- #file?(path) ⇒ Boolean
-
#initialize(url) ⇒ HTTPFileStore
constructor
A new instance of HTTPFileStore.
- #store(path, content) ⇒ Object
Constructor Details
#initialize(url) ⇒ HTTPFileStore
Returns a new instance of HTTPFileStore.
9 10 11 |
# File 'lib/scv/http_file_store.rb', line 9 def initialize(url) @base_url = url.sub(/\/$/, '') end |
Instance Attribute Details
#base_url ⇒ Object (readonly)
Returns the value of attribute base_url.
7 8 9 |
# File 'lib/scv/http_file_store.rb', line 7 def base_url @base_url end |
Instance Method Details
#fetch(path) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 |
# 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) ⇒ Boolean
34 35 36 37 38 39 40 41 42 43 44 45 |
# 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) ⇒ Object
26 27 28 29 30 31 32 |
# 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 |