class Snov::FakeClient

Public Class Methods

default_folder() click to toggle source
# File lib/snov/fake_client.rb, line 20
def self.default_folder
  "#{__dir__}/fake_client"
end
folder() click to toggle source
# File lib/snov/fake_client.rb, line 12
def self.folder
  @folder || default_folder
end
folder=(val) click to toggle source
# File lib/snov/fake_client.rb, line 3
def self.folder=(val)
  @folder = val
  FileUtils.mkdir_p(@folder)
  ["post_v1_get-profile-by-email", "get_v2_domain-emails-with-info",
   "post_v1_get-prospects-by-email", "post_v1_prospect-list", "get_v1_get-user-lists"].each do |sub_folder|
    FileUtils.cp_r "#{default_folder}/#{sub_folder}", @folder
  end
end
reset_folder() click to toggle source
# File lib/snov/fake_client.rb, line 16
def self.reset_folder
  @folder = nil
end

Public Instance Methods

get(path, payload_hash = {}) click to toggle source
# File lib/snov/fake_client.rb, line 24
def get(path, payload_hash = {})
  data = File.read(filename("get", path, payload_hash))
  MultiJson.load(data)
rescue Errno::ENOENT
  data = File.read(filename("get", path, 'not_found' => 'true'))
  MultiJson.load(data)
end
post(path, payload_hash = {}) click to toggle source
# File lib/snov/fake_client.rb, line 32
def post(path, payload_hash = {})
  data = File.read(filename("post", path, payload_hash))
  MultiJson.load(data)
rescue Errno::ENOENT => e
  file = filename("post", path, 'not_found' => 'true')
  if File.exist?(file)
    MultiJson.load(File.read(file))
  else
    raise Snov::Client::BadRequest, e.message
  end
end

Private Instance Methods

filename(method, path, payload_hash) click to toggle source
# File lib/snov/fake_client.rb, line 46
def filename(method, path, payload_hash)
  add = payload_hash.to_a.map { |v| v.join("=") }.join("&").tr(".", "_")
  add = "default" if add == ""
  "#{self.class.folder}/#{method}#{path.tr("/", "_")}/#{add.gsub('/', '-')}.json"
end