Sha256: 3706c86226111628f206914e1ebdaadb6d31be71eec38558554cdfcd67267979

Contents?: true

Size: 1.38 KB

Versions: 2

Compression:

Stored size: 1.38 KB

Contents

require 'json'
require 'base64'
require File.dirname(__FILE__) + '/response'

module NSISam
  class FakeClient
    def initialize
      @storage = {}
    end

    def store(data)
      key = Time.now.to_i.to_s
      @storage[key] = JSON.load(data.to_json)
      Response.new '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)
        Response.new '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

    def delete(key)
      if @storage.has_key?(key)
        @storage.delete key
        Response.new 'deleted' => true
      else
        raise NSISam::Errors::Client::KeyNotFoundError
      end
    end

    def update(key, value)
      if @storage.has_key?(key)
        @storage[key] = value
        Response.new 'key' => key, 'checksum' => 0
      else
        raise NSISam::Errors::Client::KeyNotFoundError
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
nsisam-0.6.3 lib/nsisam/fake_client.rb
nsisam-0.6.2 lib/nsisam/fake_client.rb