edmunds_ruby 1.0.1 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +101 -5
- data/lib/edmunds/photo.rb +43 -3
- metadata +13 -21
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 5cfe4a81f60a0f4d6c32231a9853893e7c540a9e
|
4
|
+
data.tar.gz: fb5d4063730aa7808cefbaf14a91a20cd2ed2b07
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d89114a9c780f6ec0eb5868487367e57ed360e4aaf674365462d6ff41f58af415e2bbbdc3b6ea99b20f96cdb1655fe8baa4b13ddf7dd3d49704e7260a820e618
|
7
|
+
data.tar.gz: 6e230a877f3383ef13ba80d7c85f36d59c9740192958d19bdb9178c4157d06798eaceeb5c0bd11e227c05dfa8955cdbc70d9d5f3258c5b41b43ff0e47351b339
|
data/README.md
CHANGED
@@ -1,9 +1,8 @@
|
|
1
|
-
## Ruby wrapper for the Edmunds
|
1
|
+
## Ruby wrapper for the Edmunds Vehicle API (V1)
|
2
2
|
|
3
3
|
This API wrapper will allow you to make calls to the Edmunds Vehicle API to get detailed information about nearly any make, model, and style (trim).
|
4
4
|
You can also get production images for each vehicle.
|
5
5
|
|
6
|
-
|
7
6
|
## Setup:
|
8
7
|
|
9
8
|
First, include the gem in your Gemfile:
|
@@ -28,7 +27,7 @@ You will need to create an account with Edmunds and get a free developer Vehicle
|
|
28
27
|
|
29
28
|
Once you get your API key, either create an initializer file to place it in OR add it to your .bashrc script
|
30
29
|
|
31
|
-
####
|
30
|
+
#### option 1 - put api key in an initializer file:
|
32
31
|
|
33
32
|
Create a new file in config/initializers called edmunds.rb, like so:
|
34
33
|
|
@@ -41,7 +40,7 @@ Add this line, with your api key:
|
|
41
40
|
Save the file and exit.
|
42
41
|
|
43
42
|
|
44
|
-
####
|
43
|
+
#### option 2 - put api key in your .bashrc script:
|
45
44
|
|
46
45
|
Open .bashrc file:
|
47
46
|
|
@@ -57,6 +56,14 @@ Save and close the file, then source the file to make the changes take effect:
|
|
57
56
|
|
58
57
|
Now you can use the Vehicle API as you like.
|
59
58
|
|
59
|
+
### Verify API key:
|
60
|
+
|
61
|
+
Open a console and try this:
|
62
|
+
|
63
|
+
Edmunds::API.new.api_key
|
64
|
+
|
65
|
+
You should see your API key returned... if not, go back to the above steps and verify that you have it in an initializer or your bashrc script as described.
|
66
|
+
|
60
67
|
|
61
68
|
## Usage:
|
62
69
|
|
@@ -75,9 +82,98 @@ For the Model class, you will have to provide an id first (which you can get fro
|
|
75
82
|
m = Edmunds::Model.new
|
76
83
|
m.find_by_id("Lamborghini_Diablo")
|
77
84
|
|
85
|
+
## Here is a complete list of available methods:
|
78
86
|
|
79
|
-
|
87
|
+
The method descriptions were pulled from the Edmunds API documentation.
|
88
|
+
|
89
|
+
http://developer.edmunds.com/docs/read/Home
|
90
|
+
|
91
|
+
The method names in this wrapper were kept as close to the original Edmunds API method names as possible, to avoid confusion.
|
92
|
+
|
93
|
+
While I plan on wrapping the entire Vehicle API, I currently only have the Make, Model, ModelYear, Style, and Photo methods covered.
|
94
|
+
|
95
|
+
#### Edmunds::Make.new
|
96
|
+
|
97
|
+
http://developer.edmunds.com/docs/read/the_vehicle_api/Make_Repository
|
98
|
+
|
99
|
+
find_all # Get the list of all makes and their all their models
|
100
|
+
find_by_id(make_id) # Find a make and its models by providing a make ID
|
101
|
+
find_future_makes # Find all future makes and their models
|
102
|
+
find_make_by_name(name) # Find a make details by its name
|
103
|
+
find_makes_by_model_year(model_year) # Find a make by a year
|
104
|
+
find_makes_by_publication_state(state) # Find makes by their state (new or used)
|
105
|
+
find_new_and_used # Find all new and used makes
|
106
|
+
find_new_and_used_makes_by_model_year(model_year) # Find all new and used makes for a particular year
|
107
|
+
find_new_makes # Find only new makes
|
108
|
+
find_used_makes # Find only old makes
|
109
|
+
|
110
|
+
#### Edmunds::Model.new
|
111
|
+
|
112
|
+
http://developer.edmunds.com/docs/read/the_vehicle_api/Model_Repository
|
113
|
+
|
114
|
+
find_by_id(model_id) # Get a vehicle's model details by the model ID
|
115
|
+
find_by_make_id(make_id) # Get a vehicle's model details by the make ID
|
116
|
+
find_future_models_by_make_id(make_id) # Get a list of all future models by the make ID
|
117
|
+
find_model_by_make_model_name(make, model) # Get a vehicle model by the make and model names
|
118
|
+
find_models_by_make(make) # Get a list of models by the make name
|
119
|
+
find_models_by_make_and_publication_state(make, state) # Get a list of models by the make name and the publication state
|
120
|
+
find_models_by_make_and_year(make, year) # Get a list of models by the make name and year
|
121
|
+
find_new_and_used_models_by_make_id(make_id) # Get a list of new and used models by the make ID
|
122
|
+
find_new_models_by_make_id(make_id) # Get a list of new models by the make ID
|
123
|
+
find_used_models_by_make_id(make_id) # Get a list of used models by the make ID
|
124
|
+
|
125
|
+
#### Edmunds::ModelYear.new
|
126
|
+
|
127
|
+
http://developer.edmunds.com/docs/read/the_vehicle_api/Year_Repository
|
80
128
|
|
129
|
+
find_by_id(model_year_id) # Get details on a specifc vehicle by its model year ID
|
130
|
+
find_distinct_year_with_new # Get a list of years under which there are new vehicle listings
|
131
|
+
find_distinct_year_with_new_or_used # Get a list of years under which there are new or used vehicle listings
|
132
|
+
find_distinct_year_with_used # Get a list of years under which there are used vehicle listings
|
133
|
+
find_future_model_years_by_model_id(model_id) # Get a list of future model years by the model ID
|
134
|
+
find_model_years_by_make_and_year(make, year) # Get a list of model years for a specific make and year
|
135
|
+
find_model_years_by_make_model(make, model) # Get a list of model years for a specific make and model
|
136
|
+
find_new_and_used_model_years_by_make_id_and_year(make_id, year) # Get a list of new and used model years for a specific make ID and year
|
137
|
+
find_new_model_years_by_model_id(model_id) # Get a list of new model years by the model ID
|
138
|
+
find_used_model_years_by_model_id(model_id) # Get a list of used model years by the model ID
|
139
|
+
find_years_by_category_and_publication_state(category, state) # Get a list of model years for a specific category and publication state
|
140
|
+
for_model_id(model_id) # Get a list of model years by the model ID
|
141
|
+
for_year_make_model(year, make, model) # Get a list of model years for a specific make, model and year
|
142
|
+
|
143
|
+
#### Edmunds::Style.new
|
144
|
+
|
145
|
+
http://developer.edmunds.com/docs/read/the_vehicle_api/Style_Repository
|
146
|
+
|
147
|
+
find_by_id(style_id) # Get a style details by the style ID
|
148
|
+
find_styles_by_make_model_year(make, model, year) # Get a list of styles by make, model and year
|
149
|
+
find_styles_by_model_year_id(model_year_id) # Get a list of styles by model year ID
|
150
|
+
|
151
|
+
#### Edmunds::Photo.new
|
152
|
+
|
153
|
+
http://developer.edmunds.com/docs/read/the_vehicle_api/Photos
|
154
|
+
|
155
|
+
find_by_style_id(style_id) # Get an array of photo detail objects for a particular vehicle style
|
156
|
+
find_sample_by_style_id(style_id) # Get a sample photo url for a particular vehicle style - tries to get a exterior front view image if available.
|
157
|
+
|
158
|
+
Note that the image arrays returned by the find_photos_by_style_id() method return an array of image links that will still need the base url attached to them in order to view the image.
|
159
|
+
|
160
|
+
The image base url can be accessed from any of the classes, for instance these all return the same image base url:
|
161
|
+
|
162
|
+
Edmunds::API.new.image_base_url
|
163
|
+
Edmunds::Make.new.image_base_url
|
164
|
+
Edmunds::Photo.new.image_base_url
|
165
|
+
|
166
|
+
or if you set the new instance to a variable:
|
167
|
+
|
168
|
+
p = Edmunds::Photo.new
|
169
|
+
p.image_base_url
|
170
|
+
|
171
|
+
Will both return the base url (url prefix) that must be prepended to the links returned by the Photo API method.
|
172
|
+
|
173
|
+
With this in mind, I added that last photo method to grab a sample url for an image of any style, then go ahead and add the image base url to the beginning, thus making a valid url that you can click on to see the image... it is not listed as an Edmunds API method, but I found it useful.
|
174
|
+
|
175
|
+
|
176
|
+
More documentation on the way...
|
81
177
|
|
82
178
|
## Bug reports and Pull requests
|
83
179
|
|
data/lib/edmunds/photo.rb
CHANGED
@@ -11,12 +11,52 @@ module Edmunds
|
|
11
11
|
# get the array of images, then sample one image from the group of exterior and front quarter panel (FQ) shots, then go ahead and append the base url so you can view the image directly.
|
12
12
|
# if no sample is found, just return the entire array.
|
13
13
|
def find_sample_by_style_id(style_id)
|
14
|
-
|
15
|
-
|
16
|
-
|
14
|
+
if style_id.is_a?(Array)
|
15
|
+
style_id.each do |id|
|
16
|
+
fetch_image_groups(id)
|
17
|
+
break if @json.present?
|
18
|
+
end
|
19
|
+
else
|
20
|
+
fetch_image_groups(style_id)
|
21
|
+
end
|
22
|
+
select_group
|
23
|
+
concatenate
|
17
24
|
rescue
|
18
25
|
@json
|
19
26
|
end
|
20
27
|
|
28
|
+
private
|
29
|
+
|
30
|
+
def fetch_image_groups(style_id)
|
31
|
+
@url = "photo/service/findphotosbystyleid?styleId=#{style_id}&"
|
32
|
+
call_api
|
33
|
+
end
|
34
|
+
|
35
|
+
def select_group
|
36
|
+
exterior = @json.select{|s| s["subType"] == "exterior" }
|
37
|
+
if exterior.present?
|
38
|
+
# first try to get a front quarter panel shot "FQ"
|
39
|
+
preferred = exterior.select{|s| s["shotTypeAbbreviation"] == "FQ" }
|
40
|
+
# if not available try to get any quarter panel shot "Q"
|
41
|
+
preferred = exterior.select{|s| s["shotTypeAbbreviation"].match(/Q/) } unless preferred.present?
|
42
|
+
# if not available try to get a front shot "F"
|
43
|
+
preferred = exterior.select{|s| s["shotTypeAbbreviation"] == "F" } unless preferred.present?
|
44
|
+
# if not available try to get a side shot "S"
|
45
|
+
preferred = exterior.select{|s| s["shotTypeAbbreviation"] == "S" } unless preferred.present?
|
46
|
+
if preferred.present?
|
47
|
+
selected = preferred.first
|
48
|
+
else
|
49
|
+
selected = exterior.first
|
50
|
+
end
|
51
|
+
else
|
52
|
+
selected = @json.first
|
53
|
+
end
|
54
|
+
@sample = selected["photoSrcs"].select{|s| s.match(/\d{3}(.jpg)/) }.max
|
55
|
+
end
|
56
|
+
|
57
|
+
def concatenate
|
58
|
+
@image = @image_base_url + @sample
|
59
|
+
end
|
60
|
+
|
21
61
|
end
|
22
62
|
end
|
metadata
CHANGED
@@ -1,62 +1,55 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: edmunds_ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
5
|
-
prerelease:
|
4
|
+
version: 1.0.2
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- JD Warren
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date: 2013-
|
11
|
+
date: 2013-08-05 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: rails
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
|
-
- -
|
17
|
+
- - '>='
|
20
18
|
- !ruby/object:Gem::Version
|
21
19
|
version: '0'
|
22
20
|
type: :runtime
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
|
-
- -
|
24
|
+
- - '>='
|
28
25
|
- !ruby/object:Gem::Version
|
29
26
|
version: '0'
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
28
|
name: rest-client
|
32
29
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
30
|
requirements:
|
35
|
-
- -
|
31
|
+
- - '>='
|
36
32
|
- !ruby/object:Gem::Version
|
37
33
|
version: '0'
|
38
34
|
type: :runtime
|
39
35
|
prerelease: false
|
40
36
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
37
|
requirements:
|
43
|
-
- -
|
38
|
+
- - '>='
|
44
39
|
- !ruby/object:Gem::Version
|
45
40
|
version: '0'
|
46
41
|
- !ruby/object:Gem::Dependency
|
47
42
|
name: crack
|
48
43
|
requirement: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
44
|
requirements:
|
51
|
-
- -
|
45
|
+
- - '>='
|
52
46
|
- !ruby/object:Gem::Version
|
53
47
|
version: '0'
|
54
48
|
type: :runtime
|
55
49
|
prerelease: false
|
56
50
|
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
51
|
requirements:
|
59
|
-
- -
|
52
|
+
- - '>='
|
60
53
|
- !ruby/object:Gem::Version
|
61
54
|
version: '0'
|
62
55
|
description: Ruby warapper for the Edmunds auto API
|
@@ -79,26 +72,25 @@ files:
|
|
79
72
|
- README.md
|
80
73
|
homepage: https://github.com/johndavid400/edmunds_ruby
|
81
74
|
licenses: []
|
75
|
+
metadata: {}
|
82
76
|
post_install_message:
|
83
77
|
rdoc_options: []
|
84
78
|
require_paths:
|
85
79
|
- lib
|
86
80
|
required_ruby_version: !ruby/object:Gem::Requirement
|
87
|
-
none: false
|
88
81
|
requirements:
|
89
|
-
- -
|
82
|
+
- - '>='
|
90
83
|
- !ruby/object:Gem::Version
|
91
84
|
version: '0'
|
92
85
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
93
|
-
none: false
|
94
86
|
requirements:
|
95
|
-
- -
|
87
|
+
- - '>='
|
96
88
|
- !ruby/object:Gem::Version
|
97
89
|
version: '0'
|
98
90
|
requirements: []
|
99
91
|
rubyforge_project:
|
100
|
-
rubygems_version: 1.
|
92
|
+
rubygems_version: 2.1.0.rc.1
|
101
93
|
signing_key:
|
102
|
-
specification_version:
|
94
|
+
specification_version: 4
|
103
95
|
summary: Edmunds auto API
|
104
96
|
test_files: []
|