lib/immoscout/models/actions/contact.rb in immoscout-1.3.2 vs lib/immoscout/models/actions/contact.rb in immoscout-1.4.0
- old
+ new
@@ -1,15 +1,14 @@
# frozen_string_literal: true
require 'json'
require_relative '../concerns/modelable'
-# rubocop:disable Metrics/BlockLength because this is how an ActiveSupport
-# concern looks like
module Immoscout
module Models
module Actions
+ # Actions to work with contacts.
module Contact
extend ActiveSupport::Concern
included do
include Immoscout::Models::Concerns::Modelable
@@ -18,12 +17,10 @@
hash
.fetch('common.realtorContactDetailsList', {})
.fetch('realtorContactDetails', nil)
end
- # rubocop:disable Metrics/AbcSize because this is the
- # bare minimum logic
def save
response = \
if id
api.put("user/#{api.user_name}/contact/#{id}", as_json)
else
@@ -32,11 +29,10 @@
handle_response(response)
self.id = id_from_response(response) unless id
self
end
- # rubocop:enable Metrics/AbcSize
def destroy
response = api.delete("user/#{api.user_name}/contact/#{id}")
handle_response(response)
self
@@ -59,25 +55,18 @@
response = api.get("user/#{api.user_name}/contact")
handle_response(response)
objects = unpack_collection.call(response.body)
objects.map { |object| new(object) }
end
+ delegate :first, to: :all
+ delegate :last, to: :all
- def first
- all.first
- end
-
- def last
- all.last
- end
-
def create(hash)
instance = new(hash)
instance.save
instance
end
end
end
end
end
end
-# rubocop:enable Metrics/BlockLength