Class: Edmunds::API
- Inherits:
-
Object
- Object
- Edmunds::API
- Defined in:
- lib/edmunds/api.rb
Instance Attribute Summary collapse
-
#api_key ⇒ Object
readonly
Returns the value of attribute api_key.
-
#base ⇒ Object
readonly
Returns the value of attribute base.
-
#base_url ⇒ Object
readonly
Returns the value of attribute base_url.
-
#format ⇒ Object
readonly
Returns the value of attribute format.
-
#image_base_url ⇒ Object
readonly
Returns the value of attribute image_base_url.
Instance Method Summary collapse
- #call_api ⇒ Object
-
#initialize ⇒ API
constructor
A new instance of API.
- #set_key ⇒ Object
Constructor Details
#initialize ⇒ API
Returns a new instance of API.
12 13 14 15 16 17 18 19 20 |
# File 'lib/edmunds/api.rb', line 12 def initialize if set_key @base = "http://api.edmunds.com/v1/api/vehicle" @image_base_url = "http://media.ed.edmunds-media.com" @format = "fmt=json&api_key=#{@api_key}" else return @errors end end |
Instance Attribute Details
#api_key ⇒ Object (readonly)
Returns the value of attribute api_key.
10 11 12 |
# File 'lib/edmunds/api.rb', line 10 def api_key @api_key end |
#base ⇒ Object (readonly)
Returns the value of attribute base.
10 11 12 |
# File 'lib/edmunds/api.rb', line 10 def base @base end |
#base_url ⇒ Object (readonly)
Returns the value of attribute base_url.
10 11 12 |
# File 'lib/edmunds/api.rb', line 10 def base_url @base_url end |
#format ⇒ Object (readonly)
Returns the value of attribute format.
10 11 12 |
# File 'lib/edmunds/api.rb', line 10 def format @format end |
#image_base_url ⇒ Object (readonly)
Returns the value of attribute image_base_url.
10 11 12 |
# File 'lib/edmunds/api.rb', line 10 def image_base_url @image_base_url end |
Instance Method Details
#call_api ⇒ Object
29 30 31 32 33 |
# File 'lib/edmunds/api.rb', line 29 def call_api @base_url = @base + @url + @format @resp = RestClient.get(@base_url) @json = Crack::JSON.parse(@resp) end |
#set_key ⇒ Object
22 23 24 25 26 27 |
# File 'lib/edmunds/api.rb', line 22 def set_key @api_key = ENV["EDMUNDS_VEHICLE"] || Rails.configuration.edmunds_vehicle_api_key rescue @errors = "You need to set your Edmunds Vehicle API key first" return false end |