Skip to content

Instantly share code, notes, and snippets.

@JesseHerrick
Created October 29, 2014 15:13
Show Gist options
  • Save JesseHerrick/b72c19f9bee4ab6feb8f to your computer and use it in GitHub Desktop.
Save JesseHerrick/b72c19f9bee4ab6feb8f to your computer and use it in GitHub Desktop.
Basic attempt at using Best Buy's API.
require 'faraday'
require 'json'
class BestBuy
API_KEY = 'APIKEYHERE' # get one at developer.bestbuy.com
# initializes faraday and adds API key to options hash
def initialize
@options = { apiKey: API_KEY }
@conn = Faraday.new(url: 'http://api.remix.bestbuy.com') do |f|
f.request :url_encoded
f.response :logger
f.adapter :excon
end
end
# returns response (as a hash) of product listing
def product(sku)
response = @conn.get "/v1/products/#{sku}.json", @options
JSON.parse response.body
end
end
bb = BestBuy.new
bb.product 8880044
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment