RDC 0.1.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: a07c12269137a5a3dd6bca0cb50d26713609cf1cc7144701cb14a37cfb9b7bd9
4
+ data.tar.gz: 57a9febb60d4f25cb0822b38f323666ae471bf3acaad973cd7400e2ddceca99b
5
+ SHA512:
6
+ metadata.gz: d07f8b8b20af061fa3882baf073ae00eab0b7a8fd1c760037ef50a17ae14f2ee16dfff21af7af591b6d9f9c65638b9df427b0b7234f62c70a6e96dc158fe56af
7
+ data.tar.gz: 9320d4073c1d2d3e77f9b8e3119734f5cd51033b935e61e1eaf9134e9d5bea5d8930c494b9af3c27db8629977c83110c0bd604dc3f20da802afc15737ae18cf2
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
12
+ /downloads
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,6 @@
1
+ ---
2
+ language: ruby
3
+ cache: bundler
4
+ rvm:
5
+ - 2.6.3
6
+ before_install: gem install bundler -v 2.1.4
data/Gemfile ADDED
@@ -0,0 +1,16 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in RDC.gemspec
4
+ gemspec
5
+
6
+ gem 'rake', '~> 12.0'
7
+ gem 'net-sftp', '~> 3.0.0'
8
+ gem 'rubyzip', '~> 2.3.0'
9
+ gem 'activesupport', '5.2.3'
10
+
11
+ group :development, :test do
12
+ gem 'pry'
13
+ gem 'rspec', '~> 3.0'
14
+ gem 'webmock'
15
+ gem 'http'
16
+ end
@@ -0,0 +1,92 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ RDC (0.1.0)
5
+ activesupport (= 5.2.3)
6
+ net-sftp (= 3.0.0)
7
+ rubyzip (= 2.3.0)
8
+
9
+ GEM
10
+ remote: https://rubygems.org/
11
+ specs:
12
+ activesupport (5.2.3)
13
+ concurrent-ruby (~> 1.0, >= 1.0.2)
14
+ i18n (>= 0.7, < 2)
15
+ minitest (~> 5.1)
16
+ tzinfo (~> 1.1)
17
+ addressable (2.7.0)
18
+ public_suffix (>= 2.0.2, < 5.0)
19
+ coderay (1.1.3)
20
+ concurrent-ruby (1.1.7)
21
+ crack (0.4.4)
22
+ diff-lcs (1.4.4)
23
+ domain_name (0.5.20190701)
24
+ unf (>= 0.0.5, < 1.0.0)
25
+ ffi (1.13.1)
26
+ ffi-compiler (1.0.1)
27
+ ffi (>= 1.0.0)
28
+ rake
29
+ hashdiff (1.0.1)
30
+ http (4.4.1)
31
+ addressable (~> 2.3)
32
+ http-cookie (~> 1.0)
33
+ http-form_data (~> 2.2)
34
+ http-parser (~> 1.2.0)
35
+ http-cookie (1.0.3)
36
+ domain_name (~> 0.5)
37
+ http-form_data (2.3.0)
38
+ http-parser (1.2.2)
39
+ ffi-compiler
40
+ i18n (1.8.5)
41
+ concurrent-ruby (~> 1.0)
42
+ method_source (1.0.0)
43
+ minitest (5.14.2)
44
+ net-sftp (3.0.0)
45
+ net-ssh (>= 5.0.0, < 7.0.0)
46
+ net-ssh (6.1.0)
47
+ pry (0.13.1)
48
+ coderay (~> 1.1)
49
+ method_source (~> 1.0)
50
+ public_suffix (4.0.6)
51
+ rake (12.3.3)
52
+ rspec (3.9.0)
53
+ rspec-core (~> 3.9.0)
54
+ rspec-expectations (~> 3.9.0)
55
+ rspec-mocks (~> 3.9.0)
56
+ rspec-core (3.9.3)
57
+ rspec-support (~> 3.9.3)
58
+ rspec-expectations (3.9.2)
59
+ diff-lcs (>= 1.2.0, < 2.0)
60
+ rspec-support (~> 3.9.0)
61
+ rspec-mocks (3.9.1)
62
+ diff-lcs (>= 1.2.0, < 2.0)
63
+ rspec-support (~> 3.9.0)
64
+ rspec-support (3.9.3)
65
+ rubyzip (2.3.0)
66
+ thread_safe (0.3.6)
67
+ tzinfo (1.2.8)
68
+ thread_safe (~> 0.1)
69
+ unf (0.1.4)
70
+ unf_ext
71
+ unf_ext (0.0.7.7)
72
+ webmock (3.10.0)
73
+ addressable (>= 2.3.6)
74
+ crack (>= 0.3.2)
75
+ hashdiff (>= 0.4.0, < 2.0.0)
76
+
77
+ PLATFORMS
78
+ ruby
79
+
80
+ DEPENDENCIES
81
+ RDC!
82
+ activesupport (= 5.2.3)
83
+ http
84
+ net-sftp (~> 3.0.0)
85
+ pry
86
+ rake (~> 12.0)
87
+ rspec (~> 3.0)
88
+ rubyzip (~> 2.3.0)
89
+ webmock
90
+
91
+ BUNDLED WITH
92
+ 2.1.2
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'lib/RDC/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'RDC'
7
+ spec.version = RDC::VERSION
8
+ spec.authors = %w[davidrichey aditya-kapoor]
9
+ spec.email = ['daveyrichey@gmail.com', 'adityakapoor.mait@gmail.com']
10
+
11
+ spec.summary = 'Ruby gem that wraps restaurants.com API'
12
+ spec.description = 'Ruby gem that wraps restaurants.com API'
13
+ spec.homepage = 'https://github.com/memberhubteam/RDC'
14
+ spec.required_ruby_version = Gem::Requirement.new('>= 2.3.0')
15
+
16
+ spec.metadata['allowed_push_host'] = 'https://rubygems.org/'
17
+
18
+ spec.metadata['homepage_uri'] = spec.homepage
19
+ spec.metadata['source_code_uri'] = 'https://github.com/memberhubteam/RDC'
20
+ spec.metadata['changelog_uri'] = 'https://github.com/memberhubteam/RDC/blob/master/CHANGELOG.md'
21
+
22
+ # Specify which files should be added to the gem when it is released.
23
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
24
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
25
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
26
+ end
27
+ spec.bindir = 'exe'
28
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
29
+ spec.require_paths = ['lib']
30
+
31
+ spec.add_dependency 'activesupport', '5.2.3'
32
+ spec.add_dependency 'net-sftp', '3.0.0'
33
+ spec.add_dependency 'rubyzip'
34
+ end
@@ -0,0 +1,36 @@
1
+ # RDC
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/RDC`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'RDC'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle install
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install RDC
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ 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.
30
+
31
+ 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).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/RDC.
36
+
@@ -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
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "RDC"
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(__FILE__)
@@ -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
@@ -0,0 +1,16 @@
1
+ require "RDC/version"
2
+ require "RDC/catalog"
3
+ require "RDC/restaurant_info"
4
+
5
+ module RDC
6
+ class Error < StandardError; end
7
+
8
+ class << self
9
+ attr_accessor :api_key, :environment
10
+ attr_accessor :ftp_username, :ftp_password, :ftp_url
11
+
12
+ def root
13
+ File.dirname __dir__
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'RDC/request'
4
+
5
+ module RDC
6
+ class Cart
7
+ class << self
8
+ def create(sku_id)
9
+ request = Request.new("/validate_sku?sku=#{sku_id}")
10
+ reponse = request.get
11
+ response.json
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,58 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'net/sftp'
4
+ require 'zip'
5
+ require 'active_support/core_ext/hash'
6
+ require_relative 'restaurant'
7
+
8
+ module RDC
9
+ class Catalog
10
+ class << self
11
+ def fetch(skip_downloading = false)
12
+ download_xml_catalog unless skip_downloading
13
+ extract_zip_file unless skip_downloading
14
+ parse_xml_file
15
+ process_xml_content
16
+ end
17
+
18
+ def download_xml_catalog
19
+ puts '[RDC] Start Downloading ZIP File from FTP Server.'
20
+ Net::SFTP.start(RDC.ftp_url, RDC.ftp_username, password: RDC.ftp_password) do |sftp|
21
+ sftp.download!('/rdc_MemberHub.zip', downloads_directory.join('rdc_MemberHub.zip').to_s)
22
+ end
23
+ puts '[RDC] Finished Downloading ZIP File from FTP Server.'
24
+ end
25
+
26
+ def extract_zip_file
27
+ puts '[RDC] Starting Extracting XML File from ZIP File.'
28
+ Zip::File.open(downloads_directory.join('rdc_MemberHub.zip')) do |zip_file|
29
+ zip_file.each do |f|
30
+ fpath = File.join(downloads_directory.to_s, f.name)
31
+ zip_file.extract(f, fpath) unless File.exist?(fpath)
32
+ end
33
+ end
34
+ puts '[RDC] Done Extracting XML File from ZIP File.'
35
+ end
36
+
37
+ def parse_xml_file
38
+ puts '[RDC] Parsing XML'
39
+ xml_file_path = downloads_directory.join('rdc_MemberHub.xml')
40
+ @xml = Hash.from_xml(File.open(xml_file_path))
41
+ puts '[RDC] Finished parsing XML'
42
+ end
43
+
44
+ def process_xml_content
45
+ puts '[RDC] Starting XML Processing'
46
+ @catalog = @xml["Catalogs"]["catalog"].collect { |catalog_hash| RDC::Restaurant.new(catalog_hash) }
47
+ puts '[RDC] Finished XML Processing'
48
+ @catalog
49
+ end
50
+
51
+ private
52
+
53
+ def downloads_directory
54
+ @downloads_directory ||= Pathname.new(RDC.root).join('downloads')
55
+ end
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RDC
4
+ class Item
5
+ attr_accessor :sku, :legacy_sku, :value, :price, :restriction, :restriction_detail
6
+
7
+ def initialize(hash_values)
8
+ puts "Hash Values :: #{hash_values}"
9
+ @sku = hash_values['ProductSKU']
10
+ @legacy_sku = hash_values['LegacyProductSKU']
11
+ @value = hash_values['ItemValue']
12
+ @price = hash_values['ItemPrice']
13
+ @restriction = hash_values['ItemRestriction']
14
+ @restriction_detail = hash_values['ItemRestrictionDetail']
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'http'
4
+
5
+ module RDC
6
+ class Request
7
+ def initialize(path)
8
+ @path = path
9
+ end
10
+
11
+ attr_accessor :path, :response, :json
12
+
13
+ def base_url
14
+ if RDC.environment == 'production'
15
+ 'http://connect.restaurant.com/api'
16
+ else
17
+ 'https://dev-connect.restaurant.com/api'
18
+ end
19
+ end
20
+
21
+ def get(params = {})
22
+ self.response = HTTP.headers(headers)
23
+ .get(url, { params: params })
24
+ self.json = JSON.parse(response.body.to_s, symbolize_names: true)
25
+ self
26
+ end
27
+
28
+ def url
29
+ "#{base_url}#{path}"
30
+ end
31
+
32
+ private
33
+
34
+ def headers
35
+ {
36
+ apikey: RDC.api_key
37
+ }
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'item'
4
+
5
+ module RDC
6
+ class Restaurant
7
+ attr_accessor :name, :items, :short_description, :long_description,
8
+ :online, :address, :image
9
+
10
+ def initialize(hash_values)
11
+ puts "Initializing Restaurant #{hash_values['RestaurantName']}"
12
+ @name = hash_values['RestaurantName']
13
+ @short_description = hash_values['ShortDescription']
14
+ @long_description = hash_values['LongDescription']
15
+ @online = hash_values['OnlineReservation']
16
+
17
+ @address = hash_values['LocationAddress']
18
+ @image = hash_values.dig('CatalogImagesFullPath', 'MainLogo')
19
+ @items = Array.wrap(hash_values.dig('Items', 'Item')).collect { |item_hash| RDC::Item.new(item_hash) }
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'RDC/request'
4
+
5
+ module RDC
6
+ class RestaurantInfo
7
+ class << self
8
+ def retrieve(restaurant_id)
9
+ request = Request.new("/restaurant_info/#{restaurant_id}")
10
+ reponse = request.get
11
+ response.json
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'RDC/request'
4
+
5
+ module RDC
6
+ class Sku
7
+ class << self
8
+ def validate(sku_id)
9
+ request = Request.new("/validate_sku?sku=#{sku_id}")
10
+ reponse = request.get
11
+ response.json
12
+ end
13
+
14
+ def verify_inventory_and_price(skus)
15
+ request = Request.new("/verify_inventory_and_price?sku=#{skus}")
16
+ reponse = request.get
17
+ response.json
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,3 @@
1
+ module RDC
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,109 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: RDC
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - davidrichey
8
+ - aditya-kapoor
9
+ autorequire:
10
+ bindir: exe
11
+ cert_chain: []
12
+ date: 2020-12-03 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: activesupport
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - '='
19
+ - !ruby/object:Gem::Version
20
+ version: 5.2.3
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - '='
26
+ - !ruby/object:Gem::Version
27
+ version: 5.2.3
28
+ - !ruby/object:Gem::Dependency
29
+ name: net-sftp
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - '='
33
+ - !ruby/object:Gem::Version
34
+ version: 3.0.0
35
+ type: :runtime
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - '='
40
+ - !ruby/object:Gem::Version
41
+ version: 3.0.0
42
+ - !ruby/object:Gem::Dependency
43
+ name: rubyzip
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ type: :runtime
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ description: Ruby gem that wraps restaurants.com API
57
+ email:
58
+ - daveyrichey@gmail.com
59
+ - adityakapoor.mait@gmail.com
60
+ executables: []
61
+ extensions: []
62
+ extra_rdoc_files: []
63
+ files:
64
+ - ".gitignore"
65
+ - ".rspec"
66
+ - ".travis.yml"
67
+ - Gemfile
68
+ - Gemfile.lock
69
+ - RDC.gemspec
70
+ - README.md
71
+ - Rakefile
72
+ - bin/console
73
+ - bin/setup
74
+ - lib/RDC.rb
75
+ - lib/RDC/cart.rb
76
+ - lib/RDC/catalog.rb
77
+ - lib/RDC/item.rb
78
+ - lib/RDC/request.rb
79
+ - lib/RDC/restaurant.rb
80
+ - lib/RDC/restaurant_info.rb
81
+ - lib/RDC/sku.rb
82
+ - lib/RDC/version.rb
83
+ homepage: https://github.com/memberhubteam/RDC
84
+ licenses: []
85
+ metadata:
86
+ allowed_push_host: https://rubygems.org/
87
+ homepage_uri: https://github.com/memberhubteam/RDC
88
+ source_code_uri: https://github.com/memberhubteam/RDC
89
+ changelog_uri: https://github.com/memberhubteam/RDC/blob/master/CHANGELOG.md
90
+ post_install_message:
91
+ rdoc_options: []
92
+ require_paths:
93
+ - lib
94
+ required_ruby_version: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ version: 2.3.0
99
+ required_rubygems_version: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ requirements: []
105
+ rubygems_version: 3.0.3
106
+ signing_key:
107
+ specification_version: 4
108
+ summary: Ruby gem that wraps restaurants.com API
109
+ test_files: []