Permalink
Browse files

first release, added store_locator and current_promotion, some refact…

…oring
  • Loading branch information...
1 parent 66259b1 commit 9c8597ee0fb78242597a93b2fb7b8232ba0dfd5f @rjspotter committed Jan 26, 2012
Showing with 50 additions and 13 deletions.
  1. +1 −1 Rakefile
  2. +14 −4 lib/sears-api.rb
  3. +1 −1 sears-api.gemspec
  4. +34 −7 spec/sears-api_spec.rb
View
2 Rakefile
@@ -18,7 +18,7 @@ Jeweler::Tasks.new do |gem|
gem.homepage = "http://github.com/rjspotter/sears-api"
gem.license = "MIT"
gem.summary = %Q{gem for the sears developer api}
- gem.description = %Q{just your basic wrapper}
+ gem.description = %Q{just your basic wrapper'}
gem.email = "rjspotter@gmail.com"
gem.authors = ["rjspotter"]
# dependencies defined in Gemfile
View
18 lib/sears-api.rb
@@ -26,6 +26,10 @@ def kget(path,opt = {})
Response.new(get(path, opt))
end
+ def store_locator(zip, opt = {})
+ kget('/StoreLocator', :query => {:zipCode => '94132'}.merge(opt))
+ end
+
def product_details(part_number, opt = {})
kget('/productdetails', :query => {:partNumber => part_number}.merge(opt))
end
@@ -36,6 +40,10 @@ def product_search_by_keyword(keyword, opt = {})
merge(opt))
end
+ def current_promotions(opt = {})
+ kget('/CurrentPromotions', :query => opt)
+ end
+
# for each foo in the first array create methods prefixed with
# the store names like kmart_foo, mygofer_foo, sears_foo
# although sears_foo == foo
@@ -69,19 +77,21 @@ class Response
def initialize(resp)
@resp = resp
- self.extend Search if Ick::Try.instance.invoke(resp) {|x| x.first.first} == "MercadoResult"
- self.extend ProductDetails if Ick::Try.instance.invoke(resp) {|x| x.first.first} == "ProductDetail"
+
+ %w[MercadoResult ProductDetail].each do |y|
+ self.extend eval(y) if Ick::Try.instance.invoke(resp) {|x| x.first.first} == y
+ end
end
end
- module Search
+ module MercadoResult
def deligate
resp.first[1]['Products']['Product'].map {|x| Record.new(OpenStruct.new(x))}
end
end
- module ProductDetails
+ module ProductDetail
def deligate
Record.new(OpenStruct.new(resp.first[1]['SoftHardProductDetails']))
end
View
2 sears-api.gemspec
@@ -10,7 +10,7 @@ Gem::Specification.new do |s|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["rjspotter"]
s.date = "2012-01-24"
- s.description = "TODO: longer description of your gem"
+ s.description = "just your basic wrapper"
s.email = "rjspotter@gmail.com"
s.extra_rdoc_files = [
"LICENSE.txt",
View
41 spec/sears-api_spec.rb
@@ -57,6 +57,20 @@
end
+ context "store locator" do
+ it "takes a zipcode" do
+ subject.should_receive(:kget).
+ with('/StoreLocator', :query => {:zipCode => '94132'})
+ subject.store_locator('94132')
+ end
+
+ it "takes an override" do
+ subject.should_receive(:kget).
+ with('/StoreLocator', :query => {:zipCode => '94132', :stateCode => 'CA'})
+ subject.store_locator('94132', {:stateCode => 'CA'})
+ end
+ end
+
context "product details" do
it "searches by partnumber" do
subject.should_receive(:kget).
@@ -104,6 +118,19 @@
end
+ context "current promotions" do
+ it "calls kget to CurrentPromotions" do
+ subject.should_receive(:kget).
+ with('/CurrentPromotions', :query => {})
+ subject.current_promotions
+ end
+ it "takes an opt hash" do
+ subject.should_receive(:kget).
+ with('/CurrentPromotions', :query => {:sortFlag => true})
+ subject.current_promotions(:sortFlag => true)
+ end
+ end
+
end
describe "Response" do
@@ -116,16 +143,16 @@
subject.new(@resp).resp.should == @resp
end
- it "is extended with Search if needed" do
+ it "is extended with MercadoResult if needed" do
@resp.stub_chain(:first,:first).and_return("MercadoResult")
subject.new(@resp).singleton_class.included_modules.
- should include(SearsApi::Search)
+ should include(SearsApi::MercadoResult)
end
- it "is extended with Search if needed" do
+ it "is extended with ProductDetail if needed" do
@resp.stub_chain(:first,:first).and_return("ProductDetail")
subject.new(@resp).singleton_class.included_modules.
- should include(SearsApi::ProductDetails)
+ should include(SearsApi::ProductDetail)
end
describe "instance" do
@@ -154,11 +181,11 @@
end
- describe "Search Results Mixin" do
+ describe "MercadoResult Results Mixin" do
subject do
s = OpenStruct.new(:resp => stub)
- s.extend(SearsApi::Search)
+ s.extend(SearsApi::MercadoResult)
s
end
@@ -175,7 +202,7 @@
subject do
s = OpenStruct.new(:resp => stub)
- s.extend(SearsApi::ProductDetails)
+ s.extend(SearsApi::ProductDetail)
s
end

0 comments on commit 9c8597e

Please sign in to comment.