justimmo_client 0.5.1 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (32) hide show
  1. checksums.yaml +4 -4
  2. data/.gitlab-ci.yml +2 -2
  3. data/README.md +4 -5
  4. data/examples/client.rb +1 -1
  5. data/lib/justimmo_client/api/v1/interfaces/employee_interface.rb +30 -8
  6. data/lib/justimmo_client/api/v1/interfaces/justimmo_interface.rb +32 -0
  7. data/lib/justimmo_client/api/v1/interfaces/realty_interface.rb +93 -20
  8. data/lib/justimmo_client/api/v1/models/country.rb +1 -1
  9. data/lib/justimmo_client/api/v1/models/geo_location.rb +5 -3
  10. data/lib/justimmo_client/api/v1/models/realty.rb +1 -1
  11. data/lib/justimmo_client/api/v1/models/realty_price.rb +2 -1
  12. data/lib/justimmo_client/api/v1/models/realty_usage.rb +1 -1
  13. data/lib/justimmo_client/api/v1/representers/json/city_representer.rb +16 -0
  14. data/lib/justimmo_client/api/v1/representers/json/contact_representer.rb +6 -21
  15. data/lib/justimmo_client/api/v1/representers/json/country_representer.rb +13 -0
  16. data/lib/justimmo_client/api/v1/representers/json/employee_representer.rb +32 -0
  17. data/lib/justimmo_client/api/v1/representers/json/federal_state_representer.rb +15 -0
  18. data/lib/justimmo_client/api/v1/representers/json/{location_representer.rb → geo_location_representer.rb} +2 -1
  19. data/lib/justimmo_client/api/v1/representers/json/realty_area_representer.rb +27 -0
  20. data/lib/justimmo_client/api/v1/representers/json/realty_category_representer.rb +4 -12
  21. data/lib/justimmo_client/api/v1/representers/json/realty_price_representer.rb +31 -0
  22. data/lib/justimmo_client/api/v1/representers/json/realty_representer.rb +66 -0
  23. data/lib/justimmo_client/api/v1/representers/json/realty_room_count_representer.rb +21 -0
  24. data/lib/justimmo_client/api/v1/representers/json/realty_type_representer.rb +12 -0
  25. data/lib/justimmo_client/api/v1/representers/json/region_representer.rb +12 -0
  26. data/lib/justimmo_client/api/v1/requests/justimmo_request.rb +1 -9
  27. data/lib/justimmo_client/core/caching.rb +0 -16
  28. data/lib/justimmo_client/version.rb +1 -1
  29. metadata +14 -6
  30. data/lib/justimmo_client/api/v1/representers/json/attachment_image_representer.rb +0 -16
  31. data/lib/justimmo_client/api/v1/representers/json/attachment_representer.rb +0 -15
  32. data/lib/justimmo_client/api/v1/representers/json/realty_detail_representer.rb +0 -69
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ca35fda69d2b9c35d6dfa8b7f79b10eb129a2ed7
4
- data.tar.gz: b36be58f5d1c265e62ad4bf35664221797df362b
3
+ metadata.gz: 1111c8bd67a8a48f624bc368fe44db21199b6e1a
4
+ data.tar.gz: 6d8c62a4cc9e2373ae2ff999b446027ed05998b4
5
5
  SHA512:
6
- metadata.gz: d16797d4e4d26181d2f4eef09e72df50246a14f1325a9a5a2fdd49bb9a437e050f5ec4648617d62827ffedff06b5b772573cdbe672601d543ac48dc27673dcd0
7
- data.tar.gz: 3f80eb73170d6e615dc6a212b5207982e3f9137cba36bf7a8ae7d3bf8ffccde929b80c1ab1bac46a0ce571899af3d841c5f128a3c609fce82e1f149193a61220
6
+ metadata.gz: 66da6c40804b2acdf9580898fdeccec4dcc0fc04ef4c1b5829754748a8f12d05126609981c1ccd61ad835187eb7e1f1d4a6d945289f284de6c52994e9eddef55
7
+ data.tar.gz: 19f6be67d186e5e7a4dd3ec56854f6556669624beb53bdb23b9e16cf8ce5745de506c61035d4efc2b6cdf9c5c3b8f6e04f8edfcdf1db0b1fdfb7630e3e29163f
@@ -69,8 +69,8 @@ test:rubocop:
69
69
  <<: *ruby_2_4
70
70
  script:
71
71
  - bundle exec rubocop
72
- only:
73
- - dev
72
+ except:
73
+ - master
74
74
  tags:
75
75
  - ruby
76
76
 
data/README.md CHANGED
@@ -1,9 +1,8 @@
1
- [![build status](https://gitlab.com/exacting/justimmo-client-ruby/badges/master/build.svg)](https://gitlab.com/exacting/justimmo-client-ruby/pipelines)
2
- [![coverage report](https://gitlab.com/exacting/justimmo-client-ruby/badges/master/coverage.svg)](https://valeth.gitlab.io/justimmo-client-ruby)
3
- [![Codacy Badge](https://api.codacy.com/project/badge/Grade/7cfe6c9965214c439470cc0a480e0e49)](https://www.codacy.com/app/exacting/justimmo-client-ruby?utm_source=gitlab.com&amp;utm_medium=referral&amp;utm_content=exacting/justimmo-client-ruby&amp;utm_campaign=Badge_Grade)
1
+ [![pipeline status](https://gitlab.com/exacting/justimmo_client/badges/master/pipeline.svg)](https://gitlab.com/exacting/justimmo_client/commits/master)
2
+ [![coverage report](https://gitlab.com/exacting/justimmo_client/badges/master/coverage.svg)](https://exacting.gitlab.io/justimmo_client)
3
+ [![Codacy Badge](https://api.codacy.com/project/badge/Grade/d3b88fedb58d44048a527234f3541430)](https://www.codacy.com/app/Exacting/justimmo_client?utm_source=gitlab.com&amp;utm_medium=referral&amp;utm_content=exacting/justimmo_client&amp;utm_campaign=Badge_Grade)
4
4
  [![Inline docs](http://inch-ci.org/github/exacting/justimmo-client-ruby.svg?branch=master)](http://inch-ci.org/github/exacting/justimmo-client-ruby)
5
5
 
6
-
7
6
  # Justimmo Client
8
7
 
9
8
  Ruby client for the [Justimmo](http://www.justimmo.at) [REST API](http://api-docs.justimmo.at/api/index.html).
@@ -46,7 +45,7 @@ end
46
45
  ```ruby
47
46
  class RealtyController < ApplicationController
48
47
  def index
49
- @realties = JustimmoClient::Realty.list(zip_code: 6020, limit: 5)
48
+ @realties = JustimmoClient.realties(zip_code: 6020, limit: 5)
50
49
  end
51
50
  end
52
51
  ```
@@ -13,4 +13,4 @@ JustimmoClient.configure do |config|
13
13
  config.cache = ActiveSupport::Cache.lookup_store(:memory_store)
14
14
  end
15
15
 
16
- pp JustimmoClient::Realty.list(zip_code: 6800, limit: 5)
16
+ pp JustimmoClient.realties(zip_code: 6800, limit: 5)
@@ -4,31 +4,53 @@ module JustimmoClient::V1
4
4
  # Public employee query interface
5
5
  module EmployeeInterface
6
6
  extend JustimmoClient::Utils
7
+ extend JustimmoInterface
7
8
 
8
9
  module_function
9
10
 
10
11
  # @return [Array<Employee>]
11
12
  def list
12
- xml_response = request(:employee).list
13
- model = Struct.new(:employees).new
14
- representer(:employee_list).new(model).from_xml(xml_response).employees
13
+ with_cache cache_key("employee/list"),
14
+ on_hit: ->(cached) do
15
+ representer(:employee, :json).for_collection.new([]).from_json(cached)
16
+ end,
17
+ on_miss: -> do
18
+ xml_response = request(:employee).list
19
+ model = Struct.new(:employees).new
20
+ represented = representer(:employee_list).new(model).from_xml(xml_response).employees
21
+ new_cache = representer(:employee, :json).for_collection.new(represented).to_json
22
+ [represented, new_cache]
23
+ end
15
24
  rescue JustimmoClient::RetrievalFailed
16
25
  []
17
26
  end
18
27
 
19
28
  # @return [Employee]
20
29
  def detail(id)
21
- xml_response = request(:employee).detail(id)
22
- model = model(:employee).new
23
- representer(:employee).new(model).from_xml(xml_response)
30
+ with_cache cache_key("employee/detail", id: id),
31
+ on_hit: ->(cached) do
32
+ representer(:employee, :json).new(model(:employee).new).from_json(cached)
33
+ end,
34
+ on_miss: -> do
35
+ xml_response = request(:employee).detail(id)
36
+ model = model(:employee).new
37
+ represented = representer(:employee).new(model).from_xml(xml_response)
38
+ new_cache = representer(:employee, :json).new(represented).to_json
39
+ [represented, new_cache]
40
+ end
24
41
  rescue JustimmoClient::RetrievalFailed
25
42
  nil
26
43
  end
27
44
 
28
45
  # @return [Array<Integer>]
29
46
  def ids
30
- json_response = request(:employee).ids
31
- ::JSON.parse(json_response).map(&:to_i)
47
+ with_cache cache_key("employee/ids"),
48
+ on_hit: ->(cached) { ::JSON.parse(cached) },
49
+ on_miss: -> do
50
+ json_response = request(:employee).ids
51
+ json_parsed = ::JSON.parse(json_response).map(&:to_i)
52
+ [json_parsed, ::JSON.generate(json_parsed)]
53
+ end
32
54
  rescue JustimmoClient::RetrievalFailed
33
55
  []
34
56
  end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ module JustimmoClient::V1
4
+ module JustimmoInterface
5
+ include JustimmoClient::Caching
6
+ include JustimmoClient::Logging
7
+
8
+ def cache_key(endpoint, params = {})
9
+ key = Digest::SHA256.new
10
+ key << endpoint
11
+ key << params.to_s
12
+ key.hexdigest
13
+ end
14
+
15
+ def with_cache(key, on_hit:, on_miss:, **options)
16
+ log.debug("Looking up cache key #{key}")
17
+ data = nil
18
+ cached = cache.read(key)
19
+
20
+ if cached.nil?
21
+ log.debug("Cache miss for #{key}")
22
+ data, new_cache = on_miss.call()
23
+ cache.write(key, new_cache, options)
24
+ else
25
+ log.debug("Cache hit for #{key}")
26
+ data = on_hit.call(cached)
27
+ end
28
+
29
+ data
30
+ end
31
+ end
32
+ end
@@ -4,8 +4,12 @@ require "json"
4
4
 
5
5
  module JustimmoClient::V1
6
6
  # Public realty query interface
7
+ #
8
+ # Glues all components together.
9
+ # Handles caching, parsing and converting XML and JSON into data models.
7
10
  module RealtyInterface
8
11
  extend JustimmoClient::Utils
12
+ extend JustimmoInterface
9
13
 
10
14
  module_function
11
15
 
@@ -55,9 +59,17 @@ module JustimmoClient::V1
55
59
  # @option options [String] :location
56
60
  # @return [Array<Realty>] An array of basic realty objects, or an empty array on error.
57
61
  def list(options = {})
58
- xml_response = request(:realty).list(options)
59
- model = Struct.new(:realties).new
60
- representer(:realty_list).new(model).from_xml(xml_response).realties
62
+ with_cache cache_key("realty/list", options),
63
+ on_hit: ->(cached) do
64
+ representer(:realty, :json).for_collection.new([]).from_json(cached)
65
+ end,
66
+ 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
70
+ new_cache = representer(:realty, :json).for_collection.new(realties).to_json
71
+ [represented, new_cache]
72
+ end
61
73
  rescue JustimmoClient::RetrievalFailed
62
74
  []
63
75
  end
@@ -66,9 +78,17 @@ module JustimmoClient::V1
66
78
  # @param [Symbol, String] lang
67
79
  # @return [Realty, nil] A detailed realty object, or nil if it could not be found.
68
80
  def detail(id, lang: nil)
69
- xml_response = request(:realty).detail(id, lang: lang)
70
- model = Struct.new(:realty).new
71
- representer(:realty_detail).new(model).from_xml(xml_response).realty
81
+ with_cache cache_key("realty/detail", options),
82
+ on_hit: ->(cached) do
83
+ representer(:realty, :json).new(model(:realty)).from_json(cached)
84
+ end,
85
+ on_miss: -> do
86
+ 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
+ new_cache = representer(:realty, :json).new(realty).to_json
90
+ [represented, new_cache]
91
+ end
72
92
  rescue JustimmoClient::RetrievalFailed
73
93
  nil
74
94
  end
@@ -82,8 +102,13 @@ module JustimmoClient::V1
82
102
  # @option (see list)
83
103
  # @return [Array<Integer>] An array of realty ids, empty array if no results.
84
104
  def ids(options = {})
85
- json_response = request(:realty).ids(options)
86
- ::JSON.parse(json_response).map(&:to_i)
105
+ with_cache cache_key("realty/ids", options),
106
+ on_hit: ->(cached) { ::JSON.parse(cached) },
107
+ on_miss: -> do
108
+ json_response = request(:realty).ids(options)
109
+ json_parsed = ::JSON.parse(json_response).map(&:to_i)
110
+ [json_parsed, ::JSON.generate(json_parsed)]
111
+ end
87
112
  rescue JustimmoClient::RetrievalFailed
88
113
  []
89
114
  end
@@ -91,8 +116,16 @@ module JustimmoClient::V1
91
116
  # @option options [Boolean] :all (false)
92
117
  # @return [Array<RealtyCategory>]
93
118
  def categories(options = {})
94
- xml_response = request(:realty).categories(options)
95
- representer(:realty_category).for_collection.new([]).from_xml(xml_response)
119
+ with_cache cache_key("realty/categories", options),
120
+ on_hit: ->(cached) do
121
+ representer(:realty_category, :json).for_collection.new([]).from_json(cached)
122
+ end,
123
+ on_miss: -> do
124
+ xml_response = request(:realty).categories(options)
125
+ represented = representer(:realty_category).for_collection.new([]).from_xml(xml_response)
126
+ new_cache = representer(:realty_category, :json).for_collection.new(represented).to_json
127
+ [represented, new_cache]
128
+ end
96
129
  rescue JustimmoClient::RetrievalFailed
97
130
  []
98
131
  end
@@ -100,8 +133,16 @@ module JustimmoClient::V1
100
133
  # @option options [Boolean] :all (false)
101
134
  # @return [Array<RealtyType>]
102
135
  def types(options = {})
103
- xml_response = request(:realty).types(options)
104
- representer(:realty_type).for_collection.new([]).from_xml(xml_response)
136
+ with_cache cache_key("realty/types", options),
137
+ on_hit: ->(cached) do
138
+ representer(:realty_type, :json).for_collection.new([]).from_json(cached)
139
+ end,
140
+ on_miss: -> do
141
+ xml_response = request(:realty).types(options)
142
+ represented = representer(:realty_type).for_collection.new([]).from_xml(xml_response)
143
+ new_cache = representer(:realty_type, :json).for_collection.new(represented).to_json
144
+ [represented, new_cache]
145
+ end
105
146
  rescue JustimmoClient::RetrievalFailed
106
147
  []
107
148
  end
@@ -109,8 +150,16 @@ module JustimmoClient::V1
109
150
  # @option options [Boolean] :all (false)
110
151
  # @return [Array<Country>]
111
152
  def countries(options = {})
112
- xml_response = request(:realty).countries(options)
113
- representer(:country).for_collection.new([]).from_xml(xml_response)
153
+ with_cache cache_key("realty/countries", options),
154
+ on_hit: ->(cached) do
155
+ representer(:country, :json).for_collection.new([]).from_json(cached)
156
+ end,
157
+ on_miss: -> do
158
+ xml_response = request(:realty).countries(options)
159
+ represented = representer(:country).for_collection.new([]).from_xml(xml_response)
160
+ new_cache = representer(:country, :json).for_collection.new(represented).to_json
161
+ [represented, new_cache]
162
+ end
114
163
  rescue JustimmoClient::RetrievalFailed
115
164
  []
116
165
  end
@@ -119,8 +168,16 @@ module JustimmoClient::V1
119
168
  # @option options [Integer] :country (nil)
120
169
  # @return [Array<FederalState>]
121
170
  def federal_states(options = {})
122
- xml_response = request(:realty).federal_states(options)
123
- representer(:federal_state).for_collection.new([]).from_xml(xml_response)
171
+ with_cache cache_key("realty/federal_states", options),
172
+ on_hit: ->(cached) do
173
+ representer(:federal_states, :json).for_collection.new([]).from_json(cached)
174
+ end,
175
+ on_miss: -> do
176
+ xml_response = request(:realty).federal_states(options)
177
+ represented = representer(:federal_state).for_collection.new([]).from_xml(xml_response)
178
+ new_cache = representer(:federal_state, :json).for_collection.new(represented).to_json
179
+ [represented, new_cache]
180
+ end
124
181
  rescue JustimmoClient::RetrievalFailed
125
182
  []
126
183
  end
@@ -130,8 +187,16 @@ module JustimmoClient::V1
130
187
  # @option options [Integer] :federal_state (nil)
131
188
  # @return [Array<Region>]
132
189
  def regions(options = {})
133
- xml_response = request(:realty).regions(options)
134
- representer(:region).for_collection.new([]).from_xml(xml_response)
190
+ with_cache cache_key("realty/regions", options),
191
+ on_hit: ->(cached) do
192
+ representer(:region, :json).for_collection.new([]).from_json(cached)
193
+ end,
194
+ on_miss: -> do
195
+ xml_response = request(:realty).regions(options)
196
+ represented = representer(:region).for_collection.new([]).from_xml(xml_response)
197
+ new_cache = representer(:region, :json).for_collection.new(represented).to_json
198
+ [represented, new_cache]
199
+ end
135
200
  rescue JustimmoClient::RetrievalFailed
136
201
  []
137
202
  end
@@ -141,8 +206,16 @@ module JustimmoClient::V1
141
206
  # @option options [Integer] :federal_state (nil)
142
207
  # @return [Array<City>]
143
208
  def zip_codes_and_cities(options = {})
144
- xml_response = request(:realty).zip_codes_and_cities(options)
145
- representer(:city).for_collection.new([]).from_xml(xml_response)
209
+ with_cache cache_key("realty/cities", options),
210
+ on_hit: ->(cached) do
211
+ representer(:city, :json).for_collection.new([]).from_json(cached)
212
+ end,
213
+ on_miss: -> do
214
+ xml_response = request(:realty).zip_codes_and_cities(options)
215
+ represented = representer(:city).for_collection.new([]).from_xml(xml_response)
216
+ new_cache = representer(:city, :json).for_collection.new(represented).to_json
217
+ [represented, new_cache]
218
+ end
146
219
  rescue JustimmoClient::RetrievalFailed
147
220
  []
148
221
  end
@@ -10,7 +10,7 @@ module JustimmoClient::V1
10
10
  # @return [$2]
11
11
  attribute :id, Integer
12
12
  attribute :alpha2, String
13
- attribute :alpha2, String
13
+ attribute :alpha3, String
14
14
 
15
15
  # @!group Instance Method Summary
16
16
 
@@ -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, IsoCountryCodes::Code
13
+ attribute :country, String
14
14
  attribute :zip_code, Integer
15
15
  attribute :latitude, Float
16
16
  attribute :longitude, Float
@@ -20,8 +20,10 @@ module JustimmoClient::V1
20
20
 
21
21
  # @!group Instance Method Summary
22
22
 
23
- def country=(iso3)
24
- @country = IsoCountryCodes.find(iso3)
23
+ def country=(iso3_or_name)
24
+ @country = IsoCountryCodes.find(iso3_or_name).name
25
+ rescue IsoCountryCodes::UnknownCodeError
26
+ @country = iso3_or_name
25
27
  end
26
28
 
27
29
  def floor=(flr)
@@ -50,7 +50,7 @@ module JustimmoClient::V1
50
50
  # @param date [String]
51
51
  # @return [String, DateTime]
52
52
  def available=(date)
53
- @available = DateTime.parse(date)
53
+ @available = DateTime.parse(date) unless date.nil?
54
54
  rescue ArgumentError
55
55
  log.error("Failed to convert date: #{date}")
56
56
  @available = date
@@ -36,7 +36,7 @@ module JustimmoClient::V1
36
36
  rent rent_net rent_cold rent_including_heating rent_per_sqm deposit
37
37
  ].each do |meth|
38
38
  define_method("#{meth}=") do |amount|
39
- log.debug("Using currency #{currency.name} for #{meth}")
39
+ # log.debug("Using currency #{currency.name} for #{meth}")
40
40
  instance_variable_set("@#{meth}", Monetize.parse(amount))
41
41
  end
42
42
  end
@@ -57,6 +57,7 @@ module JustimmoClient::V1
57
57
  end
58
58
 
59
59
  def currency=(cur)
60
+ return if cur.nil?
60
61
  @currency = Money::Currency.new(cur)
61
62
  Money.default_currency = @currency
62
63
  log.debug("Set currency to #{currency.name}")
@@ -40,7 +40,7 @@ module JustimmoClient::V1
40
40
  end
41
41
 
42
42
  def to_s
43
- map_translated.join(", ")
43
+ translated.join(", ")
44
44
  end
45
45
  end
46
46
  end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module JustimmoClient::V1
4
+ module JSON
5
+ class CityRepresenter < JustimmoRepresenter
6
+ property :id
7
+ property :country_id
8
+ property :region_id
9
+ property :zip_code
10
+ property :location
11
+ property :federal_state_id
12
+
13
+ collection_representer class: City
14
+ end
15
+ end
16
+ end
@@ -2,29 +2,14 @@
2
2
 
3
3
  module JustimmoClient::V1
4
4
  module JSON
5
- class ContactRepresenter < JustimmoRepresenter
6
- property :id
7
- property :number
8
- property :last_name
9
- property :first_name
10
- property :phone
11
- property :phone_mobile
12
- property :salutation
13
- property :email
5
+ class ContactRepresenter < EmployeeRepresenter
14
6
  property :email_feedback
7
+ property :email
8
+ property :last_name
15
9
  property :company
16
- property :street
17
- property :zip_code
18
- property :location
19
- property :website
20
-
21
- property :picture,
22
- decorator: AttachmentImageRepresenter,
23
- class: AttachmentImage
24
-
25
- property :attachment,
26
- decorator: AttachmentRepresenter,
27
- class: Attachment
10
+ property :salutation
11
+ property :phone
12
+ property :mobile
28
13
  end
29
14
  end
30
15
  end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module JustimmoClient::V1
4
+ module JSON
5
+ class CountryRepresenter < JustimmoRepresenter
6
+ property :id
7
+ property :alpha2
8
+ property :alpha3
9
+
10
+ collection_representer class: Country
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ module JustimmoClient::V1
4
+ module JSON
5
+ class EmployeeRepresenter < JustimmoRepresenter
6
+ property :id
7
+ property :number
8
+ property :first_name
9
+ property :last_name
10
+ property :salutation
11
+ property :position
12
+ property :phone
13
+ property :mobile
14
+ property :fax
15
+ property :email
16
+ property :street
17
+ property :zip_code
18
+ property :location
19
+ property :website
20
+
21
+ property :picture, class: Image do
22
+ %i[small medium big pfad_medium].each do |size|
23
+ property size,
24
+ setter: ->(represented:, fragment:, **) { represented.add_url(fragment, default: :user_big) },
25
+ getter: ->(represented:, **) { represented[size] }
26
+ end
27
+ end
28
+
29
+ collection_representer class: Employee
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module JustimmoClient::V1
4
+ module JSON
5
+ class FederalStateRepresenter < JustimmoRepresenter
6
+ property :id
7
+ property :name
8
+ property :country_id
9
+ property :fips
10
+ property :iso
11
+
12
+ collection_representer class: FederalState
13
+ end
14
+ end
15
+ end
@@ -2,10 +2,11 @@
2
2
 
3
3
  module JustimmoClient::V1
4
4
  module JSON
5
- class LocationRepresenter < JustimmoRepresenter
5
+ class GeoLocationRepresenter < JustimmoRepresenter
6
6
  property :zip_code
7
7
  property :location
8
8
  property :federal_state
9
+ property :floor
9
10
  property :country
10
11
  property :latitude
11
12
  property :longitude
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ module JustimmoClient::V1
4
+ module JSON
5
+ class RealtyAreaRepresenter < JustimmoRepresenter
6
+ %i[
7
+ balcony_terrace
8
+ balcony
9
+ office
10
+ garage
11
+ garden
12
+ total
13
+ surface
14
+ property
15
+ basement
16
+ storage
17
+ loggia
18
+ floor
19
+ parking
20
+ terrace
21
+ buildable
22
+ sales
23
+ living
24
+ ].each { |k| property k }
25
+ end
26
+ end
27
+ end
@@ -3,19 +3,11 @@
3
3
  module JustimmoClient::V1
4
4
  module JSON
5
5
  class RealtyCategoryRepresenter < JustimmoRepresenter
6
- property :usage, class: RealtyUsage do
7
- property :living
8
- property :business
9
- property :investment
10
- end
6
+ property :id
7
+ property :name
8
+ property :sortablerank
11
9
 
12
- property :marketing, class: RealtyMarketing do
13
- property :buy
14
- property :rent
15
- end
16
-
17
- property :type_id
18
- property :sub_type_id
10
+ collection_representer class: RealtyCategory
19
11
  end
20
12
  end
21
13
  end
@@ -0,0 +1,31 @@
1
+ module JustimmoClient::V1
2
+ module JSON
3
+ class RealtyPriceRepresenter < JustimmoRepresenter
4
+ property :currency
5
+ property :purcase
6
+ property :purcase_net
7
+ property :on_demand
8
+
9
+ property :rent
10
+ property :rent_net
11
+ property :rent_vat
12
+
13
+ property :deposit
14
+ property :rent_cold
15
+ property :rent_including_heating
16
+ property :rent_per_sqm
17
+ property :operating_cost_per_sqm
18
+
19
+ property :provision
20
+ property :including_vat
21
+ property :commission
22
+
23
+ property :real_estate_taxes
24
+ property :land_registry
25
+
26
+ property :operating_cost
27
+ property :operating_cost_net
28
+ property :operating_cost_vat
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,66 @@
1
+ # frozen_string_literal: true
2
+
3
+ module JustimmoClient::V1
4
+ module JSON
5
+ class RealtyRepresenter < JustimmoRepresenter
6
+ property :usage, class: RealtyUsage do
7
+ property :living
8
+ property :business
9
+ property :investment
10
+ end
11
+ property :marketing, class: RealtyMarketing do
12
+ property :buy
13
+ property :rent
14
+ end
15
+ property :type_id
16
+ property :sub_type_id
17
+
18
+ property :id
19
+ property :number
20
+ property :created_at
21
+ property :updated_at
22
+ property :status_id
23
+ property :title
24
+ property :teaser
25
+ property :description
26
+ property :floor
27
+ property :area,
28
+ decorator: RealtyAreaRepresenter,
29
+ class: RealtyArea
30
+ property :geo,
31
+ decorator: GeoLocationRepresenter,
32
+ class: GeoLocation
33
+ property :room_count,
34
+ decorator: RealtyRoomCountRepresenter,
35
+ class: RealtyRoomCount
36
+
37
+ property :openimmo_id
38
+ property :available
39
+ property :construction_year
40
+ property :contact,
41
+ decorator: ContactRepresenter,
42
+ class: Employee
43
+ property :description_furniture
44
+ property :furniture
45
+ property :price,
46
+ decorator: RealtyPriceRepresenter,
47
+ class: RealtyPrice
48
+ collection :images, class: Image do
49
+ property :category
50
+ property :origin
51
+ property :title
52
+ %i[pfad small medium big2 medium2 s220x155 fullhd].each do |size|
53
+ property size,
54
+ setter: ->(represented:, fragment:, **) { represented.add_url(fragment, default: :big) },
55
+ getter: ->(represented:, **) { represented[size] }
56
+ end
57
+ end
58
+ property :documents
59
+ property :images360
60
+ property :videos
61
+ property :links
62
+
63
+ collection_representer class: Realty
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module JustimmoClient::V1
4
+ module JSON
5
+ class RealtyRoomCountRepresenter < JustimmoRepresenter
6
+ %i[
7
+ store
8
+ bathroom
9
+ balcony_terrace
10
+ balcony
11
+ garden
12
+ garage
13
+ loggia
14
+ basement
15
+ toilet
16
+ parking_space
17
+ total
18
+ ].each { |k| property k }
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ module JustimmoClient::V1
4
+ module JSON
5
+ class RealtyTypeRepresenter < JustimmoRepresenter
6
+ property :id
7
+ property :name
8
+
9
+ collection_representer class: RealtyType
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ module JustimmoClient::V1
4
+ module JSON
5
+ class RegionRepresenter < JustimmoRepresenter
6
+ property :id
7
+ property :name
8
+
9
+ collection_representer class: Region
10
+ end
11
+ end
12
+ end
@@ -8,10 +8,9 @@ module JustimmoClient::V1
8
8
  # @api private
9
9
  module JustimmoRequest
10
10
  include JustimmoClient::Logging
11
- include JustimmoClient::Caching
12
11
 
13
12
  def get(path, params = {})
14
- with_cache(cache_key(path, params)) { request(path, params) }
13
+ request(path, params)
15
14
  end
16
15
 
17
16
  def request(path, params = {})
@@ -55,12 +54,5 @@ module JustimmoClient::V1
55
54
 
56
55
  Retriable.retriable(options) { yield }
57
56
  end
58
-
59
- def cache_key(path, params)
60
- key = Digest::SHA256.new
61
- key << path
62
- key << params.to_s
63
- key.hexdigest
64
- end
65
57
  end
66
58
  end
@@ -35,21 +35,5 @@ module JustimmoClient
35
35
  def cache
36
36
  JustimmoClient::Caching.cache
37
37
  end
38
-
39
- # TODO: JSON serialize/deserialize the cached value
40
- def with_cache(key, **options)
41
- log.debug("Looking up cache key #{key}")
42
- data = cache.read(key)
43
-
44
- if data.nil?
45
- log.debug("Cache miss for #{key}")
46
- data = yield
47
- cache.write(key, data, options)
48
- else
49
- log.debug("Cache hit for #{key}")
50
- end
51
-
52
- data
53
- end
54
38
  end
55
39
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module JustimmoClient
4
- VERSION = "0.5.1"
4
+ VERSION = "0.6.0"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: justimmo_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.1
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Patrick Auernig
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-10-19 00:00:00.000000000 Z
11
+ date: 2017-10-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -206,6 +206,7 @@ files:
206
206
  - lib/justimmo_client.rb
207
207
  - lib/justimmo_client/api/v1.rb
208
208
  - lib/justimmo_client/api/v1/interfaces/employee_interface.rb
209
+ - lib/justimmo_client/api/v1/interfaces/justimmo_interface.rb
209
210
  - lib/justimmo_client/api/v1/interfaces/realty_interface.rb
210
211
  - lib/justimmo_client/api/v1/models/city.rb
211
212
  - lib/justimmo_client/api/v1/models/country.rb
@@ -225,13 +226,20 @@ files:
225
226
  - lib/justimmo_client/api/v1/models/realty_usage.rb
226
227
  - lib/justimmo_client/api/v1/models/region.rb
227
228
  - lib/justimmo_client/api/v1/representers/json.rb
228
- - lib/justimmo_client/api/v1/representers/json/attachment_image_representer.rb
229
- - lib/justimmo_client/api/v1/representers/json/attachment_representer.rb
229
+ - lib/justimmo_client/api/v1/representers/json/city_representer.rb
230
230
  - lib/justimmo_client/api/v1/representers/json/contact_representer.rb
231
+ - lib/justimmo_client/api/v1/representers/json/country_representer.rb
232
+ - lib/justimmo_client/api/v1/representers/json/employee_representer.rb
233
+ - lib/justimmo_client/api/v1/representers/json/federal_state_representer.rb
234
+ - lib/justimmo_client/api/v1/representers/json/geo_location_representer.rb
231
235
  - lib/justimmo_client/api/v1/representers/json/justimmo_representer.rb
232
- - lib/justimmo_client/api/v1/representers/json/location_representer.rb
236
+ - lib/justimmo_client/api/v1/representers/json/realty_area_representer.rb
233
237
  - lib/justimmo_client/api/v1/representers/json/realty_category_representer.rb
234
- - lib/justimmo_client/api/v1/representers/json/realty_detail_representer.rb
238
+ - lib/justimmo_client/api/v1/representers/json/realty_price_representer.rb
239
+ - lib/justimmo_client/api/v1/representers/json/realty_representer.rb
240
+ - lib/justimmo_client/api/v1/representers/json/realty_room_count_representer.rb
241
+ - lib/justimmo_client/api/v1/representers/json/realty_type_representer.rb
242
+ - lib/justimmo_client/api/v1/representers/json/region_representer.rb
235
243
  - lib/justimmo_client/api/v1/representers/xml.rb
236
244
  - lib/justimmo_client/api/v1/representers/xml/city_representer.rb
237
245
  - lib/justimmo_client/api/v1/representers/xml/contact_representer.rb
@@ -1,16 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module JustimmoClient::V1
4
- module JSON
5
- class AttachmentImageRepresenter < JustimmoRepresenter
6
- property :small
7
- property :small2
8
- property :medium
9
- property :medium2
10
- property :big
11
- property :big2
12
- property :fullhd
13
- property :path
14
- end
15
- end
16
- end
@@ -1,15 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module JustimmoClient::V1
4
- module JSON
5
- class AttachmentRepresenter < JustimmoRepresenter
6
- property :category
7
- property :origin
8
- property :title
9
- property :format
10
- property :data,
11
- decorator: AttachmentImageRepresenter,
12
- class: AttachmentImage
13
- end
14
- end
15
- end
@@ -1,69 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module JustimmoClient::V1
4
- module JSON
5
- class RealtyDetailRepresenter < JustimmoRepresenter
6
- property :category,
7
- decorator: RealtyCategoryRepresenter,
8
- class: RealtyCategory
9
-
10
- property :location,
11
- decorator: LocationRepresenter,
12
- class: Location
13
-
14
- property :contact,
15
- decorator: ContactRepresenter,
16
- class: Contact
17
-
18
- property :documents
19
- property :images360
20
- property :videos
21
- property :links
22
-
23
- property :title
24
- property :description
25
- property :description_furniture
26
- property :furniture
27
-
28
- property :balcony_terrace_area, as: :balkon_terrasse_flaeche
29
- property :balcony_area, as: :balkons_flaeche
30
- property :office_area, as: :bueroflaeche
31
- property :garage_area, as: :garagen_flaeche
32
- property :garden_area, as: :gartenflaeche
33
- property :total_area, as: :gesamtflaeche
34
- property :surface_area, as: :grundflaeche
35
- property :property_area, as: :grundstueksflaeche
36
- property :basement_area, as: :kellerflaeche
37
- property :storage_area, as: :lagerflaeche
38
- property :loggia_area, as: :loggias_flaeche
39
- property :floor_area, as: :nutzflaeche
40
- property :parking_area, as: :stellplatz_flaeche
41
- property :terrace_area, as: :terrassen_flaeche
42
- property :buildable_area, as: :verbaubare_flaeche
43
- property :sales_area, as: :verkaufsflaeche
44
- property :living_area, as: :wohnflaeche
45
- property :store_rooms, as: :anzahl_abstellraum
46
- property :bathrooms, as: :anzahl_badezimmer
47
- property :balconies_terraces, as: :anzahl_balkon_terrassen
48
- property :balconies, as: :anzahl_balkone
49
- property :balconies, as: :anzahl_balkons
50
- property :gardens, as: :anzahl_garten
51
- property :garages, as: :anzahl_garagen
52
- property :loggias, as: :anzahl_loggias
53
- property :basements, as: :anzahl_keller
54
- property :toilet_rooms, as: :anzahl_sep_wc
55
- property :parking_spaces, as: :anzahl_stellplaetze
56
- property :rooms, as: :anzahl_zimmer
57
-
58
- property :available_from
59
- property :status_id
60
- property :id
61
- property :number
62
- property :openimmo_id
63
-
64
- collection :attachments,
65
- decorator: AttachmentRepresenter,
66
- class: Attachment
67
- end
68
- end
69
- end