rsr_group 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 1cf787a6f722349d415f43ece1f73ab55f1b0f1a
4
+ data.tar.gz: f6f0af9ee77334697d1edb5d3ac80f7dbf6f3ba7
5
+ SHA512:
6
+ metadata.gz: 383d849c852970284e0a0221e5a815b6d21f61290b815ba2a661a95bd009a1a2faee804ffe7f331d7a357cfc425cffa449dfff50330f70f56fd9015bbe0b29ef
7
+ data.tar.gz: 6f48302df46707640ae1a77e735c5390a71b29f183bd28704417f6110a8b3a0b3e7f36fab7984faa4474fbd1ec8a0e579a8c7a0bf4382ccdbe79a3c37245971a
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.ruby-gemset ADDED
@@ -0,0 +1 @@
1
+ rsr_group
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.2.0
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.2.0
5
+ before_install: gem install bundler -v 1.13.1
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in rsr_group.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Dale Campbell
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,39 @@
1
+ # RSR Group
2
+
3
+ Ruby library for RSR's Electronic Ordering System.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'rsr_group'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install rsr_group
20
+
21
+ ## Usage
22
+
23
+ TODO: Write usage instructions here
24
+
25
+ ## Development
26
+
27
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
28
+
29
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
30
+
31
+ ## Contributing
32
+
33
+ Bug reports and pull requests are welcome on GitHub at https://github.com/ammoready/rsr_group.
34
+
35
+
36
+ ## License
37
+
38
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
39
+
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "rsr_group"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/lib/rsr_group.rb ADDED
@@ -0,0 +1,15 @@
1
+ require 'rsr_group/version'
2
+
3
+ require 'csv'
4
+ require 'date'
5
+ require 'net/ftp'
6
+
7
+ require 'rsr_group/base'
8
+ require 'rsr_group/department'
9
+ require 'rsr_group/inventory'
10
+ require 'rsr_group/user'
11
+
12
+ module RsrGroup
13
+ class NotAuthenticated < StandardError; end
14
+ class UnknownDepartment < StandardError; end
15
+ end
@@ -0,0 +1,37 @@
1
+ module RsrGroup
2
+ class Base
3
+
4
+ FTP_HOST = 'ftp.rsrgroup.com'
5
+
6
+ protected
7
+
8
+ # Wrapper to `self.requires!` that can be used as an instance method.
9
+ def requires!(*args)
10
+ self.class.requires!(*args)
11
+ end
12
+
13
+ def self.requires!(hash, *params)
14
+ params.each do |param|
15
+ if param.is_a?(Array)
16
+ raise ArgumentError.new("Missing required parameter: #{param.first}") unless hash.has_key?(param.first)
17
+
18
+ valid_options = param[1..-1]
19
+ raise ArgumentError.new("Parameter: #{param.first} must be one of: #{valid_options.join(', ')}") unless valid_options.include?(hash[param.first])
20
+ else
21
+ raise ArgumentError.new("Missing required parameter: #{param}") unless hash.has_key?(param)
22
+ end
23
+ end
24
+ end
25
+
26
+ def connect(options = {})
27
+ requires!(options, :username, :password)
28
+
29
+ Net::FTP.open(FTP_HOST, options[:username], options[:password]) do |ftp|
30
+ yield ftp
31
+ end
32
+ rescue Net::FTPPermError
33
+ raise RsrGroup::NotAuthenticated
34
+ end
35
+
36
+ end
37
+ end
@@ -0,0 +1,60 @@
1
+ module RsrGroup
2
+ class Department
3
+
4
+ NAMES = {
5
+ '01' => 'Handguns',
6
+ '02' => 'Used Handguns',
7
+ '03' => 'Used Long Guns',
8
+ '04' => 'Tasers',
9
+ '05' => 'Sporting Long Guns',
10
+ '06' => 'SOTS',
11
+ '07' => 'Black Powder Firearms',
12
+ '08' => 'Scopes',
13
+ '09' => 'Scope Mounts',
14
+ '10' => 'Magazines',
15
+ '11' => 'Grips/Pads/Stocks',
16
+ '12' => 'Soft Gun Cases',
17
+ '13' => 'Misc. Accessories',
18
+ '14' => 'Holsters/Pouches',
19
+ '15' => 'Reloading Equipment',
20
+ '16' => 'Black Powder Accessories',
21
+ '17' => 'Closeout Accessories',
22
+ '18' => 'Ammunition',
23
+ '19' => 'Survival Supplies',
24
+ '20' => 'Flashlights & Batteries',
25
+ '21' => 'Cleaning Equipment',
26
+ '22' => 'Airguns',
27
+ '23' => 'Knives',
28
+ '24' => 'High Capacity Magazines',
29
+ '25' => 'Safes/Security',
30
+ '26' => 'Safety/Protection',
31
+ '27' => 'Non-Lethal Defense',
32
+ '28' => 'Binoculars',
33
+ '29' => 'Spotting Scopes',
34
+ '30' => 'Sights/Lasers/Lights',
35
+ '31' => 'Optical Accessories',
36
+ '32' => 'Barrels/Choke Tubes',
37
+ '33' => 'Clothing',
38
+ '34' => 'Parts',
39
+ '35' => 'Slings/Swivels',
40
+ '36' => 'Electronics',
41
+ '37' => 'Not Used',
42
+ '38' => 'Books/Software',
43
+ '39' => 'Targets',
44
+ '40' => 'Hard gun Cases',
45
+ '41' => 'Upper Receivers/Conv Kits',
46
+ '42' => 'SBR Uppers',
47
+ '43' => 'Upper/Conv Kits-High Cap',
48
+ }
49
+
50
+ def initialize(id)
51
+ @id = id
52
+ raise RsrGroup::UnknownDepartment.new("Invalid ID: valid ID range: #{NAMES.keys.first}-#{NAMES.keys.last}") unless NAMES.keys.include?(@id)
53
+ end
54
+
55
+ def name
56
+ NAMES[@id]
57
+ end
58
+
59
+ end
60
+ end
@@ -0,0 +1,113 @@
1
+ module RsrGroup
2
+ class Inventory < Base
3
+
4
+ INVENTORY_DIR = 'ftpdownloads'
5
+ INVENTORY_FILENAME = 'rsrinventory-new.txt'
6
+
7
+ def initialize(options = {})
8
+ requires!(options, :username, :password)
9
+ @options = options
10
+ end
11
+
12
+ def self.all(options = {})
13
+ requires!(options, :username, :password)
14
+ new(options).all
15
+ end
16
+
17
+ def all
18
+ items = []
19
+
20
+ connect(@options) do |ftp|
21
+ ftp.chdir(INVENTORY_DIR)
22
+
23
+ lines = ftp.gettextfile(INVENTORY_FILENAME, nil)
24
+
25
+ # Use a zero-byte char as `quote_char` since the data has no quote character.
26
+ CSV.parse(lines, col_sep: ';', quote_char: "\x00") do |row|
27
+ items << {
28
+ stock_number: row[0],
29
+ upc: row[1],
30
+ description: row[2],
31
+ department: row[3].nil? ? row[3] : RsrGroup::Department.new(row[3]),
32
+ manufacturer_id: row[4],
33
+ retail_price: row[5],
34
+ regular_price: row[6],
35
+ weight: row[7],
36
+ quantity: row[8],
37
+ model: row[9],
38
+ manufacturer_name: row[10],
39
+ manufacturer_part_number: row[11],
40
+ allocated_closeout_deleted: row[12],
41
+ description_full: row[13],
42
+ image_name: row[14],
43
+ restricted_states: {
44
+ AK: row[15] == 'Y',
45
+ AL: row[16] == 'Y',
46
+ AR: row[17] == 'Y',
47
+ AZ: row[18] == 'Y',
48
+ CA: row[19] == 'Y',
49
+ CO: row[20] == 'Y',
50
+ CT: row[21] == 'Y',
51
+ DC: row[22] == 'Y',
52
+ DE: row[23] == 'Y',
53
+ FL: row[24] == 'Y',
54
+ GA: row[25] == 'Y',
55
+ HI: row[26] == 'Y',
56
+ IA: row[27] == 'Y',
57
+ ID: row[28] == 'Y',
58
+ IL: row[29] == 'Y',
59
+ IN: row[30] == 'Y',
60
+ KS: row[31] == 'Y',
61
+ KY: row[32] == 'Y',
62
+ LA: row[33] == 'Y',
63
+ MA: row[36] == 'Y',
64
+ MD: row[37] == 'Y',
65
+ ME: row[38] == 'Y',
66
+ MI: row[39] == 'Y',
67
+ MN: row[40] == 'Y',
68
+ MO: row[41] == 'Y',
69
+ MS: row[42] == 'Y',
70
+ MT: row[43] == 'Y',
71
+ NC: row[44] == 'Y',
72
+ ND: row[45] == 'Y',
73
+ NE: row[46] == 'Y',
74
+ NH: row[47] == 'Y',
75
+ NJ: row[48] == 'Y',
76
+ NM: row[49] == 'Y',
77
+ NV: row[50] == 'Y',
78
+ NY: row[51] == 'Y',
79
+ OH: row[52] == 'Y',
80
+ OK: row[53] == 'Y',
81
+ OR: row[54] == 'Y',
82
+ PA: row[55] == 'Y',
83
+ RI: row[56] == 'Y',
84
+ SC: row[57] == 'Y',
85
+ SD: row[58] == 'Y',
86
+ TN: row[59] == 'Y',
87
+ TX: row[60] == 'Y',
88
+ UT: row[61] == 'Y',
89
+ VA: row[62] == 'Y',
90
+ VT: row[63] == 'Y',
91
+ WA: row[64] == 'Y',
92
+ WI: row[65] == 'Y',
93
+ WV: row[66] == 'Y',
94
+ WY: row[67] == 'Y',
95
+ },
96
+ ground_shipping_only: row[68] == 'Y',
97
+ adult_signature_required: row[69] == 'Y',
98
+ blocked_from_drop_ship: row[70] == 'Y',
99
+ date_entered: row[71].nil? ? row[71] : Date.strptime(row[71], '%Y%m%d'),
100
+ retail_map: row[72],
101
+ image_disclaimer: row[73] == 'Y',
102
+ shipping_length: row[74],
103
+ shipping_width: row[75],
104
+ shipping_height: row[76],
105
+ }
106
+ end
107
+ end
108
+
109
+ items
110
+ end
111
+
112
+ end
113
+ end
@@ -0,0 +1,17 @@
1
+ module RsrGroup
2
+ class User < Base
3
+
4
+ def initialize(options = {})
5
+ requires!(options, :username, :password)
6
+ @options = options
7
+ end
8
+
9
+ def authenticated?
10
+ connect(@options) { |ftp| ftp.status }
11
+ true
12
+ rescue RsrGroup::NotAuthenticated
13
+ false
14
+ end
15
+
16
+ end
17
+ end
@@ -0,0 +1,3 @@
1
+ module RsrGroup
2
+ VERSION = "0.1.0"
3
+ end
data/rsr_group.gemspec ADDED
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'rsr_group/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "rsr_group"
8
+ spec.version = RsrGroup::VERSION
9
+ spec.authors = ["Dale Campbell"]
10
+ spec.email = ["oshuma@gmail.com"]
11
+
12
+ spec.summary = %q{RSR Group Ruby library.}
13
+ spec.description = %q{}
14
+ spec.homepage = ""
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
+ f.match(%r{^(test|spec|features)/})
19
+ end
20
+ spec.bindir = "exe"
21
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
+ spec.require_paths = ["lib"]
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.13"
25
+ spec.add_development_dependency "rake", "~> 10.0"
26
+ spec.add_development_dependency "rspec", "~> 3.0"
27
+ end
metadata ADDED
@@ -0,0 +1,104 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rsr_group
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Dale Campbell
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-09-27 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.13'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.13'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ description: ''
56
+ email:
57
+ - oshuma@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - ".rspec"
64
+ - ".ruby-gemset"
65
+ - ".ruby-version"
66
+ - ".travis.yml"
67
+ - Gemfile
68
+ - LICENSE.txt
69
+ - README.md
70
+ - Rakefile
71
+ - bin/console
72
+ - bin/setup
73
+ - lib/rsr_group.rb
74
+ - lib/rsr_group/base.rb
75
+ - lib/rsr_group/department.rb
76
+ - lib/rsr_group/inventory.rb
77
+ - lib/rsr_group/user.rb
78
+ - lib/rsr_group/version.rb
79
+ - rsr_group.gemspec
80
+ homepage: ''
81
+ licenses:
82
+ - MIT
83
+ metadata: {}
84
+ post_install_message:
85
+ rdoc_options: []
86
+ require_paths:
87
+ - lib
88
+ required_ruby_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ required_rubygems_version: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ requirements: []
99
+ rubyforge_project:
100
+ rubygems_version: 2.4.5
101
+ signing_key:
102
+ specification_version: 4
103
+ summary: RSR Group Ruby library.
104
+ test_files: []