immoscout 1.3.2 → 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (56) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/documentation.yml +3 -2
  3. data/.github/workflows/test.yml +6 -5
  4. data/.rspec +2 -1
  5. data/.rubocop.yml +23 -4
  6. data/.simplecov +12 -0
  7. data/Appraisals +1 -5
  8. data/CHANGELOG.md +8 -0
  9. data/Dockerfile +2 -3
  10. data/Envfile +0 -3
  11. data/Guardfile +44 -0
  12. data/LICENSE +1 -1
  13. data/Makefile +24 -10
  14. data/Rakefile +13 -66
  15. data/gemfiles/rails_5.2.gemfile +3 -5
  16. data/immoscout.gemspec +45 -44
  17. data/lib/immoscout/api/client.rb +1 -0
  18. data/lib/immoscout/api/connection.rb +8 -9
  19. data/lib/immoscout/api/request.rb +3 -2
  20. data/lib/immoscout/configuration.rb +12 -6
  21. data/lib/immoscout/errors/failed.rb +1 -0
  22. data/lib/immoscout/models/actions/attachment.rb +2 -3
  23. data/lib/immoscout/models/actions/contact.rb +3 -14
  24. data/lib/immoscout/models/actions/publish.rb +1 -3
  25. data/lib/immoscout/models/actions/real_estate.rb +4 -14
  26. data/lib/immoscout/models/apartment_buy.rb +3 -0
  27. data/lib/immoscout/models/base.rb +2 -1
  28. data/lib/immoscout/models/concerns/modelable.rb +2 -0
  29. data/lib/immoscout/models/concerns/propertiable.rb +4 -1
  30. data/lib/immoscout/models/concerns/renderable.rb +5 -5
  31. data/lib/immoscout/models/contact.rb +2 -0
  32. data/lib/immoscout/models/document.rb +2 -0
  33. data/lib/immoscout/models/house_buy.rb +3 -0
  34. data/lib/immoscout/models/parts/address.rb +3 -0
  35. data/lib/immoscout/models/parts/api_search_data.rb +3 -0
  36. data/lib/immoscout/models/parts/contact.rb +3 -0
  37. data/lib/immoscout/models/parts/coordinate.rb +3 -0
  38. data/lib/immoscout/models/parts/courtage.rb +3 -0
  39. data/lib/immoscout/models/parts/energy_certificate.rb +3 -0
  40. data/lib/immoscout/models/parts/energy_source.rb +3 -0
  41. data/lib/immoscout/models/parts/firing_type.rb +3 -0
  42. data/lib/immoscout/models/parts/geo_code.rb +3 -0
  43. data/lib/immoscout/models/parts/geo_hierarchy.rb +3 -0
  44. data/lib/immoscout/models/parts/international_country_region.rb +3 -0
  45. data/lib/immoscout/models/parts/price.rb +3 -0
  46. data/lib/immoscout/models/parts/publish_channel.rb +3 -0
  47. data/lib/immoscout/models/parts/real_estate.rb +3 -0
  48. data/lib/immoscout/models/parts/url.rb +3 -0
  49. data/lib/immoscout/models/parts/urls.rb +3 -0
  50. data/lib/immoscout/models/picture.rb +2 -0
  51. data/lib/immoscout/models/publish.rb +2 -0
  52. data/lib/immoscout/models.rb +0 -1
  53. data/lib/immoscout/version.rb +19 -1
  54. data/lib/immoscout.rb +1 -0
  55. metadata +96 -76
  56. data/gemfiles/rails_6.0.gemfile +0 -9
@@ -2,6 +2,7 @@
2
2
 
3
3
  module Immoscout
4
4
  module Errors
5
+ # Representation of a failed API request/response.
5
6
  class Failed < StandardError
6
7
  def initialize(response)
7
8
  @status = response.status
@@ -8,6 +8,7 @@ require_relative '../concerns/modelable'
8
8
  module Immoscout
9
9
  module Models
10
10
  module Actions
11
+ # Actions to work with attachments.
11
12
  module Attachment
12
13
  extend ActiveSupport::Concern
13
14
 
@@ -54,7 +55,7 @@ module Immoscout
54
55
  self
55
56
  end
56
57
 
57
- private
58
+ protected
58
59
 
59
60
  def file_extension
60
61
  File.extname(file_name)
@@ -80,7 +81,6 @@ module Immoscout
80
81
  }.fetch(ext)
81
82
  end
82
83
 
83
- # rubocop:disable Metrics/AbcSize because of the mapping logic
84
84
  def all(real_estate_id)
85
85
  response = api.get(
86
86
  "user/#{api.user_name}/realestate/#{real_estate_id}/attachment"
@@ -91,7 +91,6 @@ module Immoscout
91
91
  .map { |object| new(object) }
92
92
  .select { |object| object.type =~ /#{name.demodulize}/i }
93
93
  end
94
- # rubocop:enable Metrics/AbcSize
95
94
  end
96
95
  end
97
96
  end
@@ -3,11 +3,10 @@
3
3
  require 'json'
4
4
  require_relative '../concerns/modelable'
5
5
 
6
- # rubocop:disable Metrics/BlockLength because this is how an ActiveSupport
7
- # concern looks like
8
6
  module Immoscout
9
7
  module Models
10
8
  module Actions
9
+ # Actions to work with contacts.
11
10
  module Contact
12
11
  extend ActiveSupport::Concern
13
12
 
@@ -20,8 +19,6 @@ module Immoscout
20
19
  .fetch('realtorContactDetails', nil)
21
20
  end
22
21
 
23
- # rubocop:disable Metrics/AbcSize because this is the
24
- # bare minimum logic
25
22
  def save
26
23
  response = \
27
24
  if id
@@ -34,7 +31,6 @@ module Immoscout
34
31
  self.id = id_from_response(response) unless id
35
32
  self
36
33
  end
37
- # rubocop:enable Metrics/AbcSize
38
34
 
39
35
  def destroy
40
36
  response = api.delete("user/#{api.user_name}/contact/#{id}")
@@ -61,14 +57,8 @@ module Immoscout
61
57
  objects = unpack_collection.call(response.body)
62
58
  objects.map { |object| new(object) }
63
59
  end
64
-
65
- def first
66
- all.first
67
- end
68
-
69
- def last
70
- all.last
71
- end
60
+ delegate :first, to: :all
61
+ delegate :last, to: :all
72
62
 
73
63
  def create(hash)
74
64
  instance = new(hash)
@@ -80,4 +70,3 @@ module Immoscout
80
70
  end
81
71
  end
82
72
  end
83
- # rubocop:enable Metrics/BlockLength
@@ -6,6 +6,7 @@ require_relative '../concerns/modelable'
6
6
  module Immoscout
7
7
  module Models
8
8
  module Actions
9
+ # Actions to publish a Real Estate.
9
10
  module Publish
10
11
  extend ActiveSupport::Concern
11
12
 
@@ -26,9 +27,6 @@ module Immoscout
26
27
  self
27
28
  end
28
29
  end
29
-
30
- class_methods do
31
- end
32
30
  end
33
31
  end
34
32
  end
@@ -8,6 +8,7 @@ require_relative '../concerns/modelable'
8
8
  module Immoscout
9
9
  module Models
10
10
  module Actions
11
+ # Actions to work with real estate objects.
11
12
  module RealEstate
12
13
  extend ActiveSupport::Concern
13
14
 
@@ -21,8 +22,6 @@ module Immoscout
21
22
  .fetch('realEstateElement', nil)
22
23
  end
23
24
 
24
- # rubocop:disable Metrics/AbcSize because this is the
25
- # bare minimum logic
26
25
  def save
27
26
  response = \
28
27
  if id
@@ -35,7 +34,6 @@ module Immoscout
35
34
  self.id = id_from_response(response) unless id
36
35
  self
37
36
  end
38
- # rubocop:enable Metrics/AbcSize
39
37
 
40
38
  def destroy
41
39
  response = api.delete("user/#{api.user_name}/realestate/#{id}")
@@ -79,7 +77,7 @@ module Immoscout
79
77
  self
80
78
  end
81
79
 
82
- private
80
+ protected
83
81
 
84
82
  def check_placement_type(type)
85
83
  raise ArgumentError, "Unknown placement type '#{type}'" unless %w[
@@ -100,7 +98,6 @@ module Immoscout
100
98
  find("ext-#{external_id}")
101
99
  end
102
100
 
103
- # rubocop:disable Metrics/AbcSize because of the mapping logic
104
101
  def all
105
102
  response = api.get("user/#{api.user_name}/realestate")
106
103
  handle_response(response)
@@ -109,15 +106,8 @@ module Immoscout
109
106
  .map { |object| new(object) }
110
107
  .select { |object| object.type =~ /#{name.demodulize}/i }
111
108
  end
112
- # rubocop:enable Metrics/AbcSize
113
-
114
- def first
115
- all.first
116
- end
117
-
118
- def last
119
- all.last
120
- end
109
+ delegate :first, to: :all
110
+ delegate :last, to: :all
121
111
 
122
112
  def create(hash)
123
113
  instance = new(hash)
@@ -12,6 +12,9 @@ require_relative 'parts/energy_source'
12
12
 
13
13
  module Immoscout
14
14
  module Models
15
+ # Real Estate. (selling an apartment)
16
+ # See: https://bit.ly/3iH3DNL
17
+ # See: https://bit.ly/3H7mQkY
15
18
  class ApartmentBuy < Base
16
19
  include Immoscout::Models::Concerns::Renderable
17
20
  include Immoscout::Models::Concerns::Propertiable
@@ -2,6 +2,7 @@
2
2
 
3
3
  module Immoscout
4
4
  module Models
5
+ # The base/abstract model.
5
6
  class Base
6
7
  attr_reader :base
7
8
 
@@ -10,7 +11,7 @@ module Immoscout
10
11
  set_properties
11
12
  end
12
13
 
13
- private
14
+ protected
14
15
 
15
16
  def prepared_hash
16
17
  base
@@ -5,6 +5,8 @@ require 'json'
5
5
  module Immoscout
6
6
  module Models
7
7
  module Concerns
8
+ # Provides base functionality to reference/map/(de)serialize
9
+ # models against the immoscout API.
8
10
  module Modelable
9
11
  extend ActiveSupport::Concern
10
12
 
@@ -3,6 +3,8 @@
3
3
  module Immoscout
4
4
  module Models
5
5
  module Concerns
6
+ # Includes functionality to access and modify
7
+ # model attributes transparently.
6
8
  module Propertiable
7
9
  extend ActiveSupport::Concern
8
10
 
@@ -14,7 +16,7 @@ module Immoscout
14
16
  # :reek:ControlParameter - standard stuff, reek!
15
17
  # :reek:TooManyStatements
16
18
  def method_missing(method_name, *arguments, &block)
17
- if method_name =~ /build\_(\w+)/
19
+ if method_name =~ /build_(\w+)/
18
20
  match = Regexp.last_match(1).intern
19
21
  properties = self.class.properties
20
22
  coerce_klass = properties.fetch(match).fetch(:coerce, nil)
@@ -39,6 +41,7 @@ module Immoscout
39
41
  class_methods do
40
42
  def property(name, **opts)
41
43
  attr_accessor(name)
44
+
42
45
  alias_name = opts.fetch(:alias, false)
43
46
  if alias_name
44
47
  alias_method alias_name, name
@@ -7,6 +7,7 @@ require 'json'
7
7
  module Immoscout
8
8
  module Models
9
9
  module Concerns
10
+ # Includes functionality to serialize a Ruby model properly.
10
11
  module Renderable
11
12
  extend ActiveSupport::Concern
12
13
 
@@ -15,12 +16,12 @@ module Immoscout
15
16
  wrapped? ? to_json_wrapped : to_json_unwrapped
16
17
  end
17
18
 
18
- def to_json
19
+ def to_json(*)
19
20
  as_json.to_json
20
21
  end
21
22
  alias_method :to_s, :to_json
22
23
 
23
- private
24
+ protected
24
25
 
25
26
  def wrapped?
26
27
  self.class.try(:json_wrapper)
@@ -30,6 +31,7 @@ module Immoscout
30
31
  # bare minimum logic
31
32
  # rubocop:disable Metrics/MethodLength dito
32
33
  # rubocop:disable Metrics/CyclomaticComplexity dito
34
+ # rubocop:disable Metrics/AbcSize dito
33
35
  def to_h
34
36
  self.class.properties.each_with_object({}) do |(key, value), memo|
35
37
  # skip if it's readonly and should not be exposed in #as_json
@@ -54,6 +56,7 @@ module Immoscout
54
56
  # rubocop:enable Metrics/PerceivedComplexity
55
57
  # rubocop:enable Metrics/MethodLength
56
58
  # rubocop:enable Metrics/CyclomaticComplexity
59
+ # rubocop:enable Metrics/AbcSize
57
60
 
58
61
  def to_json_wrapped
59
62
  { self.class.try(:json_wrapper) => to_json_unwrapped }
@@ -66,9 +69,6 @@ module Immoscout
66
69
  .deep_transform_keys { |key| key.camelize :lower }
67
70
  end
68
71
  end
69
-
70
- class_methods do
71
- end
72
72
  end
73
73
  end
74
74
  end
@@ -7,6 +7,8 @@ require_relative 'parts/address'
7
7
 
8
8
  module Immoscout
9
9
  module Models
10
+ # A contact.
11
+ # See: https://bit.ly/3WcYquD
10
12
  class Contact < Base
11
13
  include Immoscout::Models::Concerns::Renderable
12
14
  include Immoscout::Models::Concerns::Propertiable
@@ -6,6 +6,8 @@ require_relative 'actions/attachment'
6
6
 
7
7
  module Immoscout
8
8
  module Models
9
+ # Attachment (document) of a Real Estate.
10
+ # See: https://bit.ly/3Xx32gj
9
11
  class Document < Base
10
12
  include Immoscout::Models::Concerns::Renderable
11
13
  include Immoscout::Models::Concerns::Propertiable
@@ -14,6 +14,9 @@ require_relative 'parts/firing_type'
14
14
 
15
15
  module Immoscout
16
16
  module Models
17
+ # Real Estate. (selling a house)
18
+ # See: https://bit.ly/3iH3DNL
19
+ # See: https://bit.ly/3CSGnmN
17
20
  class HouseBuy < Base
18
21
  include Immoscout::Models::Concerns::Renderable
19
22
  include Immoscout::Models::Concerns::Propertiable
@@ -10,9 +10,12 @@ require_relative '../concerns/renderable'
10
10
  module Immoscout
11
11
  module Models
12
12
  module Parts
13
+ # Shared address-related property definitions.
14
+ # See: https://bit.ly/3CSGnmN
13
15
  class Address < Base
14
16
  include Immoscout::Models::Concerns::Renderable
15
17
  include Immoscout::Models::Concerns::Propertiable
18
+
16
19
  property :street
17
20
  property :house_number
18
21
  property :postcode
@@ -7,9 +7,12 @@ require_relative '../concerns/renderable'
7
7
  module Immoscout
8
8
  module Models
9
9
  module Parts
10
+ # Shared search-related property definitions.
11
+ # See: https://bit.ly/3CSGnmN
10
12
  class ApiSearchData < Base
11
13
  include Immoscout::Models::Concerns::Renderable
12
14
  include Immoscout::Models::Concerns::Propertiable
15
+
13
16
  property :search_field1
14
17
  property :search_field2
15
18
  property :search_field3
@@ -7,9 +7,12 @@ require_relative '../concerns/renderable'
7
7
  module Immoscout
8
8
  module Models
9
9
  module Parts
10
+ # Shared contact-related property definitions.
11
+ # See: https://bit.ly/3CSGnmN
10
12
  class Contact < Base
11
13
  include Immoscout::Models::Concerns::Renderable
12
14
  include Immoscout::Models::Concerns::Propertiable
15
+
13
16
  property :id, alias: :@id
14
17
  property :external_id, alias: :@external_id
15
18
  end
@@ -7,9 +7,12 @@ require_relative '../concerns/renderable'
7
7
  module Immoscout
8
8
  module Models
9
9
  module Parts
10
+ # Shared coordinates-related property definitions.
11
+ # See: https://bit.ly/3CSGnmN
10
12
  class Coordinate < Base
11
13
  include Immoscout::Models::Concerns::Renderable
12
14
  include Immoscout::Models::Concerns::Propertiable
15
+
13
16
  property :latitude
14
17
  property :longitude
15
18
  end
@@ -7,9 +7,12 @@ require_relative '../concerns/renderable'
7
7
  module Immoscout
8
8
  module Models
9
9
  module Parts
10
+ # Shared courtage-related property definitions.
11
+ # See: https://bit.ly/3CSGnmN
10
12
  class Courtage < Base
11
13
  include Immoscout::Models::Concerns::Renderable
12
14
  include Immoscout::Models::Concerns::Propertiable
15
+
13
16
  property :has_courtage
14
17
  property :courtage
15
18
  property :courtage_note
@@ -7,9 +7,12 @@ require_relative '../concerns/renderable'
7
7
  module Immoscout
8
8
  module Models
9
9
  module Parts
10
+ # Shared energy-certificate-related property definitions.
11
+ # See: https://bit.ly/3CSGnmN
10
12
  class EnergyCertificate < Base
11
13
  include Immoscout::Models::Concerns::Renderable
12
14
  include Immoscout::Models::Concerns::Propertiable
15
+
13
16
  property :energy_certificate_availability
14
17
  property :energy_certificate_creation_date
15
18
  property :energy_efficiency_class
@@ -7,9 +7,12 @@ require_relative '../concerns/renderable'
7
7
  module Immoscout
8
8
  module Models
9
9
  module Parts
10
+ # Shared energy-source-related property definitions.
11
+ # See: https://bit.ly/3CSGnmN
10
12
  class EnergySource < Base
11
13
  include Immoscout::Models::Concerns::Renderable
12
14
  include Immoscout::Models::Concerns::Propertiable
15
+
13
16
  property :energy_source_enev2014
14
17
  end
15
18
  end
@@ -7,9 +7,12 @@ require_relative '../concerns/renderable'
7
7
  module Immoscout
8
8
  module Models
9
9
  module Parts
10
+ # Shared firing-type-related property definitions.
11
+ # See: https://bit.ly/3CSGnmN
10
12
  class FiringType < Base
11
13
  include Immoscout::Models::Concerns::Renderable
12
14
  include Immoscout::Models::Concerns::Propertiable
15
+
13
16
  property :firing_type
14
17
  end
15
18
  end
@@ -7,9 +7,12 @@ require_relative '../concerns/renderable'
7
7
  module Immoscout
8
8
  module Models
9
9
  module Parts
10
+ # Shared geo-coding-related property definitions.
11
+ # See: https://bit.ly/3CSGnmN
10
12
  class GeoCode < Base
11
13
  include Immoscout::Models::Concerns::Renderable
12
14
  include Immoscout::Models::Concerns::Propertiable
15
+
13
16
  property :geo_code_id
14
17
  property :full_geo_code_id
15
18
  end
@@ -8,9 +8,12 @@ require_relative 'geo_code'
8
8
  module Immoscout
9
9
  module Models
10
10
  module Parts
11
+ # Shared geo-hierarchy-related property definitions.
12
+ # See: https://bit.ly/3CSGnmN
11
13
  class GeoHierarchy < Base
12
14
  include Immoscout::Models::Concerns::Renderable
13
15
  include Immoscout::Models::Concerns::Propertiable
16
+
14
17
  property :continent, coerce: Immoscout::Models::Parts::GeoCode
15
18
  property :country, coerce: Immoscout::Models::Parts::GeoCode
16
19
  property :region, coerce: Immoscout::Models::Parts::GeoCode
@@ -7,9 +7,12 @@ require_relative '../concerns/renderable'
7
7
  module Immoscout
8
8
  module Models
9
9
  module Parts
10
+ # Shared country-region-related property definitions.
11
+ # See: https://bit.ly/3CSGnmN
10
12
  class InternationalCountryRegion < Base
11
13
  include Immoscout::Models::Concerns::Renderable
12
14
  include Immoscout::Models::Concerns::Propertiable
15
+
13
16
  property :country
14
17
  property :region
15
18
  end
@@ -7,9 +7,12 @@ require_relative '../concerns/renderable'
7
7
  module Immoscout
8
8
  module Models
9
9
  module Parts
10
+ # Shared price-related property definitions.
11
+ # See: https://bit.ly/3CSGnmN
10
12
  class Price < Base
11
13
  include Immoscout::Models::Concerns::Renderable
12
14
  include Immoscout::Models::Concerns::Propertiable
15
+
13
16
  property :value
14
17
  property :currency
15
18
  property :marketing_type
@@ -7,9 +7,12 @@ require_relative '../concerns/renderable'
7
7
  module Immoscout
8
8
  module Models
9
9
  module Parts
10
+ # Shared publish-channel-related property definitions.
11
+ # See: https://bit.ly/3CSGnmN
10
12
  class PublishChannel < Base
11
13
  include Immoscout::Models::Concerns::Renderable
12
14
  include Immoscout::Models::Concerns::Propertiable
15
+
13
16
  property :id, alias: :@id, default: 10_000
14
17
  end
15
18
  end
@@ -7,9 +7,12 @@ require_relative '../concerns/renderable'
7
7
  module Immoscout
8
8
  module Models
9
9
  module Parts
10
+ # Shared real-estate-related property definitions.
11
+ # See: https://bit.ly/3CSGnmN
10
12
  class RealEstate < Base
11
13
  include Immoscout::Models::Concerns::Renderable
12
14
  include Immoscout::Models::Concerns::Propertiable
15
+
13
16
  property :id, alias: :@id
14
17
  end
15
18
  end
@@ -7,9 +7,12 @@ require_relative '../concerns/renderable'
7
7
  module Immoscout
8
8
  module Models
9
9
  module Parts
10
+ # Shared URL-related property definitions.
11
+ # See: https://bit.ly/3CSGnmN
10
12
  class Url < Base
11
13
  include Immoscout::Models::Concerns::Renderable
12
14
  include Immoscout::Models::Concerns::Propertiable
15
+
13
16
  property :scale, alias: :@scale
14
17
  property :href, alias: :@href
15
18
  end
@@ -8,9 +8,12 @@ require_relative 'url'
8
8
  module Immoscout
9
9
  module Models
10
10
  module Parts
11
+ # Shared URLs-related property definitions.
12
+ # See: https://bit.ly/3CSGnmN
11
13
  class Urls < Base
12
14
  include Immoscout::Models::Concerns::Renderable
13
15
  include Immoscout::Models::Concerns::Propertiable
16
+
14
17
  property :url, coerce: Immoscout::Models::Parts::Url, array: true
15
18
  end
16
19
  end
@@ -7,6 +7,8 @@ require_relative 'actions/attachment'
7
7
 
8
8
  module Immoscout
9
9
  module Models
10
+ # Attachment (picture) of a Real Estate.
11
+ # See: https://bit.ly/3iE6K9h
10
12
  class Picture < Base
11
13
  include Immoscout::Models::Concerns::Renderable
12
14
  include Immoscout::Models::Concerns::Propertiable
@@ -8,6 +8,8 @@ require_relative 'parts/publish_channel'
8
8
 
9
9
  module Immoscout
10
10
  module Models
11
+ # The Publish (object) of a Real Estate.
12
+ # See: https://bit.ly/3ZFoYYI
11
13
  class Publish < Base
12
14
  include Immoscout::Models::Concerns::Renderable
13
15
  include Immoscout::Models::Concerns::Propertiable
@@ -2,7 +2,6 @@
2
2
 
3
3
  require_relative 'errors/failed'
4
4
  require_relative 'api/client'
5
- # renderable models
6
5
  require_relative 'models/house_buy'
7
6
  require_relative 'models/apartment_buy'
8
7
  require_relative 'models/contact'
@@ -1,5 +1,23 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # The gem version details.
3
4
  module Immoscout
4
- VERSION = '1.3.2'
5
+ # The version of the +immoscout+ gem
6
+ VERSION = '1.4.0'
7
+
8
+ class << self
9
+ # Returns the version of gem as a string.
10
+ #
11
+ # @return [String] the gem version as string
12
+ def version
13
+ VERSION
14
+ end
15
+
16
+ # Returns the version of the gem as a +Gem::Version+.
17
+ #
18
+ # @return [Gem::Version] the gem version as object
19
+ def gem_version
20
+ Gem::Version.new VERSION
21
+ end
22
+ end
5
23
  end
data/lib/immoscout.rb CHANGED
@@ -8,6 +8,7 @@ require 'immoscout/version'
8
8
  require 'immoscout/configuration'
9
9
  require 'immoscout/models'
10
10
 
11
+ # The top-namespace of the +immoscout+ gem.
11
12
  module Immoscout
12
13
  class << self
13
14
  attr_writer :configuration