book-value 0.0.1 → 0.0.3

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
  SHA256:
3
- metadata.gz: 3486778f29f7596a49211757edad68992313807f0fc2ada242dfcea365f2b358
4
- data.tar.gz: f209f2f4c05e4eba2bfdb61e61652acb0d8b52a54abe21acf9e5a326b68dd202
3
+ metadata.gz: ed291369351306ff8e17eba798235e353214752282ae1b9b48a5174366664ba6
4
+ data.tar.gz: a34bf2c5abdd71e46237096ee49199619bf0f7c033c4a32b049f72d61b24cfe2
5
5
  SHA512:
6
- metadata.gz: 83a23f501ef44bd7cbccdd8316073719d459137d9bf6060e04df998ef6ba074845f171935cf6511de6fec222e11703f58137af66477c880efcd266b2aa121c91
7
- data.tar.gz: 21a9eac0b5cc840dc92b74245f27bbd3b2d774b0336cd8acfebf71b89cd0f7eb8787f9b7d3a57dc3cb9139c2f609ed2fa6363f4e6958cf94e184de2927503c23
6
+ metadata.gz: e20a91c25c2975525f2f10cd29d07ce39832b9bd4569d812fc600fa77e43c05108c1523981a13e3e723459b42c0e349cdbf2d0f04994dd41ffc0efea3fa64b2b
7
+ data.tar.gz: 017ad5d8a9757fd8433b154d5869162c271c2b43bb6c8457d2722d0cda76c2fe6f94f1c1a57eb4bf3bac146bd8eed8c4a1ffe20092ec4369e1561c8c7f2402c7
data/README.md CHANGED
@@ -31,7 +31,7 @@ Or install it yourself as:
31
31
  client = BookValue::Client.new
32
32
 
33
33
  # Some example calls
34
- client.car_models
34
+ client.car_makes
35
35
  client.car_models(make)
36
36
  client.car_features(make, model)
37
37
  client.get_book_value(make, model, features, mileage, year, condition_score)
@@ -38,50 +38,60 @@ module BookValue
38
38
  options
39
39
  end
40
40
 
41
+ # TODO: Fix model to try `-`
41
42
  def car_features(make, model)
42
- raw_page = authorise_and_send(http_method: :get, command: "calculate/#{make.downcase}/#{model.downcase.gsub(' ', '')}")
43
- doc = Nokogiri::HTML(raw_page['body'])
43
+ process_model(model) do |model_name|
44
+ raw_page = authorise_and_send(http_method: :get, command: "calculate/#{make.downcase}/#{model_name}")
45
+ next if raw_page == {}
44
46
 
45
- raw_page = authorise_and_send(http_method: :get, command: "calculate/#{make.downcase}/#{model.downcase.gsub(' ', '')}")
46
- doc = Nokogiri::HTML(raw_page['body'])
47
+ doc = Nokogiri::HTML(raw_page['body'])
47
48
 
48
- checkbox_options = {}
49
+ checkbox_options = {}
49
50
 
50
- doc.css(".list-group li div").each do |checkbox|
51
- input_of_child = checkbox.children.find { |child| child.name == 'input' }
52
- label_of_child = checkbox.children.find { |child| child.name == 'label' }
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
- checkbox_options[input_of_child[:name]] = label_of_child.children.first.to_s
55
- end
55
+ checkbox_options[input_of_child[:name]] = label_of_child.children.first.to_s
56
+ end
56
57
 
57
- checkbox_options
58
+ return checkbox_options
59
+ end
58
60
  end
59
61
 
60
62
  # Features are just the list of features
61
63
  # condition_score is between 1-10, 10 is perfect, 1 is bad
62
- def get_book_value(make, model, features, mileage, year, condition_score)
63
- feature_params = ""
64
+ def get_book_value(make, model, features, mileage, year, condition_score = 10)
65
+ process_model(model) do |model_name|
66
+ feature_params = ""
64
67
 
65
- features.each do |feature_id|
66
- feature_params = "#{feature_params}#{feature_id}=on&"
67
- end
68
+ features.each do |feature_id|
69
+ feature_params = "#{feature_params}#{feature_id}=on&"
70
+ end
68
71
 
69
- feature_params = feature_params[0..-2]
72
+ feature_params = feature_params[0..-2]
70
73
 
71
- milage_form_page = authorise_and_send(http_method: :post, payload: feature_params, command: "calculate/#{make.downcase}/#{model.downcase.gsub(' ', '')}")
72
- condition_url = milage_form_page['headers']['location']
74
+ milage_form_page = authorise_and_send(http_method: :post, payload: feature_params, command: "calculate/#{make.downcase}/#{model_name}")
75
+ next if milage_form_page == {}
73
76
 
74
- _condition_page = HTTParty.post(condition_url, body: "mileage=#{mileage}&year=#{year}")
77
+ condition_url = milage_form_page['headers']['location']
75
78
 
76
- book_value_url = condition_url.gsub('/4', '/5')
77
- book_value_page = HTTParty.post(book_value_url, body: "condition_score=#{condition_score}")
79
+ _condition_page = HTTParty.post(condition_url, body: "mileage=#{mileage}&year=#{year}")
78
80
 
79
- doc = Nokogiri::HTML(book_value_page.body)
80
- doc.at('h4').text
81
+ book_value_url = condition_url.gsub('/4', '/5')
82
+ book_value_page = HTTParty.post(book_value_url, body: "condition_score=#{condition_score}")
83
+
84
+ doc = Nokogiri::HTML(book_value_page.body)
85
+ return doc.at('h4').text
86
+ end
81
87
  end
82
88
 
83
89
  private
84
90
 
91
+ def process_model(model)
92
+ [model.downcase.gsub(' ', ''), model.downcase.gsub(' ', '-')]
93
+ end
94
+
85
95
  def img_path(name)
86
96
  "#{base_path}/data/makes/#{snake_case(name)}"
87
97
  end
@@ -1,3 +1,3 @@
1
1
  module BookValue
2
- VERSION = '0.0.1'
2
+ VERSION = '0.0.3'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: book-value
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - trex22
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-03-15 00:00:00.000000000 Z
11
+ date: 2023-03-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty