Class: Edmunds::API

Inherits:
Object
  • Object
show all
Defined in:
lib/edmunds/api.rb

Direct Known Subclasses

Make, Model, ModelYear, Photo, Style

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeAPI

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_keyObject (readonly)

Returns the value of attribute api_key.



10
11
12
# File 'lib/edmunds/api.rb', line 10

def api_key
  @api_key
end

#baseObject (readonly)

Returns the value of attribute base.



10
11
12
# File 'lib/edmunds/api.rb', line 10

def base
  @base
end

#base_urlObject (readonly)

Returns the value of attribute base_url.



10
11
12
# File 'lib/edmunds/api.rb', line 10

def base_url
  @base_url
end

#formatObject (readonly)

Returns the value of attribute format.



10
11
12
# File 'lib/edmunds/api.rb', line 10

def format
  @format
end

#image_base_urlObject (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_apiObject



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_keyObject



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