Class: SportsSouth::Catalog
Constant Summary collapse
- API_URL =
'http://webservices.theshootingwarehouse.com/smart/inventory.asmx'- CATALOG_CODES =
{ 'S' => :special, 'C' => :closeout, 'F' => :flyer, 'B' => :buyers_special, 'N' => :net_price, }
- ITEM_TYPES =
{ '1' => :handgun, '2' => :long_gun, '3' => :accessory, '4' => :ammunition, '5' => :optics, '6' => :archery, '7' => :reloading, '8' => :suppressor, }
Constants inherited from Base
Base::CONTENT_TYPE, Base::TIMEOUT, Base::USER_AGENT
Class Method Summary collapse
Instance Method Summary collapse
- #all(chunk_size, &block) ⇒ Object
-
#initialize(options = {}) ⇒ Catalog
constructor
A new instance of Catalog.
Constructor Details
#initialize(options = {}) ⇒ Catalog
Returns a new instance of Catalog.
25 26 27 28 29 |
# File 'lib/sports_south/catalog.rb', line 25 def initialize( = {}) requires!(, :username, :password) = end |
Class Method Details
.all(chunk_size = 15, options = {}, &block) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/sports_south/catalog.rb', line 31 def self.all(chunk_size = 15, = {}, &block) requires!(, :username, :password) if [:last_updated].present? [:last_updated] = [:last_updated].strftime("%-m/%-d/%Y") else [:last_updated] ||= '1/1/1990' end [:last_item] ||= '-1' new().all(chunk_size, &block) end |
Instance Method Details
#all(chunk_size, &block) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/sports_south/catalog.rb', line 45 def all(chunk_size, &block) chunker = SportsSouth::Chunker.new(chunk_size) http, request = get_http_and_request(API_URL, '/DailyItemUpdate') request.set_form_data(form_params().merge({ LastUpdate: [:last_updated], LastItem: [:last_item].to_s })) response = http.request(request) xml_doc = Nokogiri::XML(sanitize_response(response)) xml_doc.css('Table').map do |item| if chunker.is_full? yield(chunker.chunk) chunker.reset! else chunker.add(self.map_hash(item)) end if chunker.chunk.count > 0 yield(chunker.chunk) end end end |