lib/book-value/client.rb in book-value-0.0.4 vs lib/book-value/client.rb in book-value-0.0.5
- old
+ new
@@ -36,17 +36,15 @@
end
options
end
- # TODO: Fix model to try `-`
def car_features(make, model)
checkbox_options = {}
- process_model(model) do |model_name|
+ process_model(model).each do |model_name|
raw_page = authorise_and_send(http_method: :get, command: "calculate/#{make.downcase}/#{model_name}")
- next if raw_page == {}
doc = Nokogiri::HTML(raw_page['body'])
doc.css(".list-group li div").each do |checkbox|
input_of_child = checkbox.children.find { |child| child.name == 'input' }
@@ -63,21 +61,20 @@
# condition_score is between 1-10, 10 is perfect, 1 is bad
def get_book_value(make, model, features, mileage, year, condition_score = 10)
output = ''
feature_params = ''
- process_model(model) do |model_name|
+ process_model(model).each do |model_name|
features.each do |feature_id|
feature_params = "#{feature_params}#{feature_id}=on&"
end
feature_params = feature_params[0..-2]
milage_form_page = authorise_and_send(http_method: :post, payload: feature_params, command: "calculate/#{make.downcase}/#{model_name}")
- next if milage_form_page == {}
-
condition_url = milage_form_page['headers']['location']
+ next unless condition_url
_condition_page = HTTParty.post(condition_url, body: "mileage=#{mileage}&year=#{year}")
book_value_url = condition_url.gsub('/4', '/5')
book_value_page = HTTParty.post(book_value_url, body: "condition_score=#{condition_score}")
@@ -140,10 +137,11 @@
total_time = end_time - start_time
{
'start_time' => start_time,
'end_time' => end_time,
- 'total_time' => total_time
+ 'total_time' => total_time,
+ 'ok' => response.ok?
}
end
def body_is_present?(response)
!body_is_missing?(response)