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
|
# File 'lib/sports_south/inventory.rb', line 6
def initialize(options = {})
requires!(options, :username, :password)
@options = options
end
|
Class Method Details
.all(options = {}, &block) ⇒ Object
21
22
23
24
25
26
27
28
29
30
31
32
33
|
# File 'lib/sports_south/inventory.rb', line 21
def self.all(options = {}, &block)
requires!(options, :username, :password)
if options[:last_updated].present?
options[:last_updated] = options[:last_updated].strftime('%Y-%m-%dT%H:%M:00.00%:z')
else
options[:last_updated] = '1990-09-25T14:15:47-04:00'
end
options[:last_item] ||= '-1'
new(options).all(&block)
end
|
.get(item_identifier, options = {}) ⇒ Object
35
36
37
38
|
# File 'lib/sports_south/inventory.rb', line 35
def self.get(item_identifier, options = {})
requires!(options, :username, :password)
new(options).get(item_identifier)
end
|
.get_quantity_file(options = {}) ⇒ Object
12
13
14
15
16
17
18
19
|
# File 'lib/sports_south/inventory.rb', line 12
def self.get_quantity_file(options = {})
requires!(options, :username, :password)
options[:last_updated] = '1990-09-25T14:15:47-04:00'
options[:last_item] = '-1'
new(options).get_quantity_file
end
|
.quantity(options = {}, &block) ⇒ Object
76
77
78
79
80
81
82
83
84
85
86
87
88
|
# File 'lib/sports_south/inventory.rb', line 76
def self.quantity(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(&block)
end
|
Instance Method Details
#all(&block) ⇒ Object
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
# File 'lib/sports_south/inventory.rb', line 40
def all(&block)
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|
yield(self.map_hash(item))
end
end
|
#get(item_identifier) ⇒ Object
90
91
92
93
94
95
96
97
|
# File 'lib/sports_south/inventory.rb', line 90
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
|
#get_quantity_file ⇒ Object
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
# File 'lib/sports_south/inventory.rb', line 56
def get_quantity_file
tempfile = Tempfile.new
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|
tempfile.puts("#{content_for(item, 'I')},#{content_for(item, 'Q')}")
end
tempfile.close
tempfile.path
end
|