GithubHelp home page GithubHelp logo

edmunds_ruby's Introduction

Ruby wrapper for the Edmunds Vehicle API (V1)

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). You can also get production images for each vehicle.

See a simple front-end demo using this gem:

http://edmunds.herokuapp.com

Code for frontend can be found here:

https://github.com/johndavid400/vehicular

Setup:

First, include the gem in your Gemfile:

vim Gemfile

gem 'edmunds_ruby'

bundle

Or if using from the console, just install the gem:

gem install 'edmunds_ruby'

Now add your API key

Get Edmunds Vehicle API key:

You will need to create an account with Edmunds and get a free developer Vehicle API key from here:

http://developer.edmunds.com

Once you get your API key, either create an initializer file to place it in OR add it to your .bashrc script

option 1 - put api key in an initializer file:

Create a new file in config/initializers called edmunds.rb, like so:

vim config/initializers/edmunds.rb

Add this line, with your api key:

Rails.configuration.edmunds_vehicle_api_key = "your_api_key_here"

Save the file and exit.

option 2 - put api key in your .bashrc script:

Open .bashrc file:

vim ~/.bashrc

Add this line near the top of the file:

export EDMUNDS_VEHICLE="your_api_key_here"

Save and close the file, then source the file to make the changes take effect:

source ~/.bashrc

Now you can use the Vehicle API as you like.

Verify API key:

Open a console and try this:

Edmunds::API.new.api_key

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.

Usage:

To use the gem, open a console and start playing. There are currently 5 classes you can call: Make, Model, ModelYear, Style, and Photo

Some of the methods require inputs, others do not. Let's try an easy one first:

m = Edmunds::Make.new
m.find_all

This should return a list of all vehicle makes in the system.

For the Model class, you will have to provide an id first (which you can get from a Make response)

m = Edmunds::Model.new
m.find_by_id("Lamborghini_Diablo")

Here is a complete list of available methods:

The method descriptions were pulled from the Edmunds API documentation.

http://developer.edmunds.com/api-documentation/vehicle/

The method names in this wrapper were kept as close to the original Edmunds API method names as possible, to avoid confusion.

While I plan on wrapping the entire Vehicle API, I currently only have the Make, Model, ModelYear, Style, and Photo methods covered.

Edmunds::Make.new

http://developer.edmunds.com/docs/read/the_vehicle_api/Make_Repository

find_all                                          # Get the list of all makes and their all their models
find_by_id(make_id)                               # Find a make and its models by providing a make ID
find_future_makes                                 # Find all future makes and their models
find_make_by_name(name)                           # Find a make details by its name
find_makes_by_model_year(model_year)              # Find a make by a year
find_makes_by_publication_state(state)            # Find makes by their state (new or used)
find_new_and_used                                 # Find all new and used makes
find_new_and_used_makes_by_model_year(model_year) # Find all new and used makes for a particular year
find_new_makes                                    # Find only new makes
find_used_makes                                   # Find only old makes

Edmunds::Model.new

http://developer.edmunds.com/docs/read/the_vehicle_api/Model_Repository

find_by_id(model_id)                                   # Get a vehicle's model details by the model ID
find_by_make_id(make_id)                               # Get a vehicle's model details by the make ID
find_future_models_by_make_id(make_id)                 # Get a list of all future models by the make ID
find_model_by_make_model_name(make, model)             # Get a vehicle model by the make and model names
find_models_by_make(make)                              # Get a list of models by the make name
find_models_by_make_and_publication_state(make, state) # Get a list of models by the make name and the publication state
find_models_by_make_and_year(make, year)               # Get a list of models by the make name and year
find_new_and_used_models_by_make_id(make_id)           # Get a list of new and used models by the make ID
find_new_models_by_make_id(make_id)                    # Get a list of new models by the make ID
find_used_models_by_make_id(make_id)                   # Get a list of used models by the make ID

Edmunds::ModelYear.new

http://developer.edmunds.com/docs/read/the_vehicle_api/Year_Repository

find_by_id(model_year_id)                                        # Get details on a specifc vehicle by its model year ID
find_distinct_year_with_new                                      # Get a list of years under which there are new vehicle listings
find_distinct_year_with_new_or_used                              # Get a list of years under which there are new or used vehicle listings
find_distinct_year_with_used                                     # Get a list of years under which there are used vehicle listings
find_future_model_years_by_model_id(model_id)                    # Get a list of future model years by the model ID
find_model_years_by_make_and_year(make, year)                    # Get a list of model years for a specific make and year
find_model_years_by_make_model(make, model)                      # Get a list of model years for a specific make and model
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
find_new_model_years_by_model_id(model_id)                       # Get a list of new model years by the model ID
find_used_model_years_by_model_id(model_id)                      # Get a list of used model years by the model ID
find_years_by_category_and_publication_state(category, state)    # Get a list of model years for a specific category and publication state
for_model_id(model_id)                                           # Get a list of model years by the model ID
for_year_make_model(year, make, model)                           # Get a list of model years for a specific make, model and year

Edmunds::Style.new

http://developer.edmunds.com/docs/read/the_vehicle_api/Style_Repository

find_by_id(style_id)                              # Get a style details by the style ID
find_styles_by_make_model_year(make, model, year) # Get a list of styles by make, model and year
find_styles_by_model_year_id(model_year_id)       # Get a list of styles by model year ID

Edmunds::Equipment.new

Documentation for these methods was derived from the API console page:

http://developer.edmunds.com/io-docs

find_engines_by_style_id(style_id)         # Get engine details by the style ID (includes Horsepower)
find_transmissions_by_style_id(style_id)   # Get transmission details by the style ID

Edmunds::Photo.new

http://developer.edmunds.com/docs/read/the_vehicle_api/Photos

find_by_style_id(style_id)          # Get an array of photo detail objects for a particular vehicle style
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.

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.

The image base url can be accessed from any of the classes, for instance these all return the same image base url:

Edmunds::API.new.image_base_url
Edmunds::Make.new.image_base_url
Edmunds::Photo.new.image_base_url

or if you set the new instance to a variable:

p = Edmunds::Photo.new
p.image_base_url

Will both return the base url (url prefix) that must be prepended to the links returned by the Photo API method.

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.

More documentation on the way...

Bug reports and Pull requests

Please open an issue on Github if you find a bug, and I will address it.

If you have an improvement to submit, please fork the repo, add your code and send a pull request.

edmunds_ruby's People

Contributors

chaudhary27 avatar johndavid400 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

edmunds_ruby's Issues

Not all Makes are regular strings

For example: when i fetch for m = Edmunds::Make.new, followed by m.find_new_and_used, I look through the JSON. I don't see just the Make "Acura" by itself as a value however the Model "SLX" and "ILX" are available. I'd just like to know why.
Thanks

License missing from gemspec

RubyGems.org doesn't report a license for your gem. This is because it is not specified in the gemspec of your last release.

via e.g.

spec.license = 'MIT'
# or
spec.licenses = ['MIT', 'GPL-2']

Including a license in your gemspec is an easy way for rubygems.org and other tools to check how your gem is licensed. As you can image, scanning your repository for a LICENSE file or parsing the README, and then attempting to identify the license or licenses is much more difficult and more error prone. So, even for projects that already specify a license, including a license in your gemspec is a good practice. See, for example, how rubygems.org uses the gemspec to display the rails gem license.

There is even a License Finder gem to help companies/individuals ensure all gems they use meet their licensing needs. This tool depends on license information being available in the gemspec. This is an important enough issue that even Bundler now generates gems with a default 'MIT' license.

I hope you'll consider specifying a license in your gemspec. If not, please just close the issue with a nice message. In either case, I'll follow up. Thanks for your time!

Appendix:

If you need help choosing a license (sorry, I haven't checked your readme or looked for a license file), GitHub has created a license picker tool. Code without a license specified defaults to 'All rights reserved'-- denying others all rights to use of the code.
Here's a list of the license names I've found and their frequencies

p.s. In case you're wondering how I found you and why I made this issue, it's because I'm collecting stats on gems (I was originally looking for download data) and decided to collect license metadata,too, and make issues for gemspecs not specifying a license as a public service :). See the previous link or my blog post aobut this project for more information.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.