pricehubble 0.4.2 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,11 +1,8 @@
1
- # frozen_string_literal: true
2
-
3
1
  # This file was generated by Appraisal
4
2
 
5
- source 'https://rubygems.org'
3
+ source "https://rubygems.org"
6
4
 
7
- gem 'activemodel', '~> 5.2.2'
8
- gem 'activesupport', '~> 5.2.2'
9
- gem 'railties', '~> 5.2.2'
5
+ gem "activemodel", "~> 5.2.0"
6
+ gem "activesupport", "~> 5.2.0"
10
7
 
11
- gemspec path: '../'
8
+ gemspec path: "../"
@@ -65,8 +65,7 @@ module PriceHubble
65
65
  # @param entity [PriceHubble::Dossier] the entity to delete
66
66
  # @param args [Hash{Symbol => Mixed}] additional arguments
67
67
  #
68
- # rubocop:disable Metrics/MethodLength because thats the bare minimum
69
- # rubocop:disable Metrics/AbcSize because the decission
68
+ # rubocop:disable Metrics/MethodLength because thats the bare minimumbecause the decission
70
69
  # handling is quite complex
71
70
  def delete_dossier(entity, **args)
72
71
  res = connection.delete do |req|
@@ -82,9 +81,8 @@ module PriceHubble
82
81
  successful?(res)
83
82
  end
84
83
  end
85
- # rubocop:enable Metrics/MethodLength
86
- # rubocop:enable Metrics/AbcSize
87
84
 
85
+ # rubocop:enable Metrics/MethodLength
88
86
  # Update a dossier entity.
89
87
  #
90
88
  # TODO: Implement this.
@@ -18,7 +18,7 @@ module PriceHubble
18
18
  # Perform the data compaction and the hash key transformation,
19
19
  # when the body is available and a hash
20
20
  env[:body] = body.deep_compact.deep_camelize_keys \
21
- if body&.is_a?(Hash)
21
+ if body.is_a?(Hash)
22
22
 
23
23
  @app.call(env)
24
24
  end
@@ -8,15 +8,15 @@ module PriceHubble
8
8
  module Request
9
9
  extend ActiveSupport::Concern
10
10
 
11
- included do
12
- # A common HTTP content type to symbol
13
- # mapping for correct header settings.
14
- CONTENT_TYPE = {
15
- json: 'application/json',
16
- multipart: 'multipart/form-data',
17
- url_encoded: 'application/x-www-form-urlencoded'
18
- }.freeze
11
+ # A common HTTP content type to symbol
12
+ # mapping for correct header settings.
13
+ CONTENT_TYPE = {
14
+ json: 'application/json',
15
+ multipart: 'multipart/form-data',
16
+ url_encoded: 'application/x-www-form-urlencoded'
17
+ }.freeze
19
18
 
19
+ included do
20
20
  # Use the configured identity to authenticate the given request.
21
21
  #
22
22
  # @param req [Faraday::Request] the request to manipulate
@@ -12,8 +12,9 @@ module PriceHubble
12
12
  # or +nil+ on error
13
13
  #
14
14
  # rubocop:disable Metrics/MethodLength because of the request handling
15
+ # rubocop:disable Metrics/AbcSize dito
15
16
  def property_value(request, **args)
16
- data = request.attributes(true)
17
+ data = request.attributes(sanitize: true)
17
18
  res = connection.post do |req|
18
19
  req.path = '/api/v1/valuation/property_value'
19
20
  req.body = data
@@ -27,6 +28,7 @@ module PriceHubble
27
28
  end
28
29
  end
29
30
  # rubocop:enable Metrics/MethodLength
31
+ # rubocop:enable Metrics/AbcSize
30
32
 
31
33
  # Map and assign the valuation response to our local
32
34
  # +PriceHubble::Valuation+ representation. While taking care of the
@@ -42,6 +44,7 @@ module PriceHubble
42
44
  #
43
45
  # rubocop:disable Metrics/MethodLength because of the request
44
46
  # to response mapping
47
+ # rubocop:disable Metrics/AbcSize dito
45
48
  def assign_valuations(data, request)
46
49
  lambda do
47
50
  # valuations[i][j] contains the valuation for property i on date j
@@ -60,6 +63,7 @@ module PriceHubble
60
63
  end
61
64
  end
62
65
  # rubocop:enable Metrics/MethodLength
66
+ # rubocop:enable Metrics/AbcSize
63
67
 
64
68
  # Generate bang method variants
65
69
  bangers :property_value
@@ -38,8 +38,8 @@ class Hash
38
38
  def deep_compact_in_object(object)
39
39
  case object
40
40
  when Hash
41
- object = object.compact.each_with_object({}) do |(key, value), result|
42
- result[key] = deep_compact_in_object(value)
41
+ object = object.compact.transform_values do |value|
42
+ deep_compact_in_object(value)
43
43
  end
44
44
  object.empty? ? nil : object.compact
45
45
  when Array
@@ -55,6 +55,7 @@ module PriceHubble
55
55
  #
56
56
  # @param child_class [Class] the child class which inherits us
57
57
  def inherited(child_class)
58
+ super
58
59
  match = ->(sym) { sym.to_s.start_with? 'inherited_setup_' }
59
60
  trigger = ->(sym) { send(sym, child_class) }
60
61
  methods.select(&match).each(&trigger)
@@ -45,8 +45,8 @@ module PriceHubble
45
45
  key = opts[:from]
46
46
 
47
47
  # Initialize an object on the association, even without data
48
- if opts[:initialize] && send(attribute).nil?
49
- hash[key] = {} unless hash.key? key
48
+ if opts[:initialize] && send(attribute).nil? && !(hash.key? key)
49
+ hash[key] = {}
50
50
  end
51
51
 
52
52
  return [struct, hash] unless hash.key? key
@@ -92,8 +92,8 @@ module PriceHubble
92
92
  key = opts[:fallback_from] if opts[:fallback_from] && !hash.key?(key)
93
93
 
94
94
  # Initialize an empty array on the association
95
- if opts[:initialize] && send(attribute).nil?
96
- hash[key] = [] unless hash.key? key
95
+ if opts[:initialize] && send(attribute).nil? && !(hash.key? key)
96
+ hash[key] = []
97
97
  end
98
98
 
99
99
  return [struct, hash] unless hash.key? key
@@ -156,6 +156,7 @@ module PriceHubble
156
156
  associations[entity] = opts
157
157
  # Generate getters and setters
158
158
  attr_accessor entity
159
+
159
160
  # Add the entity to the tracked attributes if it should be persisted
160
161
  tracked_attr entity if opts[:persist]
161
162
  end
@@ -187,6 +188,7 @@ module PriceHubble
187
188
  associations[entity] = opts
188
189
  # Generate getters and setters
189
190
  attr_accessor entity
191
+
190
192
  # Add the entity to the tracked attributes if it should be persisted
191
193
  tracked_attr entity if opts[:persist]
192
194
  end
@@ -27,7 +27,7 @@ module PriceHubble
27
27
  #
28
28
  # rubocop:disable Metrics/MethodLength because of the
29
29
  # key/value sanitization handling
30
- def attributes(sanitize = false)
30
+ def attributes(sanitize: false)
31
31
  attribute_names.each_with_object({}) do |key, memo|
32
32
  reader = key
33
33
 
@@ -43,8 +43,8 @@ module PriceHubble
43
43
  memo[key.to_s] = result
44
44
  end
45
45
  end
46
- # rubocop:enable Metrics/MethodLength
47
46
 
47
+ # rubocop:enable Metrics/MethodLength
48
48
  # A wrapper for the +ActiveModel#assign_attributes+ method with support
49
49
  # for unmapped attributes. These attributes are put into the
50
50
  # +_unmapped+ struct and all the known attributes are assigned like
@@ -73,20 +73,26 @@ module PriceHubble
73
73
  # @param obj [Mixed] the object to resolve its attributes
74
74
  # @param sanitize [Boolean] whenever to sanitize the data for transport
75
75
  # @return [Mixed] the attribute(s) data
76
- def resolve_attributes(obj, sanitize = false)
76
+ #
77
+ # rubocop:disable Metrics/MethodLength because thats the pure minimum
78
+ def resolve_attributes(obj, sanitize: false)
77
79
  if obj.respond_to? :attributes
78
80
  obj = if obj.method(:attributes).arity == 1
79
- obj.attributes(sanitize)
81
+ obj.attributes(sanitize: sanitize)
80
82
  else
81
83
  obj.attributes
82
84
  end
83
85
  end
84
86
 
85
- obj = obj.map { |elem| resolve_attributes(elem, sanitize) } \
86
- if obj.is_a? Array
87
+ if obj.is_a? Array
88
+ obj = obj.map do |elem|
89
+ resolve_attributes(elem, sanitize: sanitize)
90
+ end
91
+ end
87
92
 
88
93
  obj
89
94
  end
95
+ # rubocop:enable Metrics/MethodLength
90
96
 
91
97
  # Explicitly convert the given struct to an +RecursiveOpenStruct+ and a
92
98
  # deep symbolized key copy for further usage.
@@ -144,6 +150,7 @@ module PriceHubble
144
150
  self.attribute_names += args
145
151
  # Define getters/setters
146
152
  attr_reader(*args)
153
+
147
154
  args.each do |arg|
148
155
  class_eval <<-RUBY, __FILE__, __LINE__ + 1
149
156
  def #{arg}=(value)
@@ -43,7 +43,7 @@ module PriceHubble
43
43
  #
44
44
  # @return [Array<Hash{String => Mixed}>] the sanitized properties
45
45
  def sanitize_attr_properties
46
- properties.map { |prop| { property: prop.attributes(true) } }
46
+ properties.map { |prop| { property: prop.attributes(sanitize: true) } }
47
47
  end
48
48
 
49
49
  # Perform the property valuation request.
@@ -6,6 +6,7 @@ module PriceHubble
6
6
  # rubocop:disable Style/ClassVars because we split module code
7
7
  module Identity
8
8
  extend ActiveSupport::Concern
9
+
9
10
  class_methods do
10
11
  # Reset the current identity.
11
12
  def reset_identity!
@@ -49,7 +49,7 @@ module PriceHubble
49
49
  def initialize(on_error: :fail)
50
50
  @on_error = on_error
51
51
  @bang_proc = -> { StandardError.new }
52
- @fail_proc = @good_proc = -> { nil }
52
+ @fail_proc = @good_proc = -> {}
53
53
  end
54
54
 
55
55
  # Register a new error (bang) way. Requires a block.
@@ -1,6 +1,23 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # The gem version details.
3
4
  module PriceHubble
4
5
  # The version of the +price-hubble+ gem
5
- VERSION = '0.4.2'
6
+ VERSION = '1.1.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
6
23
  end
data/lib/pricehubble.rb CHANGED
@@ -13,7 +13,6 @@ require 'active_model'
13
13
  require 'recursive-open-struct'
14
14
  require 'faraday'
15
15
  require 'faraday_middleware'
16
- require 'pp'
17
16
 
18
17
  # Load polyfills if needed
19
18
  require 'pricehubble/core_ext/hash'
data/pricehubble.gemspec CHANGED
@@ -5,45 +5,56 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
5
  require 'pricehubble/version'
6
6
 
7
7
  Gem::Specification.new do |spec|
8
- spec.name = 'pricehubble'
9
- spec.version = PriceHubble::VERSION
10
- spec.authors = ['Hermann Mayer']
11
- spec.email = ['hermann.mayer92@gmail.com']
8
+ spec.name = 'pricehubble'
9
+ spec.version = PriceHubble::VERSION
10
+ spec.authors = ['Hermann Mayer']
11
+ spec.email = ['hermann.mayer92@gmail.com']
12
12
 
13
- spec.summary = 'Ruby client for the PriceHubble REST API'
14
- spec.description = 'Ruby client for the PriceHubble REST API'
15
- spec.homepage = 'https://github.com/hausgold/pricehubble'
13
+ spec.license = 'MIT'
14
+ spec.summary = 'Ruby client for the PriceHubble REST API'
15
+ spec.description = 'Ruby client for the PriceHubble REST API'
16
16
 
17
- spec.required_ruby_version = '~> 2.5'
17
+ base_uri = "https://github.com/hausgold/#{spec.name}"
18
+ spec.metadata = {
19
+ 'homepage_uri' => base_uri,
20
+ 'source_code_uri' => base_uri,
21
+ 'changelog_uri' => "#{base_uri}/blob/master/CHANGELOG.md",
22
+ 'bug_tracker_uri' => "#{base_uri}/issues",
23
+ 'documentation_uri' => "https://www.rubydoc.info/gems/#{spec.name}"
24
+ }
18
25
 
19
26
  spec.files = `git ls-files -z`.split("\x0").reject do |f|
20
27
  f.match(%r{^(test|spec|features)/})
21
28
  end
22
- spec.bindir = 'exe'
23
- spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
29
+
30
+ spec.bindir = 'exe'
31
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
24
32
  spec.require_paths = ['lib']
25
33
 
26
- spec.add_runtime_dependency 'activemodel', '>= 5.2.0'
27
- spec.add_runtime_dependency 'activesupport', '>= 5.2.0'
34
+ spec.required_ruby_version = '>= 2.5'
35
+
36
+ spec.add_runtime_dependency 'activemodel', '>= 5.2'
37
+ spec.add_runtime_dependency 'activesupport', '>= 5.2'
28
38
  spec.add_runtime_dependency 'faraday', '~> 1.0'
29
39
  spec.add_runtime_dependency 'faraday_middleware', '~> 1.0'
30
40
  spec.add_runtime_dependency 'recursive-open-struct', '~> 1.1'
31
41
 
32
- spec.add_development_dependency 'appraisal'
33
- spec.add_development_dependency 'bundler', '>= 1.16', '< 3'
34
- spec.add_development_dependency 'factory_bot', '~> 4.11'
35
- spec.add_development_dependency 'railties', '>= 4.2.0', '< 6.1'
36
- spec.add_development_dependency 'rake', '~> 10.0'
37
- spec.add_development_dependency 'rdoc', '~> 6.1'
38
- spec.add_development_dependency 'redcarpet', '~> 3.4'
39
- spec.add_development_dependency 'rspec', '~> 3.0'
40
- spec.add_development_dependency 'rubocop', '~> 0.63.1'
41
- spec.add_development_dependency 'rubocop-rspec', '~> 1.31'
42
- spec.add_development_dependency 'simplecov', '< 0.18'
43
- spec.add_development_dependency 'terminal-table', '~> 1.8'
44
- spec.add_development_dependency 'timecop', '~> 0.9.1'
45
- spec.add_development_dependency 'vcr', '~> 3.0'
46
- spec.add_development_dependency 'webmock', '~> 3.5'
47
- spec.add_development_dependency 'yard', '~> 0.9.18'
48
- spec.add_development_dependency 'yard-activesupport-concern', '~> 0.0.1'
42
+ spec.add_development_dependency 'appraisal', '~> 2.4'
43
+ spec.add_development_dependency 'bundler', '~> 2.3'
44
+ spec.add_development_dependency 'countless', '~> 1.1'
45
+ spec.add_development_dependency 'factory_bot', '~> 6.2'
46
+ spec.add_development_dependency 'guard-rspec', '~> 4.7'
47
+ spec.add_development_dependency 'rake', '~> 13.0'
48
+ spec.add_development_dependency 'redcarpet', '~> 3.5'
49
+ spec.add_development_dependency 'rspec', '~> 3.12'
50
+ spec.add_development_dependency 'rubocop', '~> 1.28'
51
+ spec.add_development_dependency 'rubocop-rails', '~> 2.14'
52
+ spec.add_development_dependency 'rubocop-rspec', '~> 2.10'
53
+ spec.add_development_dependency 'simplecov', '>= 0.22'
54
+ spec.add_development_dependency 'terminal-table', '~> 3.0'
55
+ spec.add_development_dependency 'timecop', '>= 0.9.6'
56
+ spec.add_development_dependency 'vcr', '~> 6.0'
57
+ spec.add_development_dependency 'webmock', '~> 3.18'
58
+ spec.add_development_dependency 'yard', '>= 0.9.28'
59
+ spec.add_development_dependency 'yard-activesupport-concern', '>= 0.0.1'
49
60
  end