justimmo_client 0.6.3 → 0.6.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. checksums.yaml +4 -4
  2. data/.simplecov +10 -0
  3. data/lib/justimmo_client/api/v1/interfaces/justimmo_interface.rb +1 -0
  4. data/lib/justimmo_client/api/v1/interfaces/realty_interface.rb +6 -5
  5. data/lib/justimmo_client/api/v1/models/attachment.rb +38 -0
  6. data/lib/justimmo_client/api/v1/models/city.rb +1 -1
  7. data/lib/justimmo_client/api/v1/models/country.rb +19 -10
  8. data/lib/justimmo_client/api/v1/models/employee.rb +26 -19
  9. data/lib/justimmo_client/api/v1/models/geo_location.rb +3 -5
  10. data/lib/justimmo_client/api/v1/models/justimmo_base.rb +1 -0
  11. data/lib/justimmo_client/api/v1/models/realty.rb +33 -36
  12. data/lib/justimmo_client/api/v1/models/realty_cost.rb +68 -0
  13. data/lib/justimmo_client/api/v1/models/realty_marketing.rb +1 -4
  14. data/lib/justimmo_client/api/v1/models/realty_price.rb +33 -57
  15. data/lib/justimmo_client/api/v1/models/realty_usage.rb +1 -5
  16. data/lib/justimmo_client/api/v1/representers/json/attachment_representer.rb +14 -0
  17. data/lib/justimmo_client/api/v1/representers/json/employee_representer.rb +3 -7
  18. data/lib/justimmo_client/api/v1/representers/json/realty_representer.rb +92 -37
  19. data/lib/justimmo_client/api/v1/representers/xml/attachment_representer.rb +31 -0
  20. data/lib/justimmo_client/api/v1/representers/xml/employee_representer.rb +11 -22
  21. data/lib/justimmo_client/api/v1/representers/xml/justimmo_representer.rb +1 -0
  22. data/lib/justimmo_client/api/v1/representers/xml/realty_price_representer.rb +4 -1
  23. data/lib/justimmo_client/api/v1/representers/xml/realty_representer.rb +192 -1
  24. data/lib/justimmo_client/api/v1/representers/xml/realty_type_representer.rb +2 -0
  25. data/lib/justimmo_client/autoload.rb +1 -0
  26. data/lib/justimmo_client/core/api_helpers.rb +29 -0
  27. data/lib/justimmo_client/core/config.rb +7 -1
  28. data/lib/justimmo_client/core/utils.rb +1 -25
  29. data/lib/justimmo_client/interface.rb +1 -0
  30. data/lib/justimmo_client/version.rb +1 -1
  31. data/locales/de.yml +3 -0
  32. metadata +8 -14
  33. data/lib/justimmo_client/api/v1/models/file.rb +0 -64
  34. data/lib/justimmo_client/api/v1/models/image.rb +0 -10
  35. data/lib/justimmo_client/api/v1/representers/json/contact_representer.rb +0 -15
  36. data/lib/justimmo_client/api/v1/representers/json/geo_location_representer.rb +0 -15
  37. data/lib/justimmo_client/api/v1/representers/json/realty_area_representer.rb +0 -27
  38. data/lib/justimmo_client/api/v1/representers/json/realty_price_representer.rb +0 -43
  39. data/lib/justimmo_client/api/v1/representers/json/realty_room_count_representer.rb +0 -21
  40. data/lib/justimmo_client/api/v1/representers/xml/contact_representer.rb +0 -15
  41. data/lib/justimmo_client/api/v1/representers/xml/realty_area_representer.rb +0 -28
  42. data/lib/justimmo_client/api/v1/representers/xml/realty_detail_representer.rb +0 -96
  43. data/lib/justimmo_client/api/v1/representers/xml/realty_list_representer.rb +0 -85
  44. data/lib/justimmo_client/api/v1/representers/xml/realty_room_count_representer.rb +0 -22
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8d91fd1ec8ab9bb56ad3aa5f310447739f072c5e
4
- data.tar.gz: 95f6f01ca3c687af8436dba6f26d389a73e830f2
3
+ metadata.gz: 9cfd5491bed0810ae55db2737e4b792c04966d6f
4
+ data.tar.gz: 5b3560ac4d3c240c33db62ab5812139bb4ac27b5
5
5
  SHA512:
6
- metadata.gz: 6d35db0035a7f905558190aa9e03d06ff75ab7e83661ac26c602aa89a3ae3798d417431f4c55faf401b9dfb9f128bfb85912a2179482c8c2062f7dabbe894554
7
- data.tar.gz: 06daf92f1fcfe2b70f983ccc071a94322260ee5407aa97f1570a7a704bd3f02683232879dc66d73c268a17fdccb9d7f17065166c99ff788398c01658b4b01d11
6
+ metadata.gz: e57be8e672d31c7ba436234bff8524baaa893ec69a0c60994c4a2da78fb5e8886c4088ee0aac2cf55a2c2fdad1e8e48d4ff0185222c302a0647d53ad44390c6c
7
+ data.tar.gz: 508c6a5368a493d5b463f2c472c99f909d1c5a8bc8de4daa80237bd90f6c8fb1c213b2a10e9eeff2a108df5029e864c897f3bf4527336c87c70357006c053c6d
data/.simplecov ADDED
@@ -0,0 +1,10 @@
1
+ SimpleCov.start do
2
+ add_filter "/bin/"
3
+ add_filter "/cache/"
4
+ add_filter "/examples/"
5
+ add_filter "/spec/"
6
+ add_group "V1/Models", "lib/justimmo_client/api/v1/models"
7
+ add_group "V1/Representers", "lib/justimmo_client/api/v1/representers"
8
+ add_group "V1/Requests", "lib/justimmo_client/api/v1/requests"
9
+ add_group "V1/Interfaces", "lib/justimmo_client/api/v1/interfaces"
10
+ end
@@ -4,6 +4,7 @@ module JustimmoClient::V1
4
4
  module JustimmoInterface
5
5
  include JustimmoClient::Caching
6
6
  include JustimmoClient::Logging
7
+ include JustimmoClient::API
7
8
 
8
9
  def cache_key(endpoint, params = {})
9
10
  key = Digest::SHA256.new
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "json"
4
+ require "nokogiri"
4
5
 
5
6
  module JustimmoClient::V1
6
7
  # Public realty query interface
@@ -64,9 +65,10 @@ module JustimmoClient::V1
64
65
  representer(:realty, :json).for_collection.new([]).from_json(cached)
65
66
  end,
66
67
  on_miss: -> do
67
- model = Struct.new(:realties).new
68
- xml_response = request(:realty).list(options)
69
- represented = representer(:realty_list).new(model).from_xml(xml_response).realties
68
+ doc = Nokogiri::XML(request(:realty).list(options))
69
+ doc.at_css("query-result").remove
70
+ xml_response = doc.to_xml
71
+ represented = representer(:realty).for_collection.new([]).from_xml(xml_response)
70
72
  new_cache = representer(:realty, :json).for_collection.new(represented).to_json
71
73
  [represented, new_cache]
72
74
  end
@@ -84,8 +86,7 @@ module JustimmoClient::V1
84
86
  end,
85
87
  on_miss: -> do
86
88
  xml_response = request(:realty).detail(id, lang: lang)
87
- model = Struct.new(:realty).new
88
- represented = representer(:realty_detail).new(model).from_xml(xml_response).realty
89
+ represented = representer(:realty).for_collection.new([]).from_xml(xml_response).first
89
90
  new_cache = representer(:realty, :json).new(represented).to_json
90
91
  [represented, new_cache]
91
92
  end
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "uri"
4
+
5
+ module JustimmoClient::V1
6
+ class Attachment < JustimmoBase
7
+ BASE_URL = "https://files.justimmo.at/public"
8
+
9
+ private_constant :BASE_URL
10
+
11
+ attribute :category, Symbol
12
+ attribute :origin, Symbol
13
+ attribute :title, String
14
+ attribute :format, String
15
+ attribute :type, String
16
+ attribute :file, String
17
+
18
+ def url=(value)
19
+ path = URI.parse(value).path.sub("/public/", "")
20
+ @type, size, file = path.split("/")
21
+ @format ||= ::File.extname(file).tr(".", "")
22
+ @file = ::File.basename(file, ".#{@format}")
23
+ @size = size.start_with?("user") ? :user_big : :big
24
+ end
25
+
26
+ def url(size = nil)
27
+ size ||= @size
28
+ "#{BASE_URL}/#{@type}/#{size}/#{file}.#{format}"
29
+ end
30
+
31
+ alias to_s url
32
+ alias [] url
33
+
34
+ def inspect
35
+ "#<#{self.class} #{self}>"
36
+ end
37
+ end
38
+ end
@@ -6,7 +6,7 @@ module JustimmoClient::V1
6
6
 
7
7
  # @!macro [attach] attribute
8
8
  # @return [$2]
9
- attribute :id, Integer
9
+ attribute :id, Integer
10
10
  attribute :country_id, Integer
11
11
  attribute :region_id, Integer
12
12
  attribute :zip_code, Integer
@@ -9,36 +9,45 @@ module JustimmoClient::V1
9
9
  # @!macro [attach] attribute
10
10
  # @return [$2]
11
11
  attribute :id, Integer
12
- attribute :alpha2, String
13
- attribute :alpha3, String
12
+ attribute :alpha2, String, default: ""
13
+ attribute :alpha3, String, default: ""
14
+ attribute :name, String, default: ""
14
15
 
15
16
  # @!group Instance Method Summary
16
17
 
17
18
  def initialize(**options)
19
+ @country = find_country(options[:name])
20
+ return unless @country
21
+ options.update(name: @country.name, alpha2: @country.alpha2, alpha3: @country.alpha3)
18
22
  super(options)
19
- @country = nil
20
23
  end
21
24
 
22
25
  def alpha2=(code)
23
- @country ||= IsoCountryCodes.find(code)
24
26
  @alpha2 ||= @country.alpha2
25
27
  end
26
28
 
27
29
  def alpha3=(code)
28
- @country ||= IsoCountryCodes.find(code)
29
30
  @alpha3 ||= @country.alpha3
30
31
  end
31
32
 
32
- def name
33
- @country&.name
34
- end
35
-
36
33
  def to_s
37
- @country&.name || ""
34
+ name
38
35
  end
39
36
 
40
37
  def inspect
41
38
  "#<#{self.class} #{self}>"
42
39
  end
40
+
41
+ private
42
+
43
+ def find_country(name_or_code)
44
+ if name_or_code.size <= 3
45
+ IsoCountryCodes.find(name_or_code)
46
+ else
47
+ IsoCountryCodes.search_by_name(name_or_code)
48
+ end
49
+ rescue IsoCountryCodes::UnknownCodeError
50
+ nil
51
+ end
43
52
  end
44
53
  end
@@ -6,31 +6,38 @@ module JustimmoClient::V1
6
6
 
7
7
  # @!macro [attach] attribute
8
8
  # @return [$2]
9
- attribute :id, Integer
10
- attribute :number, Integer
11
- attribute :email, String
12
- attribute :phone, String
13
- attribute :mobile, String
14
- attribute :fax, String
15
- attribute :last_name, String
16
- attribute :first_name, String
17
- attribute :salutation, String
18
- attribute :company, String
19
- attribute :street, String
20
- attribute :zip_code, Integer
21
- attribute :location, String
9
+ attribute :id, Integer
10
+ attribute :number, Integer
11
+ attribute :email, String
12
+ attribute :phone, String
13
+ attribute :mobile, String
14
+ attribute :fax, String
15
+ attribute :last_name, String
16
+ attribute :first_name, String
17
+ attribute :salutation, String
18
+ attribute :company, String
19
+ attribute :street, String
20
+ attribute :zip_code, Integer
21
+ attribute :location, String
22
22
  attribute :email_feedback, String
23
- attribute :website, String
24
- attribute :picture, Image
25
- attribute :attachment, Image
26
- attribute :position, String
23
+ attribute :website, String
24
+ attribute :position, String
25
+ attribute :attachments, Array[Attachment], default: []
27
26
 
28
27
  # @!group Instance Method Summary
29
28
 
30
- def image
31
- picture
29
+ def images
30
+ attachments.select { |x| x.type == "pic" }
32
31
  end
33
32
 
33
+ alias pictures images
34
+
35
+ def image(index = 0)
36
+ images[index]
37
+ end
38
+
39
+ alias picture image
40
+
34
41
  def full_name(surname_first: false, with_salutation: true)
35
42
  name = [first_name, last_name]
36
43
  name.reverse! if surname_first
@@ -10,7 +10,7 @@ module JustimmoClient::V1
10
10
  # @return [$2]
11
11
  attribute :proximity, String
12
12
  attribute :federal_state, String
13
- attribute :country, String
13
+ attribute :country, Country
14
14
  attribute :zip_code, Integer
15
15
  attribute :latitude, Float
16
16
  attribute :longitude, Float
@@ -20,10 +20,8 @@ module JustimmoClient::V1
20
20
 
21
21
  # @!group Instance Method Summary
22
22
 
23
- def country=(iso3_or_name)
24
- @country = IsoCountryCodes.find(iso3_or_name).name
25
- rescue IsoCountryCodes::UnknownCodeError
26
- @country = iso3_or_name
23
+ def country=(name)
24
+ @country = Country.new(name: name)
27
25
  end
28
26
 
29
27
  def floor=(flr)
@@ -10,6 +10,7 @@ module JustimmoClient::V1
10
10
 
11
11
  # :nodoc:
12
12
  include Virtus.model do |mod|
13
+ mod.nullify_blank = true
13
14
  mod.coercer.config.string.boolean_map = { "0" => false, "1" => true }
14
15
  end
15
16
  end
@@ -8,43 +8,40 @@ module JustimmoClient::V1
8
8
  # @return [$2]
9
9
  attribute :id, Integer
10
10
  attribute :number, Integer
11
- attribute :title, String
11
+ attribute :title, String, default: ""
12
12
  attribute :description, String, default: ""
13
- attribute :teaser, String, default: ""
14
- attribute :usage, RealtyUsage
15
- attribute :marketing, RealtyMarketing
13
+ attribute :teaser, Array[String], default: []
16
14
  attribute :type_id, Integer
17
15
  attribute :sub_type_id, Integer
18
- attribute :geo, GeoLocation
19
- attribute :area, RealtyArea
20
- attribute :room_count, RealtyRoomCount
21
- attribute :price, RealtyPrice
22
16
  attribute :status_id, Integer
23
- attribute :floor, String
24
17
  attribute :openimmo_id, String
25
- attribute :contact, Employee
26
- attribute :description_furniture, Array[String]
27
- attribute :furniture, Array[String]
28
- attribute :images, Array[Image]
29
- attribute :documents, Array
30
- attribute :videos, Array
31
- attribute :images360, Array
32
- attribute :links, Array
18
+ attribute :description_furniture, Array[String], default: []
19
+ attribute :furniture, Array[String], default: []
20
+ attribute :attachments, Array[Attachment], default: []
21
+ attribute :documents, Array, default: []
22
+ attribute :videos, Array, default: []
23
+ attribute :images360, Array, default: []
24
+ attribute :links, Array, default: []
33
25
  attribute :construction_year, Integer
34
26
  attribute :available, DateTime
35
27
  attribute :created_at, DateTime
36
28
  attribute :updated_at, DateTime
29
+ attribute :contact, Employee
30
+ attribute :usage, RealtyUsage
31
+ attribute :marketing, RealtyMarketing
32
+ attribute :geo, GeoLocation
33
+ attribute :area, RealtyArea
34
+ attribute :room_count, RealtyRoomCount
35
+ attribute :price, RealtyPrice
37
36
 
38
37
  # @!group Instance Method Summary
39
38
 
40
- def initialize(**options)
41
- super(options)
42
- @area = RealtyArea.new
43
- @room_count = RealtyRoomCount.new
44
- @geo = GeoLocation.new
45
- @usage = RealtyUsage.new
46
- @marketing = RealtyMarketing.new
47
- @price = RealtyPrice.new
39
+ def images
40
+ attachments.select { |x| x.type == "pic" }
41
+ end
42
+
43
+ def title_image
44
+ attachments.select { |x| x.category == :title_image }.first
48
45
  end
49
46
 
50
47
  # @param date [String]
@@ -52,7 +49,7 @@ module JustimmoClient::V1
52
49
  def available=(date)
53
50
  @available = DateTime.parse(date) unless date.nil?
54
51
  rescue ArgumentError
55
- log.error("Failed to convert date: #{date}")
52
+ log.debug("Failed to convert date: #{date}")
56
53
  @available = date
57
54
  end
58
55
 
@@ -60,24 +57,24 @@ module JustimmoClient::V1
60
57
  @description =
61
58
  if @teaser.empty?
62
59
  parts = desc.partition("</ul>\n")
63
- @teaser = parts[0..1].join
64
- parts.last.empty? ? @teaser : parts.last
60
+ self.teaser = parts[0..1].join
61
+ parts.last
65
62
  else
66
63
  desc
67
64
  end
68
65
  end
69
66
 
70
- def add_image(url, **options)
71
- @images ||= []
72
- image = Image.new
73
- image.add_url(url, options)
74
- @images << image
67
+ def teaser=(tea)
68
+ @teaser =
69
+ case tea
70
+ when Array then tea
71
+ when String then tea&.gsub(/<\/?(ul|li)>/, "")&.strip&.split("\n")
72
+ else []
73
+ end
75
74
  end
76
75
 
77
76
  def type
78
- end
79
-
80
- def sub_type
77
+ @type ||= RealtyInterface.types.select { |x| x.id == type_id }.first
81
78
  end
82
79
  end
83
80
  end
@@ -0,0 +1,68 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "monetize"
4
+
5
+ module JustimmoClient::V1
6
+ class Money < Virtus::Attribute
7
+ def coerce(value)
8
+ ::Monetize.parse(value)
9
+ end
10
+ end
11
+
12
+ class Currency < Virtus::Attribute
13
+ include JustimmoClient::Logging
14
+
15
+ def coerce(value)
16
+ ::Money::Currency.new(value)
17
+ rescue ::Money::Currency::UnknownCurrency
18
+ ::Money.default_currency
19
+ end
20
+ end
21
+
22
+ class RealtyCost < JustimmoBase
23
+ attribute :currency, Currency
24
+ attribute :amount, Money
25
+
26
+ def /(other)
27
+ amount / other
28
+ end
29
+
30
+ def *(other)
31
+ amount * other
32
+ end
33
+
34
+ def +(other)
35
+ amount + ::Money.new(other)
36
+ end
37
+
38
+ def -(other)
39
+ amount - ::Money.new(other)
40
+ end
41
+
42
+ def zero?
43
+ amount.zero?
44
+ end
45
+
46
+ def to_s
47
+ amount.format
48
+ end
49
+
50
+ def to_f
51
+ amount.to_f
52
+ end
53
+
54
+ def to_h
55
+ { currency: currency.id, amount: amount.to_f }
56
+ end
57
+
58
+ def to_json(*args)
59
+ to_h.to_json(args)
60
+ end
61
+
62
+ alias as_json to_json
63
+
64
+ def inspect
65
+ "#<#{self.class} #{self}>"
66
+ end
67
+ end
68
+ end
@@ -12,10 +12,7 @@ module JustimmoClient::V1
12
12
  # @!group Instance Method Summary
13
13
 
14
14
  def to_a
15
- tmp = []
16
- tmp << :buy if buy?
17
- tmp << :rent if rent?
18
- tmp
15
+ attributes.select { |_k, v| v }.keys
19
16
  end
20
17
 
21
18
  def map(&block)