pricehubble 0.4.2 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/documentation.yml +3 -2
- data/.github/workflows/release.yml +47 -0
- data/.github/workflows/test.yml +6 -5
- data/.rspec +2 -2
- data/.rubocop.yml +33 -4
- data/.simplecov +12 -0
- data/Appraisals +2 -9
- data/CHANGELOG.md +19 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Dockerfile +2 -3
- data/Envfile +0 -3
- data/Guardfile +44 -0
- data/LICENSE +1 -1
- data/Makefile +25 -10
- data/README.md +21 -8
- data/Rakefile +20 -74
- data/gemfiles/rails_5.2.gemfile +4 -7
- data/lib/pricehubble/client/dossiers.rb +2 -4
- data/lib/pricehubble/client/request/data_sanitization.rb +1 -1
- data/lib/pricehubble/client/utils/request.rb +8 -8
- data/lib/pricehubble/client/valuation.rb +5 -1
- data/lib/pricehubble/core_ext/hash.rb +2 -2
- data/lib/pricehubble/entity/base_entity.rb +1 -0
- data/lib/pricehubble/entity/concern/associations.rb +6 -4
- data/lib/pricehubble/entity/concern/attributes.rb +13 -6
- data/lib/pricehubble/entity/valuation_request.rb +1 -1
- data/lib/pricehubble/identity.rb +1 -0
- data/lib/pricehubble/utils/decision.rb +1 -1
- data/lib/pricehubble/version.rb +18 -1
- data/lib/pricehubble.rb +0 -1
- data/pricehubble.gemspec +40 -29
- metadata +87 -77
- data/gemfiles/rails_6.0.gemfile +0 -11
data/gemfiles/rails_5.2.gemfile
CHANGED
@@ -1,11 +1,8 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
1
|
# This file was generated by Appraisal
|
4
2
|
|
5
|
-
source
|
3
|
+
source "https://rubygems.org"
|
6
4
|
|
7
|
-
gem
|
8
|
-
gem
|
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
|
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.
|
@@ -8,15 +8,15 @@ module PriceHubble
|
|
8
8
|
module Request
|
9
9
|
extend ActiveSupport::Concern
|
10
10
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
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.
|
42
|
-
|
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] = {}
|
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] = []
|
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
|
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
|
-
|
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
|
-
|
86
|
-
|
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.
|
data/lib/pricehubble/identity.rb
CHANGED
data/lib/pricehubble/version.rb
CHANGED
@@ -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 = '
|
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
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
|
9
|
-
spec.version
|
10
|
-
spec.authors
|
11
|
-
spec.email
|
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.
|
14
|
-
spec.
|
15
|
-
spec.
|
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
|
-
|
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
|
-
|
23
|
-
spec.
|
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.
|
27
|
-
|
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', '
|
34
|
-
spec.add_development_dependency '
|
35
|
-
spec.add_development_dependency '
|
36
|
-
spec.add_development_dependency '
|
37
|
-
spec.add_development_dependency '
|
38
|
-
spec.add_development_dependency 'redcarpet', '~> 3.
|
39
|
-
spec.add_development_dependency 'rspec', '~> 3.
|
40
|
-
spec.add_development_dependency 'rubocop', '~>
|
41
|
-
spec.add_development_dependency 'rubocop-
|
42
|
-
spec.add_development_dependency '
|
43
|
-
spec.add_development_dependency '
|
44
|
-
spec.add_development_dependency '
|
45
|
-
spec.add_development_dependency '
|
46
|
-
spec.add_development_dependency '
|
47
|
-
spec.add_development_dependency '
|
48
|
-
spec.add_development_dependency 'yard
|
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
|