carsxe 1.0.0
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 +7 -0
- data/CHANGELOG.md +5 -0
- data/CODE_OF_CONDUCT.md +132 -0
- data/LICENSE.txt +21 -0
- data/README.md +297 -0
- data/Rakefile +6 -0
- data/bin/console +11 -0
- data/bin/setup +8 -0
- data/lib/carsxe/carsxe.rb +180 -0
- data/lib/carsxe/types.rb +57 -0
- data/lib/carsxe/version.rb +5 -0
- data/lib/carsxe.rb +2 -0
- data/sig/carsxe.rbs +4 -0
- metadata +62 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 8772fd8486f77ee741efb317c60f082cc17a359772b42a58e8a90268e55f9871
|
|
4
|
+
data.tar.gz: ebb283a4087e486016fa34066cb4949dcee572f4fc3cc08fba81aad032862332
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: ff6a99b04ef27d76cba8170a7ac7537a8e481d0bfdb18ba5622a778a36e4bca1da214e0ccd874971f68c488f1fcb349467ab960f4e69a2b11b2b6c663747022b
|
|
7
|
+
data.tar.gz: 3da21ca1907c4f97d0cbd49e2258dca19d2e455c435c8a83118c07e388ab174cee49725bd22f36ba87f7de2d475cc7f9a66a6defe48a981e86a4bade9285f95b
|
data/CHANGELOG.md
ADDED
data/CODE_OF_CONDUCT.md
ADDED
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
|
2
|
+
|
|
3
|
+
## Our Pledge
|
|
4
|
+
|
|
5
|
+
We as members, contributors, and leaders pledge to make participation in our
|
|
6
|
+
community a harassment-free experience for everyone, regardless of age, body
|
|
7
|
+
size, visible or invisible disability, ethnicity, sex characteristics, gender
|
|
8
|
+
identity and expression, level of experience, education, socio-economic status,
|
|
9
|
+
nationality, personal appearance, race, caste, color, religion, or sexual
|
|
10
|
+
identity and orientation.
|
|
11
|
+
|
|
12
|
+
We pledge to act and interact in ways that contribute to an open, welcoming,
|
|
13
|
+
diverse, inclusive, and healthy community.
|
|
14
|
+
|
|
15
|
+
## Our Standards
|
|
16
|
+
|
|
17
|
+
Examples of behavior that contributes to a positive environment for our
|
|
18
|
+
community include:
|
|
19
|
+
|
|
20
|
+
* Demonstrating empathy and kindness toward other people
|
|
21
|
+
* Being respectful of differing opinions, viewpoints, and experiences
|
|
22
|
+
* Giving and gracefully accepting constructive feedback
|
|
23
|
+
* Accepting responsibility and apologizing to those affected by our mistakes,
|
|
24
|
+
and learning from the experience
|
|
25
|
+
* Focusing on what is best not just for us as individuals, but for the overall
|
|
26
|
+
community
|
|
27
|
+
|
|
28
|
+
Examples of unacceptable behavior include:
|
|
29
|
+
|
|
30
|
+
* The use of sexualized language or imagery, and sexual attention or advances of
|
|
31
|
+
any kind
|
|
32
|
+
* Trolling, insulting or derogatory comments, and personal or political attacks
|
|
33
|
+
* Public or private harassment
|
|
34
|
+
* Publishing others' private information, such as a physical or email address,
|
|
35
|
+
without their explicit permission
|
|
36
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
|
37
|
+
professional setting
|
|
38
|
+
|
|
39
|
+
## Enforcement Responsibilities
|
|
40
|
+
|
|
41
|
+
Community leaders are responsible for clarifying and enforcing our standards of
|
|
42
|
+
acceptable behavior and will take appropriate and fair corrective action in
|
|
43
|
+
response to any behavior that they deem inappropriate, threatening, offensive,
|
|
44
|
+
or harmful.
|
|
45
|
+
|
|
46
|
+
Community leaders have the right and responsibility to remove, edit, or reject
|
|
47
|
+
comments, commits, code, wiki edits, issues, and other contributions that are
|
|
48
|
+
not aligned to this Code of Conduct, and will communicate reasons for moderation
|
|
49
|
+
decisions when appropriate.
|
|
50
|
+
|
|
51
|
+
## Scope
|
|
52
|
+
|
|
53
|
+
This Code of Conduct applies within all community spaces, and also applies when
|
|
54
|
+
an individual is officially representing the community in public spaces.
|
|
55
|
+
Examples of representing our community include using an official email address,
|
|
56
|
+
posting via an official social media account, or acting as an appointed
|
|
57
|
+
representative at an online or offline event.
|
|
58
|
+
|
|
59
|
+
## Enforcement
|
|
60
|
+
|
|
61
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
|
62
|
+
reported to the community leaders responsible for enforcement at
|
|
63
|
+
[INSERT CONTACT METHOD].
|
|
64
|
+
All complaints will be reviewed and investigated promptly and fairly.
|
|
65
|
+
|
|
66
|
+
All community leaders are obligated to respect the privacy and security of the
|
|
67
|
+
reporter of any incident.
|
|
68
|
+
|
|
69
|
+
## Enforcement Guidelines
|
|
70
|
+
|
|
71
|
+
Community leaders will follow these Community Impact Guidelines in determining
|
|
72
|
+
the consequences for any action they deem in violation of this Code of Conduct:
|
|
73
|
+
|
|
74
|
+
### 1. Correction
|
|
75
|
+
|
|
76
|
+
**Community Impact**: Use of inappropriate language or other behavior deemed
|
|
77
|
+
unprofessional or unwelcome in the community.
|
|
78
|
+
|
|
79
|
+
**Consequence**: A private, written warning from community leaders, providing
|
|
80
|
+
clarity around the nature of the violation and an explanation of why the
|
|
81
|
+
behavior was inappropriate. A public apology may be requested.
|
|
82
|
+
|
|
83
|
+
### 2. Warning
|
|
84
|
+
|
|
85
|
+
**Community Impact**: A violation through a single incident or series of
|
|
86
|
+
actions.
|
|
87
|
+
|
|
88
|
+
**Consequence**: A warning with consequences for continued behavior. No
|
|
89
|
+
interaction with the people involved, including unsolicited interaction with
|
|
90
|
+
those enforcing the Code of Conduct, for a specified period of time. This
|
|
91
|
+
includes avoiding interactions in community spaces as well as external channels
|
|
92
|
+
like social media. Violating these terms may lead to a temporary or permanent
|
|
93
|
+
ban.
|
|
94
|
+
|
|
95
|
+
### 3. Temporary Ban
|
|
96
|
+
|
|
97
|
+
**Community Impact**: A serious violation of community standards, including
|
|
98
|
+
sustained inappropriate behavior.
|
|
99
|
+
|
|
100
|
+
**Consequence**: A temporary ban from any sort of interaction or public
|
|
101
|
+
communication with the community for a specified period of time. No public or
|
|
102
|
+
private interaction with the people involved, including unsolicited interaction
|
|
103
|
+
with those enforcing the Code of Conduct, is allowed during this period.
|
|
104
|
+
Violating these terms may lead to a permanent ban.
|
|
105
|
+
|
|
106
|
+
### 4. Permanent Ban
|
|
107
|
+
|
|
108
|
+
**Community Impact**: Demonstrating a pattern of violation of community
|
|
109
|
+
standards, including sustained inappropriate behavior, harassment of an
|
|
110
|
+
individual, or aggression toward or disparagement of classes of individuals.
|
|
111
|
+
|
|
112
|
+
**Consequence**: A permanent ban from any sort of public interaction within the
|
|
113
|
+
community.
|
|
114
|
+
|
|
115
|
+
## Attribution
|
|
116
|
+
|
|
117
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
|
118
|
+
version 2.1, available at
|
|
119
|
+
[https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1].
|
|
120
|
+
|
|
121
|
+
Community Impact Guidelines were inspired by
|
|
122
|
+
[Mozilla's code of conduct enforcement ladder][Mozilla CoC].
|
|
123
|
+
|
|
124
|
+
For answers to common questions about this code of conduct, see the FAQ at
|
|
125
|
+
[https://www.contributor-covenant.org/faq][FAQ]. Translations are available at
|
|
126
|
+
[https://www.contributor-covenant.org/translations][translations].
|
|
127
|
+
|
|
128
|
+
[homepage]: https://www.contributor-covenant.org
|
|
129
|
+
[v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html
|
|
130
|
+
[Mozilla CoC]: https://github.com/mozilla/diversity
|
|
131
|
+
[FAQ]: https://www.contributor-covenant.org/faq
|
|
132
|
+
[translations]: https://www.contributor-covenant.org/translations
|
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 CarsXE
|
|
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/README.md
ADDED
|
@@ -0,0 +1,297 @@
|
|
|
1
|
+
# 🚗 CarsXE API (Ruby Gem)
|
|
2
|
+
|
|
3
|
+
[](https://rubygems.org/gems/carsxe)
|
|
4
|
+
|
|
5
|
+
**CarsXE** is a powerful and developer-friendly API that gives you instant access to a wide range of vehicle data. From VIN decoding and market value estimation to vehicle history, images, OBD code explanations, and plate recognition, CarsXE provides everything you need to build automotive applications at scale.
|
|
6
|
+
|
|
7
|
+
🌐 **Website:** [https://api.carsxe.com](https://api.carsxe.com)
|
|
8
|
+
📄 **Docs:** [https://api.carsxe.com/docs](https://api.carsxe.com/docs)
|
|
9
|
+
📦 **All Products:** [https://api.carsxe.com/all-products](https://api.carsxe.com/all-products)
|
|
10
|
+
|
|
11
|
+
To get started with the CarsXE API, follow these steps:
|
|
12
|
+
|
|
13
|
+
1. **Sign up for a CarsXE account:**
|
|
14
|
+
|
|
15
|
+
- [Register here](https://api.carsxe.com/register)
|
|
16
|
+
- Add a [payment method](https://api.carsxe.com/dashboard/billing#payment-methods) to activate your subscription and get your API key.
|
|
17
|
+
|
|
18
|
+
2. **Install the CarsXE Ruby gem:**
|
|
19
|
+
|
|
20
|
+
Run this command in your terminal:
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
gem install carsxe
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
Or add it to your Gemfile:
|
|
27
|
+
|
|
28
|
+
```ruby
|
|
29
|
+
gem 'carsxe'
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
Then run `bundle install`.
|
|
33
|
+
|
|
34
|
+
3. **Require the CarsXE API in your code:**
|
|
35
|
+
|
|
36
|
+
```ruby
|
|
37
|
+
require 'carsxe'
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
4. **Initialize the API with your API key:**
|
|
41
|
+
|
|
42
|
+
```ruby
|
|
43
|
+
API_KEY = 'YOUR_API_KEY'
|
|
44
|
+
carsxe = Carsxe::CarsXE.new(api_key: API_KEY)
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
5. **Use the various endpoint methods provided by the API to access the data you need.**
|
|
48
|
+
|
|
49
|
+
## Usage
|
|
50
|
+
|
|
51
|
+
```ruby
|
|
52
|
+
vin = 'WBAFR7C57CC811956'
|
|
53
|
+
|
|
54
|
+
begin
|
|
55
|
+
vehicle = carsxe.specs('vin' => vin)
|
|
56
|
+
puts vehicle['input']['vin']
|
|
57
|
+
rescue StandardError => error
|
|
58
|
+
puts "Error: #{error.message}"
|
|
59
|
+
end
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
---
|
|
63
|
+
|
|
64
|
+
## 📚 Endpoints
|
|
65
|
+
|
|
66
|
+
The CarsXE API provides the following endpoint methods:
|
|
67
|
+
|
|
68
|
+
### `specs` – Decode VIN & get full vehicle specifications
|
|
69
|
+
|
|
70
|
+
**Required:**
|
|
71
|
+
|
|
72
|
+
- `vin`
|
|
73
|
+
|
|
74
|
+
**Optional:**
|
|
75
|
+
|
|
76
|
+
- `deepdata`
|
|
77
|
+
- `disableIntVINDecoding`
|
|
78
|
+
|
|
79
|
+
**Example:**
|
|
80
|
+
|
|
81
|
+
```ruby
|
|
82
|
+
vehicle = carsxe.specs('vin' => 'WBAFR7C57CC811956')
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
---
|
|
86
|
+
|
|
87
|
+
### `int_vin_decoder` – Decode VIN with worldwide support
|
|
88
|
+
|
|
89
|
+
**Required:**
|
|
90
|
+
|
|
91
|
+
- `vin`
|
|
92
|
+
|
|
93
|
+
**Optional:**
|
|
94
|
+
|
|
95
|
+
- None
|
|
96
|
+
|
|
97
|
+
**Example:**
|
|
98
|
+
|
|
99
|
+
```ruby
|
|
100
|
+
intvin = carsxe.int_vin_decoder('vin' => 'WF0MXXGBWM8R43240')
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
---
|
|
104
|
+
|
|
105
|
+
### `plate_decoder` – Decode license plate info (plate, country)
|
|
106
|
+
|
|
107
|
+
**Required:**
|
|
108
|
+
|
|
109
|
+
- `plate`
|
|
110
|
+
- `country` (always required except for US, where it is optional and defaults to 'US')
|
|
111
|
+
|
|
112
|
+
**Optional:**
|
|
113
|
+
|
|
114
|
+
- `state` (required for some countries, e.g. US, AU, CA)
|
|
115
|
+
- `district` (required for Pakistan)
|
|
116
|
+
|
|
117
|
+
> **Note:**
|
|
118
|
+
>
|
|
119
|
+
> - The `state` parameter is required only when applicable (for
|
|
120
|
+
> specific countries such as US, AU, CA, etc.).
|
|
121
|
+
> - For Pakistan (`country='pk'`), both `state` and `district`
|
|
122
|
+
> are required.
|
|
123
|
+
|
|
124
|
+
**Example:**
|
|
125
|
+
|
|
126
|
+
```ruby
|
|
127
|
+
decoded_plate = carsxe.plate_decoder('plate' => '7XER187', 'state' => 'CA', 'country' => 'US')
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
---
|
|
131
|
+
|
|
132
|
+
### `market_value` – Estimate vehicle market value based on VIN
|
|
133
|
+
|
|
134
|
+
**Required:**
|
|
135
|
+
|
|
136
|
+
- `vin`
|
|
137
|
+
|
|
138
|
+
**Optional:**
|
|
139
|
+
|
|
140
|
+
- `state`
|
|
141
|
+
|
|
142
|
+
**Example:**
|
|
143
|
+
|
|
144
|
+
```ruby
|
|
145
|
+
marketvalue = carsxe.market_value('vin' => 'WBAFR7C57CC811956')
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
---
|
|
149
|
+
|
|
150
|
+
### `history` – Retrieve vehicle history
|
|
151
|
+
|
|
152
|
+
**Required:**
|
|
153
|
+
|
|
154
|
+
- `vin`
|
|
155
|
+
|
|
156
|
+
**Optional:**
|
|
157
|
+
|
|
158
|
+
- None
|
|
159
|
+
|
|
160
|
+
**Example:**
|
|
161
|
+
|
|
162
|
+
```ruby
|
|
163
|
+
history = carsxe.history('vin' => 'WBAFR7C57CC811956')
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
---
|
|
167
|
+
|
|
168
|
+
### `images` – Fetch images by make, model, year, trim
|
|
169
|
+
|
|
170
|
+
**Required:**
|
|
171
|
+
|
|
172
|
+
- `make`
|
|
173
|
+
- `model`
|
|
174
|
+
|
|
175
|
+
**Optional:**
|
|
176
|
+
|
|
177
|
+
- `year`
|
|
178
|
+
- `trim`
|
|
179
|
+
- `color`
|
|
180
|
+
- `transparent`
|
|
181
|
+
- `angle`
|
|
182
|
+
- `photoType`
|
|
183
|
+
- `size`
|
|
184
|
+
- `license`
|
|
185
|
+
|
|
186
|
+
**Example:**
|
|
187
|
+
|
|
188
|
+
```ruby
|
|
189
|
+
images = carsxe.images('make' => 'BMW', 'model' => 'X5', 'year' => '2019')
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
---
|
|
193
|
+
|
|
194
|
+
### `recalls` – Get safety recall data for a VIN
|
|
195
|
+
|
|
196
|
+
**Required:**
|
|
197
|
+
|
|
198
|
+
- `vin`
|
|
199
|
+
|
|
200
|
+
**Optional:**
|
|
201
|
+
|
|
202
|
+
- None
|
|
203
|
+
|
|
204
|
+
**Example:**
|
|
205
|
+
|
|
206
|
+
```ruby
|
|
207
|
+
recalls = carsxe.recalls('vin' => '1C4JJXR64PW696340')
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
---
|
|
211
|
+
|
|
212
|
+
### `plate_image_recognition` – Read & decode plates from images
|
|
213
|
+
|
|
214
|
+
**Required:**
|
|
215
|
+
|
|
216
|
+
- `upload_url`
|
|
217
|
+
|
|
218
|
+
**Optional:**
|
|
219
|
+
|
|
220
|
+
- None
|
|
221
|
+
|
|
222
|
+
**Example:**
|
|
223
|
+
|
|
224
|
+
```ruby
|
|
225
|
+
plateimg = carsxe.plate_image_recognition('upload_url' => 'https://api.carsxe.com/img/apis/plate_recognition.JPG')
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
---
|
|
229
|
+
|
|
230
|
+
### `vin_ocr` – Extract VINs from images using OCR
|
|
231
|
+
|
|
232
|
+
**Required:**
|
|
233
|
+
|
|
234
|
+
- `upload_url`
|
|
235
|
+
|
|
236
|
+
**Optional:**
|
|
237
|
+
|
|
238
|
+
- None
|
|
239
|
+
|
|
240
|
+
**Example:**
|
|
241
|
+
|
|
242
|
+
```ruby
|
|
243
|
+
vinocr = carsxe.vin_ocr('upload_url' => 'https://api.carsxe.com/img/apis/plate_recognition.JPG')
|
|
244
|
+
```
|
|
245
|
+
|
|
246
|
+
---
|
|
247
|
+
|
|
248
|
+
### `year_make_model` – Query vehicle by year, make, model and trim (optional)
|
|
249
|
+
|
|
250
|
+
**Required:**
|
|
251
|
+
|
|
252
|
+
- `year`
|
|
253
|
+
- `make`
|
|
254
|
+
- `model`
|
|
255
|
+
|
|
256
|
+
**Optional:**
|
|
257
|
+
|
|
258
|
+
- `trim`
|
|
259
|
+
|
|
260
|
+
**Example:**
|
|
261
|
+
|
|
262
|
+
```ruby
|
|
263
|
+
yymm = carsxe.year_make_model('year' => '2012', 'make' => 'BMW', 'model' => '5 Series')
|
|
264
|
+
```
|
|
265
|
+
|
|
266
|
+
---
|
|
267
|
+
|
|
268
|
+
### `obd_codes_decoder` – Decode OBD error/diagnostic codes
|
|
269
|
+
|
|
270
|
+
**Required:**
|
|
271
|
+
|
|
272
|
+
- `code`
|
|
273
|
+
|
|
274
|
+
**Optional:**
|
|
275
|
+
|
|
276
|
+
- None
|
|
277
|
+
|
|
278
|
+
**Example:**
|
|
279
|
+
|
|
280
|
+
```ruby
|
|
281
|
+
obdcode = carsxe.obd_codes_decoder('code' => 'P0115')
|
|
282
|
+
```
|
|
283
|
+
|
|
284
|
+
---
|
|
285
|
+
|
|
286
|
+
## Notes & Best Practices
|
|
287
|
+
|
|
288
|
+
- **Parameter requirements:** Each endpoint requires specific parameters—see the Required/Optional fields above.
|
|
289
|
+
- **Return values:** All responses are Ruby hashes for easy access and manipulation.
|
|
290
|
+
- **Error handling:** Use begin/rescue blocks to gracefully handle API errors.
|
|
291
|
+
- **More info:** For advanced usage and full details, visit the [official API documentation](https://api.carsxe.com/docs).
|
|
292
|
+
|
|
293
|
+
---
|
|
294
|
+
|
|
295
|
+
## Overall
|
|
296
|
+
|
|
297
|
+
CarsXE API provides a wide range of powerful, easy-to-use tools for accessing and integrating vehicle data into your applications and services. Whether you're a developer or a business owner, you can quickly get the information you need to take your projects to the next level—without hassle or inconvenience.
|
data/Rakefile
ADDED
data/bin/console
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
require "bundler/setup"
|
|
5
|
+
require "carsxe"
|
|
6
|
+
|
|
7
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
|
8
|
+
# with your gem easier. You can also use a different console, if you like.
|
|
9
|
+
|
|
10
|
+
require "irb"
|
|
11
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "net/http"
|
|
4
|
+
require "uri"
|
|
5
|
+
require "json"
|
|
6
|
+
require_relative "types"
|
|
7
|
+
|
|
8
|
+
module Carsxe
|
|
9
|
+
class CarsXE
|
|
10
|
+
include Types
|
|
11
|
+
|
|
12
|
+
def initialize(api_key:)
|
|
13
|
+
@api_key = api_key
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
attr_reader :api_key
|
|
17
|
+
|
|
18
|
+
def api_base_url
|
|
19
|
+
"https://api.carsxe.com"
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
# Public API methods (mirror the python template)
|
|
23
|
+
def specs(params = {})
|
|
24
|
+
get("specs", params, Types::SPECS_INPUT)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def int_vin_decoder(params = {})
|
|
28
|
+
get("v1/international-vin-decoder", params, Types::VIN_INPUT)
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def recalls(params = {})
|
|
32
|
+
get("v1/recalls", params, Types::VIN_INPUT)
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def plate_decoder(params = {})
|
|
36
|
+
# default country to US if not provided (matches Python template)
|
|
37
|
+
params = params.dup
|
|
38
|
+
params["country"] = "US" if params["country"].nil? || params["country"] == ""
|
|
39
|
+
get("v2/platedecoder", params, Types::PLATE_DECODER_PARAMS)
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def images(params = {})
|
|
43
|
+
get("images", params, Types::IMAGE_INPUT)
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def market_value(params = {})
|
|
47
|
+
# market_value: same required params as VIN_INPUT but 'state' is allowed optional
|
|
48
|
+
required, optional = required_optional(Types::VIN_INPUT, params)
|
|
49
|
+
optional |= ["state"]
|
|
50
|
+
url, query = build_url("v2/marketvalue", params, required, optional)
|
|
51
|
+
perform_get(url, query)
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def history(params = {})
|
|
55
|
+
get("history", params, Types::VIN_INPUT)
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def plate_image_recognition(params = {})
|
|
59
|
+
url = "#{api_base_url}/platerecognition?key=#{api_key}&source=ruby"
|
|
60
|
+
if params.size == 1
|
|
61
|
+
first_key, first_value = params.first
|
|
62
|
+
post_json(url, { first_key => first_value })
|
|
63
|
+
else
|
|
64
|
+
raise ArgumentError, "Expected exactly one parameter, but got #{params.size}"
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def vin_ocr(params = {})
|
|
69
|
+
url = "#{api_base_url}/v1/vinocr?key=#{api_key}&source=ruby"
|
|
70
|
+
if params.size == 1
|
|
71
|
+
first_key, first_value = params.first
|
|
72
|
+
post_json(url, { first_key => first_value })
|
|
73
|
+
else
|
|
74
|
+
raise ArgumentError, "Expected exactly one parameter, but got #{params.size}"
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
def year_make_model(params = {})
|
|
79
|
+
get("v1/ymm", params, Types::YEAR_MAKE_MODEL_INPUT)
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
def obd_codes_decoder(params = {})
|
|
83
|
+
get("obdcodesdecoder", params, Types::OBDCODESDECODER_INPUT)
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
private
|
|
87
|
+
|
|
88
|
+
# Determine required and optional keys from a param definition hash.
|
|
89
|
+
# Also applies special plate/country logic:
|
|
90
|
+
# - If country is 'PK' (Pakistan), both 'state' and 'district' are required.
|
|
91
|
+
# - Otherwise ensure 'state' is required for plate decoder (mirrors Python behavior).
|
|
92
|
+
def required_optional(param_def, params = nil)
|
|
93
|
+
required = param_def.select { |_k, v| v == :required }.keys.map(&:to_s)
|
|
94
|
+
optional = param_def.select { |_k, v| v == :optional }.keys.map(&:to_s)
|
|
95
|
+
|
|
96
|
+
# Special case for plate decoder params
|
|
97
|
+
if param_def.equal?(Types::PLATE_DECODER_PARAMS)
|
|
98
|
+
country = if params && params["country"]
|
|
99
|
+
params["country"].to_s.downcase
|
|
100
|
+
else
|
|
101
|
+
"us"
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
if country == "pk" || country == "pakistan"
|
|
105
|
+
required |= ["state", "district"]
|
|
106
|
+
optional -= ["state", "district"]
|
|
107
|
+
else
|
|
108
|
+
# ensure 'state' is required for non-PK
|
|
109
|
+
required |= ["state"]
|
|
110
|
+
optional -= ["state"]
|
|
111
|
+
end
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
# If params is provided, check all required keys exist and are non-nil
|
|
115
|
+
if params
|
|
116
|
+
missing = required.reject { |k| params.key?(k) && !params[k].nil? }
|
|
117
|
+
unless missing.empty?
|
|
118
|
+
raise ArgumentError, "Missing required parameter(s): #{missing.join(', ')}"
|
|
119
|
+
end
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
[required, optional]
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
# Build url (string) and query hash for GET requests
|
|
126
|
+
def build_url(endpoint, params, required, optional)
|
|
127
|
+
permitted = (required + optional).map(&:to_s)
|
|
128
|
+
query = {}
|
|
129
|
+
|
|
130
|
+
params.each do |k, v|
|
|
131
|
+
key = k.to_s
|
|
132
|
+
next unless permitted.include?(key)
|
|
133
|
+
next if v.nil?
|
|
134
|
+
|
|
135
|
+
query[key] = v
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
query["key"] = api_key
|
|
139
|
+
query["source"] = "ruby"
|
|
140
|
+
["#{api_base_url}/#{endpoint}", query]
|
|
141
|
+
end
|
|
142
|
+
|
|
143
|
+
# Generic GET path that validates params using the param_def.
|
|
144
|
+
def get(endpoint, params, param_def)
|
|
145
|
+
required, optional = required_optional(param_def, params)
|
|
146
|
+
url, query = build_url(endpoint, params, required, optional)
|
|
147
|
+
perform_get(url, query)
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
# Low-level HTTP get helper
|
|
151
|
+
def perform_get(url_str, query = {})
|
|
152
|
+
uri = URI(url_str)
|
|
153
|
+
uri.query = URI.encode_www_form(query) unless query.empty?
|
|
154
|
+
|
|
155
|
+
response = Net::HTTP.start(uri.host, uri.port, use_ssl: uri.scheme == "https") do |http|
|
|
156
|
+
req = Net::HTTP::Get.new(uri)
|
|
157
|
+
http.request(req)
|
|
158
|
+
end
|
|
159
|
+
|
|
160
|
+
parse_response(response)
|
|
161
|
+
end
|
|
162
|
+
|
|
163
|
+
def post_json(url_str, payload = {})
|
|
164
|
+
uri = URI(url_str)
|
|
165
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
|
166
|
+
http.use_ssl = uri.scheme == "https"
|
|
167
|
+
req = Net::HTTP::Post.new(uri)
|
|
168
|
+
req["Content-Type"] = "application/json"
|
|
169
|
+
req.body = payload.to_json
|
|
170
|
+
response = http.request(req)
|
|
171
|
+
parse_response(response)
|
|
172
|
+
end
|
|
173
|
+
|
|
174
|
+
def parse_response(response)
|
|
175
|
+
body = response.body.to_s
|
|
176
|
+
parsed=JSON.parse(body)
|
|
177
|
+
parsed
|
|
178
|
+
end
|
|
179
|
+
end
|
|
180
|
+
end
|
data/lib/carsxe/types.rb
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
#
|
|
3
|
+
# Parameter "schemas" used by the client to determine required vs optional keys.
|
|
4
|
+
# Values are :required or :optional (simple representation, enough for validation here).
|
|
5
|
+
|
|
6
|
+
module Carsxe
|
|
7
|
+
module Types
|
|
8
|
+
VIN_INPUT = {
|
|
9
|
+
"vin" => :required
|
|
10
|
+
}.freeze
|
|
11
|
+
|
|
12
|
+
PLATE_DECODER_PARAMS = {
|
|
13
|
+
"plate" => :required,
|
|
14
|
+
"country" => :optional, # country is allowed but not strictly required by default
|
|
15
|
+
"state" => :optional,
|
|
16
|
+
"district" => :optional
|
|
17
|
+
}.freeze
|
|
18
|
+
|
|
19
|
+
IMAGE_INPUT = {
|
|
20
|
+
"make" => :required,
|
|
21
|
+
"model" => :required,
|
|
22
|
+
"year" => :optional,
|
|
23
|
+
"trim" => :optional,
|
|
24
|
+
"color" => :optional,
|
|
25
|
+
"transparent" => :optional,
|
|
26
|
+
"angle" => :optional,
|
|
27
|
+
"photoType" => :optional,
|
|
28
|
+
"size" => :optional,
|
|
29
|
+
"license" => :optional
|
|
30
|
+
}.freeze
|
|
31
|
+
|
|
32
|
+
OBDCODESDECODER_INPUT = {
|
|
33
|
+
"code" => :required
|
|
34
|
+
}.freeze
|
|
35
|
+
|
|
36
|
+
PLATE_IMAGE_RECOGNITION_INPUT = {
|
|
37
|
+
"upload_url" => :required
|
|
38
|
+
}.freeze
|
|
39
|
+
|
|
40
|
+
VIN_OCR_INPUT = {
|
|
41
|
+
"upload_url" => :required
|
|
42
|
+
}.freeze
|
|
43
|
+
|
|
44
|
+
YEAR_MAKE_MODEL_INPUT = {
|
|
45
|
+
"year" => :required,
|
|
46
|
+
"make" => :required,
|
|
47
|
+
"model" => :required,
|
|
48
|
+
"trim" => :optional
|
|
49
|
+
}.freeze
|
|
50
|
+
|
|
51
|
+
SPECS_INPUT = {
|
|
52
|
+
"vin" => :required,
|
|
53
|
+
"deepData" => :optional,
|
|
54
|
+
"disableIntVINDecoding" => :optional
|
|
55
|
+
}.freeze
|
|
56
|
+
end
|
|
57
|
+
end
|
data/lib/carsxe.rb
ADDED
data/sig/carsxe.rbs
ADDED
metadata
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: carsxe
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 1.0.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- CarsXE Developer
|
|
8
|
+
- Omar Welied
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
12
|
+
dependencies: []
|
|
13
|
+
description: CarsXE Ruby gem provides a simple and efficient way to interact with
|
|
14
|
+
CarsXE APIs, enabling developers to integrate vehicle data and services into their
|
|
15
|
+
applications.
|
|
16
|
+
email:
|
|
17
|
+
- devops@carsxe.com
|
|
18
|
+
- omar.walied@carsxe.com
|
|
19
|
+
executables:
|
|
20
|
+
- console
|
|
21
|
+
- setup
|
|
22
|
+
extensions: []
|
|
23
|
+
extra_rdoc_files: []
|
|
24
|
+
files:
|
|
25
|
+
- CHANGELOG.md
|
|
26
|
+
- CODE_OF_CONDUCT.md
|
|
27
|
+
- LICENSE.txt
|
|
28
|
+
- README.md
|
|
29
|
+
- Rakefile
|
|
30
|
+
- bin/console
|
|
31
|
+
- bin/setup
|
|
32
|
+
- lib/carsxe.rb
|
|
33
|
+
- lib/carsxe/carsxe.rb
|
|
34
|
+
- lib/carsxe/types.rb
|
|
35
|
+
- lib/carsxe/version.rb
|
|
36
|
+
- sig/carsxe.rbs
|
|
37
|
+
homepage: https://github.com/carsxe/carsxe-ruby-package
|
|
38
|
+
licenses:
|
|
39
|
+
- MIT
|
|
40
|
+
metadata:
|
|
41
|
+
allowed_push_host: https://rubygems.org
|
|
42
|
+
homepage_uri: https://github.com/carsxe/carsxe-ruby-package
|
|
43
|
+
source_code_uri: https://github.com/carsxe/carsxe-ruby-package
|
|
44
|
+
changelog_uri: https://github.com/carsxe/carsxe-ruby-package/blob/main/CHANGELOG.md
|
|
45
|
+
rdoc_options: []
|
|
46
|
+
require_paths:
|
|
47
|
+
- lib
|
|
48
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
49
|
+
requirements:
|
|
50
|
+
- - ">="
|
|
51
|
+
- !ruby/object:Gem::Version
|
|
52
|
+
version: 3.2.0
|
|
53
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
54
|
+
requirements:
|
|
55
|
+
- - ">="
|
|
56
|
+
- !ruby/object:Gem::Version
|
|
57
|
+
version: '0'
|
|
58
|
+
requirements: []
|
|
59
|
+
rubygems_version: 3.6.9
|
|
60
|
+
specification_version: 4
|
|
61
|
+
summary: A Ruby gem for interacting with CarsXE APIs.
|
|
62
|
+
test_files: []
|