Module: Immoscout::Models::Actions::Contact
- Extended by:
- ActiveSupport::Concern
- Includes:
- Concerns::Modelable
- Included in:
- Contact
- Defined in:
- lib/immoscout/models/actions/contact.rb
Class Method Summary
collapse
Instance Method Summary
collapse
#api, from_raw, #handle_response, handle_response, #id_from_response, id_from_response, unpack
Class Method Details
.all ⇒ Object
58
59
60
61
62
63
|
# File 'lib/immoscout/models/actions/contact.rb', line 58
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
73
74
75
76
77
|
# File 'lib/immoscout/models/actions/contact.rb', line 73
def create(hash)
instance = new(hash)
instance.save
instance
end
|
.find(id) ⇒ Object
47
48
49
50
51
|
# File 'lib/immoscout/models/actions/contact.rb', line 47
def find(id)
response = api.get("user/#{api.user_name}/contact/#{id}")
handle_response(response)
from_raw(response.body)
end
|
.find_by(hash) ⇒ Object
53
54
55
56
|
# File 'lib/immoscout/models/actions/contact.rb', line 53
def find_by(hash)
external_id = hash.symbolize_keys.fetch(:external_id)
find("ext-#{external_id}")
end
|
.first ⇒ Object
65
66
67
|
# File 'lib/immoscout/models/actions/contact.rb', line 65
def first
all.first
end
|
.last ⇒ Object
69
70
71
|
# File 'lib/immoscout/models/actions/contact.rb', line 69
def last
all.last
end
|
Instance Method Details
#destroy ⇒ Object
rubocop:enable Metrics/AbcSize
39
40
41
42
43
|
# File 'lib/immoscout/models/actions/contact.rb', line 39
def destroy
response = api.delete("user/#{api.user_name}/contact/#{id}")
handle_response(response)
self
end
|
#save ⇒ Object
rubocop:disable Metrics/AbcSize because this is the
bare minimum logic
25
26
27
28
29
30
31
32
33
34
35
36
|
# File 'lib/immoscout/models/actions/contact.rb', line 25
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
|