justimmo_client 0.6.8 → 0.6.9

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: '084bca84fab7787d4ac96b9031ee4c6fd23cbbdb'
4
- data.tar.gz: d035d7659a897e76fc4babcc80279e4c274bba2e
3
+ metadata.gz: bfa29bb8a0b47ffee48351281374f3a20c196f24
4
+ data.tar.gz: 18fcb26eab8b27c1e8a9032581b88c4c8487a858
5
5
  SHA512:
6
- metadata.gz: 739e21cee8d7630d638a55dd7bacddc85f37c44cb83827ff51b0c7fdebadce28ab087cfaf2028a9bb0e1a49d71af06d872918141e9b8435183cd576a987c0238
7
- data.tar.gz: be8b3e5adcc8f8448b12f97659be56cc0740fec96eda1e3b6d046f56d88568e5821725593015296469e796ec25441dd0dabb4beb6130c92ebffa84c55331ee3e
6
+ metadata.gz: 8441bfa96b3ba2c464e195e168483b1c48ee8eacc731da5c9fff57a018a77f27e3bcfe55d20dfc735a71050b8c18c32834ae304cca711ce3e09a05571bb65201
7
+ data.tar.gz: e86d3766071bff80baeb426ec8c0d5e5a80b899f2d4686dbe68deb0277159bd8d2f8ab88bab428c05ecc67422ce336b34444d3ba067a692279890db35899cb31
data/Gemfile CHANGED
@@ -2,17 +2,18 @@
2
2
 
3
3
  source "https://rubygems.org"
4
4
 
5
- group :test do
6
- # Test coverage reporting
7
- gem "simplecov", require: false
8
- end
9
-
10
5
  group :test, :development do
11
- gem "rspec", "~> 3.0"
12
- gem "rubocop", "~> 0.48"
6
+ gem "rubocop", "0.51", require: false
13
7
  gem "dotenv"
14
8
  end
15
9
 
10
+ group :test do
11
+ gem "simplecov", require: false
12
+ gem "factory_girl", "4.8.1"
13
+ gem "rspec", "~> 3.0"
14
+ gem "webmock", "~> 3.1.0"
15
+ end
16
+
16
17
  group :development do
17
18
  gem "yard"
18
19
  gem "pry"
data/Rakefile CHANGED
@@ -3,8 +3,11 @@
3
3
  require "bundler/gem_tasks"
4
4
  require "rspec/core/rake_task"
5
5
  require "rubocop/rake_task"
6
+ require "factory_girl"
6
7
  require "yard"
7
8
 
9
+ require "justimmo_client"
10
+
8
11
  RSpec::Core::RakeTask.new(:spec)
9
12
  RuboCop::RakeTask.new(:rubocop)
10
13
  YARD::Rake::YardocTask.new(:doc)
@@ -12,3 +15,9 @@ YARD::Rake::YardocTask.new(:doc)
12
15
  task default: :test
13
16
 
14
17
  task test: %i[spec rubocop]
18
+
19
+ desc "Verify validity of FactoryGirl factories"
20
+ task :factory_lint do
21
+ FactoryGirl.find_definitions
22
+ FactoryGirl.lint
23
+ end
@@ -9,11 +9,13 @@ Gem::Specification.new do |spec|
9
9
  spec.name = "justimmo_client"
10
10
  spec.version = JustimmoClient::VERSION
11
11
  spec.author = "Patrick Auernig"
12
- spec.email = "patrick.auernig@mykolab.com"
12
+ spec.email = "dev.patrick.auernig@gmail.com"
13
13
  spec.license = "MIT"
14
14
  spec.summary = "API client for Justimmo"
15
15
  spec.homepage = "https://gitlab.com/exacting/justimmo-client-ruby"
16
16
 
17
+ spec.required_ruby_version = ">= 2.3"
18
+
17
19
  spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
20
  f.match(%r{^(test|spec|features)/})
19
21
  end
@@ -26,18 +28,18 @@ Gem::Specification.new do |spec|
26
28
 
27
29
  # requests
28
30
  spec.add_dependency "rest-client", "~> 2"
29
- spec.add_dependency "retriable", "~> 2.0"
31
+ spec.add_dependency "retriable", "~> 3.0"
30
32
 
31
33
  # parsing
32
- spec.add_dependency "nokogiri", "~> 1.7"
33
- spec.add_dependency "multi_json", "~> 1"
34
+ spec.add_dependency "nokogiri", "~> 1.7"
35
+ spec.add_dependency "multi_json", "~> 1"
34
36
  spec.add_dependency "representable", "~> 3.0"
35
37
 
36
38
  # models
37
- spec.add_dependency "virtus", "~> 1"
38
- spec.add_dependency "activesupport", "~> 5.1"
39
+ spec.add_dependency "virtus", "~> 1"
40
+ spec.add_dependency "activesupport", "~> 5.1"
39
41
  spec.add_dependency "iso_country_codes", "~> 0"
40
- spec.add_dependency "monetize", "~> 1"
42
+ spec.add_dependency "monetize", "~> 1"
41
43
 
42
44
  # other
43
45
  spec.add_dependency "i18n", ">= 0.7", "<= 0.9"
@@ -14,10 +14,14 @@ module JustimmoClient::V1
14
14
  attribute :format, String
15
15
  attribute :type, String
16
16
  attribute :file, String
17
+ attribute :size, Symbol
17
18
 
19
+ # FIXME: the attachment can be something other than a image file
20
+ # maybe move type detection into representer?
18
21
  def url=(value)
19
22
  path = URI.parse(value).path.sub("/public/", "")
20
23
  @type, size, file = path.split("/")
24
+ return if file.nil?
21
25
  @format ||= ::File.extname(file).tr(".", "")
22
26
  @file = ::File.basename(file, ".#{@format}")
23
27
  @size = size.start_with?("user") ? :user_big : :big
@@ -14,7 +14,7 @@ module JustimmoClient::V1
14
14
  attribute :fax, String
15
15
  attribute :last_name, String
16
16
  attribute :first_name, String
17
- attribute :salutation, String
17
+ attribute :salutation, String, default: ""
18
18
  attribute :company, String
19
19
  attribute :street, String
20
20
  attribute :zip_code, Integer
@@ -48,9 +48,5 @@ module JustimmoClient::V1
48
48
  def to_s
49
49
  full_name
50
50
  end
51
-
52
- def inspect
53
- "#<#{self.class} #{self}>"
54
- end
55
51
  end
56
52
  end
@@ -15,7 +15,6 @@ module JustimmoClient::V1
15
15
  attribute :latitude, Float
16
16
  attribute :longitude, Float
17
17
  attribute :location, String
18
- attribute :proximity, String
19
18
  attribute :floor, Integer
20
19
 
21
20
  # @!group Instance Method Summary
@@ -40,10 +39,6 @@ module JustimmoClient::V1
40
39
  "#<#{self.class} #{self}>"
41
40
  end
42
41
 
43
- def to_h
44
- { latitude: latitude, longitude: longitude }
45
- end
46
-
47
42
  def to_a
48
43
  [latitude, longitude]
49
44
  end
@@ -13,5 +13,41 @@ module JustimmoClient::V1
13
13
  mod.nullify_blank = true
14
14
  mod.coercer.config.string.boolean_map = { "0" => false, "1" => true }
15
15
  end
16
+
17
+ # Dummy method for FactoryGirl
18
+ def save!
19
+ end
20
+
21
+ def to_h
22
+ deep_to_h
23
+ end
24
+
25
+ def ==(other)
26
+ return true if equal?(other)
27
+ return false unless other.is_a?(JustimmoBase)
28
+ to_h == other.to_h
29
+ end
30
+
31
+ private
32
+
33
+ def array_to_h(array)
34
+ array.map do |elem|
35
+ if elem.respond_to?(:to_h)
36
+ elem.to_h
37
+ else
38
+ elem
39
+ end
40
+ end
41
+ end
42
+
43
+ def deep_to_h
44
+ attributes.inject({}) do |acc, (key, value)|
45
+ case value
46
+ when Array then acc.update(key => array_to_h(value))
47
+ when JustimmoBase then acc.update(key => value.to_h)
48
+ else acc.update(key => value)
49
+ end
50
+ end
51
+ end
16
52
  end
17
53
  end
@@ -36,6 +36,17 @@ module JustimmoClient::V1
36
36
 
37
37
  # @!group Instance Method Summary
38
38
 
39
+ def initialize(**options)
40
+ super(options)
41
+ @contact ||= Employee.new
42
+ @usage ||= RealtyUsage.new
43
+ @marketing ||= RealtyMarketing.new
44
+ @geo ||= GeoLocation.new
45
+ @area ||= RealtyArea.new
46
+ @room_count ||= RealtyRoomCount.new
47
+ @price ||= RealtyPrice.new
48
+ end
49
+
39
50
  def images
40
51
  attachments.select { |x| x.type == "pic" }
41
52
  end
@@ -58,17 +69,19 @@ module JustimmoClient::V1
58
69
  if @teaser.empty?
59
70
  parts = desc.partition("</ul>\n")
60
71
  self.teaser = parts[0..1].join
61
- parts.last
72
+ parts.last.strip
62
73
  else
63
- desc
74
+ desc.strip
64
75
  end
65
76
  end
66
77
 
67
78
  def teaser=(tea)
68
79
  @teaser =
69
80
  case tea
70
- when Array then tea
71
- when String then tea&.gsub(/<\/?(ul|li)>/, "")&.strip&.split("\n")
81
+ when Array
82
+ tea.map(&:strip)
83
+ when String
84
+ tea.gsub(/<\/?(ul|li)>/, "").strip.split("\n").map(&:strip)
72
85
  else []
73
86
  end
74
87
  end
@@ -147,10 +147,18 @@ module JustimmoClient::V1
147
147
  REALTY_ROOMS.each { |k, v| property k, as: v }
148
148
  end
149
149
 
150
- property :documents, as: :dokumente
151
- property :videos
152
- property :images360, as: :bilder360
153
- property :links
150
+ property :documents,
151
+ as: :dokumente,
152
+ parse_filter: ->(fragment, _options) { fragment.empty? ? nil : fragment }
153
+
154
+ property :videos,
155
+ parse_filter: ->(fragment, _options) { fragment.empty? ? nil : fragment }
156
+
157
+ property :images360, as: :bilder360,
158
+ parse_filter: ->(fragment, _options) { fragment.empty? ? nil : fragment }
159
+
160
+ property :links,
161
+ parse_filter: ->(fragment, _options) { fragment.empty? ? nil : fragment }
154
162
 
155
163
  collection :attachments,
156
164
  as: :anhang,
@@ -21,7 +21,7 @@ module JustimmoClient::V1
21
21
  Authorization: "Basic #{JustimmoClient::Config.credentials}"
22
22
  }
23
23
 
24
- with_retries do
24
+ Retriable.retriable do
25
25
  with_request_error_handler do
26
26
  log.debug("Requesting #{uri} with params #{options[:params]}")
27
27
  RestClient.proxy = JustimmoClient::Config.proxy
@@ -40,19 +40,5 @@ module JustimmoClient::V1
40
40
  rescue RestClient::Exception, SocketError, Errno::ECONNREFUSED => e
41
41
  raise JustimmoClient::RetrievalFailed, e
42
42
  end
43
-
44
- def with_retries
45
- options = {
46
- base_interval: 2.0,
47
- tries: JustimmoClient::Config.request_retries,
48
- on_retry: proc do |exception, try, elapsed_time, next_interval|
49
- log.error("#{exception.class}: #{exception}")
50
- log.error("Try #{try} in #{elapsed_time} seconds, retrying in #{next_interval} seconds.")
51
- end,
52
- on: JustimmoClient::RetrievalFailed
53
- }
54
-
55
- Retriable.retriable(options) { yield }
56
- end
57
43
  end
58
44
  end
@@ -146,9 +146,6 @@ module JustimmoClient::V1
146
146
 
147
147
  def with_error_handler
148
148
  yield
149
- rescue JustimmoClient::OptionParserError => e
150
- log.error(e)
151
- raise JustimmoClient::RetrievalFailed, e
152
149
  end
153
150
 
154
151
  # @!group Option Parsers
@@ -2,11 +2,12 @@
2
2
 
3
3
  require "justimmo_client/version"
4
4
  require "justimmo_client/errors"
5
- require "justimmo_client/misc"
6
5
 
7
6
  module JustimmoClient
8
7
  include JustimmoClient::Errors
9
8
 
9
+ require "justimmo_client/misc"
10
+
10
11
  autoload :Config, "justimmo_client/core/config"
11
12
  autoload :Logging, "justimmo_client/core/logging"
12
13
  autoload :Utils, "justimmo_client/core/utils"
@@ -7,9 +7,6 @@ module JustimmoClient::Errors
7
7
  # Raised when configuration validation fails.
8
8
  ConfigurationError = Class.new(JustimmoError)
9
9
 
10
- # Raised when option parsing fails
11
- OptionParserError = Class.new(JustimmoError)
12
-
13
10
  # Raised when authentication with the API fails.
14
11
  class AuthenticationFailed < JustimmoError
15
12
  def initialize
@@ -24,20 +21,6 @@ module JustimmoClient::Errors
24
21
  end
25
22
  end
26
23
 
27
- # Raised when the option parser rejects an option
28
- class InvalidOption < OptionParserError
29
- def initialize(key)
30
- super "Option '#{key}' not supported"
31
- end
32
- end
33
-
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"
38
- end
39
- end
40
-
41
24
  # Raised when an unsupported API version is set.
42
25
  class UnsupportedAPIVersion < ConfigurationError
43
26
  def initialize(version)
@@ -2,11 +2,28 @@
2
2
 
3
3
  require "active_support/inflector/inflections"
4
4
  require "active_support/i18n"
5
+ require "retriable"
6
+ require "justimmo_client/core/config"
7
+ require "justimmo_client/core/logging"
5
8
 
6
- ActiveSupport::Inflector.inflections do |inflect|
7
- inflect.acronym "XML"
8
- inflect.acronym "JSON"
9
- end
9
+ module JustimmoClient
10
+ extend JustimmoClient::Logging
11
+
12
+ ActiveSupport::Inflector.inflections do |inflect|
13
+ inflect.acronym "XML"
14
+ inflect.acronym "JSON"
15
+ end
10
16
 
11
- I18n.load_path += Dir[File.expand_path("../../locales/*.yml", __dir__)]
12
- I18n.default_locale = :en
17
+ I18n.load_path += Dir[File.expand_path("../../locales/*.yml", __dir__)]
18
+ I18n.default_locale = :en
19
+
20
+ Retriable.configure do |c|
21
+ c.base_interval = 2.0
22
+ c.tries = JustimmoClient::Config.request_retries
23
+ c.on_retry = proc do |exception, try, elapsed_time, next_interval|
24
+ log.error("#{exception.class}: #{exception}")
25
+ log.error("Try #{try} in #{elapsed_time} seconds, retrying in #{next_interval} seconds.")
26
+ end
27
+ c.on = JustimmoClient::RetrievalFailed
28
+ end
29
+ end
@@ -5,6 +5,29 @@ module JustimmoClient
5
5
  class OptionParser
6
6
  include JustimmoClient::Logging
7
7
 
8
+ # Raised when option parsing fails
9
+ OptionParserError = Class.new(StandardError)
10
+
11
+ # Raised when the option parser rejects an option
12
+ class InvalidOption < OptionParserError
13
+ def initialize(key)
14
+ super "Option '#{key}' not supported"
15
+ end
16
+ end
17
+
18
+ # Raised when the option parser rejects a value
19
+ class InvalidValue < OptionParserError
20
+ def initialize(value)
21
+ super "'#{value}' is not in the list of accepted values"
22
+ end
23
+ end
24
+
25
+ class DuplicateKeyGroup < OptionParserError
26
+ def initialize(key, group)
27
+ super "Key #{key} is already in group #{group}"
28
+ end
29
+ end
30
+
8
31
  attr_accessor :range_suffix
9
32
  attr_accessor :mappings
10
33
 
@@ -33,14 +56,14 @@ module JustimmoClient
33
56
  out = {}
34
57
 
35
58
  options.each do |key, value|
36
- raise JustimmoClient::InvalidOption, key unless @options.key?(key.to_sym)
59
+ raise InvalidOption, key unless @options.key?(key.to_sym)
37
60
  group = group_of(key)
38
61
 
39
62
  if group
40
63
  out[group] ||= {}
41
- out[group].update(parse_option(key.to_sym, value))
64
+ out[group].update(parse_option(key.to_sym, value).reject { |_k, v| v.nil? })
42
65
  else
43
- out.update(parse_option(key.to_sym, value))
66
+ out.update(parse_option(key.to_sym, value).reject { |_k, v| v.nil? })
44
67
  end
45
68
  end
46
69
 
@@ -50,6 +73,9 @@ module JustimmoClient
50
73
  private
51
74
 
52
75
  def add_option(key, **options, &block)
76
+ group = group_of(key)
77
+ raise DuplicateKeyGroup.new(key, group) unless group.nil?
78
+
53
79
  @options[key.to_sym] = {
54
80
  group: @context,
55
81
  type: options[:type],
@@ -94,7 +120,7 @@ module JustimmoClient
94
120
 
95
121
  def parse_option(key, value)
96
122
  values = @options.dig(key, :values)
97
- raise JustimmoClient::InvalidValue, value unless values.nil? || values.include?(value)
123
+ raise InvalidValue, value unless values.nil? || values.include?(value)
98
124
 
99
125
  key, value = apply_mod(key.to_sym, value) if has_mod?(key)
100
126
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module JustimmoClient
4
- VERSION = "0.6.8"
4
+ VERSION = "0.6.9"
5
5
  end
data/notes.md CHANGED
@@ -17,3 +17,8 @@
17
17
  * objekt/bundeslaender
18
18
  * objekt/regionen
19
19
  * objekt/plzUndOrte
20
+
21
+ # Test Todo
22
+ - [ ] models
23
+ - [ ] requests
24
+ - [x] parser
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.6.8
4
+ version: 0.6.9
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-22 00:00:00.000000000 Z
11
+ date: 2017-10-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -58,14 +58,14 @@ dependencies:
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '2.0'
61
+ version: '3.0'
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '2.0'
68
+ version: '3.0'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: nokogiri
71
71
  requirement: !ruby/object:Gem::Requirement
@@ -185,7 +185,7 @@ dependencies:
185
185
  - !ruby/object:Gem::Version
186
186
  version: '0.9'
187
187
  description:
188
- email: patrick.auernig@mykolab.com
188
+ email: dev.patrick.auernig@gmail.com
189
189
  executables: []
190
190
  extensions: []
191
191
  extra_rdoc_files: []
@@ -280,7 +280,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
280
280
  requirements:
281
281
  - - ">="
282
282
  - !ruby/object:Gem::Version
283
- version: '0'
283
+ version: '2.3'
284
284
  required_rubygems_version: !ruby/object:Gem::Requirement
285
285
  requirements:
286
286
  - - ">="