lib/nsisam/fake_client.rb in nsisam-0.5.4 vs lib/nsisam/fake_client.rb in nsisam-0.6.0
- old
+ new
@@ -1,6 +1,8 @@
require 'json'
+require 'base64'
+require File.dirname(__FILE__) + '/response'
module NSISam
class FakeClient
def initialize
@storage = {}
@@ -10,12 +12,27 @@
key = Time.now.to_i.to_s
@storage[key] = JSON.load(data.to_json)
{'key' => key, 'checksum' => 0}
end
+ def store_file(file, type=:file)
+ key = Time.now.to_i.to_s
+ @storage[key] = {type.to_s => Base64.encode64(file)}.to_json
+ Response.new "key" => key, "checksum" => 0
+ end
+
def get(key, expected_checksum=nil)
if @storage.has_key?(key)
{'data' => @storage[key]}
+ else
+ raise NSISam::Errors::Client::KeyNotFoundError
+ end
+ end
+
+ def get_file(key, type=:file)
+ if @storage.has_key?(key)
+ response = Hash.new 'data' => Base64.decode64(@storage[key][type.to_s])
+ Response.new response
else
raise NSISam::Errors::Client::KeyNotFoundError
end
end