edmunds 0.0.4 → 0.0.5

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: 917937e5e9df9c64fb0706dbb87c72f8d0ef8c18
4
- data.tar.gz: 8fbb2d8f8d64f41b847cbe8f139cf22b814b0a47
3
+ metadata.gz: 1344f0bd011e7414e7e8d61633f8d6e4138244b6
4
+ data.tar.gz: 99f01d3fa5e0ec85c904c1a1ed76e600e337224b
5
5
  SHA512:
6
- metadata.gz: 4065f0b0cbc1c39b37a4dc6e8e3d984bff0f4731796ffdf92ca83eec83a85c1928fc001ed643d1aae38747884793b5e78dd49f40576ba27cd8b1deabdf648692
7
- data.tar.gz: d9b2fcfe8e45cd6b2ceb447763b76b8e0984b0eddfd557bd8342bde244d689a6feccc9a5f9a2af5baff1678e143f9b4b6bd076ee980a6ed51a32961a57bc28e9
6
+ metadata.gz: 5b77c3fa390cdb4792ee925d23102cf95189ebd88b8f416699ab1a7a46d8a7dbc32f624d185dbde28cfc79f8bfaefa02db28324c91c210478a7ddf953cb98542
7
+ data.tar.gz: 59ab4ce5eeea4c4c2f4d85f62167e4c2ae93531ab14ccb80bd9ebb4e8d8cd73d5a21320d312848f26200abcae8578fe66e640fcf04f0ca332edfc252c3fc9ef0
data/README.md CHANGED
@@ -16,13 +16,21 @@ export EDMUNDS_API_KEY=<api_key>
16
16
  ```
17
17
 
18
18
  ## Usage
19
+ The module naming scheme of this gem is inline with how the API is documented.
19
20
  ```ruby
20
21
  require 'edmunds'
21
22
  => true
22
23
  result = Edmunds::Vehicle::Specification::VinDecoding::Basic.find("JHMAP11461T005905")
23
24
  => #<Edmunds::Vehicle::Specification::VinDecoding::Basic:0x007faa2a0e4e40 @make="Honda", @model="S2000", @year=2001>
25
+ result = Edmunds::Vehicle::Specification::Style::StylesDetails.find("honda", "s2000", 2001)
26
+ => #<Edmunds::Vehicle::Specification::Style::StylesDetails:0x007fbc719fd028 @count=1, @styles=[#<Edmunds::Vehicle::Specification::Style::Style:0x007fbc719fcf88 @id=100001280, @name="2dr Roadster (2.0L 4cyl 6M)", @trim="Base", @body="Convertible">]>
24
27
 
25
28
  ```
29
+
30
+ ## Contributors
31
+ Feel free to fork this repository and open a pull request.
32
+ If you have any questions you can open an issue or contact me directly [here](https://twitter.com/Sovietaced).
33
+
26
34
  ## License
27
35
 
28
36
  Please see LICENSE at the top level of the repository.
data/lib/edmunds.rb CHANGED
@@ -1,13 +1,13 @@
1
- require_relative "edmunds/version"
2
- require_relative "edmunds/api"
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
- require_relative "edmunds/vehicle/specification/vin_decoding"
1
+ require_relative 'edmunds/version'
2
+ require_relative 'edmunds/api'
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
+ require_relative 'edmunds/vehicle/specification/color'
9
+ require_relative 'edmunds/vehicle/specification/option'
10
+ require_relative 'edmunds/vehicle/specification/vin_decoding'
9
11
 
10
12
  module Edmunds
11
-
12
13
  end
13
-
data/lib/edmunds/api.rb CHANGED
@@ -1,15 +1,29 @@
1
1
  module Edmunds
2
2
  module Api
3
-
4
- URL = "https://api.edmunds.com/api"
3
+ URL = 'https://api.edmunds.com/api'
5
4
  URL_V1 = "#{URL}/v1"
6
5
 
7
6
  # Wrapper around Faraday.get that passses the API key
8
7
  def self.get(url, api_params = {})
9
8
  api_key_hash = { api_key: ENV['EDMUNDS_API_KEY'] }
10
9
  api_params = api_params.merge(api_key_hash)
11
- Faraday.get(url, api_params)
10
+ response = Faraday.get(url, api_params)
11
+
12
+ if not response.success?
13
+ raise Exception.new(response)
14
+ end
15
+
16
+ return response
12
17
  end
13
18
 
19
+ class Exception < StandardError
20
+ attr_reader :error_type, :message
21
+ def initialize(response)
22
+ error = JSON.parse(response.body)
23
+
24
+ @error_type = error['error']['errorType']
25
+ @message = error['error']['message']
26
+ end
27
+ end
14
28
  end
15
- end
29
+ 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 + "/vehicle/v2"
5
+ API_URL_V1 = Edmunds::Api::URL_V1 + '/vehicle'
6
+ API_URL_V2 = Edmunds::Api::URL + '/vehicle/v2'
7
7
  end
8
- end
8
+ end
@@ -0,0 +1,59 @@
1
+ require 'faraday'
2
+ require 'json'
3
+
4
+ STYLE_API_URL = Edmunds::Vehicle::API_URL_V2 + '/styles'
5
+ COLORS_API_URL = Edmunds::Vehicle::API_URL_V2 + '/colors'
6
+
7
+ module Edmunds
8
+ module Vehicle
9
+ module Specification
10
+ module Color
11
+
12
+ class ColorsByStyle
13
+ attr_reader :colors, :count
14
+
15
+ def initialize(attributes)
16
+ @colors = attributes['colors'].map { |json| ColorsDetails.new(json) } if attributes.key?('colors')
17
+ @count = attributes['colorsCount']
18
+ end
19
+
20
+ def self.find(style_id, api_params = {})
21
+ response = Edmunds::Api.get("#{STYLE_API_URL}/#{style_id}/colors", api_params)
22
+ attributes = JSON.parse(response.body)
23
+ new(attributes)
24
+ end
25
+ end
26
+
27
+ class ColorsDetails
28
+ attr_reader :id,
29
+ :name,
30
+ :equipment_type,
31
+ :availability,
32
+ :manufacture_option_name,
33
+ :manufacture_option_code,
34
+ :category,
35
+ :attributes, #not implemented
36
+ :color_chips, #not_implemented
37
+ :fabric_Types #not implemented
38
+
39
+ def initialize(attributes)
40
+ @id = attributes['id']
41
+ @name = attributes['name']
42
+ @equipment_type = attributes['equipmentType']
43
+ @availability = attributes['availability']
44
+ @manufacture_option_name = attributes['manufactureOptionName']
45
+ @manufacture_option_code = attributes['manufactureOptionCode']
46
+ @category = attributes['category']
47
+ end
48
+
49
+ def self.find(color_id, api_params = {})
50
+ response = Edmunds::Api.get("#{COLORS_API_URL}/#{color_id}", api_params)
51
+ attributes = JSON.parse(response.body)
52
+ new(attributes)
53
+ end
54
+ end
55
+
56
+ end
57
+ end
58
+ end
59
+ end
@@ -2,19 +2,18 @@ require 'faraday'
2
2
  require 'json'
3
3
 
4
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"
5
+ MAKES_API_URL = MAKE_API_URL + '/makes'
6
+ MAKES_COUNT_API_URL = MAKES_API_URL + '/count'
7
7
 
8
8
  module Edmunds
9
9
  module Vehicle
10
10
  module Specification
11
11
  module Make
12
-
13
12
  class Makes
14
13
  attr_reader :makes
15
14
 
16
15
  def initialize(attributes)
17
- @makes = attributes["makes"].map {|json| Make.new(json)} if attributes.key?("makes")
16
+ @makes = attributes['makes'].map { |json| Make.new(json) } if attributes.key?('makes')
18
17
  end
19
18
 
20
19
  def self.find(api_params = {})
@@ -28,9 +27,9 @@ module Edmunds
28
27
  attr_reader :id, :name, :models
29
28
 
30
29
  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")
30
+ @id = attributes['id']
31
+ @name = attributes['name']
32
+ @models = attributes['models'].map { |json| Edmunds::Vehicle::Specification::Model::Model.new(json) } if attributes.key?('models')
34
33
  end
35
34
 
36
35
  def self.find(name, api_params = {})
@@ -44,7 +43,7 @@ module Edmunds
44
43
  attr_reader :count
45
44
 
46
45
  def initialize(attributes)
47
- @count = attributes["makesCount"]
46
+ @count = attributes['makesCount']
48
47
  end
49
48
 
50
49
  def self.find(api_params = {})
@@ -53,7 +52,6 @@ module Edmunds
53
52
  new(attributes)
54
53
  end
55
54
  end
56
-
57
55
  end
58
56
  end
59
57
  end
@@ -7,14 +7,13 @@ module Edmunds
7
7
  module Vehicle
8
8
  module Specification
9
9
  module Model
10
-
11
10
  class Model
12
11
  attr_reader :id, :name, :years
13
12
 
14
13
  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")
14
+ @id = attributes['id']
15
+ @name = attributes['name']
16
+ @years = attributes['years'].map { |json| Edmunds::Vehicle::Specification::ModelYear::ModelYear.new(json) } if attributes.key?('years')
18
17
  end
19
18
 
20
19
  def self.find(make_name, model_name, api_params = {})
@@ -28,8 +27,8 @@ module Edmunds
28
27
  attr_reader :models, :count
29
28
 
30
29
  def initialize(attributes)
31
- @count = attributes["modelsCount"]
32
- @models = attributes["models"].map {|json| Model.new(json)} if attributes.key?("models")
30
+ @count = attributes['modelsCount']
31
+ @models = attributes['models'].map { |json| Model.new(json) } if attributes.key?('models')
33
32
  end
34
33
 
35
34
  def self.find(make_name, api_params = {})
@@ -43,7 +42,7 @@ module Edmunds
43
42
  attr_reader :count
44
43
 
45
44
  def initialize(attributes)
46
- @count = attributes["modelsCount"]
45
+ @count = attributes['modelsCount']
47
46
  end
48
47
 
49
48
  def self.find(make_name, api_params = {})
@@ -52,7 +51,6 @@ module Edmunds
52
51
  new(attributes)
53
52
  end
54
53
  end
55
-
56
54
  end
57
55
  end
58
56
  end
@@ -7,14 +7,13 @@ module Edmunds
7
7
  module Vehicle
8
8
  module Specification
9
9
  module ModelYear
10
-
11
10
  class ModelYear
12
11
  attr_reader :id, :year, :styles
13
12
 
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")
13
+ def initialize(attributes)
14
+ @id = attributes['id']
15
+ @year = attributes['year']
16
+ @styles = attributes['styles'].map { |json| Edmunds::Vehicle::Specification::Style::Style.new(json) } if attributes.key?('styles')
18
17
  end
19
18
 
20
19
  def self.find(make_name, model_name, model_year, api_params = {})
@@ -27,9 +26,9 @@ module Edmunds
27
26
  class ModelYears
28
27
  attr_reader :model_years, :count
29
28
 
30
- def initialize(attributes)
31
- @count = attributes["yearsCount"]
32
- @model_years = attributes["years"].map {|json| ModelYear.new(json)} if attributes.key?("years")
29
+ def initialize(attributes)
30
+ @count = attributes['yearsCount']
31
+ @model_years = attributes['years'].map { |json| ModelYear.new(json) } if attributes.key?('years')
33
32
  end
34
33
 
35
34
  def self.find(make_name, model_name, api_params = {})
@@ -42,8 +41,8 @@ module Edmunds
42
41
  class ModelYearsCount
43
42
  attr_reader :count
44
43
 
45
- def initialize(attributes)
46
- @count = attributes["yearsCount"]
44
+ def initialize(attributes)
45
+ @count = attributes['yearsCount']
47
46
  end
48
47
 
49
48
  def self.find(make_name, model_name, api_params = {})
@@ -52,7 +51,6 @@ module Edmunds
52
51
  new(attributes)
53
52
  end
54
53
  end
55
-
56
54
  end
57
55
  end
58
56
  end
@@ -0,0 +1,64 @@
1
+ require 'faraday'
2
+ require 'json'
3
+
4
+ STYLE_API_URL = Edmunds::Vehicle::API_URL_V2 + '/styles'
5
+ OPTIONS_API_URL = Edmunds::Vehicle::API_URL_V2 + '/options'
6
+
7
+ module Edmunds
8
+ module Vehicle
9
+ module Specification
10
+ module Option
11
+
12
+ class OptionsByStyle
13
+ attr_reader :options,
14
+ :count
15
+
16
+ def initialize(attributes)
17
+ @options = attributes['options'].map { |json| Option.new(json) } if attributes.key?('options')
18
+ @count = attributes['optionsCount']
19
+ end
20
+
21
+ def self.find(style_id, api_params = {})
22
+ response = Edmunds::Api.get("#{STYLE_API_URL}/#{style_id}/options", api_params)
23
+ attributes = JSON.parse(response.body)
24
+ new(attributes)
25
+ end
26
+ end
27
+
28
+ class Option
29
+ attr_reader :id,
30
+ :name,
31
+ :description,
32
+ :equipment_type,
33
+ :availability,
34
+ :manufacture_option_name,
35
+ :manufacture_option_code,
36
+ :category,
37
+ :attributes,
38
+ :equipment #not implemented
39
+ #TODO: The rest with pricing
40
+
41
+ def initialize(attributes)
42
+ @id = attributes['id']
43
+ @name = attributes['name']
44
+ @description = attributes['description']
45
+ @equipment_type = attributes['equipmentType']
46
+ @availability = attributes['availability']
47
+ @manufacture_option_name = attributes['manufactureOptionName']
48
+ @manufacture_option_code = attributes['manufactureOptionCode']
49
+ @category = attributes['category']
50
+ @attributes = attributes['attributes']
51
+ @equipment = attributes['equipment']
52
+ end
53
+
54
+ def self.find(option_id, api_params = {})
55
+ response = Edmunds::Api.get("#{OPTIONS_API_URL}/#{option_id}", api_params)
56
+ attributes = JSON.parse(response.body)
57
+ new(attributes)
58
+ end
59
+ end
60
+
61
+ end
62
+ end
63
+ end
64
+ end
@@ -1,22 +1,21 @@
1
1
  require 'faraday'
2
2
  require 'json'
3
3
 
4
- STYLE_API_URL = Edmunds::Vehicle::API_URL_V2 + "/styles"
4
+ STYLE_API_URL = Edmunds::Vehicle::API_URL_V2 + '/styles'
5
5
  BASE_API_URL = Edmunds::Vehicle::API_URL_V2
6
6
 
7
7
  module Edmunds
8
8
  module Vehicle
9
9
  module Specification
10
10
  module Style
11
-
12
11
  class Style
13
12
  attr_reader :id, :name, :trim, :body, :year, :make_name, :model_name
14
13
 
15
14
  def initialize(attributes)
16
- @id = attributes["id"]
17
- @name = attributes["name"]
18
- @trim = attributes["trim"]
19
- @body = attributes["submodel"]["body"]
15
+ @id = attributes['id']
16
+ @name = attributes['name']
17
+ @trim = attributes['trim']
18
+ @body = attributes['submodel']['body']
20
19
  # TODO: Not sure whether this is valuable or not to expose...
21
20
  # @year = attributes["year"]["year"]
22
21
  # @make_name = attributes["make"]["name"]
@@ -34,8 +33,8 @@ module Edmunds
34
33
  attr_reader :styles, :count
35
34
 
36
35
  def initialize(attributes)
37
- @count = attributes["stylesCount"]
38
- @styles = attributes["styles"].map {|json| Style.new(json)} if attributes.key?("styles")
36
+ @count = attributes['stylesCount']
37
+ @styles = attributes['styles'].map { |json| Style.new(json) } if attributes.key?('styles')
39
38
  end
40
39
 
41
40
  def self.find(make_name, model_name, model_year, api_params = {})
@@ -65,7 +64,7 @@ module Edmunds
65
64
  attr_reader :count
66
65
 
67
66
  def initialize(attributes)
68
- @count = attributes["stylesCount"]
67
+ @count = attributes['stylesCount']
69
68
  end
70
69
 
71
70
  def self.find(make_name, model_name, model_year, api_params = {})
@@ -79,7 +78,7 @@ module Edmunds
79
78
  attr_reader :count
80
79
 
81
80
  def initialize(attributes)
82
- @count = attributes["stylesCount"]
81
+ @count = attributes['stylesCount']
83
82
  end
84
83
 
85
84
  def self.find(make_name, model_name, api_params = {})
@@ -93,7 +92,7 @@ module Edmunds
93
92
  attr_reader :count
94
93
 
95
94
  def initialize(attributes)
96
- @count = attributes["stylesCount"]
95
+ @count = attributes['stylesCount']
97
96
  end
98
97
 
99
98
  def self.find(make_name, api_params = {})
@@ -107,7 +106,7 @@ module Edmunds
107
106
  attr_reader :count
108
107
 
109
108
  def initialize(attributes)
110
- @count = attributes["stylesCount"]
109
+ @count = attributes['stylesCount']
111
110
  end
112
111
 
113
112
  def self.find(api_params = {})
@@ -116,7 +115,6 @@ module Edmunds
116
115
  new(attributes)
117
116
  end
118
117
  end
119
-
120
118
  end
121
119
  end
122
120
  end
@@ -1,21 +1,20 @@
1
1
  require 'faraday'
2
2
  require 'json'
3
3
 
4
- BASIC_API_URL = Edmunds::Vehicle::API_URL_V1 + "/vin"
5
- FULL_API_URL = Edmunds::Vehicle::API_URL_V2 + "/vins"
4
+ BASIC_API_URL = Edmunds::Vehicle::API_URL_V1 + '/vin'
5
+ FULL_API_URL = Edmunds::Vehicle::API_URL_V2 + '/vins'
6
6
 
7
7
  module Edmunds
8
8
  module Vehicle
9
9
  module Specification
10
10
  module VinDecoding
11
-
12
11
  class Basic
13
12
  attr_reader :make, :model, :year
14
13
 
15
14
  def initialize(attributes)
16
- @make = attributes["make"]["name"]
17
- @model = attributes["model"]["name"]
18
- @year = attributes["year"]
15
+ @make = attributes['make']['name']
16
+ @model = attributes['model']['name']
17
+ @year = attributes['year']
19
18
  end
20
19
 
21
20
  # Get vehicle make, model, year, type, fuel type, number of cylinders and list of styles by decoding the vehicle's VIN.
@@ -33,11 +32,11 @@ module Edmunds
33
32
  attr_reader :make, :model, :years, :mpg_highway, :mpg_city
34
33
 
35
34
  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"]
35
+ @make = Edmunds::Vehicle::Specification::Make::Make.new(attributes['make'])
36
+ @model = Edmunds::Vehicle::Specification::Model::Model.new(attributes['model'])
37
+ @years = attributes['years'].map { |json| Edmunds::Vehicle::Specification::ModelYear::ModelYear.new(json) } if attributes.key?('years')
38
+ @mpg_highway = attributes['MPG']['highway']
39
+ @mpg_city = attributes['MPG']['city']
41
40
  end
42
41
 
43
42
  # 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.
@@ -50,7 +49,6 @@ module Edmunds
50
49
  new(attributes)
51
50
  end
52
51
  end
53
-
54
52
  end
55
53
  end
56
54
  end
@@ -1,3 +1,3 @@
1
1
  module Edmunds
2
- VERSION = "0.0.4"
2
+ VERSION = '0.0.5'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: edmunds
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jason Parraga
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-04 00:00:00.000000000 Z
11
+ date: 2015-03-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -133,9 +133,11 @@ files:
133
133
  - lib/edmunds.rb
134
134
  - lib/edmunds/api.rb
135
135
  - lib/edmunds/vehicle.rb
136
+ - lib/edmunds/vehicle/specification/color.rb
136
137
  - lib/edmunds/vehicle/specification/make.rb
137
138
  - lib/edmunds/vehicle/specification/model.rb
138
139
  - lib/edmunds/vehicle/specification/model_year.rb
140
+ - lib/edmunds/vehicle/specification/option.rb
139
141
  - lib/edmunds/vehicle/specification/style.rb
140
142
  - lib/edmunds/vehicle/specification/vin_decoding.rb
141
143
  - lib/edmunds/version.rb