lipseys 2.1.0 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/lipseys.rb +0 -2
- data/lib/lipseys/base.rb +1 -1
- data/lib/lipseys/catalog.rb +21 -76
- data/lib/lipseys/inventory.rb +8 -90
- data/lib/lipseys/version.rb +1 -1
- data/lipseys.gemspec +1 -0
- metadata +17 -4
- data/lib/lipseys/chunker.rb +0 -34
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 85dd68aea52b13495d0f693ace2247ba1f84d2fc
|
4
|
+
data.tar.gz: f38b94435002c2039c85302ef75702b8650c8501
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 556c67b9070d7223f4796024fdcdfc47751fa9fb3ff67693337e699c04cb790a2d7d3fd9ed0c728e894868ca5578740d0b8db126624688f58a6aab5f5fda1f1a
|
7
|
+
data.tar.gz: a0142d7bcaaa1c8c9283631c50e685c9f18fa51ff40cf523a02e2045e0062e309842d7dc00c252ba2ca9134b4e705dbb930a20fb6eec3d511c8cee171ac78a7f
|
data/lib/lipseys.rb
CHANGED
data/lib/lipseys/base.rb
CHANGED
data/lib/lipseys/catalog.rb
CHANGED
@@ -1,7 +1,9 @@
|
|
1
1
|
module Lipseys
|
2
2
|
class Catalog < Base
|
3
3
|
|
4
|
-
|
4
|
+
CHUNK_SIZE = 500
|
5
|
+
API_URL = 'https://www.lipseys.com/API/catalog.ashx'
|
6
|
+
ITEMTYPES = %w(ACCESSORY FIREARM NFA OPTIC)
|
5
7
|
|
6
8
|
def initialize(options = {})
|
7
9
|
requires!(options, :username, :password)
|
@@ -9,34 +11,18 @@ module Lipseys
|
|
9
11
|
@options = options
|
10
12
|
end
|
11
13
|
|
12
|
-
def self.all(
|
14
|
+
def self.all(options = {}, &block)
|
13
15
|
requires!(options, :username, :password)
|
14
|
-
new(options).all
|
16
|
+
new(options).all &block
|
15
17
|
end
|
16
18
|
|
17
|
-
def
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
def self.firearms(options = {})
|
22
|
-
new(options).firearms
|
23
|
-
end
|
24
|
-
|
25
|
-
def self.nfa(options = {})
|
26
|
-
new(options).nfa
|
27
|
-
end
|
28
|
-
|
29
|
-
def self.optics(options = {})
|
30
|
-
new(options).optics
|
31
|
-
end
|
32
|
-
|
33
|
-
def all(chunk_size, &block)
|
34
|
-
chunker = Lipseys::Chunker.new(chunk_size)
|
35
|
-
tempfile = stream_to_tempfile(API_URL, @options)
|
36
|
-
inventory = Array.new
|
19
|
+
def all(&block)
|
20
|
+
inventory_tempfile = stream_to_tempfile(Lipseys::Inventory::API_URL, @options)
|
21
|
+
catalog_tempfile = stream_to_tempfile(API_URL, @options)
|
22
|
+
inventory = Array.new
|
37
23
|
|
38
24
|
# Let's get the inventory and toss 'er into an array
|
39
|
-
Lipseys::Parser.parse(
|
25
|
+
Lipseys::Parser.parse(inventory_tempfile, 'Item') do |node|
|
40
26
|
inventory.push({
|
41
27
|
item_identifier: content_for(node, 'ItemNo'),
|
42
28
|
map_price: content_for(node, 'RetailMAP'),
|
@@ -45,67 +31,26 @@ module Lipseys
|
|
45
31
|
})
|
46
32
|
end
|
47
33
|
|
48
|
-
Lipseys::Parser.parse(
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
chunker.reset!
|
53
|
-
else
|
54
|
-
hash = map_hash(node)
|
55
|
-
availability = inventory.select { |i| i[:item_identifier] == hash[:item_identifier] }.first
|
56
|
-
|
57
|
-
if availability
|
58
|
-
hash[:price] = availability[:price]
|
59
|
-
hash[:quantity] = availability[:quantity]
|
60
|
-
hash[:map_price] = availability[:map_price]
|
34
|
+
Lipseys::Parser.parse(catalog_tempfile, 'Item') do |node|
|
35
|
+
hash = map_hash(node)
|
36
|
+
availability = inventory.select { |i| i[:item_identifier] == hash[:item_identifier] }.first
|
61
37
|
|
62
|
-
|
63
|
-
|
38
|
+
if availability
|
39
|
+
hash[:price] = availability[:price]
|
40
|
+
hash[:quantity] = availability[:quantity]
|
41
|
+
hash[:map_price] = availability[:map_price]
|
64
42
|
end
|
65
|
-
end
|
66
43
|
|
67
|
-
|
68
|
-
# since we can't get a count of the items without reading the file
|
69
|
-
# Let's just check to see if we have any left in the chunk
|
70
|
-
if chunker.chunk.count > 0
|
71
|
-
yield(chunker.chunk)
|
44
|
+
yield hash
|
72
45
|
end
|
73
46
|
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
def accessories
|
78
|
-
get_items('ACCESSORY')
|
79
|
-
end
|
80
|
-
|
81
|
-
def firearms
|
82
|
-
get_items('FIREARM')
|
83
|
-
end
|
84
|
-
|
85
|
-
def nfa
|
86
|
-
get_items('NFA')
|
87
|
-
end
|
88
|
-
|
89
|
-
def optics
|
90
|
-
get_items('OPTIC')
|
47
|
+
inventory_tempfile.unlink
|
48
|
+
catalog_tempfile.unlink
|
49
|
+
true
|
91
50
|
end
|
92
51
|
|
93
52
|
private
|
94
53
|
|
95
|
-
def get_items(item_type = nil)
|
96
|
-
@options[:itemtype] = item_type unless item_type.nil?
|
97
|
-
|
98
|
-
xml_doc = get_response_xml(API_URL, @options)
|
99
|
-
|
100
|
-
items = Array.new
|
101
|
-
|
102
|
-
xml_doc.css('LipseysCatalog/Item').each do |item|
|
103
|
-
items.push(map_hash(item))
|
104
|
-
end
|
105
|
-
|
106
|
-
items
|
107
|
-
end
|
108
|
-
|
109
54
|
def map_hash(node)
|
110
55
|
model = content_for(node, 'Model')
|
111
56
|
mfg_number = content_for(node, 'MFGModelNo')
|
data/lib/lipseys/inventory.rb
CHANGED
@@ -9,52 +9,23 @@ module Lipseys
|
|
9
9
|
@options = options
|
10
10
|
end
|
11
11
|
|
12
|
-
def self.all(
|
13
|
-
new(options).all
|
12
|
+
def self.all(options = {}, &block)
|
13
|
+
new(options).all &block
|
14
14
|
end
|
15
15
|
|
16
|
-
def self.
|
17
|
-
new(options).
|
18
|
-
end
|
19
|
-
|
20
|
-
def self.quantity(chunk_size = 100, options = {}, &block)
|
21
|
-
new(options).all(chunk_size, &block)
|
22
|
-
end
|
23
|
-
|
24
|
-
def self.accessories(options = {})
|
25
|
-
new(options).accessories
|
26
|
-
end
|
27
|
-
|
28
|
-
def self.firearms(options = {})
|
29
|
-
new(options).firearms
|
30
|
-
end
|
31
|
-
|
32
|
-
def self.nfa(options = {})
|
33
|
-
new(options).nfa
|
16
|
+
def self.quantity(options = {}, &block)
|
17
|
+
new(options).all &block
|
34
18
|
end
|
35
19
|
|
36
|
-
def self.
|
37
|
-
new(options).
|
20
|
+
def self.get_quantity_file(options = {})
|
21
|
+
new(options).get_quantity_file
|
38
22
|
end
|
39
23
|
|
40
|
-
def all(
|
41
|
-
chunker = Lipseys::Chunker.new(size)
|
24
|
+
def all(&block)
|
42
25
|
tempfile = stream_to_tempfile(API_URL, @options)
|
43
26
|
|
44
27
|
Lipseys::Parser.parse(tempfile, 'Item') do |node|
|
45
|
-
|
46
|
-
yield(chunker.chunk)
|
47
|
-
chunker.reset!
|
48
|
-
else
|
49
|
-
chunker.add(map_hash(node))
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
# HACK-david
|
54
|
-
# since we can't get a count of the items without reading the file
|
55
|
-
# Let's just check to see if we have any left in the chunk
|
56
|
-
if chunker.chunk.count > 0
|
57
|
-
yield(chunker.chunk)
|
28
|
+
yield map_hash(node)
|
58
29
|
end
|
59
30
|
|
60
31
|
tempfile.unlink
|
@@ -74,61 +45,8 @@ module Lipseys
|
|
74
45
|
tempfile.path
|
75
46
|
end
|
76
47
|
|
77
|
-
def quantity(size, &block)
|
78
|
-
chunker = Lipseys::Chunker.new(size)
|
79
|
-
tempfile = stream_to_tempfile(API_URL, @options)
|
80
|
-
|
81
|
-
Lipseys::Parser.parse(tempfile, 'Item') do |node|
|
82
|
-
if chunker.is_full?
|
83
|
-
yield(chunker.chunk)
|
84
|
-
chunker.reset!
|
85
|
-
else
|
86
|
-
chunker.add({
|
87
|
-
item_identifier: content_for(node, 'ItemNo'),
|
88
|
-
quantity: content_for(node, 'QtyOnHand')
|
89
|
-
})
|
90
|
-
end
|
91
|
-
end
|
92
|
-
|
93
|
-
if chunker.chunk.count > 0
|
94
|
-
yield(chunker.chunk)
|
95
|
-
end
|
96
|
-
|
97
|
-
tempfile.unlink
|
98
|
-
end
|
99
|
-
|
100
|
-
def accessories
|
101
|
-
get_items('ACCESSORY')
|
102
|
-
end
|
103
|
-
|
104
|
-
def firearms
|
105
|
-
get_items('FIREARM')
|
106
|
-
end
|
107
|
-
|
108
|
-
def nfa
|
109
|
-
get_items('NFA')
|
110
|
-
end
|
111
|
-
|
112
|
-
def optics
|
113
|
-
get_items('OPTIC')
|
114
|
-
end
|
115
|
-
|
116
48
|
private
|
117
49
|
|
118
|
-
def get_items(item_type = nil)
|
119
|
-
@options[:itemtype] = item_type unless item_type.nil?
|
120
|
-
|
121
|
-
xml_doc = get_response_xml(API_URL, @options)
|
122
|
-
|
123
|
-
items = Array.new
|
124
|
-
|
125
|
-
xml_doc.css('LipseysInventoryPricing/Item').each do |item|
|
126
|
-
items.push(map_hash(item))
|
127
|
-
end
|
128
|
-
|
129
|
-
items
|
130
|
-
end
|
131
|
-
|
132
50
|
def map_hash(node)
|
133
51
|
{
|
134
52
|
item_identifier: content_for(node, 'ItemNo'),
|
data/lib/lipseys/version.rb
CHANGED
data/lipseys.gemspec
CHANGED
@@ -24,6 +24,7 @@ Gem::Specification.new do |spec|
|
|
24
24
|
spec.add_dependency "nokogiri", "~> 1.6"
|
25
25
|
spec.add_dependency "savon", "~> 2.11.1"
|
26
26
|
|
27
|
+
spec.add_development_dependency "activesupport", "~> 5"
|
27
28
|
spec.add_development_dependency "bundler", "~> 1.12"
|
28
29
|
spec.add_development_dependency "rake", "~> 10.0"
|
29
30
|
spec.add_development_dependency "rspec", "~> 3.0"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lipseys
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 3.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dale Campbell
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-07-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: 2.11.1
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: activesupport
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '5'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '5'
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: bundler
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -115,7 +129,6 @@ files:
|
|
115
129
|
- lib/lipseys.rb
|
116
130
|
- lib/lipseys/base.rb
|
117
131
|
- lib/lipseys/catalog.rb
|
118
|
-
- lib/lipseys/chunker.rb
|
119
132
|
- lib/lipseys/image.rb
|
120
133
|
- lib/lipseys/inventory.rb
|
121
134
|
- lib/lipseys/invoice.rb
|
@@ -145,7 +158,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
145
158
|
version: '0'
|
146
159
|
requirements: []
|
147
160
|
rubyforge_project:
|
148
|
-
rubygems_version: 2.
|
161
|
+
rubygems_version: 2.6.12
|
149
162
|
signing_key:
|
150
163
|
specification_version: 4
|
151
164
|
summary: Ruby library for Lipsey's API.
|
data/lib/lipseys/chunker.rb
DELETED
@@ -1,34 +0,0 @@
|
|
1
|
-
module Lipseys
|
2
|
-
class Chunker
|
3
|
-
|
4
|
-
attr_accessor :chunk, :total_count, :current_count, :size
|
5
|
-
|
6
|
-
def initialize(size, total_count = nil)
|
7
|
-
@size = size
|
8
|
-
@chunk = Array.new
|
9
|
-
@current_count = 0
|
10
|
-
@total_count = total_count
|
11
|
-
end
|
12
|
-
|
13
|
-
def add(row)
|
14
|
-
self.reset! if is_full?
|
15
|
-
|
16
|
-
@chunk.push(row)
|
17
|
-
|
18
|
-
@current_count += 1
|
19
|
-
end
|
20
|
-
|
21
|
-
def reset!
|
22
|
-
@chunk.clear
|
23
|
-
end
|
24
|
-
|
25
|
-
def is_full?
|
26
|
-
@chunk.count == @size
|
27
|
-
end
|
28
|
-
|
29
|
-
def is_complete?
|
30
|
-
@total_count == @current_count
|
31
|
-
end
|
32
|
-
|
33
|
-
end
|
34
|
-
end
|