Skip to content

Instantly share code, notes, and snippets.

@handcrafted
Created June 20, 2009 17:18
Show Gist options
  • Save handcrafted/133211 to your computer and use it in GitHub Desktop.
Save handcrafted/133211 to your computer and use it in GitHub Desktop.
require 'rubygems'
gem 'httparty'
require 'httparty'
class EbayProducts
include HTTParty
base_uri "open.api.ebay.com"
default_params :responseencoding => 'XML', :callname => "FindProducts", :version => "619", :siteid => 0, :maxentries => 18
attr_reader :query, :appid
def initialize(query, appid)
@query, @appid = query, appid
end
def products
@products ||= self.class.get("/shopping", :query => {:QueryKeywords => @query, :appid => @appid})
end
end
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
describe "EbayProducts" do
context "Initializing" do
it "should raise an error without a query and appid" do
lambda {EbayProducts.new}.should raise_error
lambda {EbayProducts.new("query")}.should raise_error
end
it "save the query and appid" do
ebay = EbayProducts.new("query", "1234")
ebay.query.should == "query"
ebay.appid.should == "1234"
end
end
context "Finding" do
before(:each) do
FakeWeb.register_uri(:get, "http://open.api.ebay.com:80/shopping?QueryKeywords=harry%20potter&callname=FindProducts&siteid=0&maxentries=18&appid=123abc&version=619&responseencoding=XML", :string => File.read("#{File.dirname(__FILE__)}/samples/harry_potter.xml"))
end
it "should find the products" do
e = EbayProducts.new("harry potter", "123abc")
puts e.products
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment