Class: SportsSouth::Brand

Inherits:
Base
  • Object
show all
Defined in:
lib/sports_south/brand.rb

Constant Summary collapse

API_URL =
'http://webservices.theshootingwarehouse.com/smart/inventory.asmx'

Constants inherited from Base

SportsSouth::Base::TIMEOUT, SportsSouth::Base::USER_AGENT

Class Method Summary collapse

Class Method Details

.all(options = {}) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/sports_south/brand.rb', line 6

def self.all(options = {})
  requires!(options, :username, :password, :source, :customer_number)

  http, request = get_http_and_request(API_URL, '/BrandUpdate')

  request.set_form_data(form_params(options))
  response = http.request(request)
  body = sanitize_response(response)
  xml_doc = Nokogiri::XML(body)

  raise SportsSouth::NotAuthenticated if not_authenticated?(xml_doc)

  brands = []

  xml_doc.css('Table').each do |brand|
    brands << {
      id: content_for(brand, 'BRDNO'),
      name: content_for(brand, 'BRDNM'),
      url: content_for(brand, 'BRDURL'),
      item_count: content_for(brand, 'ITCOUNT'),
    }
  end

  brands
end