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

#api, from_raw, #handle_response, handle_response, #id_from_response, id_from_response, unpack

Class Method Details

.allObject



54
55
56
57
58
59
# File 'lib/immoscout/models/actions/contact.rb', line 54

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



63
64
65
66
67
# File 'lib/immoscout/models/actions/contact.rb', line 63

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

.find(id) ⇒ Object



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

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

.find_by(hash) ⇒ Object



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

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

Instance Method Details

#destroyObject



35
36
37
38
39
# File 'lib/immoscout/models/actions/contact.rb', line 35

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

#saveObject



22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/immoscout/models/actions/contact.rb', line 22

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