Module: Immoscout::Models::Actions::Contact

Extended by:
ActiveSupport::Concern
Includes:
Concerns::Modelable
Included in:
Contact
Defined in:
lib/immoscout/models/actions/contact.rb

Overview

Actions to work with contacts.

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Concerns::Modelable

from_raw, handle_response, id_from_response, unpack

Class Method Details

.allObject



50
51
52
53
54
55
# File 'lib/immoscout/models/actions/contact.rb', line 50

def all
  response = api.get("user/#{api.user_name}/contact")
  handle_response(response)
  objects = unpack_collection.call(response.body)
  objects.map { |object| new(object) }
end

.create(hash) ⇒ Object



59
60
61
62
63
# File 'lib/immoscout/models/actions/contact.rb', line 59

def create(hash)
  instance = new(hash)
  instance.save
  instance
end

.find(id) ⇒ Object



39
40
41
42
43
# File 'lib/immoscout/models/actions/contact.rb', line 39

def find(id)
  response = api.get("user/#{api.user_name}/contact/#{id}")
  handle_response(response)
  from_raw(response.body)
end

.find_by(hash) ⇒ Object



45
46
47
48
# File 'lib/immoscout/models/actions/contact.rb', line 45

def find_by(hash)
  external_id = hash.symbolize_keys.fetch(:external_id)
  find("ext-#{external_id}")
end

Instance Method Details

#destroyObject



31
32
33
34
35
# File 'lib/immoscout/models/actions/contact.rb', line 31

def destroy
  response = api.delete("user/#{api.user_name}/contact/#{id}")
  handle_response(response)
  self
end

#saveObject



18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/immoscout/models/actions/contact.rb', line 18

def save
  response =
    if id
      api.put("user/#{api.user_name}/contact/#{id}", as_json)
    else
      api.post("user/#{api.user_name}/contact", as_json)
    end

  handle_response(response)
  self.id = id_from_response(response) unless id
  self
end