Class: Snov::FakeClient
- Inherits:
-
Object
- Object
- Snov::FakeClient
- Defined in:
- lib/snov/fake_client.rb
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.default_folder ⇒ Object
20 21 22 |
# File 'lib/snov/fake_client.rb', line 20 def self.default_folder "#{__dir__}/fake_client" end |
.folder ⇒ Object
12 13 14 |
# File 'lib/snov/fake_client.rb', line 12 def self.folder @folder || default_folder end |
.folder=(val) ⇒ Object
3 4 5 6 7 8 9 10 |
# 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 ⇒ Object
16 17 18 |
# File 'lib/snov/fake_client.rb', line 16 def self.reset_folder @folder = nil end |
Instance Method Details
#get(path, payload_hash = {}) ⇒ Object
24 25 26 27 28 29 30 |
# 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 = {}) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 |
# 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. end end |