book-value 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 3486778f29f7596a49211757edad68992313807f0fc2ada242dfcea365f2b358
4
+ data.tar.gz: f209f2f4c05e4eba2bfdb61e61652acb0d8b52a54abe21acf9e5a326b68dd202
5
+ SHA512:
6
+ metadata.gz: 83a23f501ef44bd7cbccdd8316073719d459137d9bf6060e04df998ef6ba074845f171935cf6511de6fec222e11703f58137af66477c880efcd266b2aa121c91
7
+ data.tar.gz: 21a9eac0b5cc840dc92b74245f27bbd3b2d774b0336cd8acfebf71b89cd0f7eb8787f9b7d3a57dc3cb9139c2f609ed2fa6363f4e6958cf94e184de2927503c23
data/.gitignore ADDED
@@ -0,0 +1,56 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /spec/examples.txt
9
+ /test/tmp/
10
+ /test/version_tmp/
11
+ /tmp/
12
+
13
+ # Used by dotenv library to load environment variables.
14
+ # .env
15
+
16
+ # Ignore Byebug command history file.
17
+ .byebug_history
18
+
19
+ ## Specific to RubyMotion:
20
+ .dat*
21
+ .repl_history
22
+ build/
23
+ *.bridgesupport
24
+ build-iPhoneOS/
25
+ build-iPhoneSimulator/
26
+
27
+ ## Specific to RubyMotion (use of CocoaPods):
28
+ #
29
+ # We recommend against adding the Pods directory to your .gitignore. However
30
+ # you should judge for yourself, the pros and cons are mentioned at:
31
+ # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
32
+ #
33
+ # vendor/Pods/
34
+
35
+ ## Documentation cache and generated files:
36
+ /.yardoc/
37
+ /_yardoc/
38
+ /doc/
39
+ /rdoc/
40
+
41
+ ## Environment normalization:
42
+ /.bundle/
43
+ /vendor/bundle
44
+ /lib/bundler/man/
45
+
46
+ # for a library or gem, you might want to ignore these files since the code is
47
+ # intended to run in multiple environments; otherwise, check them in:
48
+ # Gemfile.lock
49
+ # .ruby-version
50
+ # .ruby-gemset
51
+
52
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
53
+ .rvmrc
54
+
55
+ # Used by RuboCop. Remote config files pulled in from inherit_from directive.
56
+ # .rubocop-https?--*
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behaviour that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behaviour by participants include:
24
+
25
+ * The use of sexualised language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behaviour and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behaviour.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviours that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behaviour may be
58
+ reported by contacting the project team at contact@jasonchalom.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ git_source(:github) {|repo_name| 'https://github.com/TRex22/book-value' }
4
+
5
+ # Specify your gem's dependencies in book-value.gemspec
6
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,110 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ book-value (0.0.1)
5
+ active_attr (~> 0.15.4)
6
+ httparty (~> 0.21.0)
7
+ nokogiri (~> 1.14.0)
8
+
9
+ GEM
10
+ remote: https://rubygems.org/
11
+ specs:
12
+ actionpack (7.0.4.3)
13
+ actionview (= 7.0.4.3)
14
+ activesupport (= 7.0.4.3)
15
+ rack (~> 2.0, >= 2.2.0)
16
+ rack-test (>= 0.6.3)
17
+ rails-dom-testing (~> 2.0)
18
+ rails-html-sanitizer (~> 1.0, >= 1.2.0)
19
+ actionview (7.0.4.3)
20
+ activesupport (= 7.0.4.3)
21
+ builder (~> 3.1)
22
+ erubi (~> 1.4)
23
+ rails-dom-testing (~> 2.0)
24
+ rails-html-sanitizer (~> 1.1, >= 1.2.0)
25
+ active_attr (0.15.4)
26
+ actionpack (>= 3.0.2, < 7.1)
27
+ activemodel (>= 3.0.2, < 7.1)
28
+ activesupport (>= 3.0.2, < 7.1)
29
+ activemodel (7.0.4.3)
30
+ activesupport (= 7.0.4.3)
31
+ activesupport (7.0.4.3)
32
+ concurrent-ruby (~> 1.0, >= 1.0.2)
33
+ i18n (>= 1.6, < 2)
34
+ minitest (>= 5.1)
35
+ tzinfo (~> 2.0)
36
+ addressable (2.8.1)
37
+ public_suffix (>= 2.0.2, < 6.0)
38
+ ansi (1.5.0)
39
+ builder (3.2.4)
40
+ coderay (1.1.3)
41
+ concurrent-ruby (1.2.2)
42
+ crack (0.4.5)
43
+ rexml
44
+ crass (1.0.6)
45
+ erubi (1.12.0)
46
+ hashdiff (1.0.1)
47
+ httparty (0.21.0)
48
+ mini_mime (>= 1.0.0)
49
+ multi_xml (>= 0.5.2)
50
+ i18n (1.12.0)
51
+ concurrent-ruby (~> 1.0)
52
+ loofah (2.19.1)
53
+ crass (~> 1.0.2)
54
+ nokogiri (>= 1.5.9)
55
+ method_source (1.0.0)
56
+ mini_mime (1.1.2)
57
+ minitest (5.17.0)
58
+ minitest-focus (1.3.1)
59
+ minitest (>= 4, < 6)
60
+ minitest-reporters (1.5.0)
61
+ ansi
62
+ builder
63
+ minitest (>= 5.0)
64
+ ruby-progressbar
65
+ mocha (2.0.2)
66
+ ruby2_keywords (>= 0.0.5)
67
+ multi_xml (0.6.0)
68
+ nokogiri (1.14.2-arm64-darwin)
69
+ racc (~> 1.4)
70
+ pry (0.14.2)
71
+ coderay (~> 1.1)
72
+ method_source (~> 1.0)
73
+ public_suffix (5.0.1)
74
+ racc (1.6.2)
75
+ rack (2.2.6.4)
76
+ rack-test (2.1.0)
77
+ rack (>= 1.3)
78
+ rails-dom-testing (2.0.3)
79
+ activesupport (>= 4.2.0)
80
+ nokogiri (>= 1.6)
81
+ rails-html-sanitizer (1.5.0)
82
+ loofah (~> 2.19, >= 2.19.1)
83
+ rake (13.0.6)
84
+ rexml (3.2.5)
85
+ ruby-progressbar (1.13.0)
86
+ ruby2_keywords (0.0.5)
87
+ timecop (0.9.6)
88
+ tzinfo (2.0.6)
89
+ concurrent-ruby (~> 1.0)
90
+ webmock (3.18.1)
91
+ addressable (>= 2.8.0)
92
+ crack (>= 0.3.2)
93
+ hashdiff (>= 0.4.0, < 2.0.0)
94
+
95
+ PLATFORMS
96
+ arm64-darwin-20
97
+
98
+ DEPENDENCIES
99
+ book-value!
100
+ minitest (~> 5.17.0)
101
+ minitest-focus (~> 1.3.1)
102
+ minitest-reporters (~> 1.5.0)
103
+ mocha (~> 2.0.2)
104
+ pry (~> 0.14.2)
105
+ rake (~> 13.0.6)
106
+ timecop (~> 0.9.6)
107
+ webmock (~> 3.18.1)
108
+
109
+ BUNDLED WITH
110
+ 2.3.16
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 Jason Chalom
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2023 trex22
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,64 @@
1
+ # book-value.co.za Unofficial Client
2
+ An unofficial client for book-value.co.za.
3
+
4
+ See:
5
+ - https://book-value.co.za/
6
+
7
+ This is an unofficial project and still a work in progress (WIP) ... more to come soon.
8
+
9
+ ## TODO
10
+
11
+ ## Installation
12
+
13
+ Add this line to your application's Gemfile:
14
+
15
+ ```ruby
16
+ gem 'book-value'
17
+ ```
18
+
19
+ And then execute:
20
+
21
+ $ bundle
22
+
23
+ Or install it yourself as:
24
+
25
+ $ gem install book-value
26
+
27
+ ## Usage
28
+
29
+ ```ruby
30
+ require 'book-value'
31
+ client = BookValue::Client.new
32
+
33
+ # Some example calls
34
+ client.car_models
35
+ client.car_models(make)
36
+ client.car_features(make, model)
37
+ client.get_book_value(make, model, features, mileage, year, condition_score)
38
+ ```
39
+
40
+ ### Endpoints
41
+
42
+
43
+ ## Development
44
+
45
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
46
+
47
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
48
+
49
+ ### Tests
50
+ To run tests execute:
51
+
52
+ $ rake test
53
+
54
+ ## Contributing
55
+
56
+ Bug reports and pull requests are welcome on GitHub at https://github.com/trex22/book-value. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
57
+
58
+ ## License
59
+
60
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
61
+
62
+ ## Code of Conduct
63
+
64
+ Everyone interacting in the book-value: project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/trex22/book-value/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rake/testtask'
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << 'test'
6
+ t.libs << 'lib'
7
+ t.test_files = FileList['test/**/*_test.rb']
8
+ end
9
+
10
+ task :default => :test
data/bin/console ADDED
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'book-value'
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ require 'pry'
11
+ Pry.start
data/bin/make ADDED
@@ -0,0 +1,3 @@
1
+ #!/bin/bash
2
+ gem build book-value.gemspec
3
+ gem push book-value
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,38 @@
1
+ lib = File.expand_path('../lib', __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require 'book-value/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'book-value'
7
+ spec.version = BookValue::VERSION
8
+ spec.authors = ['trex22']
9
+ spec.email = ['contact@jasonchalom.com']
10
+
11
+ spec.summary = 'An unofficial client for https://book-value.co.za/.'
12
+ spec.description = 'An unofficial client for https://book-value.co.za/.'
13
+ spec.homepage = 'https://github.com/TRex22/book-value'
14
+ spec.license = 'MIT'
15
+
16
+ # Specify which files should be added to the gem when it is released.
17
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
18
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
19
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
20
+ end
21
+ spec.bindir = 'exe'
22
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
23
+ spec.require_paths = ['lib']
24
+
25
+ spec.add_dependency "httparty", "~> 0.21.0"
26
+ spec.add_dependency "active_attr", "~> 0.15.4"
27
+ spec.add_dependency "nokogiri", "~> 1.14.0"
28
+
29
+ # Development dependancies
30
+ spec.add_development_dependency "rake", "~> 13.0.6"
31
+ spec.add_development_dependency "minitest", "~> 5.17.0"
32
+ spec.add_development_dependency "minitest-focus", "~> 1.3.1"
33
+ spec.add_development_dependency "minitest-reporters", "~> 1.5.0"
34
+ spec.add_development_dependency "timecop", "~> 0.9.6"
35
+ spec.add_development_dependency "mocha", "~> 2.0.2"
36
+ spec.add_development_dependency "pry", "~> 0.14.2"
37
+ spec.add_development_dependency "webmock", "~> 3.18.1"
38
+ end
@@ -0,0 +1,186 @@
1
+ module BookValue
2
+ class Client
3
+ include ::BookValue::Constants
4
+
5
+ attr_reader :base_path, :port
6
+
7
+ def initialize(port: 443)
8
+ @base_path = BASE_PATH
9
+ @port = port
10
+ end
11
+
12
+ def self.api_version
13
+ 'v1 2023-03-15'
14
+ end
15
+
16
+ # TODO: Handle errors
17
+ def car_makes
18
+ raw_page = authorise_and_send(http_method: :get)
19
+ doc = Nokogiri::HTML(raw_page['body'])
20
+
21
+ options = {}
22
+ doc.css("select[name='make'] option").each do |option|
23
+ options[option.text.strip] = { name: option.text.strip, value: option.values.first, img: img_path(option.text.strip) }
24
+ end
25
+
26
+ options
27
+ end
28
+
29
+ def car_models(make)
30
+ raw_page = authorise_and_send(http_method: :get, command: "calculate/#{make.downcase}")
31
+ doc = Nokogiri::HTML(raw_page['body'])
32
+
33
+ options = {}
34
+ doc.css("select[name='model'] option").each do |option|
35
+ options[option.text.strip] = { name: option.text.strip, value: option.values.first }
36
+ end
37
+
38
+ options
39
+ end
40
+
41
+ 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'])
44
+
45
+ raw_page = authorise_and_send(http_method: :get, command: "calculate/#{make.downcase}/#{model.downcase.gsub(' ', '')}")
46
+ doc = Nokogiri::HTML(raw_page['body'])
47
+
48
+ checkbox_options = {}
49
+
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' }
53
+
54
+ checkbox_options[input_of_child[:name]] = label_of_child.children.first.to_s
55
+ end
56
+
57
+ checkbox_options
58
+ end
59
+
60
+ # Features are just the list of features
61
+ # 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
+
65
+ features.each do |feature_id|
66
+ feature_params = "#{feature_params}#{feature_id}=on&"
67
+ end
68
+
69
+ feature_params = feature_params[0..-2]
70
+
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']
73
+
74
+ _condition_page = HTTParty.post(condition_url, body: "mileage=#{mileage}&year=#{year}")
75
+
76
+ book_value_url = condition_url.gsub('/4', '/5')
77
+ book_value_page = HTTParty.post(book_value_url, body: "condition_score=#{condition_score}")
78
+
79
+ doc = Nokogiri::HTML(book_value_page.body)
80
+ doc.at('h4').text
81
+ end
82
+
83
+ private
84
+
85
+ def img_path(name)
86
+ "#{base_path}/data/makes/#{snake_case(name)}"
87
+ end
88
+
89
+ def snake_case(str)
90
+ str.downcase.gsub(/\s/, '_')
91
+ end
92
+
93
+ def authorise_and_send(http_method:, command: nil, payload: {}, params: {})
94
+ start_time = micro_second_time_now
95
+
96
+ if params.nil? || params.empty?
97
+ params = {}
98
+ end
99
+
100
+ response = HTTParty.send(
101
+ http_method.to_sym,
102
+ construct_base_path(command, params),
103
+ body: payload,
104
+ headers: {
105
+ 'Content-Type': 'application/json',
106
+ "Accept": 'application/json',
107
+ },
108
+ port: port,
109
+ format: :json,
110
+ follow_redirects: false,
111
+ )
112
+
113
+ end_time = micro_second_time_now
114
+ construct_response_object(response, command, start_time, end_time)
115
+ end
116
+
117
+ def construct_response_object(response, path, start_time, end_time)
118
+ {
119
+ 'body' => parse_body(response, path),
120
+ 'headers' => response.headers,
121
+ 'metadata' => construct_metadata(response, start_time, end_time)
122
+ }
123
+ end
124
+
125
+ def construct_metadata(response, start_time, end_time)
126
+ total_time = end_time - start_time
127
+
128
+ {
129
+ 'start_time' => start_time,
130
+ 'end_time' => end_time,
131
+ 'total_time' => total_time
132
+ }
133
+ end
134
+
135
+ def body_is_present?(response)
136
+ !body_is_missing?(response)
137
+ end
138
+
139
+ def body_is_missing?(response)
140
+ response.body.nil? || response.body.empty?
141
+ end
142
+
143
+ def parse_body(response, path)
144
+ return [] if response.body == "[]"
145
+ parse_json(response) # Purposely not using HTTParty
146
+ end
147
+
148
+ def parse_json(response)
149
+ begin
150
+ JSON.parse(response.body)
151
+ rescue => _e
152
+ response.body
153
+ end
154
+ end
155
+
156
+ def micro_second_time_now
157
+ (Time.now.to_f * 1_000_000).to_i
158
+ end
159
+
160
+ def construct_base_path(command = nil, params)
161
+ if command
162
+ constructed_path = "#{base_path}/#{command}" # TODO: fix command param
163
+ else
164
+ constructed_path = "#{base_path}/"
165
+ end
166
+
167
+ if params != {}
168
+ constructed_path = "#{constructed_path}&#{process_params(params)}"
169
+ end
170
+
171
+ constructed_path.gsub('://', ':///').gsub('//', '/')
172
+ end
173
+
174
+ def process_params(params)
175
+ params.keys.map { |key| "#{key}=#{params[key]}" }.join('&')
176
+ end
177
+
178
+ def process_cursor(cursor, params: {})
179
+ unless cursor.nil? || cursor.empty?
180
+ params['cursor'] = cursor
181
+ end
182
+
183
+ params
184
+ end
185
+ end
186
+ end
@@ -0,0 +1,5 @@
1
+ module BookValue
2
+ module Constants
3
+ BASE_PATH = 'https://book-value.co.za/'
4
+ end
5
+ end
@@ -0,0 +1,3 @@
1
+ module BookValue
2
+ VERSION = '0.0.1'
3
+ end
data/lib/book-value.rb ADDED
@@ -0,0 +1,12 @@
1
+ require 'httparty'
2
+ require 'nokogiri'
3
+
4
+ require 'book-value/version'
5
+ require 'book-value/constants'
6
+
7
+ # Endpoints
8
+ require 'book-value/client'
9
+
10
+ module BookValue
11
+ class Error < StandardError; end
12
+ end
metadata ADDED
@@ -0,0 +1,213 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: book-value
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - trex22
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2023-03-15 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: httparty
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.21.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.21.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: active_attr
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 0.15.4
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 0.15.4
41
+ - !ruby/object:Gem::Dependency
42
+ name: nokogiri
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 1.14.0
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 1.14.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 13.0.6
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 13.0.6
69
+ - !ruby/object:Gem::Dependency
70
+ name: minitest
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 5.17.0
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 5.17.0
83
+ - !ruby/object:Gem::Dependency
84
+ name: minitest-focus
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 1.3.1
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 1.3.1
97
+ - !ruby/object:Gem::Dependency
98
+ name: minitest-reporters
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: 1.5.0
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: 1.5.0
111
+ - !ruby/object:Gem::Dependency
112
+ name: timecop
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: 0.9.6
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: 0.9.6
125
+ - !ruby/object:Gem::Dependency
126
+ name: mocha
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: 2.0.2
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: 2.0.2
139
+ - !ruby/object:Gem::Dependency
140
+ name: pry
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - "~>"
144
+ - !ruby/object:Gem::Version
145
+ version: 0.14.2
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - "~>"
151
+ - !ruby/object:Gem::Version
152
+ version: 0.14.2
153
+ - !ruby/object:Gem::Dependency
154
+ name: webmock
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - "~>"
158
+ - !ruby/object:Gem::Version
159
+ version: 3.18.1
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - "~>"
165
+ - !ruby/object:Gem::Version
166
+ version: 3.18.1
167
+ description: An unofficial client for https://book-value.co.za/.
168
+ email:
169
+ - contact@jasonchalom.com
170
+ executables: []
171
+ extensions: []
172
+ extra_rdoc_files: []
173
+ files:
174
+ - ".gitignore"
175
+ - CODE_OF_CONDUCT.md
176
+ - Gemfile
177
+ - Gemfile.lock
178
+ - LICENSE
179
+ - LICENSE.txt
180
+ - README.md
181
+ - Rakefile
182
+ - bin/console
183
+ - bin/make
184
+ - bin/setup
185
+ - book-value.gemspec
186
+ - lib/book-value.rb
187
+ - lib/book-value/client.rb
188
+ - lib/book-value/constants.rb
189
+ - lib/book-value/version.rb
190
+ homepage: https://github.com/TRex22/book-value
191
+ licenses:
192
+ - MIT
193
+ metadata: {}
194
+ post_install_message:
195
+ rdoc_options: []
196
+ require_paths:
197
+ - lib
198
+ required_ruby_version: !ruby/object:Gem::Requirement
199
+ requirements:
200
+ - - ">="
201
+ - !ruby/object:Gem::Version
202
+ version: '0'
203
+ required_rubygems_version: !ruby/object:Gem::Requirement
204
+ requirements:
205
+ - - ">="
206
+ - !ruby/object:Gem::Version
207
+ version: '0'
208
+ requirements: []
209
+ rubygems_version: 3.3.4
210
+ signing_key:
211
+ specification_version: 4
212
+ summary: An unofficial client for https://book-value.co.za/.
213
+ test_files: []