Module: Immoscout::Models::Concerns::Modelable
- Extended by:
- ActiveSupport::Concern
- Included in:
- Actions::Attachment, Actions::Contact, Actions::Publish, Actions::RealEstate
- Defined in:
- lib/immoscout/models/concerns/modelable.rb
Class Method Summary collapse
- .from_raw(raw_hash) ⇒ Object
- .handle_response(response) ⇒ Object
- .id_from_response(response) ⇒ Object
- .unpack(hash) ⇒ Object
Instance Method Summary collapse
Class Method Details
.from_raw(raw_hash) ⇒ Object
35 36 37 38 |
# File 'lib/immoscout/models/concerns/modelable.rb', line 35 def from_raw(raw_hash) hash = raw_hash.is_a?(String) ? JSON.parse(raw_hash) : raw_hash new(unpack(hash)) end |
.handle_response(response) ⇒ Object
40 41 42 43 44 |
# File 'lib/immoscout/models/concerns/modelable.rb', line 40 def handle_response(response) return response if response.success? raise Immoscout::Errors::Failed, response end |
.id_from_response(response) ⇒ Object
46 47 48 49 50 51 52 53 |
# File 'lib/immoscout/models/concerns/modelable.rb', line 46 def id_from_response(response) response .body .fetch('common.messages') .first .fetch('message', {}) .fetch('id', nil) end |
.unpack(hash) ⇒ Object
31 32 33 |
# File 'lib/immoscout/models/concerns/modelable.rb', line 31 def unpack(hash) hash.values.first end |
Instance Method Details
#api ⇒ Object
17 18 19 |
# File 'lib/immoscout/models/concerns/modelable.rb', line 17 def api self.class.api end |
#handle_response(response) ⇒ Object
21 22 23 |
# File 'lib/immoscout/models/concerns/modelable.rb', line 21 def handle_response(response) self.class.handle_response(response) end |
#id_from_response(response) ⇒ Object
25 26 27 |
# File 'lib/immoscout/models/concerns/modelable.rb', line 25 def id_from_response(response) self.class.id_from_response(response) end |