edmunds 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 481d130e3e474aae238c7dbfd8bc62ac6bd5510d
4
- data.tar.gz: 7b17fb30d33fdf209fcb1186225e3207eb14cd77
3
+ metadata.gz: 5d74986e9b762968e63e37e2aaa81e6e3f4e7884
4
+ data.tar.gz: 2d4103061e4fa38c5c2caf2c073dc06202059e26
5
5
  SHA512:
6
- metadata.gz: 9b33cbec6f69aefcb344037441d6974883124d549a9134988c1eb08762ea5b0576b993b4721da8433f9ab8326d30e4c828ec470a7313977db8528293e6c6290b
7
- data.tar.gz: 4d9bb098ac68dcd54a16df24c270142b2363123f4ecf714e72ddaee1c328c225bdf80b7b279dc2092fbf871a36d93681ae5b7f0597717b2de8439e99cfc06cba
6
+ metadata.gz: 69bca0aee1e1c38fc5141c24f0290b1c6acab897381305fc4072bcfb97e146474c05efb33913e99263f5b3ca3f4b59daaa75eb399c78f82e6d6d720c6a3afad1
7
+ data.tar.gz: 185beb70694a9a93cb852340a4336e0d9c26faa6511cb67a512fbbe6ba94d75fc6f06abb327e0b915eff2dc9fd297cf7306dad264f553b4ba7420934983b64bc
data/README.md CHANGED
@@ -1,6 +1,10 @@
1
- # edmunds
1
+ # edmunds
2
2
  Edmunds.com Ruby API Wrapper
3
3
 
4
+ [![Codeship Status for sovietaced/edmunds](https://codeship.io/projects/d03c61a0-a2bc-0132-516c-0e0102967270/status)](https://codeship.io/projects/65819)
5
+ [![Code Climate](https://codeclimate.com/github/Sovietaced/edmunds/badges/gpa.svg)](https://codeclimate.com/github/Sovietaced/edmunds)
6
+ [![Coverage Status](https://coveralls.io/repos/Sovietaced/edmunds/badge.svg?branch=master)](https://coveralls.io/r/Sovietaced/edmunds?branch=master)
7
+ [![Gem Version](https://badge.fury.io/rb/edmunds.svg)](http://badge.fury.io/rb/edmunds)
4
8
  ## Installation
5
9
  Install the gem
6
10
  ```bash
@@ -12,7 +16,6 @@ export EDMUNDS_API_KEY=<api_key>
12
16
  ```
13
17
 
14
18
  ## Usage
15
-
16
19
  ```ruby
17
20
  require 'edmunds'
18
21
  => true
@@ -20,7 +23,6 @@ result = Edmunds::Vehicle::Specification::VinDecoding::Basic.find("JHMAP11461T00
20
23
  => #<Edmunds::Vehicle::Specification::VinDecoding::Basic:0x007faa2a0e4e40 @make="Honda", @model="S2000", @year=2001>
21
24
 
22
25
  ```
23
-
24
26
  ## License
25
27
 
26
28
  Please see LICENSE at the top level of the repository.
@@ -1,8 +1,13 @@
1
- module Edmunds
2
- API_URL_V1 = "https://api.edmunds.com/api/v1"
3
- API_URL_V2 = "https://api.edmunds.com/api/v2"
4
- end
5
-
6
1
  require_relative "edmunds/version"
2
+ require_relative "edmunds/api"
7
3
  require_relative "edmunds/vehicle"
4
+ require_relative "edmunds/vehicle/specification/make"
5
+ require_relative "edmunds/vehicle/specification/model"
6
+ require_relative "edmunds/vehicle/specification/model_year"
7
+ require_relative "edmunds/vehicle/specification/style"
8
8
  require_relative "edmunds/vehicle/specification/vin_decoding"
9
+
10
+ module Edmunds
11
+
12
+ end
13
+
@@ -0,0 +1,15 @@
1
+ module Edmunds
2
+ module Api
3
+
4
+ URL = "https://api.edmunds.com/api"
5
+ URL_V1 = "#{URL}/v1"
6
+
7
+ # Wrapper around Faraday.get that passses the API key
8
+ def self.get(url, api_params = {})
9
+ api_key_hash = { api_key: ENV['EDMUNDS_API_KEY'] }
10
+ api_params = api_params.merge(api_key_hash)
11
+ Faraday.get(url, api_params)
12
+ end
13
+
14
+ end
15
+ end
@@ -2,7 +2,7 @@ require 'edmunds'
2
2
 
3
3
  module Edmunds
4
4
  module Vehicle
5
- API_URL_V1 = Edmunds::API_URL_V1 + "/vehicle"
6
- API_URL_V2 = Edmunds::API_URL_V2 + "/vehicle"
5
+ API_URL_V1 = Edmunds::Api::URL_V1 + "/vehicle"
6
+ API_URL_V2 = Edmunds::Api::URL + "/vehicle/v2"
7
7
  end
8
8
  end
@@ -0,0 +1,60 @@
1
+ require 'faraday'
2
+ require 'json'
3
+
4
+ MAKE_API_URL = Edmunds::Vehicle::API_URL_V2
5
+ MAKES_API_URL = MAKE_API_URL + "/makes"
6
+ MAKES_COUNT_API_URL = MAKES_API_URL + "/count"
7
+
8
+ module Edmunds
9
+ module Vehicle
10
+ module Specification
11
+ module Make
12
+
13
+ class Makes
14
+ attr_reader :makes
15
+
16
+ def initialize(attributes)
17
+ @makes = attributes["makes"].map {|json| Make.new(json)} if attributes.key?("makes")
18
+ end
19
+
20
+ def self.find(api_params = {})
21
+ response = Edmunds::Api.get("#{MAKES_API_URL}", api_params)
22
+ attributes = JSON.parse(response.body)
23
+ new(attributes)
24
+ end
25
+ end
26
+
27
+ class Make
28
+ attr_reader :id, :name, :models
29
+
30
+ def initialize(attributes)
31
+ @id = attributes["id"]
32
+ @name = attributes["name"]
33
+ @models = attributes["models"].map {|json| Edmunds::Vehicle::Specification::Model::Model.new(json)} if attributes.key?("models")
34
+ end
35
+
36
+ def self.find(name, api_params = {})
37
+ response = Edmunds::Api.get("#{MAKE_API_URL}/#{name}", api_params)
38
+ attributes = JSON.parse(response.body)
39
+ new(attributes)
40
+ end
41
+ end
42
+
43
+ class MakesCount
44
+ attr_reader :count
45
+
46
+ def initialize(attributes)
47
+ @count = attributes["makesCount"]
48
+ end
49
+
50
+ def self.find(api_params = {})
51
+ response = Edmunds::Api.get("#{MAKES_COUNT_API_URL}", api_params)
52
+ attributes = JSON.parse(response.body)
53
+ new(attributes)
54
+ end
55
+ end
56
+
57
+ end
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,29 @@
1
+ require 'faraday'
2
+ require 'json'
3
+
4
+ MODEL_API_URL = Edmunds::Vehicle::API_URL_V2
5
+
6
+ module Edmunds
7
+ module Vehicle
8
+ module Specification
9
+ module Model
10
+
11
+ class Model
12
+ attr_reader :id, :name, :years
13
+
14
+ def initialize(attributes)
15
+ @id = attributes["id"]
16
+ @name = attributes["name"]
17
+ @years = attributes["years"].map {|json| Edmunds::Vehicle::Specification::ModelYear::ModelYear.new(json)} if attributes.key?("years")
18
+ end
19
+
20
+ def self.find(make_name, model_name, api_params = {})
21
+ response = Edmunds::Api.get("#{MODEL_API_URL}/#{make_name}/#{model_name}", api_params)
22
+ attributes = JSON.parse(response.body)
23
+ new(attributes)
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,30 @@
1
+ require 'faraday'
2
+ require 'json'
3
+
4
+ MODEL_YEAR_API_URL = Edmunds::Vehicle::API_URL_V2
5
+
6
+ module Edmunds
7
+ module Vehicle
8
+ module Specification
9
+ module ModelYear
10
+
11
+ class ModelYear
12
+ attr_reader :id, :year, :styles
13
+
14
+ def initialize(attributes)
15
+ @id = attributes["id"]
16
+ @year = attributes["year"]
17
+ @styles = attributes["styles"].map {|json| Edmunds::Vehicle::Specification::Style::Style.new(json)} if attributes.key?("styles")
18
+ end
19
+
20
+ def self.find(make_name, model_name, model_year, api_params = {})
21
+ response = Edmunds::Api.get("#{MODEL_API_URL}/#{make_name}/#{model_name}/#{model_year}", api_params)
22
+ attributes = JSON.parse(response.body)
23
+ new(attributes)
24
+ end
25
+ end
26
+
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,35 @@
1
+ require 'faraday'
2
+ require 'json'
3
+
4
+ STYLE_API_URL = Edmunds::Vehicle::API_URL_V2 + "/styles"
5
+
6
+ module Edmunds
7
+ module Vehicle
8
+ module Specification
9
+ module Style
10
+
11
+ class Style
12
+ attr_reader :id, :name, :trim, :body, :year, :make_name, :model_name
13
+
14
+ def initialize(attributes)
15
+ @id = attributes["id"]
16
+ @name = attributes["name"]
17
+ @trim = attributes["trim"]
18
+ @body = attributes["submodel"]["body"]
19
+ # TODO: Not sure whether this is valuable or not to expose...
20
+ # @year = attributes["year"]["year"]
21
+ # @make_name = attributes["make"]["name"]
22
+ # @model_name = attributes["model"]["name"]
23
+ end
24
+
25
+ def self.find(id, api_params = {})
26
+ response = Edmunds::Api.get("#{STYLE_API_URL}/#{id}", api_params)
27
+ attributes = JSON.parse(response.body)
28
+ new(attributes)
29
+ end
30
+ end
31
+
32
+ end
33
+ end
34
+ end
35
+ end
@@ -1,12 +1,14 @@
1
1
  require 'faraday'
2
2
  require 'json'
3
3
 
4
- API_URL = Edmunds::Vehicle::API_URL_V1 + "/vin/"
4
+ BASIC_API_URL = Edmunds::Vehicle::API_URL_V1 + "/vin"
5
+ FULL_API_URL = Edmunds::Vehicle::API_URL_V2 + "/vins"
5
6
 
6
7
  module Edmunds
7
8
  module Vehicle
8
9
  module Specification
9
10
  module VinDecoding
11
+
10
12
  class Basic
11
13
  attr_reader :make, :model, :year
12
14
 
@@ -16,12 +18,39 @@ module Edmunds
16
18
  @year = attributes["year"]
17
19
  end
18
20
 
21
+ # Get vehicle make, model, year, type, fuel type, number of cylinders and list of styles by decoding the vehicle's VIN.
22
+ #
23
+ # @param [String] vin number of the vehicle to search for
24
+ # @return [Basic] object holding the results of the query
25
+ def self.find(vin)
26
+ response = Edmunds::Api.get("#{BASIC_API_URL}/#{vin}/configuration")
27
+ attributes = JSON.parse(response.body)
28
+ new(attributes)
29
+ end
30
+ end
31
+
32
+ class Full
33
+ attr_reader :make, :model, :years, :mpg_highway, :mpg_city
34
+
35
+ def initialize(attributes)
36
+ @make = Edmunds::Vehicle::Specification::Make::Make.new(attributes["make"])
37
+ @model = Edmunds::Vehicle::Specification::Model::Model.new(attributes["model"])
38
+ @years = attributes["years"].map {|json| Edmunds::Vehicle::Specification::ModelYear::ModelYear.new(json)} if attributes.key?("years")
39
+ @mpg_highway = attributes["MPG"]["highway"]
40
+ @mpg_city = attributes["MPG"]["city"]
41
+ end
42
+
43
+ # Get all vehicle details from make, model, year and fuel type to list of options, features and standard equipment. All this information is returned by decoding the vehicle's VIN.
44
+ #
45
+ # @param [String] vin number of the vehicle to search for
46
+ # @return [Basic] object holding the results of the query
19
47
  def self.find(vin)
20
- response = Faraday.get("#{API_URL}/#{vin}/configuration", { api_key: ENV['EDMUNDS_API_KEY'] })
48
+ response = Edmunds::Api.get("#{FULL_API_URL}/#{vin}")
21
49
  attributes = JSON.parse(response.body)
22
50
  new(attributes)
23
51
  end
24
52
  end
53
+
25
54
  end
26
55
  end
27
56
  end
@@ -1,3 +1,3 @@
1
1
  module Edmunds
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: edmunds
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jason Parraga
@@ -131,7 +131,12 @@ extra_rdoc_files: []
131
131
  files:
132
132
  - README.md
133
133
  - lib/edmunds.rb
134
+ - lib/edmunds/api.rb
134
135
  - lib/edmunds/vehicle.rb
136
+ - lib/edmunds/vehicle/specification/make.rb
137
+ - lib/edmunds/vehicle/specification/model.rb
138
+ - lib/edmunds/vehicle/specification/model_year.rb
139
+ - lib/edmunds/vehicle/specification/style.rb
135
140
  - lib/edmunds/vehicle/specification/vin_decoding.rb
136
141
  - lib/edmunds/version.rb
137
142
  homepage: ''