Created
October 29, 2014 15:13
-
-
Save JesseHerrick/b72c19f9bee4ab6feb8f to your computer and use it in GitHub Desktop.
Basic attempt at using Best Buy's API.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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