Class: SportsSouth::Inventory
- Inherits:
-
Base
- Object
- Base
- SportsSouth::Inventory
show all
- Defined in:
- lib/sports_south/inventory.rb
Constant Summary
collapse
- API_URL =
'http://webservices.theshootingwarehouse.com/smart/inventory.asmx'
Constants inherited
from Base
Base::CONTENT_TYPE, Base::TIMEOUT, Base::USER_AGENT
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(options = {}) ⇒ Inventory
Returns a new instance of Inventory.
6
7
8
9
10
11
12
|
# File 'lib/sports_south/inventory.rb', line 6
def initialize(options = {})
requires!(options, :username, :password)
@options = options
@options[:customer_number] ||= options[:username]
@options[:source] ||= 'ammor'
end
|
Class Method Details
.all(chunk_size = 15, options = {}, &block) ⇒ Object
14
15
16
17
18
19
20
21
22
23
24
25
26
|
# File 'lib/sports_south/inventory.rb', line 14
def self.all(chunk_size = 15, options = {}, &block)
requires!(options, :username, :password)
if options[:last_updated].present?
options[:last_updated] = options[:last_updated].to_s("yyyy-MM-ddTHH:mm:sszzz")
else
options[:last_updated] = '1990-09-25T14:15:47-04:00'
end
options[:last_item] ||= '-1'
new(options).all(chunk_size, &block)
end
|
.get(item_identifier, options = {}) ⇒ Object
28
29
30
31
|
# File 'lib/sports_south/inventory.rb', line 28
def self.get(item_identifier, options = {})
requires!(options, :username, :password)
new(options).get(item_identifier)
end
|
Instance Method Details
#all(chunk_size, &block) ⇒ Object
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
# File 'lib/sports_south/inventory.rb', line 33
def all(chunk_size, &block)
chunker = SportsSouth::Chunker.new(chunk_size)
http, request = get_http_and_request(API_URL, '/IncrementalOnhandUpdate')
request.set_form_data(form_params = form_params(@options).merge({
SinceDateTime: @options[:last_updated],
LastItem: @options[:last_item].to_s
}))
response = http.request(request)
xml_doc = Nokogiri::XML(sanitize_response(response))
xml_doc.css('Onhand').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
|
#get(item_identifier) ⇒ Object
60
61
62
63
64
65
66
67
|
# File 'lib/sports_south/inventory.rb', line 60
def get(item_identifier)
http, request = get_http_and_request(API_URL, '/OnhandInquiry')
request.set_form_data(form_params(@options).merge({ ItemNumber: item_identifier }))
response = http.request(request)
xml_doc = Nokogiri::XML(sanitize_response(response))
end
|