book-value 0.0.2 → 0.0.4
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 +4 -4
- data/lib/book-value/client.rb +35 -21
- data/lib/book-value/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8b2d13c166936168c1b4042f0b14aee46decf8a62306bdf8f89034ca2ec3cc44
|
4
|
+
data.tar.gz: 76b81b257574bc634ea5f4ab171eceec490c53131e115e115dd95cda9c7a23c9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9ac3663a9f2c625a9b6ada1b4846b883165b533c0128e0988dda223263621333b6950d050681dea0e4712a741dcf7c550d4f7f77049cdd8273acea29c628bd17
|
7
|
+
data.tar.gz: e847aebdd63bfd45c68b1e9320391410741984e3f2c8f61d320143409719afde93b72bd0160dbf6826c417f2e6751fa8dd21f568a313325d853d59ec879a37bb
|
data/lib/book-value/client.rb
CHANGED
@@ -38,20 +38,22 @@ module BookValue
|
|
38
38
|
options
|
39
39
|
end
|
40
40
|
|
41
|
+
# TODO: Fix model to try `-`
|
41
42
|
def car_features(make, model)
|
42
|
-
|
43
|
-
doc = Nokogiri::HTML(raw_page['body'])
|
43
|
+
checkbox_options = {}
|
44
44
|
|
45
|
-
|
46
|
-
|
45
|
+
process_model(model) do |model_name|
|
46
|
+
raw_page = authorise_and_send(http_method: :get, command: "calculate/#{make.downcase}/#{model_name}")
|
47
|
+
next if raw_page == {}
|
47
48
|
|
48
|
-
|
49
|
+
doc = Nokogiri::HTML(raw_page['body'])
|
49
50
|
|
50
|
-
|
51
|
-
|
52
|
-
|
51
|
+
doc.css(".list-group li div").each do |checkbox|
|
52
|
+
input_of_child = checkbox.children.find { |child| child.name == 'input' }
|
53
|
+
label_of_child = checkbox.children.find { |child| child.name == 'label' }
|
53
54
|
|
54
|
-
|
55
|
+
checkbox_options[input_of_child[:name]] = label_of_child.children.first.to_s
|
56
|
+
end
|
55
57
|
end
|
56
58
|
|
57
59
|
checkbox_options
|
@@ -60,28 +62,40 @@ module BookValue
|
|
60
62
|
# Features are just the list of features
|
61
63
|
# condition_score is between 1-10, 10 is perfect, 1 is bad
|
62
64
|
def get_book_value(make, model, features, mileage, year, condition_score = 10)
|
63
|
-
|
65
|
+
output = ''
|
66
|
+
feature_params = ''
|
64
67
|
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
+
process_model(model) do |model_name|
|
69
|
+
features.each do |feature_id|
|
70
|
+
feature_params = "#{feature_params}#{feature_id}=on&"
|
71
|
+
end
|
72
|
+
|
73
|
+
feature_params = feature_params[0..-2]
|
68
74
|
|
69
|
-
|
75
|
+
milage_form_page = authorise_and_send(http_method: :post, payload: feature_params, command: "calculate/#{make.downcase}/#{model_name}")
|
76
|
+
next if milage_form_page == {}
|
70
77
|
|
71
|
-
|
72
|
-
condition_url = milage_form_page['headers']['location']
|
78
|
+
condition_url = milage_form_page['headers']['location']
|
73
79
|
|
74
|
-
|
80
|
+
_condition_page = HTTParty.post(condition_url, body: "mileage=#{mileage}&year=#{year}")
|
75
81
|
|
76
|
-
|
77
|
-
|
82
|
+
book_value_url = condition_url.gsub('/4', '/5')
|
83
|
+
book_value_page = HTTParty.post(book_value_url, body: "condition_score=#{condition_score}")
|
78
84
|
|
79
|
-
|
80
|
-
|
85
|
+
doc = Nokogiri::HTML(book_value_page.body)
|
86
|
+
|
87
|
+
output = doc.at('h4').text
|
88
|
+
end
|
89
|
+
|
90
|
+
output
|
81
91
|
end
|
82
92
|
|
83
93
|
private
|
84
94
|
|
95
|
+
def process_model(model)
|
96
|
+
[model.downcase.gsub(' ', ''), model.downcase.gsub(' ', '-')]
|
97
|
+
end
|
98
|
+
|
85
99
|
def img_path(name)
|
86
100
|
"#{base_path}/data/makes/#{snake_case(name)}"
|
87
101
|
end
|
data/lib/book-value/version.rb
CHANGED