Class: FcEnrich::FakeClient

Inherits:
Object
  • Object
show all
Defined in:
lib/fc_enrich/fake_client.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.default_folderObject



20
21
22
# File 'lib/fc_enrich/fake_client.rb', line 20

def self.default_folder
  "#{__dir__}/fake_client"
end

.folderObject



12
13
14
# File 'lib/fc_enrich/fake_client.rb', line 12

def self.folder
  @folder || default_folder
end

.folder=(val) ⇒ Object



5
6
7
8
9
10
# File 'lib/fc_enrich/fake_client.rb', line 5

def self.folder=(val)
  @folder = val
  FileUtils.mkdir_p(@folder)
  FileUtils.cp_r "#{default_folder}/post_v3_company.enrich", @folder
  FileUtils.cp_r "#{default_folder}/post_v3_person.enrich", @folder
end

.reset_folderObject



16
17
18
# File 'lib/fc_enrich/fake_client.rb', line 16

def self.reset_folder
  @folder = nil
end

Instance Method Details

#post(path, payload_hash) ⇒ Object



24
25
26
27
28
29
30
# File 'lib/fc_enrich/fake_client.rb', line 24

def post(path, payload_hash)
  add = payload_hash.to_a.map { |v| v.join("=") }.join("&").tr(".", "_")
  data = File.read("#{self.class.folder}/post#{path.tr("/", "_")}/#{add}.json")
  MultiJson.load(data)
rescue Errno::ENOENT
  nil
end