justimmo_client 0.4.3 → 0.4.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f74e4f934c4b4a0d3d9e84414ada4785a6a908ab
4
- data.tar.gz: b10b66166909331951bbce4c7a33c7be2f798bc0
3
+ metadata.gz: 6889b2849895ac84cbda9609a4d40847104acd88
4
+ data.tar.gz: a90c60aef5e69d154704b24a15b13f7eef656f0c
5
5
  SHA512:
6
- metadata.gz: d966a8283487c6549a23436df247501bf9509628bdac52a80256fe12190f78367b6293fba837d151d21bf29ab7af3b9f3984b14d78cad20cf0a9949992e514ce
7
- data.tar.gz: 680da3354939fbf771cb11e5efda8b98d3eb08a6854be401ccdccc6a7877605e40b2041d7f1f77c4d5180cc1cd587114cdd81f38b1c74d872896afa88eef02b5
6
+ metadata.gz: 7168d63aa6ff0d8c4901f0893c78b268840457d048caffb9d271c6e658f4ed030caa779dcf1299eb88cae19d9d18e4d3ad1142f02e4c652e24e14853a78fffc0
7
+ data.tar.gz: 48f3d5ba3187aa261ea3ae2f72cf946ce9c616e8abbeb1c40734c2d2bacd58a7fd686e3288c5d3b0c8727206946fbff40c0c6742fe90945ae065397760c8b5a2
@@ -18,7 +18,7 @@ module JustimmoClient::V1
18
18
  type: :objektart,
19
19
  subtype: :subobjektart,
20
20
  tag: :tagname,
21
- room_count: :zimmer,
21
+ rooms: :zimmer,
22
22
  area: :flaeche,
23
23
  living_area: :wohnflaeche,
24
24
  floor_area: :nutzflaeche,
@@ -36,7 +36,9 @@ module JustimmoClient::V1
36
36
  last_name: :nachname,
37
37
  phone: :tel,
38
38
  location: :ort,
39
- all: :alle
39
+ all: :alle,
40
+ rent: :miete,
41
+ purcase: :kauf
40
42
  }.freeze
41
43
 
42
44
  module_function
@@ -46,34 +48,44 @@ module JustimmoClient::V1
46
48
  # @param [Hash] params
47
49
  # @return [String] The requested XML.
48
50
  def list(**params)
49
- get("objekt/list", list_option_parser.parse(params))
51
+ with_error_handler do
52
+ get("objekt/list", list_option_parser.parse(params))
53
+ end
50
54
  end
51
55
 
52
56
  # @param [Integer] id
53
57
  # @param [String, Symbol] lang
54
58
  # @return [String] The requested XML.
55
59
  def detail(id, lang: nil)
56
- get("objekt/detail", detail_option_parser.parse(id: id, lang: lang))
60
+ with_error_handler do
61
+ get("objekt/detail", detail_option_parser.parse(id: id, lang: lang))
62
+ end
57
63
  end
58
64
 
59
65
  # @param [Integer] id
60
66
  # @param [Hash] params
61
67
  # @return [String] The requested XML.
62
68
  def inquiry(id, **params)
63
- get("objekt/anfrage", inquiry_option_parser.parse(params.update(id: id)))
69
+ with_error_handler do
70
+ get("objekt/anfrage", inquiry_option_parser.parse(params.update(id: id)))
71
+ end
64
72
  end
65
73
 
66
74
  # @param [Hash] params
67
75
  # @return [String] A JSON string containing an array of ids.
68
76
  def ids(**params)
69
- get("objekt/ids", list_option_parser.parse(params))
77
+ with_error_handler do
78
+ get("objekt/ids", list_option_parser.parse(params))
79
+ end
70
80
  end
71
81
 
72
82
  # @todo implement this
73
83
  # @param [Hash] params
74
84
  # @return [File] The PDF file.
75
85
  def expose(**params)
76
- get("objekt/expose", params)
86
+ with_error_handler do
87
+ get("objekt/expose", params)
88
+ end
77
89
  end
78
90
 
79
91
  # @!group Basic Data Requests
@@ -81,26 +93,34 @@ module JustimmoClient::V1
81
93
  # @param [Boolean] all (false)
82
94
  # @return [String] The requested XML.
83
95
  def categories(all: false)
84
- get("objekt/kategorien", alle: all ? 1 : 0)
96
+ with_error_handler do
97
+ get("objekt/kategorien", alle: all ? 1 : 0)
98
+ end
85
99
  end
86
100
 
87
101
  # @param [Boolean] all (false)
88
102
  # @return [String] The requested XML.
89
103
  def types(all: false)
90
- get("objekt/objektarten", alle: all ? 1 : 0)
104
+ with_error_handler do
105
+ get("objekt/objektarten", alle: all ? 1 : 0)
106
+ end
91
107
  end
92
108
 
93
109
  # @param [Boolean] all (false)
94
110
  # @return [String] The requested XML.
95
111
  def countries(all: false)
96
- get("objekt/laender", alle: all ? 1 : 0)
112
+ with_error_handler do
113
+ get("objekt/laender", alle: all ? 1 : 0)
114
+ end
97
115
  end
98
116
 
99
117
  # @param [Boolean] all (false)
100
118
  # @param [Integer, String] country
101
119
  # @return [String] The requested XML.
102
120
  def federal_states(country:, all: false)
103
- get("objekt/bundeslaender", land: country, alle: all ? 1 : 0)
121
+ with_error_handler do
122
+ get("objekt/bundeslaender", land: country, alle: all ? 1 : 0)
123
+ end
104
124
  end
105
125
 
106
126
  # @param [Boolean] all (false)
@@ -108,7 +128,9 @@ module JustimmoClient::V1
108
128
  # @param [Integer] federal_state
109
129
  # @return [String] The requested XML.
110
130
  def regions(country: nil, federal_state: nil, all: false)
111
- get("objekt/regionen", land: country, bundesland: federal_state, alle: all ? 1 : 0)
131
+ with_error_handler do
132
+ get("objekt/regionen", land: country, bundesland: federal_state, alle: all ? 1 : 0)
133
+ end
112
134
  end
113
135
 
114
136
  # @param [Boolean] all (false)
@@ -116,7 +138,16 @@ module JustimmoClient::V1
116
138
  # @param [Integer] federal_state
117
139
  # @return [String] The requested XML.
118
140
  def zip_codes_and_cities(country: nil, federal_state: nil, all: false)
119
- get("objekt/plzsUndOrte", land: country, bundesland: federal_state, alle: all ? 1 : 0)
141
+ with_error_handler do
142
+ get("objekt/plzsUndOrte", land: country, bundesland: federal_state, alle: all ? 1 : 0)
143
+ end
144
+ end
145
+
146
+ def with_error_handler
147
+ yield
148
+ rescue JustimmoClient::OptionParserError => e
149
+ log.error(e)
150
+ raise JustimmoClient::RetrievalFailed, e
120
151
  end
121
152
 
122
153
  # @!group Option Parsers
@@ -131,9 +162,9 @@ module JustimmoClient::V1
131
162
  options.add :limit
132
163
  options.add :offset
133
164
  options.add :lang
134
- options.add :orderby, values: %w[price zip_code number created_at updated_at published_at]
135
- options.add :ordertype, values: %w[asc desc]
136
- options.add :picturesize, values: %w[small_unbranded small2_unbranded small3_unbranded medium_unbranded big_unbranded big2_unbranded medium big bin2]
165
+ options.add :orderby, values: %i[price zip_code number created_at updated_at published_at]
166
+ options.add :ordertype, values: %i[asc desc]
167
+ options.add :picturesize, values: %i[small_unbranded small2_unbranded small3_unbranded medium_unbranded big_unbranded big2_unbranded medium big big2]
137
168
  options.add :with_projects, type: :bool
138
169
  options.group :filter do |f|
139
170
  f.add :price_min
@@ -146,8 +177,8 @@ module JustimmoClient::V1
146
177
  f.add :zip_code
147
178
  f.add :zip_code_min
148
179
  f.add :zip_code_max
149
- f.add :room_count_min
150
- f.add :room_count_max
180
+ f.add :rooms_min
181
+ f.add :rooms_max
151
182
  f.add :number
152
183
  f.add :number_min
153
184
  f.add :number_max
@@ -166,8 +197,14 @@ module JustimmoClient::V1
166
197
  f.add :project_id
167
198
  f.add :type
168
199
  f.add :parent_id
200
+ f.add :rent, type: :bool
201
+ f.add :purcase, type: :bool
169
202
  f.add :updated_at_min, as: :aktualisiert_am_von
170
203
  f.add :updated_at_max, as: :aktualisiert_am_bis
204
+ f.add :location do |key, value|
205
+ cities = JustimmoClient::Realty.zip_codes_and_cities
206
+ [:zip_code, cities.select { |x| x.location == value }.first&.zip_code]
207
+ end
171
208
  end
172
209
  end
173
210
  end
@@ -32,10 +32,10 @@ module JustimmoClient
32
32
 
33
33
  def validate
34
34
  missing = REQUIRED.select { |r| @_config[r].nil? }
35
- raise MissingConfiguration, missing unless missing.empty?
35
+ raise JustimmoClient::MissingConfiguration, missing unless missing.empty?
36
36
 
37
37
  supported_ver = SUPPORTED_API_VERSIONS.include?(api_ver)
38
- raise UnsupportedAPIVersion, api_ver unless supported_ver
38
+ raise JustimmoClient::UnsupportedAPIVersion, api_ver unless supported_ver
39
39
  end
40
40
 
41
41
  def url
@@ -3,11 +3,13 @@
3
3
  # Exceptions for internal use
4
4
  module JustimmoClient::Errors
5
5
  JustimmoError = Class.new(StandardError)
6
- InitializationError = Class.new(JustimmoError)
7
6
 
8
7
  # Raised when configuration validation fails.
9
8
  ConfigurationError = Class.new(JustimmoError)
10
9
 
10
+ # Raised when option parsing fails
11
+ OptionParserError = Class.new(JustimmoError)
12
+
11
13
  # Raised when authentication with the API fails.
12
14
  class AuthenticationFailed < JustimmoError
13
15
  def initialize
@@ -22,37 +24,31 @@ module JustimmoClient::Errors
22
24
  end
23
25
  end
24
26
 
25
- # A mapping could not be found in the mappings hash.
26
- class MappingNotFound < JustimmoError
27
- def initialize(map)
28
- super("Could not find #{map} mapping.")
29
- end
30
- end
31
-
32
- # A key could not be found in the specified mapping.
33
- class KeyNotFound < JustimmoError
34
- def initialize(key, map)
35
- super("Key #{key} not found in #{map} mapping.")
27
+ # Raised when the option parser rejects an option
28
+ class InvalidOption < OptionParserError
29
+ def initialize(key)
30
+ super("Option '#{key}' not supported")
36
31
  end
37
32
  end
38
33
 
39
- class NotImplemented < JustimmoError
40
- def initialize(meth)
41
- super("Method #{meth} not implemented!")
34
+ # Raised when the option parser rejects a value
35
+ class InvalidValue < OptionParserError
36
+ def initialize(value)
37
+ super("'#{value}' is not in the list of accepted values")
42
38
  end
43
39
  end
44
40
 
45
41
  # Raised when an unsupported API version is set.
46
42
  class UnsupportedAPIVersion < ConfigurationError
47
43
  def initialize(version)
48
- super("API Version #{version} not supported.")
44
+ super("API Version #{version} not supported")
49
45
  end
50
46
  end
51
47
 
52
48
  # Raised on missing required configuration options.
53
49
  class MissingConfiguration < ConfigurationError
54
50
  def initialize(missing)
55
- super("Required configuration missing: #{missing}.")
51
+ super("Required configuration missing: #{missing}")
56
52
  end
57
53
  end
58
54
  end
@@ -19,8 +19,8 @@ module JustimmoClient
19
19
  parse unless options.empty?
20
20
  end
21
21
 
22
- def add(key, **options)
23
- add_option(key, options)
22
+ def add(key, **options, &block)
23
+ add_option(key, options, &block)
24
24
  end
25
25
 
26
26
  def group(groupname)
@@ -33,7 +33,7 @@ module JustimmoClient
33
33
  out = {}
34
34
 
35
35
  options.each do |key, value|
36
- raise ArgumentError, "Invalid option: #{key}" unless @options.key?(key.to_sym)
36
+ raise JustimmoClient::InvalidOption, key unless @options.key?(key.to_sym)
37
37
  group = group_of(key)
38
38
 
39
39
  if group
@@ -49,12 +49,13 @@ module JustimmoClient
49
49
 
50
50
  private
51
51
 
52
- def add_option(key, **options)
52
+ def add_option(key, **options, &block)
53
53
  @options[key.to_sym] = {
54
54
  group: @context,
55
55
  type: options[:type],
56
56
  as: options[:as],
57
- values: options[:values]
57
+ values: options[:values],
58
+ mod: block_given? ? block : nil
58
59
  }
59
60
  end
60
61
 
@@ -62,6 +63,15 @@ module JustimmoClient
62
63
  @options.dig(key, :group)
63
64
  end
64
65
 
66
+ def has_mod?(key)
67
+ @options.dig(key, :mod).is_a?(Proc)
68
+ end
69
+
70
+ def apply_mod(key, value)
71
+ new_key, new_value = @options.dig(key, :mod).call(key, value)
72
+ [(new_key || key), (new_value || value)]
73
+ end
74
+
65
75
  def mapping(key)
66
76
  @mappings.fetch(key, key)
67
77
  end
@@ -84,7 +94,9 @@ module JustimmoClient
84
94
 
85
95
  def parse_option(key, value)
86
96
  values = @options.dig(key, :values)
87
- raise ArgumentError, "Value #{value} not supported" unless values.nil? || values.include?(value)
97
+ raise JustimmoClient::InvalidValue, value unless values.nil? || values.include?(value)
98
+
99
+ key, value = apply_mod(key.to_sym, value) if has_mod?(key)
88
100
 
89
101
  coerced =
90
102
  case @options.dig(key, :type)
@@ -51,6 +51,7 @@ module JustimmoClient
51
51
  # @option options [Integer] :parent_id
52
52
  # @option options [DateTime] :updated_at_min
53
53
  # @option options [DateTime] :updated_at_max
54
+ # @option options [String] :location
54
55
  # @example Filter by zip code and limit to three results.
55
56
  # JustimmoClient::Realty.list(zip_code: 6800, limit: 3)
56
57
  # @return [Array<Object>] An array of basic realty objects, or an empty array on error.
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module JustimmoClient
4
- VERSION = "0.4.3"
4
+ VERSION = "0.4.4"
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.4.3
4
+ version: 0.4.4
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-09-16 00:00:00.000000000 Z
11
+ date: 2017-10-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler